From a6e0ea9ce13e791f3edae4edffeb3be3ccb760be Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期一, 31 三月 2025 02:14:59 +0800
Subject: [PATCH] 版本更新

---
 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Outbound.cs |  206 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 205 insertions(+), 1 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 1eaaae3..6907f4c 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"
@@ -18,6 +18,7 @@
 using MailKit.Search;
 using WIDESEA_External.Model;
 using WIDESEA_Core.CodeConfigEnum;
+using Microsoft.AspNetCore.Mvc;
 
 namespace WIDESEA_TaskInfoService
 {
@@ -74,6 +75,205 @@
                 content.Error(ex.Message);
             }
             return content;
+        }
+        /// <summary>
+        /// 鐢熸垚鎴愬搧鍑哄簱浠诲姟
+        /// </summary>
+        /// <param name="ProOutNo">鍑哄簱璁㈠崟鍙�</param>
+        /// <param name="StationCode">绔欏彴鍦板潃</param>
+        /// <returns></returns>
+        public WebResponseContent OutProductTask(int[] keys, string StationCode)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                //鑾峰彇鎴愬搧鍑哄簱璁㈠崟
+                List<Dt_ProOutOrderDetail> _ProOutOrderDetails = _outboundRepository.ProOutOrderDetailRepository.QueryData(x => keys.Contains(x.Id));
+                if (_ProOutOrderDetails.Count<=0)
+                {
+                    return content.Error("鍕鹃�夎鍗曟槑缁嗕笉瀛樺湪");
+                }
+                List<Dt_Task> tasks = new List<Dt_Task>();
+                List<StockSelectViewDTO> stockSelectViews = new List<StockSelectViewDTO>();
+                List<Dt_ProStockInfo> proStockInfos = new List<Dt_ProStockInfo>();
+                List<Dt_ProOutOrderDetail> proOutOrderDetails = new List<Dt_ProOutOrderDetail>();
+                List<Dt_OutProStockInfo> outProStockInfos = new List<Dt_OutProStockInfo>();
+                List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>();
+                (List<Dt_Task>, List<Dt_ProStockInfo>?, List<Dt_ProOutOrderDetail>?, List<Dt_OutProStockInfo>?, List<Dt_LocationInfo>?) result =
+                OutProductTaskDataHandle(_ProOutOrderDetails);
+                if (result.Item2 != null && result.Item2.Count > 0)
+                {
+                    proStockInfos.AddRange(result.Item2);
+                }
+                if (result.Item3 != null && result.Item3.Count > 0)
+                {
+                    proOutOrderDetails.AddRange(result.Item3);
+                }
+                if (result.Item4 != null && result.Item4.Count > 0)
+                {
+                    outProStockInfos.AddRange(result.Item4);
+                }
+                if (result.Item5 != null && result.Item5.Count > 0)
+                {
+                    locationInfos.AddRange(result.Item5);
+                }
+                if (result.Item1 != null && result.Item1.Count > 0)
+                {
+                    //鏇存柊鍑哄簱鐩殑浣嶇疆
+                    result.Item1.ForEach(x =>
+                    {
+                        x.TargetAddress = StationCode;
+                    });
+                    tasks.AddRange(result.Item1);
+                }
+                //澶勭悊鍑哄簱鏁版嵁
+                content = GenerateOutboundTaskDataUpdate(tasks, proStockInfos, proOutOrderDetails, outProStockInfos, locationInfos);
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+        
+        /// <summary>
+        /// 澶勭悊鍑哄簱鏁版嵁
+        /// </summary>
+        public WebResponseContent GenerateOutboundTaskDataUpdate(List<Dt_Task> tasks, List<Dt_ProStockInfo>? proStockInfos = null, List<Dt_ProOutOrderDetail>? proOutOrderDetails = null, List<Dt_OutProStockInfo>? outProStockInfos = null, List<Dt_LocationInfo>? locationInfos = null)
+        {
+            try
+            {
+                _unitOfWorkManage.BeginTran();
+
+                BaseDal.AddData(tasks);
+                if (proStockInfos != null && proStockInfos.Count > 0 && proOutOrderDetails != null && proOutOrderDetails.Count > 0 && outProStockInfos != null && outProStockInfos.Count > 0 && locationInfos != null && locationInfos.Count > 0)
+                {
+                    proStockInfos.ForEach(x =>
+                    {
+                        x.StockStatus = StockStatusEmun.鍑哄簱閿佸畾.ObjToInt();
+                    });
+                    WebResponseContent content = _outboundService.ProOutOrderDetailService.LockOutboundStockDataUpdate(proStockInfos, proOutOrderDetails, outProStockInfos, locationInfos, tasks: tasks);
+
+                    if (!content.Status)
+                    {
+                        _unitOfWorkManage.RollbackTran();
+                        return content;
+                    }
+                }
+                else if (proOutOrderDetails != null && proOutOrderDetails.Count > 0)
+                {
+                    //鑾峰彇鎴愬搧鍑哄簱鍗曚富琛�
+                    Dt_ProOutOrder proOutOrder = _outboundRepository.ProOutOrderRepository.QueryFirst(x => x.Id == proOutOrderDetails.FirstOrDefault().ProOrderId);
+                    if (proOutOrder.ProOrderStatus == OutOrderStatusEnum.鏈紑濮�.ObjToInt())
+                    {
+                        proOutOrder.ProOrderStatus = OutOrderStatusEnum.鍑哄簱涓�.ObjToInt();
+                        _outboundRepository.ProOutOrderRepository.UpdateData(proOutOrder);
+                    }
+                    proOutOrderDetails.ForEach(x =>
+                    {
+                        x.ProOrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt();
+                    });
+
+                    _outboundRepository.ProOutOrderDetailRepository.UpdateData(proOutOrderDetails);
+                }
+                _unitOfWorkManage.CommitTran();
+                PushTasksToWCS(tasks);
+                return WebResponseContent.Instance.OK();
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
+
+        }
+        /// <summary>
+        /// 澶勭悊鎴愬搧鍑哄簱鏁版嵁
+        /// </summary>
+        /// <returns></returns>
+        public (List<Dt_Task>, List<Dt_ProStockInfo>?, List<Dt_ProOutOrderDetail>?, List<Dt_OutProStockInfo>?, List<Dt_LocationInfo>?) OutProductTaskDataHandle(List<Dt_ProOutOrderDetail> proOutOrderDetails)
+        {
+            List<Dt_Task> tasks = new List<Dt_Task>();
+            List<Dt_ProStockInfo> proStockInfos = new List<Dt_ProStockInfo>();
+            List<Dt_ProOutOrderDetail> assignOutOrderDetails = new List<Dt_ProOutOrderDetail>();
+            List<Dt_OutProStockInfo> outProStockInfos=new List<Dt_OutProStockInfo>();
+            List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>();
+            //鍒嗛厤搴撳瓨
+            (List<Dt_ProStockInfo>, List<Dt_ProOutOrderDetail>, List<Dt_OutProStockInfo>, List<Dt_LocationInfo>) result = _outboundService.ProOutOrderDetailService.AssignProStockOut(proOutOrderDetails);
+            if (result.Item1!=null&&result.Item1.Count>0)
+            {
+                //鑾峰彇鎴愬搧鍗�
+                Dt_ProOutOrder proOutOrder = _outboundRepository.ProOutOrderRepository.QueryFirst(x => x.Id == proOutOrderDetails.FirstOrDefault().ProOrderId);
+                if (proOutOrder==null)
+                {
+                    throw new Exception("鏈壘鍒版垚鍝佽鍗�");
+                }
+                TaskTypeEnum typeEnum = proOutOrder.ProOrderType switch
+                {
+                    (int)OutProTypeEnum.ProOut => TaskTypeEnum.OutProduct,
+                    (int)OutProTypeEnum.SendProOut => TaskTypeEnum.OutSendProduct,
+                    _ => new TaskTypeEnum()
+                };
+                tasks = GetTasks(result.Item1, typeEnum);
+                result.Item2.ForEach(x =>
+                {
+                    x.ProOrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt();
+                });
+                result.Item3.ForEach(x =>
+                {
+                    x.Status = OutLockStockStatusEnum.鍑哄簱涓�.ObjToInt();
+                });
+
+                proStockInfos = result.Item1;
+                proOutOrderDetails = result.Item2;
+                outProStockInfos = result.Item3;
+                locationInfos = result.Item4;
+            }
+            else
+            {
+                throw new Exception("鏃犲彲鍒嗛厤搴撳瓨");
+            }
+            return (tasks, proStockInfos, proOutOrderDetails, outProStockInfos, locationInfos);
+        }
+        /// <summary>
+        /// 鐢熸垚浠诲姟
+        /// </summary>
+        /// <param name="stockInfos"></param>
+        /// <param name="taskType"></param>
+        /// <returns></returns>
+        public List<Dt_Task> GetTasks(List<Dt_ProStockInfo> stockInfos, TaskTypeEnum taskType)
+        {
+            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_Task task = new()
+                        {
+                            CurrentAddress = stockInfo.LocationCode,
+                            Grade = 0,
+                            PalletCode = stockInfo.PalletCode,
+                            NextAddress = "",
+                            Roadway = locationInfo.RoadwayNo,
+                            SourceAddress = stockInfo.LocationCode,
+                            TargetAddress = "",
+                            TaskStatus = TaskStatusEnum.New.ObjToInt(),
+                            TaskType = taskType.ObjToInt(),
+                            TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
+                            PalletType = stockInfo.PalletType,
+                            WarehouseId = stockInfo.WarehouseId,
+                        };
+                        tasks.Add(task);
+                    }
+                }
+            }
+            return tasks;
         }
         /// <summary>
         /// 搴撳瓨鏁版嵁杞嚭搴撲换鍔�
@@ -152,7 +352,7 @@
                         (int)OutOrderTypeEnum.Quality => TaskTypeEnum.OutQuality,
                         _ => new TaskTypeEnum()
                     };
-                    tasks = GetTasks(result.Item1, TaskTypeEnum.Outbound);
+                    tasks = GetTasks(result.Item1, typeEnum);
                     result.Item2.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt();
                     result.Item3.ForEach(x =>
                     {
@@ -220,6 +420,10 @@
                         _ =>new TaskTypeEnum()
                     };
                     tasks = GetTasks(result.Item1, typeEnum);
+                    tasks.ForEach(x =>
+                    {
+                        x.OrderNo = outboundOrder.UpperOrderNo;
+                    });
                     result.Item2.ForEach(x =>
                     {
                         x.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt();

--
Gitblit v1.9.3