From 04a831b2a945b9b6bcb659038a6fed1d3148e3ce Mon Sep 17 00:00:00 2001
From: hutongqing <hutongqing@hnkhzn.com>
Date: 星期六, 28 十二月 2024 14:20:01 +0800
Subject: [PATCH] Merge branch 'master' of http://115.159.85.185:8098/r/MeiRuiAn/HuaiAn

---
 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Outbound.cs |  157 ++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 120 insertions(+), 37 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Outbound.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Outbound.cs"
index 723443b..a6dd362 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Outbound.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Outbound.cs"
@@ -34,20 +34,25 @@
                 if (stockInfo != null)
                 {
                     Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == stockInfo.LocationCode);
-                    Dt_Task task = new()
+                    if (!tasks.Exists(x => x.PalletCode == stockInfo.PalletCode))
                     {
-                        CurrentAddress = stockInfo.LocationCode,
-                        Grade = 0,
-                        PalletCode = stockInfo.PalletCode,
-                        NextAddress = "",
-                        Roadway = locationInfo.RoadwayNo,
-                        SourceAddress = stockInfo.LocationCode,
-                        TargetAddress = "",
-                        TaskStatus = TaskOutStatusEnum.OutNew.ObjToInt(),
-                        TaskType = TaskOutboundTypeEnum.Outbound.ObjToInt(),
-                        TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum))
-                    };
-                    tasks.Add(task);
+                        Dt_Task task = new()
+                        {
+                            CurrentAddress = stockInfo.LocationCode,
+                            Grade = 0,
+                            PalletCode = stockInfo.PalletCode,
+                            NextAddress = "",
+                            Roadway = locationInfo.RoadwayNo,
+                            SourceAddress = stockInfo.LocationCode,
+                            TargetAddress = "",
+                            TaskStatus = TaskStatusEnum.New.ObjToInt(),
+                            TaskType = TaskTypeEnum.Outbound.ObjToInt(),
+                            TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
+                            PalletType = stockInfo.PalletType,
+                            WarehouseId = stockInfo.WarehouseId,
+                        };
+                        tasks.Add(task);
+                    }
                 }
             }
             return tasks;
@@ -114,6 +119,65 @@
         }
 
         /// <summary>
+        /// 鍑哄簱浠诲姟鏁版嵁澶勭悊
+        /// </summary>
+        /// <param name="orderDetailId"></param>
+        /// <param name="stockSelectViews"></param>
+        /// <returns></returns>
+        /// <exception cref="Exception"></exception>
+        public (List<Dt_Task>, List<Dt_StockInfo>?, List<Dt_OutboundOrderDetail>?, List<Dt_OutStockLockInfo>?, List<Dt_LocationInfo>?) OutboundTaskDataHandle(int[] keys)
+        {
+            List<Dt_Task> tasks = new List<Dt_Task>();
+            List<Dt_OutboundOrderDetail> outboundOrderDetails = _outboundService.OutboundOrderDetailService.Repository.QueryData(x => keys.Contains(x.Id));
+
+            if (outboundOrderDetails == null || outboundOrderDetails.Count == 0)
+            {
+                throw new Exception("鏈壘鍒板嚭搴撳崟鏄庣粏淇℃伅");
+            }
+
+            List<Dt_StockInfo>? stockInfos = null;
+            List<Dt_OutboundOrderDetail>? orderDetails = null;
+            List<Dt_OutStockLockInfo>? outStockLockInfos = null;
+            List<Dt_LocationInfo>? locationInfos = null;
+            //if (outboundOrderDetail.OrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt())
+            {
+                (List<Dt_StockInfo>, List<Dt_OutboundOrderDetail>, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) result = _outboundService.OutboundOrderDetailService.AssignStockOutbound(outboundOrderDetails);
+                if (result.Item1 != null && result.Item1.Count > 0)
+                {
+                    tasks = GetTasks(result.Item1);
+                    result.Item2.ForEach(x =>
+                    {
+                        x.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt();
+                    });
+                    result.Item3.ForEach(x =>
+                    {
+                        x.Status = OutLockStockStatusEnum.鍑哄簱涓�.ObjToInt();
+                    });
+
+                    stockInfos = result.Item1;
+                    orderDetails = result.Item2;
+                    outStockLockInfos = result.Item3;
+                    locationInfos = result.Item4;
+                }
+                else
+                {
+                    throw new Exception("鏃犲簱瀛�");
+                }
+            }
+            //else
+            //{
+            //    List<Dt_OutStockLockInfo> stockLockInfos = _outboundService.OutboundStockLockInfoService.GetByOrderDetailId(outboundOrderDetail.OrderId, OutLockStockStatusEnum.宸插垎閰�);
+            //    if (stockLockInfos != null && stockLockInfos.Count > 0)
+            //    {
+            //        List<Dt_StockInfo> stocks = _stockService.StockInfoService.Repository.GetStockInfosByPalletCodes(stockLockInfos.Select(x => x.PalletCode).Distinct().ToList());
+            //        tasks = GetTasks(stocks);
+            //    }
+            //}
+
+            return (tasks, stockInfos, orderDetails, outStockLockInfos, locationInfos);
+        }
+
+        /// <summary>
         /// 鐢熸垚鍑哄簱浠诲姟
         /// </summary>
         /// <param name="orderDetailId"></param>
@@ -151,7 +215,7 @@
                 _unitOfWorkManage.BeginTran();
 
                 BaseDal.AddData(tasks);
-                if (stockInfos != null && outboundOrderDetails != null && outStockLockInfos != null && locationInfos != null)
+                if (stockInfos != null && stockInfos.Count > 0 && outboundOrderDetails != null && outboundOrderDetails.Count > 0 && outStockLockInfos != null && outStockLockInfos.Count > 0 && locationInfos != null && locationInfos.Count > 0)
                 {
                     WebResponseContent content = _outboundService.OutboundOrderDetailService.LockOutboundStockDataUpdate(stockInfos, outboundOrderDetails, outStockLockInfos, locationInfos, tasks: tasks);
 
@@ -175,6 +239,7 @@
                     _outboundService.OutboundOrderDetailService.Repository.UpdateData(outboundOrderDetails);
                 }
                 _unitOfWorkManage.CommitTran();
+                PushTasksToWCS(tasks);
                 return WebResponseContent.Instance.OK();
             }
             catch (Exception ex)
@@ -188,7 +253,7 @@
         /// <summary>
         /// 鐢熸垚鍑哄簱浠诲姟
         /// </summary>
-        /// <param name="keys"></param>
+        /// <param name="keys">鍑哄簱鍗曟槑缁嗕富閿�</param>
         /// <returns></returns>
         public WebResponseContent GenerateOutboundTask(int[] keys)
         {
@@ -200,29 +265,27 @@
                 List<Dt_OutboundOrderDetail> outboundOrderDetails = new List<Dt_OutboundOrderDetail>();
                 List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>();
                 List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>();
-                foreach (int key in keys)
+
+                (List<Dt_Task>, List<Dt_StockInfo>?, List<Dt_OutboundOrderDetail>?, List<Dt_OutStockLockInfo>?, List<Dt_LocationInfo>?) result = OutboundTaskDataHandle(keys);
+                if (result.Item2 != null && result.Item2.Count > 0)
                 {
-                    (List<Dt_Task>, List<Dt_StockInfo>?, List<Dt_OutboundOrderDetail>?, List<Dt_OutStockLockInfo>?, List<Dt_LocationInfo>?) result = OutboundTaskDataHandle(key, stockSelectViews);
-                    if (result.Item2 != null && result.Item2.Count > 0)
-                    {
-                        stockInfos.AddRange(result.Item2);
-                    }
-                    if (result.Item3 != null && result.Item3.Count > 0)
-                    {
-                        outboundOrderDetails.AddRange(result.Item3);
-                    }
-                    if (result.Item4 != null && result.Item4.Count > 0)
-                    {
-                        outStockLockInfos.AddRange(result.Item4);
-                    }
-                    if (result.Item5 != null && result.Item5.Count > 0)
-                    {
-                        locationInfos.AddRange(result.Item5);
-                    }
-                    if (result.Item1 != null && result.Item1.Count > 0)
-                    {
-                        tasks.AddRange(result.Item1);
-                    }
+                    stockInfos.AddRange(result.Item2);
+                }
+                if (result.Item3 != null && result.Item3.Count > 0)
+                {
+                    outboundOrderDetails.AddRange(result.Item3);
+                }
+                if (result.Item4 != null && result.Item4.Count > 0)
+                {
+                    outStockLockInfos.AddRange(result.Item4);
+                }
+                if (result.Item5 != null && result.Item5.Count > 0)
+                {
+                    locationInfos.AddRange(result.Item5);
+                }
+                if (result.Item1 != null && result.Item1.Count > 0)
+                {
+                    tasks.AddRange(result.Item1);
                 }
 
                 WebResponseContent content = GenerateOutboundTaskDataUpdate(tasks, stockInfos, outboundOrderDetails, outStockLockInfos, locationInfos);
@@ -234,5 +297,25 @@
                 return WebResponseContent.Instance.Error(ex.Message);
             }
         }
+
+        /// <summary>
+        /// 鐢熸垚鍑哄簱浠诲姟
+        /// </summary>
+        /// <param name="outboundId">鍑哄簱鍗曚富閿�</param>
+        /// <returns></returns>
+        public WebResponseContent GenerateOutboundTaskByHeadId(int outboundId)
+        {
+            try
+            {
+                List<int> keys = _outboundService.OutboundOrderDetailService.Repository.QueryData(x => x.Id, x => x.OrderId == outboundId);
+
+                return GenerateOutboundTask(keys.ToArray());
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
+        }
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3