schangxiang@126.com
2025-04-01 de7dbe7cf85aa01abb64040aae1c04dfba74c135
CC/iWareCC_ASRS/ThreadService/02_BZ39¹¤Î»£¨²¹°åºó¹¤Î»£©/Outbound/3¡¢DataProcess_RobotBuffer_FinishTaskForOutbound.cs
@@ -8,6 +8,7 @@
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace iWareCC.ThreadService
{
@@ -29,6 +30,11 @@
                    if (SystemValue.isStartedModel)
                    {
                        var rgvLocation = StationLocationEnum.BZ39.ToString();
                        if (FormCC.stationView == null)
                        {
                            SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound = $"{rgvLocation.ToString()}-获取PLC对象为null";
                            continue;
                        }
                        var obj = FormCC.stationView.R_StationForReadCommList.Where(x => x.StationCode == rgvLocation.ToString()).FirstOrDefault();
                        if (obj.R_OutboundFinish)
                        {
@@ -52,7 +58,10 @@
                            {
                                var task = wmsDB.wms_rbline_task.Where(x =>
                                 x.TaskNo == obj.R_Outbound_TaskID.ToString()
                                && x.RbTaskType == (int)RbTaskTypeEnum.出库任务
                                //增加这两个限制条件 ã€Editby shaocx,2025-03-27】
                                && x.TaskStatus == (int)TaskStatusEnum.已下发
                                && (x.IsFlagFinish == false)
                                && (x.RbTaskType == (int)RbTaskTypeEnum.齐包出库任务 || x.RbTaskType == (int)RbTaskTypeEnum.强制出库任务)
                                ).OrderByDescending(x => x.Id).FirstOrDefault();
                                if (task == null)
                                {
@@ -63,54 +72,96 @@
                                {
                                    if (task.TaskStatus == (int)TaskStatusEnum.已完成)
                                    {
                                        //using (StationServiceClient client = new StationServiceClient())
                                        //{
                                        //    var res = await client.OutboundFinishConfirmAsync((int)EDevice.Station, true, rgvLocation);
                                        //}
                                        using (StationServiceClient client = new StationServiceClient())
                                        {
                                            var res = await client.OutboundFinishConfirmAsync((int)EDevice.Station, true, rgvLocation, false);
                                        }
                                        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_FinishTaskForOutbound = $"{rgvLocation.ToString()},根据UPI:{upiCode}没有找到对象 ";
                                    continue;
                                }
                                //库存减少
                                wms_stock_quan qun = wmsDB.wms_stock_quan.Where(x => x.PlaceCode == task.PlaceCode).FirstOrDefault();
                                wmsDB.wms_stock_quan.Remove(qun);
                                task.TaskStatus = (int)TaskStatusEnum.已完成;
                                task.TaskStatusName = TaskStatusEnum.已完成.ToString();
                                task.FinishedTime = DateTime.Now;
                                //var upiCode = task.Upi;
                                //var upiObj = wmsDB.mes_batchOrderUPI_new.Where(x => x.UPI == upiCode).FirstOrDefault();
                                //if (upiObj == null)
                                //{
                                //    SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound = $"{rgvLocation.ToString()},根据UPI:{upiCode}没有找到对象 ";
                                //    continue;
                                //}
                                ////更新板件的状态和区域
                                //if (task.RbTaskType == (int)RbTaskTypeEnum.齐包出库任务)
                                //{
                                //    upiObj.UpiStatus = (int)UpiStatusEnum.已齐包;
                                //    upiObj.AreaCode = (int)AreaCodeEnum.码垛区域;
                                //}
                                //else if (task.RbTaskType == (int)RbTaskTypeEnum.强制出库任务)
                                //{
                                //    upiObj.UpiStatus = (int)UpiStatusEnum.已下线;
                                //    upiObj.AreaCode = (int)AreaCodeEnum.下线区域;
                                //}
                                var place = StationHandler.GetPlaceByPlaceCode(task.PlaceCode, wmsDB);
                                place.PlaceStatus = (int)PlaceStatusEnum.正常;
                                ////库存减少
                                //wms_stock_quan qun = wmsDB.wms_stock_quan.Where(x => x.PlaceCode == task.PlaceCode).FirstOrDefault();
                                //wmsDB.wms_stock_quan.Remove(qun);
                                //给PLC推送任务完成确认信号
                                using (StationServiceClient client = new StationServiceClient())
                                {
                                    var res = await client.OutboundFinishConfirmAsync((int)EDevice.Station, true, rgvLocation);
                                    if (!res.result)
                                    {
                                        SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound = $"{rgvLocation.ToString()}-下发出库任务 å¤±è´¥,OutboundFinishConfirmAsync è¿”回:{res.resMsg}";
                                        continue;
                                    }
                                    else
                                    {
                                        Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-下发出库任务 æˆåŠŸ,OutboundFinishConfirmAsync,参数: ç«™ç‚¹{rgvLocation}");
                                    }
                                }
                                //task.TaskStatus = (int)TaskStatusEnum.已完成;
                                //task.FinishedTime = DateTime.Now;
                                wmsDB.SaveChanges();
                                //var place = StationHandler.GetPlaceByPlaceCode(task.PlaceCode, wmsDB);
                                //place.PlaceStatus = (int)PlaceStatusEnum.正常;
                                ////给PLC推送任务完成确认信号
                                //using (StationServiceClient client = new StationServiceClient())
                                //{
                                //    var res = await client.OutboundFinishConfirmAsync((int)EDevice.Station, true, rgvLocation, true);
                                //    if (!res.result)
                                //    {
                                //        SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound = $"{rgvLocation.ToString()}-下发出库任务 å¤±è´¥,OutboundFinishConfirmAsync è¿”回:{res.resMsg}";
                                //        continue;
                                //    }
                                //    else
                                //    {
                                //        Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-下发出库任务 æˆåŠŸ,OutboundFinishConfirmAsync,参数: ç«™ç‚¹{rgvLocation}");
                                //    }
                                //}
                                //WmsRecordUpiProcessHandler.SaveWmsRecordUpiProcess(wmsDB, upiObj, task.PlaceCode, $"出缓存库:{task.PlaceCode}," + task.TaskMsg);
                                //wmsDB.SaveChanges();
                            }
                        }
                        else
                        {
                            using (StationServiceClient client = new StationServiceClient())
                            {
                                var res = await client.OutboundFinishConfirmAsync((int)EDevice.Station, false, rgvLocation, false);
                            }
                            using (WmsDBModel wmsDB = new WmsDBModel())
                            {
                                var task = wmsDB.wms_rbline_task.Where(x =>
                                 x.IsFlagFinish == true
                               && (x.RbTaskType == (int)RbTaskTypeEnum.齐包出库任务 || x.RbTaskType == (int)RbTaskTypeEnum.强制出库任务)
                                && x.TaskStatus == (int)TaskStatusEnum.已下发
                                ).OrderByDescending(x => x.Id).FirstOrDefault();
                                if (task == null)
                                {
                                    SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound = $"{rgvLocation.ToString()},没有找到已下发,并且标记强制完成的任务 ";
                                    continue;
                                }
                                var isSuccess = await HandlerData(wmsDB, task, rgvLocation, logType, true);
                                if (isSuccess == false)
                                {
                                    continue;
                                }
                            }
                        }
                    }
                }
@@ -122,5 +173,63 @@
            }
        }
        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_FinishTaskForOutbound = $"{rgvLocation.ToString()},根据UPI:{upiCode}没有找到对象 ";
                return false;
            }
            //更新板件的状态和区域
            if (task.RbTaskType == (int)RbTaskTypeEnum.齐包出库任务)
            {
                upiObj.UpiStatus = (int)UpiStatusEnum.已齐包;
                upiObj.AreaCode = (int)AreaCodeEnum.码垛区域;
            }
            else if (task.RbTaskType == (int)RbTaskTypeEnum.强制出库任务)
            {
                upiObj.UpiStatus = (int)UpiStatusEnum.已下线;
                upiObj.AreaCode = (int)AreaCodeEnum.下线区域;
            }
            //库存减少
            wms_stock_quan qun = wmsDB.wms_stock_quan.Where(x => x.PlaceCode == task.PlaceCode).FirstOrDefault();
            wmsDB.wms_stock_quan.Remove(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.OutboundFinishConfirmAsync((int)EDevice.Station, true, rgvLocation, true);
                    if (!res.result)
                    {
                        SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTaskForOutbound = $"{rgvLocation.ToString()}-下发出库任务 å¤±è´¥,OutboundFinishConfirmAsync è¿”回:{res.resMsg}";
                        return false;
                    }
                    else
                    {
                        Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-下发出库任务 æˆåŠŸ,OutboundFinishConfirmAsync,参数: ç«™ç‚¹{rgvLocation}");
                    }
                }
            }
            var flag = isFlagFinish ? "人工强制完成" : "(自动完成)";
            WmsRecordUpiProcessHandler.SaveWmsRecordUpiProcess(wmsDB, upiObj, task.PlaceCode, $"出缓存库:{task.PlaceCode}(" + flag + ")," + task.TaskMsg);
            wmsDB.SaveChanges();
            return true;
        }
    }
}