From 36226b8adcbfb46fe71fc9526134a54886b3312c Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期五, 17 十月 2025 23:21:32 +0800
Subject: [PATCH] 1

---
 新建文件夹/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/DeliveryOrderServices.cs |  168 ++++++++++++++++++++++++++-----------------------------
 1 files changed, 80 insertions(+), 88 deletions(-)

diff --git "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/DeliveryOrderServices.cs" "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/DeliveryOrderServices.cs"
index 874c196..2b13edc 100644
--- "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/DeliveryOrderServices.cs"
+++ "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/DeliveryOrderServices.cs"
@@ -1,4 +1,5 @@
 锘縰sing HslCommunication;
+using MailKit.Search;
 using Newtonsoft.Json;
 using System;
 using System.Collections.Generic;
@@ -25,7 +26,7 @@
 
 namespace WIDESEA_SquareCabinServices
 {
-    public class DeliveryOrderServices : ServiceBase<Dt_DeliveryOrder, IRepository<Dt_DeliveryOrder>>, IDeliveryOrderServices
+    public partial class DeliveryOrderServices : ServiceBase<Dt_DeliveryOrder, IRepository<Dt_DeliveryOrder>>, IDeliveryOrderServices
     {
         static string SearchDate = "";
         private readonly IBasicService _basicService;
@@ -34,8 +35,9 @@
         private readonly IInventoryInfoService _inventoryInfoService;
         private readonly IDeliveryOrderDetailServices _deliveryOrderDetailServices;
         private readonly ISupplyTaskService _supplyTaskService;
+        private readonly ICabinOrderServices _cabinOrderServices;
         public IRepository<Dt_DeliveryOrder> Repository => BaseDal;
-        public DeliveryOrderServices(IRepository<Dt_DeliveryOrder> BaseDal, IBasicService basicService, IUnitOfWorkManage unitOfWorkManage, IInventory_BatchServices inventory_BatchServices, IInventoryInfoService inventoryInfoService, IDeliveryOrderDetailServices deliveryOrderDetailServices, ISupplyTaskService supplyTaskService) : base(BaseDal)
+        public DeliveryOrderServices(IRepository<Dt_DeliveryOrder> BaseDal, IBasicService basicService, IUnitOfWorkManage unitOfWorkManage, IInventory_BatchServices inventory_BatchServices, IInventoryInfoService inventoryInfoService, IDeliveryOrderDetailServices deliveryOrderDetailServices, ISupplyTaskService supplyTaskService, ICabinOrderServices cabinOrderServices) : base(BaseDal)
         {
             _basicService = basicService;
             _unitOfWorkManage = unitOfWorkManage;
@@ -43,6 +45,7 @@
             _supplyTaskService = supplyTaskService;
             _inventory_BatchServices = inventory_BatchServices;
             _inventoryInfoService = inventoryInfoService;
+            _cabinOrderServices = cabinOrderServices;
         }
 
         /// <summary>
@@ -275,7 +278,7 @@
                                 return q.OrderBy(i => i.InDate).ToList();
                             };
 
-                            // 4锔忊儯鍒嗛厤鏁d欢锛堜紭鍏堢珛搴� Status=1锛�
+                            // 4锔忊儯鍒嗛厤鏁d欢锛堜紭鍏堢珛搴� Status=0锛�
                             decimal remainingPartial = partialQty;
                             if (remainingPartial > 0)
                             {
@@ -301,7 +304,7 @@
                                     };
                                     entityOrder.Details.Add(detail);
 
-                                    inv.OutboundQuantity += (float)use;
+                                    inv.OutboundQuantity += use;
                                     BaseDal.Db.Updateable(inv).ExecuteCommand();
 
                                     remainingPartial -= use;
@@ -332,7 +335,7 @@
                                         };
                                         entityOrder.Details.Add(detail);
 
-                                        inv.OutboundQuantity += (float)use;
+                                        inv.OutboundQuantity += use;
                                         BaseDal.Db.Updateable(inv).ExecuteCommand();
 
                                         remainingPartial -= use;
@@ -375,7 +378,7 @@
                                     };
                                     entityOrder.Details.Add(detail);
 
-                                    inv.OutboundQuantity += (float)useQty;
+                                    inv.OutboundQuantity += useQty;
                                     BaseDal.Db.Updateable(inv).ExecuteCommand();
 
                                     remainingFullBoxes -= useBoxes;
@@ -410,7 +413,7 @@
                                         };
                                         entityOrder.Details.Add(detail);
 
-                                        inv.OutboundQuantity += (float)useQty;
+                                        inv.OutboundQuantity += useQty;
                                         BaseDal.Db.Updateable(inv).ExecuteCommand();
 
                                         remainingFullBoxes -= useBoxes;
@@ -525,9 +528,16 @@
                             decimal orderQty = (decimal)item.order_qty;
 
                             //  2锔忊儯 鏌ョ墿鏂欏熀纭�淇℃伅锛堣幏鍙栫瑙勶級
-                            var medication = BaseDal.Db.Queryable<Dt_MedicineGoods>()
-                                .Where(m => m.Goods_no == item.goods_no)
+                            var medication = BaseDal.Db.Queryable<Dt_MaterielInfo>()
+                                .Where(m => m.MaterielCode == item.goods_no)
                                 .First();
+                            //濡傛灉鐗╂枡淇℃伅涓嶅瓨鍦紝璺宠繃鏁翠釜鍏ュ簱鍗�
+                            if (medication == null)
+                            {
+                                skipOrder = true;
+                                Console.WriteLine($"璺宠繃鍏ュ簱鍗� {outorder.order_no}锛屽師鍥狅細鏈壘鍒板晢鍝� [{item.goods_no}] 鐨勭墿鏂欎俊鎭��");
+                                break;
+                            }
 
 
                             //  鑻ョ墿鏂欎笉瀛樺湪鎴� MaterielSourceType 涓虹┖锛屽垯璺宠繃鏁翠釜鍑哄簱鍗�
@@ -595,7 +605,7 @@
                                     };
                                     entityOrder.Details.Add(detail);
 
-                                    inv.OutboundQuantity += (float)use;
+                                    inv.OutboundQuantity += use;
                                     BaseDal.Db.Updateable(inv).ExecuteCommand();
 
                                     remainingPartial -= use;
@@ -626,7 +636,7 @@
                                         };
                                         entityOrder.Details.Add(detail);
 
-                                        inv.OutboundQuantity += (float)use;
+                                        inv.OutboundQuantity += use;
                                         BaseDal.Db.Updateable(inv).ExecuteCommand();
 
                                         remainingPartial -= use;
@@ -669,7 +679,7 @@
                                     };
                                     entityOrder.Details.Add(detail);
 
-                                    inv.OutboundQuantity += (float)useQty;
+                                    inv.OutboundQuantity += useQty;
                                     BaseDal.Db.Updateable(inv).ExecuteCommand();
 
                                     remainingFullBoxes -= useBoxes;
@@ -704,7 +714,7 @@
                                         };
                                         entityOrder.Details.Add(detail);
 
-                                        inv.OutboundQuantity += (float)useQty;
+                                        inv.OutboundQuantity += useQty;
                                         BaseDal.Db.Updateable(inv).ExecuteCommand();
 
                                         remainingFullBoxes -= useBoxes;
@@ -785,10 +795,10 @@
                         string materialCode = "YY";//榛樿鍊�
                                                    //鑾峰彇褰撳墠璁㈠崟鐨勭涓�涓槑缁嗛」
                         var firstDetail = order.Details.FirstOrDefault();
-                        if (firstDetail?.MedicineGoods != null && !string.IsNullOrEmpty(firstDetail.MedicineGoods.MaterialCode))
+                        if (firstDetail?.MedicineGoods != null && !string.IsNullOrEmpty(firstDetail.MedicineGoods.MaterielErpType))
                         {
                             //濡傛灉鏉′欢婊¤冻锛屽皢鐗╂枡浠g爜璁剧疆涓虹涓�涓槑缁嗛」瀵瑰簲鐨勮嵂鍝佺墿鏂欎唬鐮�
-                            materialCode = firstDetail.MedicineGoods.MaterialCode;
+                            materialCode = firstDetail.MedicineGoods.MaterielErpType;
                         }
                         // 3. 缁勮 DTO
                         var ediDto = new TowcsDto.ToediOutInfo
@@ -803,8 +813,8 @@
                             {
                                 batchNo = d.Batch_num,
                                 productCode = d.Goods_no,
-                                productName = d.MedicineGoods?.Goods_spm,
-                                productSpecifications = d.MedicineGoods?.Model,
+                                productName = d.MedicineGoods?.MaterielName,
+                                productSpecifications = d.MedicineGoods?.MaterielModel,
                                 quantity = (int)d.Order_qty,
                                 //stocktakingDetails = order.Out_type == "3"
                                 //    ? new List<ToOutediInStock>
@@ -1065,7 +1075,7 @@
         }
 
 
-    
+
 
         /// <summary>
         /// 鎺ㄩ�佸紓甯镐俊鎭粰涓婃父绯荤粺 1.鍏ュ簱鍗曟帴鍙o紱2.鍏ュ簱鍗曟姤瀹屾垚鎺ュ彛锛�3.鍑哄簱鍗曟帴鍙o紱4.鍑哄簱鎶ュ畬鎴愭帴鍙o紱5.鑽搧鍩虹淇℃伅鍚屾鎺ュ彛锛�6.渚涘簲鍟嗕俊鎭帴鍙o紱7.瀹㈡埛淇℃伅鎺ュ彛锛�8.搴撳瓨鏌ヨ鎺ュ彛
@@ -1094,33 +1104,6 @@
             }
         }
 
-        public WebResponseContent GetPdDeliveryOrders(SaveModel saveModel)
-        {
-            WebResponseContent content = new WebResponseContent();
-            try
-            {
-                int pageNo = saveModel.MainData["pageNo"].ObjToInt();
-                string warehouseCode = saveModel.MainData["warehouseId"].ToString();
-                string orderNo = saveModel.MainData["orderNo"].ToString();
-                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);
-                }
-                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);
-                }
-
-                content.OK(data: dt_ReceiveOrders);
-            }
-            catch (Exception)
-            {
-
-                throw;
-            }
-            return content;
-        }
 
         public WebResponseContent GetDeliveryOrders(SaveModel saveModel)
         {
@@ -1137,7 +1120,7 @@
                 }
                 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 != "3" && x.Warehouse_no == warehouseCode).OrderByDescending(x => x.CreateDate).Includes(x => x.Details).ToPageList(pageNo, 5);
                 }
 
                 content.OK(data: dt_ReceiveOrders);
@@ -1149,7 +1132,13 @@
             }
             return content;
         }
-
+        /// <summary>
+        /// 鏌ヨ鍑哄簱/鐩樼偣鍗曡鎯�
+        /// </summary>
+        /// <param name="pageNo"></param>
+        /// <param name="orderNo"></param>
+        /// <param name="isPick"></param>
+        /// <returns></returns>
         public WebResponseContent GetDeliveryOrderDetail(int pageNo, string orderNo, bool isPick)
         {
             WebResponseContent content = new WebResponseContent();
@@ -1162,25 +1151,29 @@
             content.OK(data: cabinOrderDetails);
             return content;
         }
-        public WebResponseContent MatPicking(SaveModel saveModel)
+        public WebResponseContent OutFinish(SaveModel saveModel)
         {
             WebResponseContent content = new WebResponseContent();
             try
             {
-                var LocationCode = saveModel.MainData["LocationCode"].ToString();
-                var orderNo = saveModel.MainData["orderNo"].ToString();
-                var batchNo = saveModel.MainData["batchNo"].ToString();
-                var Inqty = saveModel.MainData["Inqty"].ObjToInt();
-                var warehouseCode = saveModel.MainData["warehouseCode"].ToString();
-                Dt_DeliveryOrder cabinOrder = BaseDal.Db.Queryable<Dt_DeliveryOrder>().Where(x => x.Out_no == orderNo && x.Warehouse_no == warehouseCode && x.Out_type == "3").Includes(x => x.Details).First();
-                if (cabinOrder == null) return WebResponseContent.Instance.Error($"鐩樼偣鍗曞凡瀹屾垚");
-                Dt_DeliveryOrderDetail cabinOrderDetail = cabinOrder.Details.Where(x => x.Batch_num == batchNo && x.Reservoirarea == warehouseCode).First();
-                if (cabinOrderDetail == null) return WebResponseContent.Instance.Error($"鐩樼偣鍗曟槑缁嗗凡瀹屾垚");
+                var LocationCode = saveModel.MainData["locationCode"].ToString();
+                var TaskId = saveModel.MainData["taskId"].ObjToInt();
+                Dt_SupplyTask supplyTask = _supplyTaskService.Repository.QueryFirst(x => x.TaskId == TaskId && x.TaskStatus == SupplyStatusEnum.NewOut.ObjToInt());
+                if (supplyTask == null) throw new Exception("褰撳墠鍑哄簱浠诲姟宸插畬鎴�");
+                if (supplyTask.LocationCode != LocationCode) throw new Exception($"褰撳墠鍑哄簱璐т綅銆恵LocationCode}銆戜笌浠诲姟鍒嗛厤璐т綅涓嶅尮閰�");
+                supplyTask.TaskStatus = SupplyStatusEnum.OutFinish.ObjToInt();
+
+                Dt_DeliveryOrder cabinOrder = BaseDal.Db.Queryable<Dt_DeliveryOrder>().Where(x => x.Out_no == supplyTask.OrderNo && x.Warehouse_no == supplyTask.WarehouseCode).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);
                 if (materielInfo == null) return WebResponseContent.Instance.Error($"璇风淮鎶ょ墿鏂欑紪鍙枫�恵cabinOrderDetail.Goods_no}銆戠殑鐗╂枡淇℃伅");
-                cabinOrderDetail.Order_Outqty += Inqty;
+                cabinOrderDetail.Order_Outqty += supplyTask.StockQuantity;
                 if (cabinOrderDetail.Order_Outqty > cabinOrderDetail.Order_qty)
-                    return WebResponseContent.Instance.Error($"瀹炵洏鏁伴噺涓嶅彲瓒呭嚭璐﹂潰鏁伴噺");
+                    return WebResponseContent.Instance.Error($"鍑哄簱鏁伴噺涓嶅彲瓒呭嚭鍗曟嵁鏁伴噺");
+
 
                 #region 澶勭悊鍑哄簱鍗曪紝璐т綅锛屽簱瀛橈紝搴撳瓨鎵规淇℃伅
                 _unitOfWorkManage.BeginTran();
@@ -1197,54 +1190,51 @@
                 {
                     _deliveryOrderDetailServices.Repository.UpdateData(cabinOrderDetail);
                 }
-                var cabinOrder1 = BaseDal.Db.Queryable<Dt_DeliveryOrder>().Where(x => x.Out_no == cabinOrder.Out_no && x.Out_type == "3").Includes(x => x.Details).First();
+                var cabinOrder1 = BaseDal.Db.Queryable<Dt_DeliveryOrder>().Where(x => x.Out_no == cabinOrder.Out_no && x.Out_type != "3").Includes(x => x.Details).First();
                 if (cabinOrder1.Details == null || cabinOrder1.Details.Count < 1) cabinOrder.OutStatus = "宸插畬鎴�";
-                if (cabinOrder.OutStatus == "宸插畬鎴�")
-                    Repository.DeleteAndMoveIntoHty(cabinOrder, OperateTypeEnum.鑷姩瀹屾垚);
-                else
-                    Repository.UpdateData(cabinOrder);
+                Repository.UpdateData(cabinOrder);
                 #endregion
 
                 #region 搴撳瓨
                 Dt_InventoryInfo inventoryInfo = _inventoryInfoService.Repository.QueryFirst(x => x.BatchNo == cabinOrderDetail.Batch_num && x.MaterielCode == cabinOrderDetail.Goods_no && x.LocationCode == LocationCode);
                 if (inventoryInfo == null) return WebResponseContent.Instance.Error($"鏈壘鍒拌揣浣嶃�恵LocationCode}銆戠殑搴撳瓨淇℃伅");
-                inventoryInfo.SupplyQuantity += Inqty;
-                _inventoryInfoService.UpdateData(inventoryInfo);
+                inventoryInfo.StockQuantity -= supplyTask.StockQuantity;
+                if (inventoryInfo.StockQuantity <= 0)
+                    _inventoryInfoService.DeleteData(inventoryInfo);
+                else
+                    _inventoryInfoService.UpdateData(inventoryInfo);
                 #endregion
 
-                #region 浠诲姟璁板綍
-                Dt_SupplyTask supplyTask = new Dt_SupplyTask()
+                #region 璐т綅
+                var location = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == LocationCode);
+                if (location == null) return WebResponseContent.Instance.Error($"璇风淮鎶よ揣浣嶇紪鍙枫�恵LocationCode}銆戠殑璐т綅淇℃伅");
+                if (location.EnableStatus == EnableStatusEnum.Disable.ObjToInt())
+                    return WebResponseContent.Instance.Error($"璐т綅缂栧彿銆恵LocationCode}銆戝凡绂佺敤锛岃鎭㈠姝e父鍐嶄娇鐢�");
+                Dt_InventoryInfo inventoryInfo1 = _inventoryInfoService.Repository.QueryFirst(x => x.LocationCode == LocationCode);
+                if (inventoryInfo1 == null)
                 {
-                    WarehouseCode = cabinOrderDetail.Reservoirarea,
-                    BatchNo = inventoryInfo.BatchNo,
-                    MaterielName = inventoryInfo.MaterielName,
-                    MaterielCode = inventoryInfo.MaterielCode,
-                    MaterielSpec = inventoryInfo.MaterielSpec,
-                    TaskType = TaskTypeEnum.OutInventory.ObjToInt(),
-                    CreateDate = DateTime.Now,
-                    Creater = App.User.UserName,
-                    LocationCode = LocationCode,
-                    OrderNo = cabinOrder.Out_no,
-                    StockQuantity = inventoryInfo.StockQuantity,
-                    SupplyQuantity = Inqty,
-                    Remark = "鐩樼偣"
-                };
-                _supplyTaskService.AddData(supplyTask);
+                    location.LocationStatus = LocationStatusEnum.Free.ObjToInt();
+                    _basicService.LocationInfoService.UpdateData(location);
+                }
                 #endregion
+
+                _supplyTaskService.UpdateData(supplyTask);
 
                 #region 搴撳瓨鎵规
                 Dt_Inventory_Batch inventory_Batch = _inventory_BatchServices.Repository.QueryFirst(x => x.BatchNo == inventoryInfo.BatchNo && x.MaterielCode == inventoryInfo.MaterielCode);
                 if (inventory_Batch != null)
                 {
-                    inventory_Batch.SupplyQuantity += Inqty;
-                    _inventory_BatchServices.UpdateData(inventory_Batch);
+                    inventory_Batch.StockQuantity -= supplyTask.StockQuantity;
+                    if (inventory_Batch.StockQuantity <= 0)
+                        _inventory_BatchServices.DeleteData(inventory_Batch);
+                    else
+                        _inventory_BatchServices.UpdateData(inventory_Batch);
                 }
                 #endregion
 
                 _unitOfWorkManage.CommitTran();
                 #endregion
-
-                content.OK(cabinOrderDetail.Order_Outqty.ToString());
+                content.OK();
             }
             catch (Exception ex)
             {
@@ -1253,7 +1243,8 @@
             }
             return content;
         }
-        public WebResponseContent FeedbackOut(SaveModel saveModel)
+
+        public WebResponseContent MatPicking(SaveModel saveModel)
         {
             WebResponseContent content = new WebResponseContent();
             try
@@ -1324,6 +1315,7 @@
                     MaterielName = inventoryInfo.MaterielName,
                     MaterielCode = inventoryInfo.MaterielCode,
                     MaterielSpec = inventoryInfo.MaterielSpec,
+                    TaskStatus = SupplyStatusEnum.OutFinish.ObjToInt(),
                     TaskType = TaskTypeEnum.OutPick.ObjToInt(),
                     CreateDate = DateTime.Now,
                     Creater = App.User.UserName,

--
Gitblit v1.9.3