schangxiang@126.com
2025-04-01 de7dbe7cf85aa01abb64040aae1c04dfba74c135
CC/iWareCC_ASRS/ThreadService/02_BZ39¹¤Î»£¨²¹°åºó¹¤Î»£©/Inbound/3¡¢DataProcess_RobotBuffer_FinishTask.cs
@@ -1,5 +1,6 @@
using Admin.NET.Application;
using iWareCC.Common.Helper;
using iWareCC.SrmService;
using iWareCC.StationService;
using iWareCommon.Common.Globle;
using iWareCommon.Utils;
@@ -9,6 +10,7 @@
using iWareSql.WmsDBModel;
using System;
using System.Collections.Generic;
using System.Data.Entity.Core.Metadata.Edm;
using System.Linq;
using System.ServiceModel.Configuration;
using System.Text;
@@ -16,6 +18,7 @@
using System.Threading.Tasks;
using WZ.Useful.Commons;
using XiGang.Core.Model;
using LogType = iWareCommon.Utils.LogType;
namespace iWareCC.ThreadService
{
@@ -34,7 +37,7 @@
                SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTask = string.Empty;
                try
                {
                    if ( SystemValue.isStartedModel)//SystemValue.isAllowRuning_DataProcess_RobotBuffer_FinishTask &&
                    if (SystemValue.isStartedModel)//SystemValue.isAllowRuning_DataProcess_RobotBuffer_FinishTask &&
                    {
                        var rgvLocation = StationLocationEnum.BZ39.ToString();
                        if (FormCC.stationView == null)
@@ -44,15 +47,7 @@
                        }
                        var obj = FormCC.stationView.R_StationForReadCommList.Where(x => x.StationCode == rgvLocation.ToString()).FirstOrDefault();
                        if (obj.R_InboundFinish)
                        //if (true)//模拟
                        {
                            //var result = obj.R_InboundNumber;
                            //if (string.IsNullOrEmpty(result))
                            //{
                            //    SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTask = $"{rgvLocation.ToString()}- å…¥åº“库位号是空的,此次循环结束";
                            //    continue;
                            //}
                            //obj.R_Inbound_TaskID = 17797;//模拟
                            var result2 = obj.R_Inbound_TaskID;
                            if (result2 == 0)
                            {
@@ -60,87 +55,91 @@
                                continue;
                            }
                            var qitaoReault = false;
                            using (WmsDBModel wmsDB = new WmsDBModel())
                            {
                                var task = wmsDB.wms_rbline_task.Where(x =>
                                 x.TaskNo == obj.R_Inbound_TaskID.ToString()
                                && x.RbTaskType == (int)RbTaskTypeEnum.入库任务
                                ).OrderByDescending(x=>x.Id).FirstOrDefault();
                                ).OrderByDescending(x => x.Id).FirstOrDefault();
                                if (task == null)
                                {
                                    SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTask = $"{rgvLocation.ToString()},根据 R_InboundNumber:{obj.R_InboundNumber}没有找到已下发的任务 ";
                                    continue;
                                }
                                else
                                else
                                {
                                    if (task.TaskStatus == (int)TaskStatusEnum.已完成)
                                    {
                                        using (StationServiceClient client = new StationServiceClient())
                                        {
                                            var res = await client.InboundFinishConfirmAsync((int)EDevice.Station, true, rgvLocation);
                                        }
                                        continue;
                                    }
                                }
                                var upiCode = task.Upi;
                                var upiObj = wmsDB.mes_batchOrderUPI_new.Where(x => x.UPI == upiCode).FirstOrDefault();
                                if (upiObj == null)
                                var isSuccess = await HandlerData(wmsDB, task, rgvLocation, logType, false);
                                if (isSuccess == false)
                                {
                                    SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTask = $"{rgvLocation.ToString()},根据UPI:{upiCode}没有找到对象 ";
                                    continue;
                                }
                                //增加库存
                                wms_stock_quan qun = new wms_stock_quan()
                                {
                                    Id = Yitter.IdGenerator.YitIdHelper.NextId(),
                                    Upi = upiCode,
                                    PlanNo = task.PlanNo,
                                    DetailName = upiObj.DetailName,
                                    OrderId = task.OrderId,
                                    CreateTime = DateTime.Now,
                                    CreateUserName = "CC",
                                    InTime = DateTime.Now,
                                    OperReason = "入库",
                                    PackageCode = task.PackageCode,
                                    Length = task.Length,
                                    Width = task.Width,
                                    Thk = task.Thk,
                                    PlaceCode = task.PlaceCode,
                                    StockStatus = (int)StockStatusEnum.在库,
                                    StockStatusName = StockStatusEnum.在库.ToString(),
                                };
                                wmsDB.wms_stock_quan.Add(qun);
                                //var upiCode = task.Upi;
                                //var upiObj = wmsDB.mes_batchOrderUPI_new.Where(x => x.UPI == upiCode).FirstOrDefault();
                                //if (upiObj == null)
                                //{
                                //    SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTask = $"{rgvLocation.ToString()},根据UPI:{upiCode}没有找到对象 ";
                                //    continue;
                                //}
                                ////增加库存
                                //wms_stock_quan qun = new wms_stock_quan()
                                //{
                                //    Id = Yitter.IdGenerator.YitIdHelper.NextId(),
                                //    Upi = upiCode,
                                //    PlanNo = task.PlanNo,
                                //    DetailName = upiObj.DetailName,
                                //    OrderId = task.OrderId,
                                //    CreateTime = DateTime.Now,
                                //    CreateUserName = SysGloble.WCSSystem,
                                //    InTime = DateTime.Now,
                                //    OperReason = "入库",
                                //    PackageCode = task.PackageCode,
                                //    Length = task.Length,
                                //    Width = task.Width,
                                //    Thk = task.Thk,
                                //    PlaceCode = task.PlaceCode,
                                //    StockStatus = (int)StockStatusEnum.在库,
                                //    StockStatusName = StockStatusEnum.在库.ToString(),
                                task.TaskStatus = (int)TaskStatusEnum.已完成;
                                task.FinishedTime = DateTime.Now;
                                //};
                                //wmsDB.wms_stock_quan.Add(qun);
                                //task.TaskStatus = (int)TaskStatusEnum.已完成;
                                //task.FinishedTime = DateTime.Now;
                                var place = StationHandler.GetPlaceByPlaceCode(task.PlaceCode, wmsDB);
                                place.PlaceStatus = (int)PlaceStatusEnum.正常;
                                //var place = StationHandler.GetPlaceByPlaceCode(task.PlaceCode, wmsDB);
                                //place.PlaceStatus = (int)PlaceStatusEnum.正常;
                                //给PLC推送任务完成确认信号
                                using (StationServiceClient client = new StationServiceClient())
                                {
                                    var res = await client.InboundFinishConfirmAsync((int)EDevice.Station, true, rgvLocation);
                                    if (!res.result)
                                    {
                                        SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTask = $"{rgvLocation.ToString()}-下发入库任务 å¤±è´¥,InboundFinishConfirmAsync è¿”回:{res.resMsg}";
                                        continue;
                                    }
                                    else
                                    {
                                        Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-下发入库任务 æˆåŠŸ,InboundFinishConfirmAsync,参数: ç«™ç‚¹{rgvLocation}");
                                    }
                                }
                                ////给PLC推送任务完成确认信号
                                //using (StationServiceClient client = new StationServiceClient())
                                //{
                                //    var res = await client.InboundFinishConfirmAsync((int)EDevice.Station, true, rgvLocation);
                                //    if (!res.result)
                                //    {
                                //        SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTask = $"{rgvLocation.ToString()}-下发入库任务 å¤±è´¥,InboundFinishConfirmAsync è¿”回:{res.resMsg}";
                                //        continue;
                                //    }
                                //    else
                                //    {
                                //        Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-下发入库任务 æˆåŠŸ,InboundFinishConfirmAsync,参数: ç«™ç‚¹{rgvLocation}");
                                //    }
                                //}
                                WmsRecordUpiProcessHandler.SaveWmsRecordUpiProcess(wmsDB, upiObj, task.PlaceCode, "缓存入库完成:"+ task.PlaceCode);
                                //WmsRecordUpiProcessHandler.SaveWmsRecordUpiProcess(wmsDB, upiObj, task.PlaceCode, "缓存入库完成:" + task.PlaceCode);
                                wmsDB.SaveChanges();
                                //wmsDB.SaveChanges();
                            }
                        }
                        else
@@ -154,6 +153,26 @@
                            }
                            using (WmsDBModel wmsDB = new WmsDBModel())
                            {
                                var task = wmsDB.wms_rbline_task.Where(x =>
                                 x.IsFlagFinish == true
                                && x.RbTaskType == (int)RbTaskTypeEnum.入库任务
                                && x.TaskStatus == (int)TaskStatusEnum.已下发
                                ).OrderByDescending(x => x.Id).FirstOrDefault();
                                if (task == null)
                                {
                                    SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTask = $"{rgvLocation.ToString()},没有找到已下发,并且标记强制完成的任务 ";
                                    continue;
                                }
                                var isSuccess = await HandlerData(wmsDB, task, rgvLocation, logType, true);
                                if (isSuccess == false)
                                {
                                    continue;
                                }
                            }
                        }
                    }
                }
@@ -165,5 +184,102 @@
            }
        }
        public static async Task<bool> HandlerData(WmsDBModel wmsDB, wms_rbline_task task, string rgvLocation, iWareCommon.Utils.LogType logType, bool isFlagFinish)
        {
            var upiCode = task.Upi;
            var upiObj = wmsDB.mes_batchOrderUPI_new.Where(x => x.UPI == upiCode).FirstOrDefault();
            if (upiObj == null)
            {
                SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTask = $"{rgvLocation.ToString()},根据UPI:{upiCode}没有找到对象 ";
                return false;
            }
            //增加库存
            wms_stock_quan qun = new wms_stock_quan()
            {
                Id = Yitter.IdGenerator.YitIdHelper.NextId(),
                Shelf = upiObj.Shelf,
                Upi = upiCode,
                PlanNo = task.PlanNo,
                DetailName = upiObj.DetailName,
                OrderId = task.OrderId,
                CreateTime = DateTime.Now,
                CreateUserName = SysGloble.WCSSystem,
                InTime = DateTime.Now,
                OperReason = "入库",
                PackageCode = task.PackageCode,
                Length = task.Length,
                Width = task.Width,
                Thk = task.Thk,
                PlaceCode = task.PlaceCode,
                StockStatus = (int)StockStatusEnum.在库,
                StockStatusName = StockStatusEnum.在库.ToString(),
            };
            wmsDB.wms_stock_quan.Add(qun);
            task.TaskStatus = (int)TaskStatusEnum.已完成;
            task.FinishedTime = DateTime.Now;
            var place = StationHandler.GetPlaceByPlaceCode(task.PlaceCode, wmsDB);
            place.PlaceStatus = (int)PlaceStatusEnum.正常;
            //if (isFlagFinish == false)
            //{
            //    //给PLC推送任务完成确认信号
            //    using (StationServiceClient client = new StationServiceClient())
            //    {
            //        var res = await client.InboundFinishConfirmAsync((int)EDevice.Station, true, rgvLocation);
            //        if (!res.result)
            //        {
            //            SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTask = $"{rgvLocation.ToString()}-下发入库任务 å¤±è´¥,InboundFinishConfirmAsync è¿”回:{res.resMsg}";
            //            return false;
            //        }
            //        else
            //        {
            //            Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-下发入库任务 æˆåŠŸ,InboundFinishConfirmAsync,参数: ç«™ç‚¹{rgvLocation}");
            //        }
            //    }
            //}
            var flag = isFlagFinish ? "人工强制完成" : "(自动完成)";
            WmsRecordUpiProcessHandler.SaveWmsRecordUpiProcess(wmsDB, upiObj, task.PlaceCode, "缓存入库完成(" + flag + "):" + task.PlaceCode);
            int changeNum = wmsDB.SaveChanges();
            if (changeNum > 0)
            {
                //必须要给PLC下发成功,解决可能会给PLC重复下发任务的情况
                var isRight = true;
                if (isFlagFinish == false)
                {
                    while (isRight)
                    {
                        var obj = FormCC.stationView.R_StationForReadCommList.Where(x => x.StationCode == rgvLocation.ToString()).FirstOrDefault();
                        isRight = obj.R_InboundFinish;
                        //给PLC推送任务完成确认信号
                        using (StationServiceClient client = new StationServiceClient())
                        {
                            var res = await client.InboundFinishConfirmAsync((int)EDevice.Station, true, rgvLocation);
                            if (!res.result)
                            {
                                SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTask = $"{rgvLocation.ToString()}-下发入库任务 å¤±è´¥,InboundFinishConfirmAsync è¿”回:{res.resMsg}";
                                Log4NetHelper.WriteErrorLog(logType, $"{rgvLocation.ToString()}-完成入库任务写入【true】 å¤±è´¥,InboundFinishConfirmAsync,返回:{res.resMsg},参数:TaskNo:{task.TaskNo}, PlaceCode:{task.PlaceCode},条码:{task.Upi}");
                            }
                            else
                            {
                                Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-完成入库任务写入【true】 æˆåŠŸ,InboundFinishConfirmAsync,参数:TaskNo:{task.TaskNo}, PlaceCode:{task.PlaceCode},条码:{task.Upi}");
                                //isRight = false;
                            }
                        }
                        Thread.Sleep(1000);
                    }
                }
            }
            return true;
        }
    }
}