From 189ef97da64b5e3156199320c28e897c19b06eb9 Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期四, 16 一月 2025 17:20:19 +0800
Subject: [PATCH] 入库上报优化

---
 代码管理/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs |   99 ++++++++++++++++++++++++++-----------------------
 1 files changed, 53 insertions(+), 46 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
index 875c1e5..1edf744 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService.cs"
@@ -198,15 +198,20 @@
 
                 stockInfo.LocationCode = locationInfo.LocationCode;
 
-                #region 绌虹鍏ュ簱/鎷i�夊洖搴�
-                if (task.TaskType == TaskTypeEnum.InEmpty.ObjToInt() || task.TaskType == TaskTypeEnum.InPick.ObjToInt())
+                #region 绌虹鍏ュ簱/鎷i�夊洖搴�/鐢熶骇閫�鏂�
+                if (task.TaskType == TaskTypeEnum.InEmpty.ObjToInt() || task.TaskType == TaskTypeEnum.InPick.ObjToInt() || task.TaskType==TaskTypeEnum.ProductionReturn.ObjToInt())
                 {
                     stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
                     task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
+                    stockInfo.Details.ForEach(x =>
+                    {
+                        x.Status = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
+                    });
                     _unitOfWorkManage.BeginTran();
                     BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? OperateTypeEnum.浜哄伐瀹屾垚 : OperateTypeEnum.鑷姩瀹屾垚);
                     _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, stockInfo.PalletType, LocationStatusEnum.InStock, stockInfo.WarehouseId);
                     _stockRepository.StockInfoRepository.UpdateData(stockInfo);
+                    _stockRepository.StockInfoDetailRepository.UpdateData(stockInfo.Details);
                     _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, lastStatus, LocationStatusEnum.InStock, LocationChangeType.InboundCompleted);
                     _unitOfWorkManage.CommitTran();
                     return WebResponseContent.Instance.OK();
@@ -214,51 +219,54 @@
                 #endregion
 
                 Dt_InboundOrder? inboundOrder = _inboundRepository.InboundOrderRepository.Db.Queryable<Dt_InboundOrder>().Where(x => x.InboundOrderNo == stockInfo.Details.FirstOrDefault().OrderNo).Includes(x => x.Details).First();
-                if (inboundOrder == null)
-                {
-                    return WebResponseContent.Instance.Error($"瀵瑰簲鍏ュ簱鍗曚笉瀛樺湪");
-                }
-                //鏌ヨ鍘熷畬鎴愮殑鍏ュ簱鏄庣粏鏁伴噺
-                int overCount = inboundOrder.Details.Where(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).ToList().Count;
                 Dt_InboundOrderDetail? inboundOrderDetail = null;
-                if (stockInfo.StockStatus == StockStatusEmun.鍏ュ簱纭.ObjToInt())
+                //鏍囧噯鍏ュ簱娴佺▼鏌ユ壘鍏ュ簱鍗曟嵁
+                if (inboundOrder != null && stockInfo.StockStatus == StockStatusEmun.鍏ュ簱纭.ObjToInt())
                 {
-                    inboundOrderDetail = inboundOrder.Details.FirstOrDefault(x => x.RowNo == stockInfo.Details.FirstOrDefault()?.InboundOrderRowNo);
-                    foreach (var item in stockInfo.Details)
+                    //鏌ヨ鍘熷畬鎴愮殑鍏ュ簱鏄庣粏鏁伴噺
+                    int overCount = inboundOrder.Details.Where(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).ToList().Count;
+                    if (stockInfo.StockStatus == StockStatusEmun.鍏ュ簱纭.ObjToInt())
                     {
-                        if (inboundOrderDetail == null)
+                        inboundOrderDetail = inboundOrder.Details.FirstOrDefault(x => x.RowNo == stockInfo.Details.FirstOrDefault()?.InboundOrderRowNo);
+                        foreach (var item in stockInfo.Details)
                         {
-                            continue;
-                        }
-                        ERPInboundDetailModel detailModel = new ERPInboundDetailModel()
-                        {
-                            ExpiryDate = item.EffectiveDate ?? "",
-                            LocationCode = warehouse.WarehouseCode,
-                            MaterialsCode = item.MaterielCode,
-                            MfgDate = item.ProductionDate ?? "",
-                            QtyCustoms = "0",
-                            Quantity = item.StockQuantity.ToString(),
-                            Rack = stockInfo.LocationCode,
-                            ReceiptCode = inboundOrder.UpperOrderNo,
-                            ReceiptSerNo = item.InboundOrderRowNo.ToString()
-                        };
-                        inboundOrderDetail.OverInQuantity += item.StockQuantity;
-                        if (inboundOrderDetail.OverInQuantity == inboundOrderDetail.OrderQuantity)
-                        {
-                            inboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
-                            overCount += 1;
-                        }
-                        else if (inboundOrderDetail.OrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt())
-                        {
-                            inboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Inbounding.ObjToInt();
+                            if (inboundOrderDetail == null)
+                            {
+                                continue;
+                            }
+                            ERPInboundDetailModel detailModel = new ERPInboundDetailModel()
+                            {
+                                ExpiryDate = item.EffectiveDate ?? "",
+                                LocationCode = warehouse.WarehouseCode,
+                                MaterialsCode = item.MaterielCode,
+                                MfgDate = item.ProductionDate ?? "",
+                                QtyCustoms = "0",
+                                Quantity = item.StockQuantity.ToString(),
+                                Rack = stockInfo.LocationCode,
+                                ReceiptCode = inboundOrder.UpperOrderNo,
+                                ReceiptSerNo = item.InboundOrderRowNo.ToString()
+                            };
+                            inboundOrderDetail.OverInQuantity += item.StockQuantity;
+                            if (inboundOrderDetail.OverInQuantity == inboundOrderDetail.OrderQuantity)
+                            {
+                                inboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
+                                overCount += 1;
+                            }
+                            else if (inboundOrderDetail.OrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt())
+                            {
+                                inboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Inbounding.ObjToInt();
+                            }
                         }
                     }
+                    if (inboundOrder.Details.Count == overCount)
+                    {
+                        inboundOrder.OrderStatus = InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt();
+                    }
+                    if (inboundOrder.OrderStatus == InOrderStatusEnum.鏈紑濮�.ObjToInt())
+                    {
+                        inboundOrder.OrderStatus = InOrderStatusEnum.鍏ュ簱涓�.ObjToInt();
+                    }
                 }
-                if (inboundOrder.Details.Count == overCount)
-                {
-                    inboundOrder.OrderStatus = InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt();
-                }
-
                 if ((stockInfo.StockStatus == StockStatusEmun.鍏ュ簱纭.ObjToInt() || stockInfo.StockStatus == StockStatusEmun.鎵嬪姩缁勭洏鍏ュ簱纭.ObjToInt()) && warehouse.WarehouseCode == WarehouseEnum.HA64.ToString())
                 {
                     foreach (var model in stockInfo.Details)
@@ -266,7 +274,6 @@
                         TestSynStock(new TestToolSynInfo() { ToolCode = model.BatchNo, MaterialName = model.MaterielName, Life = int.TryParse(model.Remark, out int val) ? val : 1000 });
                     }
                 }
-
                 //娴嬭瘯鏋跺叆搴撳簱瀛樼姸鎬�
                 if (task.TaskType == TaskTypeEnum.Inbound.ObjToInt() && warehouse.WarehouseCode == WarehouseEnum.HA64.ToString() && stockInfo.StockStatus != StockStatusEmun.鎵嬪姩缁勭洏鍏ュ簱纭.ObjToInt())
                 {
@@ -275,14 +282,13 @@
                 else
                 {
                     stockInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
-
                 }
                 stockInfo.Details.ForEach(x =>
                 {
                     x.Status = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
                 });
                 //鏇存柊浠诲姟鐘舵��
-                task.TaskStatus = (int)TaskStatusEnum.Finish;
+                task.TaskStatus = TaskStatusEnum.Finish.ObjToInt();
                 _unitOfWorkManage.BeginTran();
                 BaseDal.DeleteAndMoveIntoHty(task, App.User.UserId > 0 ? OperateTypeEnum.浜哄伐瀹屾垚 : OperateTypeEnum.鑷姩瀹屾垚);
                 _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, stockInfo.PalletType, LocationStatusEnum.InStock, stockInfo.WarehouseId);
@@ -290,13 +296,14 @@
                 _stockRepository.StockInfoDetailRepository.UpdateData(stockInfo.Details);
                 _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, lastStatus, LocationStatusEnum.InStock, LocationChangeType.InboundCompleted);
                 _recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, stockInfo.Details, stockInfo.Details.Sum(x => x.StockQuantity), stockInfo.Details.Sum(x => x.StockQuantity), StockChangeTypeEnum.Inbound, taskNum);
-                _inboundRepository.InboundOrderRepository.UpdateData(inboundOrder);
-                if (inboundOrderDetail != null)
+                if (inboundOrder != null)
                 {
+                    _inboundRepository.InboundOrderRepository.UpdateData(inboundOrder);
                     _inboundRepository.InboundOrderDetailRepository.UpdateData(inboundOrderDetail);
                 }
                 _unitOfWorkManage.CommitTran();
-                if (inboundOrder.OrderStatus == InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt())
+                //瀛樺湪鍏ュ簱鍗曞苟鐘舵�佷负瀹屾垚鐘舵�佹帹閫佽嚦ERP
+                if (inboundOrder != null && inboundOrder.OrderStatus == InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt())
                     _inboundOrderService.FeedbackInboundOrder(inboundOrder);
                 return WebResponseContent.Instance.OK();
             }

--
Gitblit v1.9.3