From 3d3598eea1b93ed7f977d077355ebbcc1270ba38 Mon Sep 17 00:00:00 2001
From: yanjinhui <3306209981@qq.com>
Date: 星期日, 02 十一月 2025 12:17:33 +0800
Subject: [PATCH] 优化

---
 新建文件夹/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/extend/Check.cs |  106 ++++++++++++++++++++++++++++++-----------------------
 1 files changed, 60 insertions(+), 46 deletions(-)

diff --git "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/extend/Check.cs" "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/extend/Check.cs"
index 0566819..9679eb4 100644
--- "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/extend/Check.cs"
+++ "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/extend/Check.cs"
@@ -29,12 +29,15 @@
             try
             {
                 List<Dt_DeliveryOrder> deliveryOrders = new List<Dt_DeliveryOrder>();
-                List<Dt_SupplyTask> supplyTasks = new List<Dt_SupplyTask>();
+                //List<Dt_SupplyTask> supplyTasks = new List<Dt_SupplyTask>();
+                List<Dt_SupplyTask> supplyTasks1 = new List<Dt_SupplyTask>();
                 List<Dt_InventoryInfo> _InventoryInfos = new List<Dt_InventoryInfo>();
                 List<Dt_Inventory_Batch> inventory_Batches = _inventory_BatchServices.Repository.QueryData(x => keys.Contains(x.Id));
                 foreach (var item in inventory_Batches)
                 {
-                    supplyTasks = _supplyTaskService.Repository.QueryData(x => x.MaterielCode == item.MaterielCode && x.BatchNo == item.BatchNo && x.TaskStatus == SupplyStatusEnum.NewCheck.ObjToInt()).ToList();
+                    var supplyTasks = _supplyTaskService.Repository.QueryData(x => x.MaterielCode == item.MaterielCode && x.BatchNo == item.BatchNo && x.TaskStatus == SupplyStatusEnum.NewCheck.ObjToInt()).ToList();
+                    if (supplyTasks.Count > 0) throw new Exception($"鐗╂枡缂栧彿銆恵item.MaterielCode}銆戞壒娆″彿銆恵item.BatchNo}銆戝凡瀛樺湪鐩樼偣浠诲姟锛岃鍏堝畬鎴愬綋鍓嶇洏鐐逛换鍔�");
+                    supplyTasks = _supplyTaskService.Repository.QueryData(x => x.MaterielCode == item.MaterielCode && x.BatchNo == item.BatchNo && x.TaskStatus == SupplyStatusEnum.NewOut.ObjToInt()).ToList();
                     if (supplyTasks.Count > 0) throw new Exception($"鐗╂枡缂栧彿銆恵item.MaterielCode}銆戞壒娆″彿銆恵item.BatchNo}銆戝凡瀛樺湪鐩樼偣浠诲姟锛岃鍏堝畬鎴愬綋鍓嶇洏鐐逛换鍔�");
                     List<Dt_InventoryInfo> inventoryInfos = _inventoryInfoService.Repository.QueryData(x => item.MaterielCode == x.MaterielCode && x.BatchNo == item.BatchNo);
                     if (inventoryInfos.Count > 0)
@@ -44,7 +47,7 @@
                             Dt_DeliveryOrder deliveryOrder = new Dt_DeliveryOrder()
                             {
                                 Out_no = item.MaterielCode + "_" + item.BatchNo,
-                                Out_type = "3",
+                                Out_type = "20",
                                 OutStatus = "鏂板缓",
                                 Warehouse_no = items.Key,
                                 Details = new List<Dt_DeliveryOrderDetail>()
@@ -65,8 +68,6 @@
                             deliveryOrder.Details.Add(deliveryOrderDetail);
                             deliveryOrders.Add(deliveryOrder);
                             #region 鍒涘缓鐩樼偣浠诲姟
-                            //if (items.Key != "001")// 闈炵珛搴撳尯鍩熼渶瑕佸垱寤虹洏鐐逛换鍔�
-                            //{
                             foreach (var inventory in items)
                             {
                                 Dt_SupplyTask supplyTask = new Dt_SupplyTask()
@@ -86,7 +87,7 @@
                                     SupplyQuantity = 0,
                                     Remark = "鐩樼偣"
                                 };
-                                supplyTasks.Add(supplyTask);
+                                supplyTasks1.Add(supplyTask);
                                 _InventoryInfos.Add(inventory);
                             }
                             //}
@@ -100,7 +101,7 @@
                 });
                 _unitOfWorkManage.BeginTran();
                 _inventoryInfoService.UpdateData(_InventoryInfos);
-                _supplyTaskService.AddData(supplyTasks);
+                _supplyTaskService.AddData(supplyTasks1);
                 BaseDal.Db.InsertNav(deliveryOrders)
                         .Include(x => x.Details)
                         .ExecuteCommand();
@@ -133,11 +134,11 @@
                 List<Dt_DeliveryOrder> dt_ReceiveOrders = new List<Dt_DeliveryOrder>();
                 if (string.IsNullOrEmpty(orderNo))
                 {
-                    dt_ReceiveOrders = Db.Queryable<Dt_DeliveryOrder>().Where(x => (x.OutStatus == "鏂板缓" || x.OutStatus == "寮�濮�") && x.Warehouse_no == warehouseCode && x.Out_type == "3").Includes(x => x.Details).OrderByDescending(x => x.CreateDate).ToPageList(pageNo, 5);
+                    dt_ReceiveOrders = Db.Queryable<Dt_DeliveryOrder>().Where(x => (x.OutStatus == "鏂板缓" || x.OutStatus == "寮�濮�") && x.Warehouse_no == warehouseCode && x.Out_type == "20").Includes(x => x.Details).OrderByDescending(x => x.CreateDate).ToPageList(pageNo, 5);
                 }
                 else
                 {
-                    dt_ReceiveOrders = Db.Queryable<Dt_DeliveryOrder>().Where(x => (x.Out_no.Contains(orderNo) || x.Client_no.Contains(orderNo)) && (x.OutStatus == "鏂板缓" || x.OutStatus == "寮�濮�") && x.Out_type == "3" && x.Warehouse_no == warehouseCode).OrderByDescending(x => x.CreateDate).Includes(x => x.Details).ToPageList(pageNo, 5);
+                    dt_ReceiveOrders = Db.Queryable<Dt_DeliveryOrder>().Where(x => (x.Out_no.Contains(orderNo) || x.Client_no.Contains(orderNo)) && (x.OutStatus == "鏂板缓" || x.OutStatus == "寮�濮�") && x.Out_type == "20" && x.Warehouse_no == warehouseCode).OrderByDescending(x => x.CreateDate).Includes(x => x.Details).ToPageList(pageNo, 5);
                 }
 
                 content.OK(data: dt_ReceiveOrders);
@@ -218,24 +219,24 @@
             try
             {
                 supplyTask.TaskStatus = SupplyStatusEnum.CheckFinish.ObjToInt();
-                Dt_DeliveryOrder cabinOrder = BaseDal.Db.Queryable<Dt_DeliveryOrder>().Where(x => x.Out_no == supplyTask.OrderNo && x.Warehouse_no == supplyTask.WarehouseCode && x.Out_type == "3").Includes(x => x.Details).First();
+                Dt_DeliveryOrder cabinOrder = BaseDal.Db.Queryable<Dt_DeliveryOrder>().Where(x => x.Out_no == supplyTask.OrderNo && x.Warehouse_no == supplyTask.WarehouseCode && x.Out_type == "20").Includes(x => x.Details).First();
                 if (cabinOrder == null) return WebResponseContent.Instance.Error($"鐩樼偣鍗曞凡瀹屾垚");
                 Dt_DeliveryOrderDetail cabinOrderDetail = cabinOrder.Details.Where(x => x.Batch_num == supplyTask.BatchNo && x.Reservoirarea == supplyTask.WarehouseCode && x.Goods_no == supplyTask.MaterielCode).First();
                 if (cabinOrderDetail == null) return WebResponseContent.Instance.Error($"鐩樼偣鍗曟槑缁嗗凡瀹屾垚");
-                Dt_MaterielInfo materielInfo = _basicService.MaterielInfoService.Repository.QueryFirst(x => x.MaterielCode == cabinOrderDetail.Goods_no);
+                Dt_MaterielInfo materielInfo = _materielInfoService.Repository.QueryFirst(x => x.MaterielCode == cabinOrderDetail.Goods_no);
                 if (materielInfo == null) return WebResponseContent.Instance.Error($"璇风淮鎶ょ墿鏂欑紪鍙枫�恵cabinOrderDetail.Goods_no}銆戠殑鐗╂枡淇℃伅");
                 cabinOrderDetail.Order_Outqty += supplyTask.SupplyQuantity;
-                //if (cabinOrderDetail.Order_Outqty > cabinOrderDetail.Order_qty)
-                //    return WebResponseContent.Instance.Error($"瀹炵洏鏁伴噺涓嶅彲瓒呭嚭璐﹂潰鏁伴噺");
-
-                #region 澶勭悊鍑哄簱鍗曪紝璐т綅锛屽簱瀛橈紝搴撳瓨鎵规淇℃伅
-                _unitOfWorkManage.BeginTran();
+                #region 骞冲簱鐩樼偣鍙兘鍑虹幇鏁寸宸紓
+                if (supplyTask.WarehouseCode == WarehouseEnum.澶т欢搴�.ObjToInt().ToString("000"))
+                {
+                    var Qty = supplyTask.SupplyQuantity % materielInfo.BoxQty;
+                    if (Qty != 0) return WebResponseContent.Instance.Error($"澶т欢搴撳簱瀛樹负鏁寸锛佺洏鐐规暟閲忎笉鑳藉瓨鍦ㄦ暎浠�");
+                }
+                #endregion
 
                 #region 淇敼鐩樼偣鍗�
                 cabinOrder.OutStatus = "寮�濮�";
                 cabinOrderDetail.OotDetailStatus = "寮�濮�";
-                Repository.UpdateData(cabinOrder);
-                _deliveryOrderDetailServices.Repository.UpdateData(cabinOrderDetail);
                 #endregion
 
                 #region 搴撳瓨
@@ -250,38 +251,23 @@
                     inventoryInfo = _inventoryInfoService.Repository.QueryFirst(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no && x.WarehouseCode == supplyTask.WarehouseCode);
                 }
                 inventoryInfo.SupplyQuantity = supplyTask.SupplyQuantity;
-                _inventoryInfoService.UpdateData(inventoryInfo);
-                #endregion
-
-                #region 浠诲姟璁板綍
-                //_supplyTaskService.UpdateData(supplyTask);
-                _supplyTaskService.Repository.DeleteAndMoveIntoHty(supplyTask, OperateTypeEnum.鑷姩瀹屾垚);
                 #endregion
 
                 #region 鍒ゆ柇褰撳墠鐗╂枡鎵规鐨勭洏鐐逛换鍔℃槸鍚﹀叏閮ㄥ畬鎴�
-                List<Dt_SupplyTask> supplyTasks = _supplyTaskService.Repository.QueryData(x => x.MaterielCode == supplyTask.MaterielCode && x.BatchNo == supplyTask.BatchNo && x.TaskStatus == SupplyStatusEnum.NewCheck.ObjToInt() && x.WarehouseCode == supplyTask.WarehouseCode).ToList();
-                if (supplyTasks.Count < 1)
-                {
-                    #region 瀹屾垚鐩樼偣鍗�
-                    cabinOrder.OutStatus = "宸插畬鎴�";
-                    cabinOrder.Details.ForEach(x =>
-                    {
-                        x.OotDetailStatus = "宸插畬鎴�";
-                    });
-                    Repository.DeleteAndMoveIntoHty(cabinOrder, OperateTypeEnum.鑷姩瀹屾垚);
-                    _deliveryOrderDetailServices.Repository.DeleteAndMoveIntoHty(cabinOrder.Details, OperateTypeEnum.鑷姩瀹屾垚);
-                    #endregion
-                }
-                supplyTasks = _supplyTaskService.Repository.QueryData(x => x.MaterielCode == supplyTask.MaterielCode && x.BatchNo == supplyTask.BatchNo && x.TaskStatus == SupplyStatusEnum.NewCheck.ObjToInt()).ToList();
-                if (supplyTasks.Count < 1)
+                List<Dt_SupplyTask> supplyTasks = _supplyTaskService.Repository.QueryData(x => x.MaterielCode == supplyTask.MaterielCode && x.BatchNo == supplyTask.BatchNo && x.TaskStatus == SupplyStatusEnum.NewCheck.ObjToInt() && x.WarehouseCode == supplyTask.WarehouseCode && x.TaskId != supplyTask.TaskId).ToList();
+                List<Dt_SupplyTask> supplyTasks1 = _supplyTaskService.Repository.QueryData(x => x.MaterielCode == supplyTask.MaterielCode && x.BatchNo == supplyTask.BatchNo && x.TaskStatus == SupplyStatusEnum.NewCheck.ObjToInt() && x.TaskId != supplyTask.TaskId).ToList();
+                Dt_Inventory_Batch inventory_Batch = new Dt_Inventory_Batch();
+                List<Dt_InventoryInfo> inventoryInfos = new List<Dt_InventoryInfo>();
+                if (supplyTasks1.Count < 1)
                 {
                     #region 鏌ユ壘搴撳瓨
-                    var inventoryInfos = _inventoryInfoService.Repository.QueryData(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no);
-                    var SupplyQuantitys = inventoryInfos.Select(x => x.SupplyQuantity).ToList().Sum();
+                    inventoryInfos = _inventoryInfoService.Repository.QueryData(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no && x.Id != inventoryInfo.Id);
+                    var SupplyQuantitys = inventoryInfos.Sum(x => x.SupplyQuantity) + supplyTask.SupplyQuantity;
                     #endregion
 
                     #region 搴撳瓨鎵规
-                    Dt_Inventory_Batch inventory_Batch = _inventory_BatchServices.Repository.QueryFirst(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no);
+                    inventory_Batch = _inventory_BatchServices.Repository.QueryFirst(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no);
+                    //濡傛灉鐩樼偣鏁板拰鎵规鎬绘暟瀵逛笂浜嗭紝鐩樼偣鏁拌祴鍊间负0锛岃祴鍊煎氨娣诲姞鐩樼偣鏁�
                     if (SupplyQuantitys == inventory_Batch.StockQuantity)
                     {
                         foreach (var item in inventoryInfos)
@@ -290,20 +276,48 @@
                             item.SupplyQuantity = 0;
                             item.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
                         }
-                        _inventoryInfoService.UpdateData(inventoryInfos);
+                        inventoryInfo.StockQuantity = supplyTask.SupplyQuantity;
+                        inventoryInfo.SupplyQuantity = 0;
+                        inventoryInfo.StockStatus = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
                     }
                     else
                     {
                         inventory_Batch.SupplyQuantity = SupplyQuantitys;
-                        _inventory_BatchServices.UpdateData(inventory_Batch);
                     }
-                #endregion
+                    #endregion
                 }
+                _unitOfWorkManage.BeginTran();
+                #region 澶勭悊鐩樼偣鍗�
+                if (supplyTasks.Count < 1)
+                {
+                    #region 瀹屾垚鐩樼偣鍗�
+                    cabinOrder.OutStatus = "宸插畬鎴�";
+                    cabinOrder.Details.ForEach(x =>
+                    {
+                        x.OotDetailStatus = "宸插畬鎴�";
+                    });
+                    _deliveryOrderDetailServices.Repository.DeleteAndMoveIntoHty(cabinOrder.Details, OperateTypeEnum.鑷姩瀹屾垚);
+                    cabinOrder.Details = null;
+                    BaseDal.DeleteAndMoveIntoHty(cabinOrder, OperateTypeEnum.鑷姩瀹屾垚);
 
+                    #endregion
+                }
+                else
+                {
+                    BaseDal.UpdateData(cabinOrder);
+                    _deliveryOrderDetailServices.Repository.UpdateData(cabinOrderDetail);
+                }
+                #endregion
+                _inventoryInfoService.UpdateData(inventoryInfo);
+                _supplyTaskService.Repository.DeleteAndMoveIntoHty(supplyTask, OperateTypeEnum.鑷姩瀹屾垚);
+                if (inventoryInfos.Count >= 1)
+                {
+                    _inventoryInfoService.UpdateData(inventoryInfos);
+                    _inventory_BatchServices.UpdateData(inventory_Batch);
+                }
                 _unitOfWorkManage.CommitTran();
                 #endregion
                 content.OK();
-                #endregion
             }
             catch (Exception ex)
             {

--
Gitblit v1.9.3