From 23f7d0e0cf31ea6a7cde81bf23ef07091bd4f3a7 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期一, 03 十一月 2025 14:22:35 +0800
Subject: [PATCH] 添加人工触发调拨单

---
 新建文件夹/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/extend/Allocat.cs |  155 +++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 112 insertions(+), 43 deletions(-)

diff --git "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/extend/Allocat.cs" "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/extend/Allocat.cs"
index d840053..5b88b7e 100644
--- "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/extend/Allocat.cs"
+++ "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/extend/Allocat.cs"
@@ -6,9 +6,11 @@
 using System.Net.NetworkInformation;
 using System.Text;
 using System.Threading.Tasks;
+using WIDESEA_Common;
 using WIDESEA_Common.OrderEnum;
 using WIDESEA_Common.StockEnum;
 using WIDESEA_Common.TaskEnum;
+using WIDESEA_Common.WareHouseEnum;
 using WIDESEA_Core;
 using WIDESEA_ISquareCabinServices;
 using WIDESEA_Model.Models;
@@ -18,7 +20,7 @@
 {
     public partial class DeliveryOrderServices
     {
-        #region 鍒涘缓骞冲簱璋冩嫧鍑哄簱鍗曘�佺珛搴撹皟鎷ㄥ叆搴撳崟
+        #region 鍒涘缓骞冲簱璋冩嫧鍑哄簱鍗曘�佺珛搴撹皟鎷ㄥ叆搴撳崟  鍦ㄧ珛搴撳嚭搴撳畬鎴愬悗璋冪敤  鍦ㄥ嚭搴撳畬鎴愬悗灏嗙墿鏂欒〃涓殑涓氬姟鏁伴噺锛圔usiness_qty锛夊噺鍘诲疄闄呭嚭搴撴暟閲�
         /// <summary>
         /// 鍒涘缓璋冩嫧鍗�
         /// </summary>
@@ -29,51 +31,62 @@
             WebResponseContent response = new WebResponseContent();
             try
             {
+                string WareCode = WarehouseEnum.澶т欢搴�.ObjToInt().ToString("000");
+                if (materielInfo.Business_qty >= materielInfo.MinQty) return response;
+                Dt_Tactics tactics = _tacticsService.Repository.QueryFirst(x => x.TacticeName == "鍑哄簱绛栫暐");
                 List<Dt_SupplyTask> supplyTasks = new List<Dt_SupplyTask>();
-                List<Dt_InventoryInfo> dt_InventoryInfos = _inventoryInfoService.Repository.QueryData(x => x.MaterielCode == materielInfo.MaterielCode && x.StockStatus == StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt() && x.StockQuantity > x.OutboundQuantity).OrderBy(x => x.InDate).ToList();
-                decimal Qty = 0;
+                //// 鏌ヨ澶т欢搴撲腑鍙敤鐨勫簱瀛�
+                List<Dt_InventoryInfo> dt_InventoryInfos = _inventoryInfoService.Repository.QueryData(x => x.MaterielCode == materielInfo.MaterielCode && x.StockStatus == StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt() && x.AvailableQuantity > 0 && x.WarehouseCode == WareCode);
+                if (dt_InventoryInfos.Count < 1) throw new Exception($"鐗╂枡缂栧彿銆恵materielInfo.MaterielCode}銆戝ぇ浠跺簱鏃犲簱瀛橈紒璇峰強鏃惰ˉ鍏呭簱瀛橈紒");
+                if (tactics.SelectTactice == TacticsEnum.ComeOutonFirstTime.ObjToInt())
+                    dt_InventoryInfos = dt_InventoryInfos.OrderBy(x => x.ValidityPeriod).ToList();
+                else
+                    dt_InventoryInfos = dt_InventoryInfos.OrderBy(x => x.InDate).ToList();
+                Dt_DeliveryOrder deliveryOrder = new Dt_DeliveryOrder()
+                {
+                    Out_no = DateTime.Now.ToString("yyMMddHHmmss"),
+                    Warehouse_no = WareCode,
+                    Out_type = OutOrderTypeEnum.Allocate.ObjToInt().ToString(),
+                    OutStatus = "鏂板缓",
+                    Details = new List<Dt_DeliveryOrderDetail>()
+                };
                 foreach (var item in dt_InventoryInfos)
                 {
+                    decimal Qty = 0;
                     if (materielInfo.Business_qty >= materielInfo.MinQty) break;
-                    item.StockStatus = StockStatusEmun.鍑哄簱閿佸畾.ObjToInt();
+                    //item.StockStatus = StockStatusEmun.鍑哄簱閿佸畾.ObjToInt();
                     while (item.StockQuantity > item.OutboundQuantity && materielInfo.Business_qty < materielInfo.MinQty)
                     {
                         Qty += materielInfo.BoxQty;
                         materielInfo.Business_qty += materielInfo.BoxQty;
                         item.OutboundQuantity += materielInfo.BoxQty;
                     }
-                }
-
-                #region 娣诲姞璋冩嫧鍑哄簱鍗�
-                Dt_DeliveryOrder deliveryOrder = new Dt_DeliveryOrder()
-                {
-                    Out_no = DateTime.Now.ToString("yyMMddHHmmss"),
-                    Out_type = OutOrderTypeEnum.Allocate.ObjToInt().ToString(),
-                    OutStatus = "鏂板缓",
-                    Details = new List<Dt_DeliveryOrderDetail>()
-                };
-                dt_InventoryInfos = dt_InventoryInfos.Where(X => X.StockStatus == StockStatusEmun.鍑哄簱閿佸畾.ObjToInt()).ToList();
-                foreach (var item in dt_InventoryInfos.GroupBy(x => x.BatchNo))
-                {
-                    Dt_DeliveryOrderDetail deliveryOrderDetail = new Dt_DeliveryOrderDetail()
+                    item.AvailableQuantity = item.StockQuantity - item.OutboundQuantity;
+                    #region 娣诲姞璋冩嫧鍑哄簱鍗�
+                    Dt_DeliveryOrderDetail? deliveryOrderDetail = deliveryOrder.Details.FirstOrDefault(x => x.Batch_num == item.BatchNo);
+                    if (deliveryOrderDetail == null)
                     {
-                        Batch_num = item.Key,
-                        Order_Outqty = 0,
-                        Order_qty = item.Select(x => x.OutboundQuantity).Sum(),
-                        CreateDate = DateTime.Now,
-                        Creater = App.User.UserName ?? "System",
-                        Goods_no = item.First().MaterielCode,
-                        OotDetailStatus = "鏂板缓",
-                        Status = 2,
-                        Reservoirarea = item.First().WarehouseCode
-                    };
-                    deliveryOrder.Details.Add(deliveryOrderDetail);
-                }
-                #endregion
-
-                #region 娣诲姞璋冩嫧鍑哄簱浠诲姟
-                foreach (var item in dt_InventoryInfos)
-                {
+                        deliveryOrderDetail = new Dt_DeliveryOrderDetail()
+                        {
+                            Batch_num = item.BatchNo,
+                            Order_Outqty = 0,
+                            Order_qty = Qty,
+                            CreateDate = DateTime.Now,
+                            Creater = App.User.UserName ?? "System",
+                            Goods_no = item.MaterielCode,
+                            OotDetailStatus = "鏂板缓",
+                            Status = 2,
+                            Reservoirarea = WareCode
+                        };
+                        deliveryOrder.Details.Add(deliveryOrderDetail);
+                    }
+                    else
+                    {
+                        deliveryOrderDetail.Order_qty += Qty;
+                    }
+                    deliveryOrder.Details.Add(deliveryOrderDetail); 
+                    #endregion
+                    #region 娣诲姞璋冩嫧鍑哄簱浠诲姟
                     Dt_SupplyTask supplyTask = new Dt_SupplyTask()
                     {
                         WarehouseCode = item.WarehouseCode,
@@ -87,12 +100,67 @@
                         Creater = App.User.UserName ?? "System",
                         LocationCode = item.LocationCode,
                         OrderNo = deliveryOrder.Out_no,
-                        StockQuantity = item.OutboundQuantity,
+                        StockQuantity = Qty,
                         SupplyQuantity = 0,
                         Remark = "璋冩嫧鍑哄簱"
                     };
-                    supplyTasks.Add(supplyTask);
+                    supplyTasks.Add(supplyTask); 
+                    #endregion
                 }
+                #region 澶т欢搴撹ˉ绔嬪簱鍚庣珛搴撲笟鍔″簱瀛樻暟杩樻槸灏忎簬绔嬪簱鏈�灏忓簱瀛樻暟锛屾坊鍔犳彁绀轰俊鎭�
+                //娣诲姞鎶ヨ淇℃伅
+                if (materielInfo.Business_qty < materielInfo.MinQty)
+                {
+                    _messageInfoService.AddMessageInfo(MessageGroupByEnum.InventoryLowAlarm, $"鐗╂枡鍚嶇О:{materielInfo.MaterielName}", $"銆愮墿鏂欑紪鐮亄materielInfo.MaterielCode}宸茬敓鎴愯皟鎷ㄥ嚭鍏ュ簱鍗曪紝璇疯繘琛屽嚭鍏ュ簱娴佺▼銆傚ぇ浠跺簱搴撳瓨杩囦綆锛佽鍙婃椂琛ュ厖搴撳瓨锛併��");
+                }
+                else
+                {
+                    _messageInfoService.AddMessageInfo(MessageGroupByEnum.InventoryLowAlarm, $"鐗╂枡鍚嶇О:{materielInfo.MaterielName}", $"銆愮墿鏂欑紪鐮亄materielInfo.MaterielCode}宸茬敓鎴愯皟鎷ㄥ嚭鍏ュ簱鍗曪紝璇疯繘琛屽嚭鍏ュ簱娴佺▼銆�");
+                }
+                #endregion
+                #region 娣诲姞璋冩嫧鍑哄簱鍗�
+                //dt_InventoryInfos = dt_InventoryInfos.Where(X => X.StockStatus == StockStatusEmun.鍑哄簱閿佸畾.ObjToInt()).ToList();
+                //foreach (var item in dt_InventoryInfos.GroupBy(x => x.BatchNo)) //杩欓噷鎸夋壒娆″垎缁勪簡
+                //{
+                //    Dt_DeliveryOrderDetail deliveryOrderDetail = new Dt_DeliveryOrderDetail()
+                //    {
+                //        Batch_num = item.Key,
+                //        Order_Outqty = 0,
+                //        Order_qty = item.Select(x => x.OutboundQuantity).Sum(),
+                //        CreateDate = DateTime.Now,
+                //        Creater = App.User.UserName ?? "System",
+                //        Goods_no = item.First().MaterielCode,
+                //        OotDetailStatus = "鏂板缓",
+                //        Status = 2,
+                //        Reservoirarea = item.First().WarehouseCode
+                //    };
+                //    deliveryOrder.Warehouse_no = item.First().WarehouseCode;
+                //    deliveryOrder.Details.Add(deliveryOrderDetail);
+                //}
+                #endregion
+
+                #region 娣诲姞璋冩嫧鍑哄簱浠诲姟
+                //foreach (var item in dt_InventoryInfos)
+                //{
+                //    Dt_SupplyTask supplyTask = new Dt_SupplyTask()
+                //    {
+                //        WarehouseCode = item.WarehouseCode,
+                //        BatchNo = item.BatchNo,
+                //        MaterielName = item.MaterielName,
+                //        MaterielCode = item.MaterielCode,
+                //        MaterielSpec = item.MaterielSpec,
+                //        TaskStatus = SupplyStatusEnum.NewOut.ObjToInt(),
+                //        TaskType = TaskTypeEnum.AllocatOut.ObjToInt(),
+                //        CreateDate = DateTime.Now,
+                //        Creater = App.User.UserName ?? "System",
+                //        LocationCode = item.LocationCode,
+                //        OrderNo = deliveryOrder.Out_no,
+                //        StockQuantity = item.OutboundQuantity,
+                //        SupplyQuantity = 0,
+                //        Remark = "璋冩嫧鍑哄簱"
+                //    };
+                //    supplyTasks.Add(supplyTask);
+                //}
                 #endregion
 
                 #region 娣诲姞璋冩嫧鍏ュ簱鍗�
@@ -111,7 +179,6 @@
                         Reservoirarea = cabinOrder.Warehouse_no,
                         Goods_no = item.Goods_no,
                         Order_qty = item.Order_qty,
-                        Order_Inqty = item.Order_qty,
                         Batch_num = item.Batch_num,
                         OrderDetailStatus = "鏂板缓",
                         Status = 0
@@ -120,16 +187,18 @@
                 }
                 #endregion
 
-                _unitOfWorkManage.BeginTran();
+                //_unitOfWorkManage.BeginTran();
+                _materielInfoService.UpdateData(materielInfo);
                 _inventoryInfoService.Repository.UpdateData(dt_InventoryInfos);
                 _supplyTaskService.AddData(supplyTasks);
-                BaseDal.Db.InsertNav(deliveryOrder).Include(x => x.Details).ExecuteCommand();
-                _cabinOrderServices.Repository.Db.InsertNav(cabinOrder).Include(x => x.Details).ExecuteCommand();
-                _unitOfWorkManage.CommitTran();
+                if (deliveryOrder.Details.Count > 1) BaseDal.Db.InsertNav(deliveryOrder).Include(x => x.Details).ExecuteCommand();
+                if (cabinOrder.Details.Count > 1) _cabinOrderServices.Repository.Db.InsertNav(cabinOrder).Include(x => x.Details).ExecuteCommand();
+                //_unitOfWorkManage.CommitTran();
             }
             catch (Exception ex)
             {
-                _unitOfWorkManage.RollbackTran();
+                //_unitOfWorkManage.RollbackTran();
+                _messageInfoService.AddMessageInfo(MessageGroupByEnum.InventoryLowAlarm, "澶т欢搴撹ˉ璐х珛搴�", ex.Message);
                 response.Error(ex.Message);
             }
             return response;

--
Gitblit v1.9.3