From c6f6be2d942214580e61c2647c846d7e11e06f48 Mon Sep 17 00:00:00 2001
From: yangpeixing <yangpeixing@hnkhzn.com>
Date: 星期一, 19 一月 2026 15:42:11 +0800
Subject: [PATCH] 1

---
 WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs |  354 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 334 insertions(+), 20 deletions(-)

diff --git a/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs b/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
index 5f2ea4b..511a80a 100644
--- a/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
+++ b/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs
@@ -886,6 +886,158 @@
                             }
                         }
                     }
+                    else if (warehouse.WarehouseCode.Contains("DW") || warehouse.WarehouseCode.Contains("YS"))
+                    {
+                        Dt_InboundOrder? inboundOrder = _inboundService.InbounOrderService.Db.Queryable<Dt_InboundOrder>().Where(x => x.OrderNo == dt_StockInfo.Details.FirstOrDefault().OrderNo).Includes(x => x.Details).First();
+                        //Dt_InboundOrderDetail? inboundOrderDetail = null;
+                        //鍑哄簱鍏ュ簱閫昏緫
+                        if (task.TaskType == TaskTypeEnum.Inbound.ObjToInt())
+                        {
+                            int lastStatus = dt_LocationInfo.LocationStatus;
+                            dt_LocationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
+                            // 鏍规嵁鎵樼洏鏄庣粏鑾峰彇瀵瑰簲鐨勫叆搴撳崟鏄庣粏
+                            List<Dt_InboundOrderDetail> inboundOrderDetails = new List<Dt_InboundOrderDetail>();
+
+                            // 澶勭悊澶氫釜搴撳瓨鏄庣粏鐨勬儏鍐�
+                            foreach (var stockDetail in dt_StockInfo.Details)
+                            {
+                                if (!string.IsNullOrEmpty(stockDetail.OrderNo))
+                                {
+                                    var detail = inboundOrder.Details.FirstOrDefault(x => x.LinId == stockDetail.LinId && x.BatchNo == stockDetail.BatchNo);
+
+                                    if (detail != null && !inboundOrderDetails.Any(x => x.Id == detail.Id))
+                                    {
+                                        inboundOrderDetails.Add(detail);
+                                    }
+                                }
+                            }
+                            if (!inboundOrderDetails.Any())
+                            {
+                                return WebResponseContent.Instance.Error($"鏈壘鍒板搴旂殑鍏ュ簱鍗曟槑缁�");
+                            }
+                            // 鏇存柊鍏ュ簱鍗曟槑缁嗙姸鎬�
+                            foreach (var inboundOrderDetail in inboundOrderDetails)
+                            {
+                                // 妫�鏌ヨ鏄庣粏鏄惁宸插叏閮ㄥ叆搴�
+                                decimal totalStockQuantity = dt_StockInfo.Details
+                                    .Where(x => x.LinId == inboundOrderDetail.LinId && x.BatchNo == inboundOrderDetail.BatchNo)
+                                    .Sum(x => x.StockQuantity);
+
+                                decimal orderQuantity = Convert.ToDecimal(inboundOrderDetail.OrderQuantity);
+                                decimal receiptQuantity = Convert.ToDecimal(inboundOrderDetail.ReceiptQuantity);
+                                decimal overInQuantity = Convert.ToDecimal(inboundOrderDetail.OverInQuantity);
+
+                                // 鏇存柊鏀惰揣鏁伴噺
+                                inboundOrderDetail.OverInQuantity = totalStockQuantity += overInQuantity;
+
+                                // 妫�鏌ユ槸鍚﹀叏閮ㄥ畬鎴�
+                                if (inboundOrderDetail.OverInQuantity == inboundOrderDetail.OrderQuantity)
+                                {
+                                    inboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
+                                }
+                                else
+                                {
+                                    inboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Inbounding.ObjToInt();
+                                }
+                            }
+                            ///鏇存柊搴撳瓨鐘舵��
+                            dt_StockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+                            // 鏇存柊搴撳瓨鏄庣粏鐘舵��
+                            dt_StockInfo.Details.ForEach(x => x.Status = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt());
+                            try
+                            {
+                                _unitOfWorkManage.BeginTran();
+
+                                // 鏇存柊浠诲姟鐘舵��
+                                UpdateTaskStatus(task);
+
+                                // 鏇存柊璐т綅鐘舵��
+                                UpdateLocationStatus(dt_LocationInfo, lastStatus);
+
+                                // 鏇存柊搴撳瓨淇℃伅
+                                UpdateStockInfo(dt_StockInfo);
+
+                                // 娣诲姞璁板綍
+                                AddRecords(task, dt_StockInfo, dt_LocationInfo, lastStatus);
+
+                                // 鏇存柊鍏ュ簱鍗曟槑缁�
+                                if (inboundOrderDetails.Any())
+                                {
+                                    BaseDal.Db.Updateable(inboundOrderDetails).ExecuteCommand();
+
+                                    // 妫�鏌ュ叆搴撳崟鏄惁鍏ㄩ儴瀹屾垚
+                                    bool allCompleted = inboundOrder.Details.All(x =>
+                                        x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt());
+
+                                    if (allCompleted)
+                                    {
+                                        inboundOrder.OrderStatus = InboundStatusEnum.鍏ュ簱瀹屾垚.ObjToInt();
+                                    }
+                                    else
+                                    {
+                                        inboundOrder.OrderStatus = InboundStatusEnum.鍏ュ簱涓�.ObjToInt();
+                                    }
+                                }
+
+                                // 鏇存柊鍏ュ簱鍗�
+                                UpdateInboundOrder(inboundOrder, inboundOrderDetails.FirstOrDefault());
+
+                                // 鍗曟嵁鏁伴噺鍏ㄩ儴涓婃灦瀹屾垚锛屽鐞哤MS鍥炰紶
+                                if (inboundOrderDetails.Any(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()) && inboundOrder.System.Equals("ERP"))
+                                {
+                                    if(inboundOrder.OrderStatus == InboundStatusEnum.鍏ュ簱瀹屾垚.ObjToInt())
+                                    {
+                                        bool allCompleted = inboundOrder.Details.All(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt());
+                                        if (allCompleted)
+                                        {
+                                            foreach (var detail in inboundOrder.Details)
+                                            {
+                                                FeedBackInboundERP(inboundOrder.UpperOrderNo, detail.LinId);
+                                            }
+                                        }
+                                    }
+                                }
+                                if (inboundOrder.OrderStatus == InboundStatusEnum.鍏ュ簱瀹屾垚.ObjToInt() && inboundOrder.OrderType == 0 && inboundOrder.System.Equals("SMOM"))
+                                {
+
+                                }
+                                else if (inboundOrder.OrderStatus == InboundStatusEnum.鍏ュ簱瀹屾垚.ObjToInt() && inboundOrder.OrderType == 2 && inboundOrder.System.Equals("SMOM"))
+                                {
+                                    SendAllocateInfoToWMS(task, inboundOrder, dt_StockInfo);
+                                }
+
+                                _unitOfWorkManage.CommitTran();
+                                return WebResponseContent.Instance.OK();
+                            }
+                            catch (Exception ex)
+                            {
+                                _unitOfWorkManage.RollbackTran();
+                                throw new Exception($"鍏ュ簱澶勭悊澶辫触锛歿ex.Message}", ex);
+                            }
+
+                        }
+                        if (task.TaskType == TaskTypeEnum.SurplusReturn.ObjToInt() || task.TaskType == TaskTypeEnum.ReverseIn.ObjToInt())
+                        {
+                            return ReturnInbound(task, dt_StockInfo, dt_LocationInfo);
+                        }
+                        if (task.TaskType == TaskTypeEnum.InInventory.ObjToInt())
+                        {
+                            int lastStatus = dt_LocationInfo.LocationStatus;
+                            dt_LocationInfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt();
+                            dt_StockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+                            // 鏇存柊搴撳瓨鏄庣粏鐘舵��
+                            dt_StockInfo.Details.ForEach(x => x.Status = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt());
+                            _unitOfWorkManage.BeginTran();
+                            UpdateTaskStatus(task);
+                            UpdateLocationStatus(dt_LocationInfo, lastStatus);
+                            UpdateStockInfo(dt_StockInfo);
+                            AddRecords(task, dt_StockInfo, dt_LocationInfo, lastStatus);
+                            _unitOfWorkManage.CommitTran();
+                            return WebResponseContent.Instance.OK();
+
+                        }
+
+                    }
                     else
                     {
                         Dt_InboundOrder? inboundOrder = _inboundService.InbounOrderService.Db.Queryable<Dt_InboundOrder>().Where(x => x.OrderNo == dt_StockInfo.Details.FirstOrDefault().OrderNo).Includes(x => x.Details).First();
@@ -984,7 +1136,7 @@
             int lastStatus, Dt_InboundOrder inboundOrder, Dt_InboundOrderDetail inboundOrderDetail)
         {
             // 鏇存柊鍏ュ簱鍗曟槑缁嗙姸鎬�
-            UpdateInboundOrderDetails(stockInfo, inboundOrder, ref inboundOrderDetail);
+               UpdateInboundOrderDetails(stockInfo, inboundOrder, ref inboundOrderDetail);
             ///鏇存柊搴撳瓨鐘舵��
             stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
             // 鏇存柊搴撳瓨鏄庣粏鐘舵��
@@ -1007,21 +1159,21 @@
                 AddRecords(task, stockInfo, locationInfo, lastStatus);
 
                 // 鏇存柊鍏ュ簱鍗�
-                UpdateInboundOrder(inboundOrder, inboundOrderDetail);
+                    UpdateInboundOrder(inboundOrder, inboundOrderDetail);
 
-                // 鍗曟嵁鏁伴噺鍏ㄩ儴涓婃灦瀹屾垚锛屽鐞哤MS鍥炰紶
-                if (inboundOrderDetail.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt() && inboundOrder.System.Equals("ERP"))
-                {
-                    FeedBackInboundERP(inboundOrder.UpperOrderNo, inboundOrderDetail.LinId);
+                    // 鍗曟嵁鏁伴噺鍏ㄩ儴涓婃灦瀹屾垚锛屽鐞哤MS鍥炰紶
+                    if (inboundOrderDetail.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt() && inboundOrder.System.Equals("ERP"))
+                    {
+                            FeedBackInboundERP(inboundOrder.UpperOrderNo, inboundOrderDetail.LinId);
+                        }
+                    if (inboundOrder.OrderStatus == InboundStatusEnum.鍏ュ簱瀹屾垚.ObjToInt() && inboundOrder.OrderType == 0 && inboundOrder.System.Equals("SMOM"))
+                    {
+                        //SendInboundInfoToWMS(task, inboundOrder, stockInfo);
                 }
-                if (inboundOrder.OrderStatus == InboundStatusEnum.鍏ュ簱瀹屾垚.ObjToInt() && inboundOrder.OrderType == 0 && inboundOrder.System.Equals("SMOM"))
-                {
-                    //SendInboundInfoToWMS(task, inboundOrder, stockInfo);
-                }
-                else if (inboundOrder.OrderStatus == InboundStatusEnum.鍏ュ簱瀹屾垚.ObjToInt() && inboundOrder.OrderType == 2 && inboundOrder.System.Equals("SMOM"))
-                {
-                    SendAllocateInfoToWMS(task, inboundOrder, stockInfo);
-                }
+                    else if (inboundOrder.OrderStatus == InboundStatusEnum.鍏ュ簱瀹屾垚.ObjToInt() && inboundOrder.OrderType == 2 && inboundOrder.System.Equals("SMOM"))
+                    {
+                        SendAllocateInfoToWMS(task, inboundOrder, stockInfo);
+                    }
 
                 _unitOfWorkManage.CommitTran();
                 return WebResponseContent.Instance.OK();
@@ -1779,6 +1931,41 @@
                             return WebResponseContent.Instance.Error($"澶勭悊澶辫触: {ex.Message}");
                         }
                     }
+                    else if(warehouse.WarehouseCode.Contains("DW") || warehouse.WarehouseCode.Contains("YS"))
+                    {
+                        Dt_OutboundOrder inboundOrder = _outboundService.OutboundOrderService.Db.Queryable<Dt_OutboundOrder>()
+                        .Where(x => x.OrderNo == task.OrderNo)
+                        .Includes(x => x.Details)
+                        .First();
+
+                        if (inboundOrder == null) return WebResponseContent.Instance.Error("鏈壘鍒板嚭搴撳崟淇℃伅");
+
+                        Dt_OutboundOrderDetail outboundOrderDetail = new Dt_OutboundOrderDetail();
+                        foreach(var detail in stockInfo.Details)
+                        {
+                            outboundOrderDetail = _outboundService.OutboundOrderService.Db.Queryable<Dt_OutboundOrderDetail>()
+                            .Where(x => x.OrderId == inboundOrder.Id && x.BatchNo == detail.BatchNo)
+                            .First();
+                            if(outboundOrderDetail != null) break;
+
+                        }
+
+                        if (outboundOrderDetail.LocationName != null && outboundOrderDetail.LocationName != "")
+                        {
+                          foreach(var detail in stockInfo.Details)
+                          {
+                                outboundOrderDetail = _outboundService.OutboundOrderService.Db.Queryable<Dt_OutboundOrderDetail>()
+                                .Where(x => x.OrderId == inboundOrder.Id && x.BatchNo == detail.BatchNo && x.LocationName == stockInfo.LocationCode)
+                                .First();
+                                if (outboundOrderDetail != null) break;
+                           }
+                        }
+
+                        if (outboundOrderDetail == null) return WebResponseContent.Instance.Error("鏈壘鍒板嚭搴撳崟淇℃伅");
+                        DWANDYSUpdateOutboundOrderDetails(stockInfo, inboundOrder, ref outboundOrderDetail);
+                        // 3. 鎵ц鏍稿績鍑哄簱閫昏緫
+                        return ExecuteOutboundLogic(task, stockInfo, locationInfo, outboundOrderDetail, inboundOrder);
+                    }
                     else
                     {
                         Dt_OutboundOrder inboundOrder = _outboundService.OutboundOrderService.Db.Queryable<Dt_OutboundOrder>()
@@ -1872,8 +2059,15 @@
                 _outboundService.OutboundOrderDetailService.Repository.UpdateData(outboundOrderDetails);
 
                 // 鏇存柊搴撳瓨鐘舵�� 鍥炲簱鍗�
-                AddRetrueOrder(stockInfo, inboundOrder);
-
+                if(locationInfo.RoadwayNo.Contains("DW") || locationInfo.RoadwayNo.Contains("YS"))
+                {
+                    AddDWANDYSRetrueOrder(stockInfo, inboundOrder);
+                }
+                else
+                {
+                    AddRetrueOrder(stockInfo, inboundOrder);
+                }
+                   
                 // 鍖哄垎鍗曟嵁鏁版嵁鏉ユ簮鏇存柊璐т綅鐘舵��
                 if (inboundOrder.System == null)
                 {
@@ -1951,6 +2145,39 @@
                 {
                     inboundOrderDetail.OrderDetailStatus = OutboundStatusEnum.鍑哄簱涓�.ObjToInt();
                     inboundOrder.OrderStatus = OutboundStatusEnum.鍑哄簱涓�.ObjToInt();
+                }
+            }
+            if (inboundOrder.Details.Count == overCount)
+            {
+                inboundOrder.OrderStatus = OutboundStatusEnum.鍑哄簱瀹屾垚.ObjToInt();
+            }
+        }
+
+        //浣庢俯銆佽嵂姘�
+        private void DWANDYSUpdateOutboundOrderDetails(Dt_StockInfo stockInfo, Dt_OutboundOrder inboundOrder, ref Dt_OutboundOrderDetail inboundOrderDetail)
+        {
+            string BatchNo = inboundOrderDetail.BatchNo;
+            int overCount = inboundOrder.Details.Where(x => x.BatchNo == BatchNo).Count(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt());
+            //inboundOrderDetail = inboundOrder.Details.FirstOrDefault(x => x.BatchNo == stockInfo.Details.FirstOrDefault()?.BatchNo&&x.LPNNo==stockInfo.PalletCode);
+
+            foreach (var item in stockInfo.Details)
+            {
+                if (inboundOrderDetail == null) continue;
+
+                if(inboundOrderDetail.BatchNo == item.BatchNo)
+                {
+                    inboundOrderDetail.OverOutQuantity += item.OutboundQuantity;
+
+                    if (inboundOrderDetail.OverOutQuantity == inboundOrderDetail.OrderQuantity)
+                    {
+                        inboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
+                        overCount++;
+                    }
+                    else if (inboundOrderDetail.OrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt())
+                    {
+                        inboundOrderDetail.OrderDetailStatus = OutboundStatusEnum.鍑哄簱涓�.ObjToInt();
+                        inboundOrder.OrderStatus = OutboundStatusEnum.鍑哄簱涓�.ObjToInt();
+                    }
                 }
             }
             if (inboundOrder.Details.Count == overCount)
@@ -2221,8 +2448,7 @@
         private void AddRetrueOrder(Dt_StockInfo stockInfo, Dt_OutboundOrder outboundOrder)
         {
             Dt_StockInfoDetail stockInfoDetail = _stockService.StockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
-           .Where(x => x.StockId == stockInfo.Id)
-           .First();
+           .Where(x => x.StockId == stockInfo.Id).First();
             if (stockInfoDetail == null)
             {
                 throw new Exception("寤虹珛鍥炲簱鍗曟椂锛屾湭鎵惧埌璇ュ簱瀛樹俊鎭�");
@@ -2282,6 +2508,95 @@
                     DeleteAndMoveIntoHtStockStatus(stockInfo);
                 }
             }
+
+
+        }
+
+        //浣庢俯銆佽嵂姘村洖搴撳崟
+        private void AddDWANDYSRetrueOrder(Dt_StockInfo stockInfo, Dt_OutboundOrder outboundOrder)
+        {
+
+            List<Dt_StockInfoDetail> stockInfoDetails = _stockService.StockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+           .Where(x => x.StockId == stockInfo.Id).ToList();
+
+            Dt_ReturnOrder? lastReturnOrder = null; 
+            foreach (var stockInfoDetail in stockInfoDetails)
+            {
+                if (stockInfoDetail == null)
+                {
+                    throw new Exception("寤虹珛鍥炲簱鍗曟椂锛屾湭鎵惧埌璇ュ簱瀛樹俊鎭�");
+                }
+                if (outboundOrder.OrderType == OrderTypeEnum.鍙嶆嫞鍑哄簱鍗�.ObjToInt())
+                {
+                    Dt_ReturnOrder returnOrder = _returnOrderRepository.QueryFirst(x => x.LPNNo == stockInfo.PalletCode && x.LocationCode == stockInfo.LocationCode && x.OrderStatus == InOrderStatusEnum.鏈紑濮�.ObjToInt());
+                    if (returnOrder == null)
+                    {
+                        throw new Exception("鍙嶆嫞鍑哄簱鍚庯紝鏈壘鍒板搴斿弽鎷e洖搴撳崟淇℃伅");
+                    }
+                    stockInfo.LocationCode = "";
+                    stockInfo.StockStatus = StockStatusEmun.鍙嶆嫞鍏ュ簱.ObjToInt();
+                    stockInfo.Remark = "鍙嶆嫞鍏ュ簱";
+                    stockInfoDetail.OutboundQuantity = 0;
+                    stockInfoDetail.StockQuantity += returnOrder.OrderQuantity;
+                    stockInfoDetail.OrderNo = returnOrder.OrderNo;
+                }
+                else
+                {
+                    bool allowCompeted = stockInfo.Details.All(x => x.StockQuantity == x.OutboundQuantity);
+                    if (allowCompeted)
+                    {
+                        DeleteAndMoveIntoHtStockStatus(stockInfo);
+                    }
+                    else
+                    {
+                        decimal returnQuantity = stockInfoDetail.StockQuantity - stockInfoDetail.OutboundQuantity;
+                        if (returnQuantity > 0)
+                        {
+                            Dt_ReturnOrder returnOrder = new Dt_ReturnOrder
+                            {
+                                MaterielCode = stockInfoDetail.MaterielCode,
+                                MaterielName = stockInfoDetail.MaterielName,
+                                BatchNo = stockInfoDetail.BatchNo,
+                                OrderQuantity = returnQuantity,
+                                ReceiptQuantity = returnQuantity,
+                                OrderStatus = InOrderStatusEnum.鏈紑濮�.ObjToInt(),
+                                LinId = stockInfoDetail.LinId,
+                                LPNNo = stockInfo.PalletCode,
+                                Creater = "LK",
+                                CreateDate = DateTime.Now,
+                                OrderType = OrderTypeEnum.浣欐枡鍥炲簱鍗�.ObjToInt(),
+                                System = "WMS",
+                                Remark = stockInfoDetail.BatchNo
+                            };
+                            if(lastReturnOrder != null)
+                            {
+                                lastReturnOrder.Remark = lastReturnOrder.Remark + $", {returnOrder.BatchNo}";
+                                _returnOrderRepository.UpdateData(lastReturnOrder);
+                            }
+                            if (outboundOrder.System == "SMOM" && stockInfo.LocationCode != null)
+                            {
+                                returnOrder.LocationCode = stockInfo.LocationCode;
+                            }
+                            _unitOfWorkManage.BeginTran();
+                            if(lastReturnOrder == null)
+                            {
+                                _returnOrderRepository.AddData(returnOrder);
+                                lastReturnOrder = returnOrder;
+                            }
+                            stockInfo.LocationCode = "";
+                            stockInfo.StockStatus = StockStatusEmun.浣欐枡閫�搴�.ObjToInt();
+                            stockInfo.Remark = "浣欐枡閫�搴�";
+                            stockInfoDetail.OutboundQuantity = 0;
+                            stockInfoDetail.StockQuantity = returnQuantity;
+                            stockInfoDetail.OrderNo = lastReturnOrder.OrderNo;
+                            _stockService.StockInfoService.Repository.UpdateData(stockInfo);
+                            _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetail);
+                            _unitOfWorkManage.CommitTran();
+                        }
+                    }
+                }
+            }
+
 
         }
 
@@ -2356,8 +2671,7 @@
                         var matchedStockDetail = stockInfoDetails.FirstOrDefault(x => x.MaterielCode == outboundDetail.MaterielCode && x.BatchNo == outboundDetail.BatchNo);
                         if (matchedStockDetail == null)
                         {
-                            matchedStockDetail = stockInfoDetails.FirstOrDefault(x =>
-               x.MaterielCode == outboundDetail.MaterielCode);
+                            matchedStockDetail = stockInfoDetails.FirstOrDefault(x =>x.MaterielCode == outboundDetail.MaterielCode);
 
                             if (matchedStockDetail == null)
                             {

--
Gitblit v1.9.3