From 482ece71c06bcc49c38b0dc5d747b37a60d227fd Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期三, 11 二月 2026 17:25:04 +0800
Subject: [PATCH] 托盘半成品呼叫流程

---
 项目代码/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Outbound.cs |  415 +++++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 330 insertions(+), 85 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Outbound.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Outbound.cs"
index d06a1c4..f665f95 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Outbound.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_TaskInfoService/TaskService_Outbound.cs"
@@ -25,6 +25,7 @@
 using WIDESEA_DTO.MES;
 using WIDESEA_DTO.Outbound;
 using Microsoft.IdentityModel.Tokens;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
 
 namespace WIDESEA_TaskInfoService
 {
@@ -135,12 +136,32 @@
                     if (proStockInfo != null && proStockInfo.StockStatus==StockStatusEmun.鍑哄簱閿佸畾.ObjToInt())
                     {
                         task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
+                        //鑾峰彇鎵�鏈夊嚭搴撹鎯呮暟鎹�
+                        List<Dt_OutStockLockInfo>? outStockLockInfos = _outboundRepository.OutStockLockInfoRepository.QueryData(x => x.TaskNum == task.TaskNum);
                         _unitOfWorkManage.BeginTran();
                         proStockInfo.StockStatus = StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt();
                         _stockRepository.ProStockInfoRepository.DeleteAndMoveIntoHty(proStockInfo,App.User.UserId > 0 ? OperateTypeEnum.浜哄伐瀹屾垚 : OperateTypeEnum.鑷姩瀹屾垚);
                         if (proStockInfo.proStockInfoDetails!=null && proStockInfo.proStockInfoDetails.Count>0)
                         {
                             _stockRepository.ProStockInfoDetailRepository.DeleteAndMoveIntoHty(proStockInfo.proStockInfoDetails, App.User.UserId > 0 ? OperateTypeEnum.浜哄伐瀹屾垚 : OperateTypeEnum.鑷姩瀹屾垚);
+                        }
+                        if (outStockLockInfos != null && outStockLockInfos.Count > 0)
+                        {
+                            outStockLockInfos.ForEach(x =>
+                            {
+                                x.Status = OutLockStockStatusEnum.鍑哄簱瀹屾垚.ObjToInt();
+                            });
+                            List<Dt_OutStockLockInfo> outStockLockInfosMES = outStockLockInfos.Where(x => x.OrderType == OutOrderTypeEnum.OutMESPick.ObjToInt()).ToList();
+                            if (outStockLockInfosMES != null && outStockLockInfosMES.Count() > 0)
+                            {
+                                Dt_AGVStationInfo aGVStationInfo = _basicRepository.AGVStationInfoRepository.QueryFirst(x => x.AGVStationCode == task.TargetAddress);
+                                MESDeliveryModel mESDeliveryModel = MESDeliveryUp(outStockLockInfosMES, aGVStationInfo.MESPointCode);
+                                MESResponse response = _invokeMESService.MESDelivery(mESDeliveryModel).DeserializeObject<MESResponse>() ?? throw new Exception("鏈幏鍙栧埌杩斿洖淇℃伅");
+                                if (!response.Result)
+                                {
+                                    throw new Exception($"MES閰嶉�佸嚭鍙戞帴鍙h皟鐢ㄦ姤閿�,MES杩斿洖淇℃伅{DecodeUnicode(response.Msg)}");
+                                }
+                            }
                         }
                         _basicService.LocationInfoService.UpdateLocationStatus(locationInfoStart, proStockInfo.PalletType, LocationStatusEnum.Free, proStockInfo.WarehouseId);
                         BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? OperateTypeEnum.浜哄伐瀹屾垚 : OperateTypeEnum.鑷姩瀹屾垚);
@@ -163,6 +184,7 @@
                         return content.Error($"璐т綅鐘舵�佷笉姝g‘");
                     }
                     Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == task.PalletCode);
+                    int wareId=stockInfo.WarehouseId;
                     if (stockInfo != null && stockInfo.StockStatus == StockStatusEmun.鍑哄簱閿佸畾.ObjToInt())
                     {
                         task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
@@ -189,9 +211,24 @@
                                 x.Status=OutLockStockStatusEnum.鍑哄簱瀹屾垚.ObjToInt();
                             });
                             _outboundRepository.OutStockLockInfoRepository.UpdateData(outStockLockInfos);
-                            _outboundService.OutLineViewService.SaveLineView(outStockLockInfos);
+                            List<Dt_OutStockLockInfo> outStockLockInfosSG = outStockLockInfos.Where(x => x.OrderType == OutOrderTypeEnum.OutSGPick.ObjToInt()).ToList();
+                            List<Dt_OutStockLockInfo> outStockLockInfosMES = outStockLockInfos.Where(x => x.OrderType == OutOrderTypeEnum.OutMESPick.ObjToInt()).ToList();
+                            if (outStockLockInfosSG !=null && outStockLockInfosSG.Count()>0)
+                            {
+                                _outboundService.OutLineViewService.SaveLineView(outStockLockInfosSG);
+                            }
+                            if (outStockLockInfosMES != null && outStockLockInfosMES.Count() > 0)
+                            {
+                                Dt_AGVStationInfo aGVStationInfo = _basicRepository.AGVStationInfoRepository.QueryFirst(x=>x.AGVStationCode==task.TargetAddress);
+                                MESDeliveryModel mESDeliveryModel = MESDeliveryUp(outStockLockInfosMES, aGVStationInfo.MESPointCode);
+                                MESResponse response = _invokeMESService.MESDelivery(mESDeliveryModel).DeserializeObject<MESResponse>() ?? throw new Exception("鏈幏鍙栧埌杩斿洖淇℃伅");
+                                if (!response.Result)
+                                {
+                                    throw new Exception($"MES閰嶉�佸嚭鍙戞帴鍙h皟鐢ㄦ姤閿�,MES杩斿洖淇℃伅{DecodeUnicode(response.Msg)}");
+                                }
+                            }
                         }
-                        _basicService.LocationInfoService.UpdateLocationStatus(locationInfoStart, stockInfo.PalletType, LocationStatusEnum.Free, stockInfo.WarehouseId);
+                        _basicService.LocationInfoService.UpdateLocationStatus(locationInfoStart, stockInfo.PalletType, LocationStatusEnum.Free, wareId);
                         BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? OperateTypeEnum.浜哄伐瀹屾垚 : OperateTypeEnum.鑷姩瀹屾垚);
                         _unitOfWorkManage.CommitTran();
                     }
@@ -207,6 +244,34 @@
                 _unitOfWorkManage.RollbackTran();
                 return content.Error(ex.Message);
             }
+        }
+        /// <summary>
+        /// 閰嶉�侀�佽揪淇℃伅
+        /// </summary>
+        /// <returns></returns>
+        public MESDeliveryModel MESDeliveryUp(List<Dt_OutStockLockInfo> outStockLockInfos,string address)
+        {
+            MESDeliveryModel mESDeliveryModel = new MESDeliveryModel()
+            {
+                PRO_DispatchPlanMaterialsInfoNew= new List<MESDeliveryInfo>()
+            };
+            foreach (var item in outStockLockInfos)
+            {
+                MESDeliveryInfo mESDeliveryInfo = new MESDeliveryInfo()
+                {
+                    InvItemCode=item.MaterielCode,
+                    DispatchPlanMaterialId=item.OrderDetailId,
+                    UnitCode=item.Unit,
+                    GradeCode="001",
+                    MainQuantity=item.OriginalQuantity,
+                    AssistUnitCode=item.AssistUnit,
+                    LocationCode= address,
+                    LotNumber=item.BatchNo,
+                    MaterialBarCode=item.PalletCode
+                };
+                mESDeliveryModel.PRO_DispatchPlanMaterialsInfoNew.Add(mESDeliveryInfo);
+            }
+            return mESDeliveryModel;
         }
         /// <summary>
         /// 搴撳瓨鏁版嵁杞嚭搴撲换鍔�(鍘熸枡/鍗婃垚鍝�)
@@ -254,7 +319,59 @@
             return tasks;
         }
         /// <summary>
-        /// 搴撳瓨鏁版嵁杞嚭搴撲换鍔�(MES宸ュ崟)
+        /// 搴撳瓨鏁版嵁杞嚭搴撲换鍔�(MES宸ュ崟鎴愬搧)
+        /// </summary>
+        /// <param name="stockInfos"></param>
+        /// <returns></returns>
+        public List<Dt_Task> GetTasks(List<Dt_ProStockInfo> stockInfos, List<Dt_OutStockLockInfo> outStockLockInfos, TaskTypeEnum taskType = new TaskTypeEnum())
+        {
+            List<Dt_Task> tasks = new List<Dt_Task>();
+            for (int i = 0; i < stockInfos.Count; i++)
+            {
+                Dt_ProStockInfo stockInfo = stockInfos[i];
+
+                if (stockInfo != null)
+                {
+                    Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == stockInfo.LocationCode);
+                    if (!tasks.Exists(x => x.PalletCode == stockInfo.PalletCode))
+                    {
+                        Dt_OutStockLockInfo outStockLockInfo = outStockLockInfos.FirstOrDefault(x => x.PalletCode == stockInfo.PalletCode);
+                        taskType = outStockLockInfo.MachineName.ObjToInt() switch
+                        {
+                            (int)StationAreaEnum.浜屾ゼ绾歌 or
+                            (int)StationAreaEnum.浜屾ゼ鏃犵汉甯冭 or
+                            (int)StationAreaEnum.浜屾ゼ绾告澂 => TaskTypeEnum.OutCarton,
+                            (int)StationAreaEnum.涓�妤兼棤绾虹粐甯� => TaskTypeEnum.OutWFB,
+                            _ => throw new Exception($"鏈壘鍒板姞宸ヤ腑蹇冧换鍔$被鍨嬪垎閰�")
+                        };
+                        Dt_Task task = new()
+                        {
+                            CurrentAddress = stockInfo.LocationCode,
+                            Grade = 0,
+                            PalletCode = stockInfo.PalletCode,
+                            NextAddress = "",
+                            Roadway = locationInfo.RoadwayNo,
+                            SourceAddress = stockInfo.LocationCode,
+                            TargetAddress = "",
+                            TaskStatus = TaskStatusEnum.CallPending.ObjToInt(),
+                            TaskType = taskType.ObjToInt(),
+                            TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
+                            PalletType = stockInfo.PalletType,
+                            WarehouseId = stockInfo.WarehouseId,
+                            MaterielCode = stockInfo.proStockInfoDetails?.FirstOrDefault().ProductCode ??"",
+                            Quantity = stockInfo.proStockInfoDetails?.Sum(x=>x.StockQty) ?? 0,
+                            OrderNo = outStockLockInfo.OrderNo,
+                            DispatchPlanId = outStockLockInfo.OrderDetailId,
+                            WorkCentreCode = outStockLockInfo.MakeCode
+                        };
+                        tasks.Add(task);
+                    }
+                }
+            }
+            return tasks;
+        }
+        /// <summary>
+        /// 搴撳瓨鏁版嵁杞嚭搴撲换鍔�(MES宸ュ崟鍘熸枡)
         /// </summary>
         /// <param name="stockInfos"></param>
         /// <returns></returns>
@@ -275,6 +392,7 @@
                         {
                             (int)StationAreaEnum.浜屾ゼ绾歌 => TaskTypeEnum.PaperYLOutZDGL,
                             (int)StationAreaEnum.涓�妤煎嵃鍒� => TaskTypeEnum.PrintYLOutbound,
+                            (int)StationAreaEnum.涓�妤煎垎鍒� => TaskTypeEnum.OutFenQie,
                             _ => throw new Exception($"鏈壘鍒板姞宸ヤ腑蹇冧换鍔$被鍨嬪垎閰�")
                         };
                         Dt_Task task = new()
@@ -294,7 +412,9 @@
                             MaterielCode = stockInfo.MaterielCode,
                             RfidCode = stockInfo.RfidCode,
                             Quantity = stockInfo.StockLength,
-                            OrderNo= outStockLockInfo.OrderNo
+                            OrderNo= outStockLockInfo.OrderNo,
+                            DispatchPlanId=outStockLockInfo.OrderDetailId,
+                            WorkCentreCode=outStockLockInfo.MakeCode
                         };
                         if (stockInfo.MaterielWide > 0)
                         {
@@ -336,7 +456,7 @@
                             PalletType = stockInfo.PalletType,
                             WarehouseId = stockInfo.WarehouseId,
                             MaterielCode= stockInfo.proStockInfoDetails?.FirstOrDefault().ProductCode ?? "" ,
-                            Quantity = 0,
+                            Quantity = stockInfo.proStockInfoDetails?.Sum(x=>x.StockQty) ?? 0,
                         };
                         tasks.Add(task);
                     }
@@ -408,6 +528,7 @@
                     nameof(StationAreaEnum.涓�妤煎垎鍒�) => TaskTypeEnum.OutFenQie,
                     nameof(StationAreaEnum.涓�妤兼ā鍒�) => TaskTypeEnum.OutMoQie,
                     nameof(StationAreaEnum.涓�妤煎啿鍒�) => TaskTypeEnum.OutChongQie,
+                    nameof(StationAreaEnum.涓�妤兼垚鍝�) => TaskTypeEnum.OutProduct,
                     nameof(StationAreaEnum.浜屾ゼ绾歌) or 
                     nameof(StationAreaEnum.浜屾ゼ鏃犵汉甯冭) or 
                     nameof(StationAreaEnum.浜屾ゼ绾告澂) => TaskTypeEnum.OutCarton,
@@ -620,7 +741,7 @@
             if (result.Item1 != null && result.Item1.Count > 0)
             {
                 //鑾峰彇浠诲姟
-                tasks = GetTasks(result.Item1, TaskTypeEnum.OldYLOutbound);
+                tasks = GetTasks(result.Item1.Where(x=> !x.LocationCode.IsNullOrEmpty()).ToList(), TaskTypeEnum.OldYLOutbound);
                 result.Item2.ForEach(x =>
                 {
                     if (result.Item3.FirstOrDefault(t=>t.OrderDetailId==x.Id)!=null)
@@ -630,7 +751,14 @@
                 });
                 result.Item3.ForEach(x =>
                 {
-                    x.Status = OutLockStockStatusEnum.鍑哄簱涓�.ObjToInt();
+                    if (x.LocationCode== "鑰佸巶缂撳瓨鍖�")
+                    {
+                        x.Status = OutLockStockStatusEnum.鍑哄簱瀹屾垚.ObjToInt();
+                    }
+                    else
+                    {
+                        x.Status = OutLockStockStatusEnum.鍑哄簱涓�.ObjToInt();
+                    }
                 });
 
                 stockInfos = result.Item1;
@@ -708,42 +836,70 @@
             WebResponseContent content = new WebResponseContent();
             try
             {
-                //鏂板
-                List<BSTPickInfoDTO> bSTPickInfosAdd = bSTPickInfoDTOs.Where(x => x.Way == 1).ToList();
-                //鑾峰彇鏂板鏄庣粏棰嗘枡
-                List<PaperMattakeDetailItem>? paperMattakeDetailItemsAdd = null;
-                //淇敼
-                List<BSTPickInfoDTO> bSTPickInfosUp = bSTPickInfoDTOs.Where(x => x.Way == 2).ToList();
-                //鑾峰彇鏂板鏄庣粏棰嗘枡
-                List<PaperMattakeDetailItem>? paperMattakeDetailItemsUp = null;
-                if (bSTPickInfosAdd != null && bSTPickInfosAdd.Count > 0)
-                {
-                    paperMattakeDetailItemsAdd = bSTPickInfosAdd.SelectMany(x => x.PaperMattakeDetails).ToList();
-                }
-                if (bSTPickInfosUp != null && bSTPickInfosUp.Count > 0)
-                {
-                    paperMattakeDetailItemsUp = bSTPickInfosUp.SelectMany(x => x.PaperMattakeDetails).ToList();
-                }
-                //鑾峰彇鎵�鏈夊緟棰嗘枡鐨勫嚭搴撹鎯�
-                List<Dt_OutStockLockInfo> outStockLockInfos = _outboundRepository.OutStockLockInfoRepository.QueryData(x => x.OrderType == OutOrderTypeEnum.OutSGPick.ObjToInt() && x.Status==OutLockStockStatusEnum.鍑哄簱瀹屾垚.ObjToInt());
-                #region 棰嗘枡閫昏緫
-                if (paperMattakeDetailItemsAdd != null && paperMattakeDetailItemsAdd.Count > 0)
-                {
-                    foreach (var item in paperMattakeDetailItemsAdd)
-                    {
-                        //鑾峰彇瀵瑰簲鐨�
-                    }
-                }
                 
-                if (paperMattakeDetailItemsUp != null && paperMattakeDetailItemsUp.Count > 0)
+                //鑾峰彇棰嗘枡鏉$爜鍙婂簱瀛�
+                List<string> lockCodes = bSTPickInfoDTOs.SelectMany(x => x.PaperMattakeDetails).Select(x=>x.Barcode).Distinct().ToList();
+                List<Dt_StockInfo> stockInfos = _stockRepository.StockInfoRepository.QueryData(x => lockCodes.Contains(x.PalletCode) && x.WarehouseId == WarehouseEnum.LLDOldCache.ObjToInt());
+                List<string> ExistNoCodes = lockCodes.Where(x => !stockInfos.Select(x=>x.PalletCode).Contains(x)).ToList();
+                //鑾峰彇寰呴鏂欑殑鍑哄簱璇︽儏
+                List<Dt_OutStockLockInfo> outStockLockInfos = _outboundRepository.OutStockLockInfoRepository.QueryData(x => x.OrderType == OutOrderTypeEnum.OutSGPick.ObjToInt() && x.Status==OutLockStockStatusEnum.鍑哄簱瀹屾垚.ObjToInt() && lockCodes.Distinct().ToList().Contains(x.PalletCode));
+                //鍑哄簱璇︽儏鐘舵�佹洿鏂�
+                if (outStockLockInfos.Count > 0)
                 {
-                    foreach (var item in paperMattakeDetailItemsUp)
+                    outStockLockInfos.ForEach(x =>
                     {
-                        
+                        x.Status = OutLockStockStatusEnum.鍏抽棴.ObjToInt();
+                    });
+                }
+                List<int> BSTPickDetailsId = outStockLockInfos.Select(x => x.OrderDetailId).Distinct().ToList();
+                //鑾峰彇瀵瑰簲鎺掔▼
+                List<Dt_OutSGOrder> outSGOrders = BaseDal.Db.Queryable<Dt_OutSGOrder>().Where(x => x.OutSGOrderStatus < OutOrderStatusEnum.鍑哄簱瀹屾垚.ObjToInt()).Includes(x => x.Details)
+                    .Where(x => x.Details
+                    .Any(v =>
+                        BSTPickDetailsId.Contains(v.Id))
+                    ).OrderBy(x => x.CreateDate).ToList();
+                List<Dt_OutSGOrderDetail> orderDetails = new List<Dt_OutSGOrderDetail>();
+                //澶勭悊鎺掔▼
+                if (outSGOrders.Count>0)
+                {
+                    orderDetails = outSGOrders.SelectMany(x=>x.Details).Where(x=> BSTPickDetailsId.Contains(x.Id)).ToList();
+                    orderDetails.ForEach(x =>
+                    {
+                        x.OutSGOrderDetailStatus = OutOrderStatusEnum.鍑哄簱瀹屾垚.ObjToInt();
+                    });
+                    foreach (var item in outSGOrders)
+                    {
+                        int overCount = item.Details.Where(x=>x.OutSGOrderDetailStatus==OutLockStockStatusEnum.鍑哄簱瀹屾垚.ObjToInt()).Count();
+                        int thisCount = orderDetails.Where(x => x.OutSGOrderId == item.Id).Count();
+                        if ((overCount + thisCount) == item.Details.Count)
+                        {
+                            item.OutSGOrderStatus = OutOrderStatusEnum.鍑哄簱瀹屾垚.ObjToInt();
+                        }
                     }
-
+                }
+                //鑾峰彇鎵�鏈夊緟棰嗘枡鐨勫簱瀛�
+                #region 棰嗘枡閫昏緫
+                foreach (var item in stockInfos)
+                {
+                    if (item.StockStatus==StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt())
+                    {
+                        item.StockLength = 0;
+                        item.MaterielWeight = 0;
+                        item.MaterielThickness = 0;
+                        item.MaterielWide = 0;
+                        item.StockOutLength = 0;
+                        item.IsFull = WhetherEnum.True.ObjToInt();
+                        item.IsPick = WhetherEnum.True.ObjToInt();
+                    }
                 }
                 #endregion
+                _unitOfWorkManage.BeginTran();
+                _stockRepository.StockInfoRepository.UpdateData(stockInfos);
+                _outboundRepository.OutStockLockInfoRepository.UpdateData(outStockLockInfos);
+                _outboundRepository.OutSGOrderRepository.UpdateData(outSGOrders);
+                _outboundRepository.OutSGOrderDetailRepository.UpdateData(orderDetails);
+                _unitOfWorkManage.CommitTran();
+                content.OK(ExistNoCodes.Count>0 ? string.Join(",", ExistNoCodes)+"鑰佸巶鍙墸搴撳瓨涓嶅瓨鍦�" : "");
             }
             catch (Exception ex)
             {
@@ -842,66 +998,155 @@
                     Dt_MakeCenterInfo makeCenterInfo=makeCenterInfos.FirstOrDefault(x => x.MakeCode == item.MakeCode);
                     item.MakeArea = makeCenterInfo.MakeArea;
                     item.WarehouseId = materielInfo.WarehouseId;
+                    item.MaterielUnit = materielInfo.MaterielUnit;
+                    item.AssistUnitCode = materielInfo.AssistUnitCode;
                 }
                 
                 _unitOfWorkManage.BeginTran();
                 //鎿嶄綔鏁版嵁锛屽苟鍒嗛厤闇�姹傚簱瀛�
                 _outboundRepository.OutMESOrderRepository.AddData(AddoutMESOrders);
-                List<Dt_OutMESOrder> mESOrders = _outboundRepository.OutMESOrderRepository.QueryData(x => AddoutMESOrders.Select(x => x.OutDetailId).Contains(x.OutDetailId));
-                List<Dt_Task> tasks = new List<Dt_Task>();
-                List<Dt_StockInfo>? stockInfos = null;
-                List<Dt_OutMESOrder>? Orders = null;
-                List<Dt_OutStockLockInfo>? outStockLockInfos = null;
-                List<Dt_LocationInfo>? locationInfos = null;
-                {
-                    //鍒嗛厤搴撳瓨
-                    (List<Dt_StockInfo>, List<Dt_OutMESOrder>, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) result = _outboundService.OutMESOrderService.AssignStockOutbound(mESOrders);
-                    if (result.Item1 != null && result.Item1.Count > 0)
-                    {
-                        //鍒涘缓浠诲姟
-                        tasks = GetTasks(result.Item1, result.Item3);
-                        result.Item2.ForEach(x =>
-                        {
-                            OutOrderStatusEnum.鍑哄簱涓�.ObjToInt();
-                        });
-                        result.Item3.ForEach(x =>
-                        {
-                            x.Status = OutLockStockStatusEnum.鍑哄簱涓�.ObjToInt();
-                        });
+                //List<Dt_OutMESOrder> mESOrders = _outboundRepository.OutMESOrderRepository.QueryData(x => AddoutMESOrders.Select(x => x.OutDetailId).Contains(x.OutDetailId));
+                //{
+                //    List<Dt_Task> tasks = new List<Dt_Task>();
+                //    List<Dt_ProStockInfo>? stockInfos = null;
+                //    List<Dt_OutMESOrder>? Orders = null;
+                //    List<Dt_OutStockLockInfo>? outStockLockInfos = null;
+                //    List<Dt_LocationInfo>? locationInfos = null;
+                //    {
+                //        if (mESOrders.Where(x => x.WarehouseId == WarehouseEnum.LLDFL.ObjToInt()).ToList().Count>0)
+                //        {
+                //            //鍒嗛厤搴撳瓨
+                //            (List<Dt_ProStockInfo>, List<Dt_OutMESOrder>, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) result = _outboundService.OutMESOrderService.AssignProStockOutbound(mESOrders.Where(x => x.WarehouseId == WarehouseEnum.LLDFL.ObjToInt()).ToList());
+                //            if (result.Item1 != null && result.Item1.Count > 0)
+                //            {
+                //                //鍒涘缓浠诲姟
+                //                tasks = GetTasks(result.Item1, result.Item3);
+                //                result.Item3.ForEach(x =>
+                //                {
+                //                    x.Status = OutLockStockStatusEnum.鍑哄簱涓�.ObjToInt();
+                //                });
+                //                stockInfos = result.Item1;
+                //                Orders = result.Item2;
+                //                outStockLockInfos = result.Item3;
+                //                locationInfos = result.Item4;
+                //            }
+                //        }
+                //    }
+                //    if (stockInfos != null && stockInfos.Count > 0 && outStockLockInfos != null && outStockLockInfos.Count > 0 && locationInfos != null && locationInfos.Count > 0 && tasks.Count>0)
+                //    {
+                //        BaseDal.AddData(tasks);
+                //        stockInfos.ForEach(x =>
+                //        {
+                //            x.StockStatus = StockStatusEmun.鍑哄簱閿佸畾.ObjToInt();
+                //        });
+                //        WebResponseContent contentResponse = _outboundService.OutMESOrderService.LockOutboundStockDataUpdate(stockInfos, Orders, outStockLockInfos, locationInfos, tasks: tasks);
 
-                        stockInfos = result.Item1;
-                        Orders = result.Item2;
-                        outStockLockInfos = result.Item3;
-                        locationInfos = result.Item4;
-                    }
-                    else
-                    {
-                        throw new Exception("鏃犲簱瀛�");
-                    }
-                }
-                int id = BaseDal.AddData(tasks);
-
-                if (stockInfos != null && stockInfos.Count > 0 && outStockLockInfos != null && outStockLockInfos.Count > 0 && locationInfos != null && locationInfos.Count > 0)
-                {
-                    stockInfos.ForEach(x =>
-                    {
-                        x.StockStatus=StockStatusEmun.鍑哄簱閿佸畾.ObjToInt();
-                    });
-                    WebResponseContent contentResponse = _outboundService.OutMESOrderService.LockOutboundStockDataUpdate(stockInfos, Orders, outStockLockInfos, locationInfos, tasks: tasks);
-
-                    if (!contentResponse.Status)
-                    {
-                        _unitOfWorkManage.RollbackTran();
-                        return content.Error(contentResponse.Message);
-                    }
-                }
-
+                //        if (!contentResponse.Status)
+                //        {
+                //            _unitOfWorkManage.RollbackTran();
+                //            return content.Error(contentResponse.Message);
+                //        }
+                //    }
+                //}
+                //{
+                //    List<Dt_Task> tasks = new List<Dt_Task>();
+                //    List<Dt_StockInfo>? stockInfos = null;
+                //    List<Dt_OutMESOrder>? Orders = null;
+                //    List<Dt_OutStockLockInfo>? outStockLockInfos = null;
+                //    List<Dt_LocationInfo>? locationInfos = null;
+                //    {
+                //        if (mESOrders.Where(x => x.WarehouseId == WarehouseEnum.LLDYL.ObjToInt()).ToList().Count > 0)
+                //        {
+                //            //鍒嗛厤搴撳瓨
+                //            (List<Dt_StockInfo>, List<Dt_OutMESOrder>, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) result = _outboundService.OutMESOrderService.AssignStockOutbound(mESOrders.Where(x => x.WarehouseId == WarehouseEnum.LLDYL.ObjToInt()).ToList());
+                //            if (result.Item1 != null && result.Item1.Count > 0)
+                //            {
+                //                //鍒涘缓浠诲姟
+                //                tasks = GetTasks(result.Item1, result.Item3);
+                //                result.Item3.ForEach(x =>
+                //                {
+                //                    x.Status = OutLockStockStatusEnum.鍑哄簱涓�.ObjToInt();
+                //                });
+                //                stockInfos = result.Item1;
+                //                Orders = result.Item2;
+                //                outStockLockInfos = result.Item3;
+                //                locationInfos = result.Item4;
+                //            }
+                //        }
+                //    }
+                //    if (stockInfos != null && stockInfos.Count > 0 && outStockLockInfos != null && outStockLockInfos.Count > 0 && locationInfos != null && locationInfos.Count > 0 && tasks.Count>0)
+                //    {
+                //        BaseDal.AddData(tasks);
+                //        stockInfos.ForEach(x =>
+                //        {
+                //            x.StockStatus = StockStatusEmun.鍑哄簱閿佸畾.ObjToInt();
+                //        });
+                //        WebResponseContent contentResponse = _outboundService.OutMESOrderService.LockOutboundStockDataUpdate(stockInfos, Orders, outStockLockInfos, locationInfos, tasks: tasks);
+                //        if (!contentResponse.Status)
+                //        {
+                //            _unitOfWorkManage.RollbackTran();
+                //            return content.Error(contentResponse.Message);
+                //        }
+                //    }
+                //}
                 _unitOfWorkManage.CommitTran();
                 
                 return content.OK("鎺ユ敹鎴愬姛");
             }
             catch (Exception ex)
             {
+                _unitOfWorkManage.RollbackTran();
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+        /// <summary>
+        /// 绌烘墭鍙犵洏鍑哄簱
+        /// </summary>
+        /// <returns></returns>
+        public WebResponseContent PlateOutbound(string stationCode)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                //鑾峰彇鎵�鏈夋湀鍙板嚭搴撲换鍔�
+                Dt_Task TasksOut = BaseDal.QueryFirst(x => x.TaskType == TaskTypeEnum.OutEmptyPlate.ObjToInt());
+                if (TasksOut != null)
+                    throw new Exception($"浠诲姟宸插瓨鍦�");
+                //鑾峰彇璐т綅
+                List<Dt_LocationInfo> locationInfos = _basicRepository.LocationInfoRepository.QueryData(x => x.WarehouseId == WarehouseEnum.LLDCP.ObjToInt() && x.EnableStatus == EnableStatusEnum.Normal.ObjToInt() && x.LocationStatus == LocationStatusEnum.InStock.ObjToInt());
+                Dt_ProStockInfo? stockInfo = BaseDal.Db.Queryable<Dt_ProStockInfo>().Where(x => locationInfos.Select(x => x.LocationCode).Contains(x.LocationCode) && x.StockStatus == StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt() && x.ProStockAttribute == ProStockAttributeEnum.绌烘墭.ObjToInt()).OrderBy(x => x.CreateDate).ToList().FirstOrDefault() ?? throw new Exception($"搴撳瓨绌烘墭鏁伴噺涓嶈冻");
+
+                Dt_LocationInfo locationInfo = locationInfos.FirstOrDefault(x => x.LocationCode == stockInfo.LocationCode);
+                stockInfo.StockStatus = StockStatusEmun.鍑哄簱閿佸畾.ObjToInt();
+
+                TaskTypeEnum typeEnum = TaskTypeEnum.OutEmptyPlate;
+
+                List<Dt_Task> tasks = GetTasks(new List<Dt_ProStockInfo>() { stockInfo }, typeEnum, new List<Dt_LocationInfo>() { locationInfo });
+                if (tasks == null || tasks.Count <= 0)
+                {
+                    return content.Error($"鐢熸垚浠诲姟澶辫触");
+                }
+                tasks.ForEach(x =>
+                {
+                    x.TargetAddress = stationCode;
+                });
+                //鍒ゆ柇鏄惁鏈夊嚭搴撳崟淇℃伅
+                _unitOfWorkManage.BeginTran();
+                //鏇存柊搴撳瓨鐘舵��
+                _stockRepository.ProStockInfoRepository.UpdateData(stockInfo);
+                //鏇存柊璐т綅鐘舵��
+                _basicRepository.LocationInfoRepository.UpdateLocationStatus(new List<Dt_LocationInfo>() { locationInfo }, LocationStatusEnum.Lock);
+                //鍔犲叆璐т綅鍙樺姩璁板綍
+                _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(new List<Dt_LocationInfo>() { locationInfo }, LocationStatusEnum.Lock, LocationChangeType.OutboundAssignLocation, taskNums: tasks.Select(x => x.TaskNum).ToList());
+                //鏂板缓浠诲姟
+                BaseDal.AddData(tasks);
+                _unitOfWorkManage.CommitTran();
+                PushTasksToWCS(tasks);
+                content.OK();
+            }
+            catch (Exception ex)
+            {
                 content.Error(ex.Message);
             }
             return content;

--
Gitblit v1.9.3