From c30ac3ad95328c1a34661ecde471e4215df9dab3 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期五, 17 十月 2025 19:54:03 +0800
Subject: [PATCH] 添加盘点功能、添加立方智能库补货功能(入库平库调拨出库,立库调拨入库)

---
 新建文件夹/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/DeliveryOrderServices.cs |  305 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 296 insertions(+), 9 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 3454eb6..9b662bd 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"
@@ -5,12 +5,18 @@
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using WIDESEA_Common.LocationEnum;
+using WIDESEA_Common.OrderEnum;
+using WIDESEA_Common.TaskEnum;
 using WIDESEA_Core;
 using WIDESEA_Core.BaseRepository;
 using WIDESEA_Core.BaseServices;
+using WIDESEA_Core.Enums;
 using WIDESEA_Core.Helper;
 using WIDESEA_DTO.SquareCabin;
+using WIDESEA_IBasicService;
 using WIDESEA_ISquareCabinServices;
+using WIDESEA_IWMsInfoServices;
 using WIDESEA_Model.Models;
 using static WIDESEA_DTO.SquareCabin.OrderDto;
 
@@ -18,12 +24,26 @@
 
 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 = "";
-
-        public DeliveryOrderServices(IRepository<Dt_DeliveryOrder> BaseDal) : base(BaseDal)
+        private readonly IBasicService _basicService;
+        private readonly IUnitOfWorkManage _unitOfWorkManage;
+        private readonly IInventory_BatchServices _inventory_BatchServices;
+        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, ICabinOrderServices cabinOrderServices) : base(BaseDal)
         {
+            _basicService = basicService;
+            _unitOfWorkManage = unitOfWorkManage;
+            _deliveryOrderDetailServices = deliveryOrderDetailServices;
+            _supplyTaskService = supplyTaskService;
+            _inventory_BatchServices = inventory_BatchServices;
+            _inventoryInfoService = inventoryInfoService;
+            _cabinOrderServices = cabinOrderServices;
         }
 
         /// <summary>
@@ -282,7 +302,7 @@
                                     };
                                     entityOrder.Details.Add(detail);
 
-                                    inv.OutboundQuantity += (float)use;
+                                    inv.OutboundQuantity += use;
                                     BaseDal.Db.Updateable(inv).ExecuteCommand();
 
                                     remainingPartial -= use;
@@ -313,7 +333,7 @@
                                         };
                                         entityOrder.Details.Add(detail);
 
-                                        inv.OutboundQuantity += (float)use;
+                                        inv.OutboundQuantity += use;
                                         BaseDal.Db.Updateable(inv).ExecuteCommand();
 
                                         remainingPartial -= use;
@@ -356,7 +376,7 @@
                                     };
                                     entityOrder.Details.Add(detail);
 
-                                    inv.OutboundQuantity += (float)useQty;
+                                    inv.OutboundQuantity += useQty;
                                     BaseDal.Db.Updateable(inv).ExecuteCommand();
 
                                     remainingFullBoxes -= useBoxes;
@@ -391,7 +411,7 @@
                                         };
                                         entityOrder.Details.Add(detail);
 
-                                        inv.OutboundQuantity += (float)useQty;
+                                        inv.OutboundQuantity += useQty;
                                         BaseDal.Db.Updateable(inv).ExecuteCommand();
 
                                         remainingFullBoxes -= useBoxes;
@@ -511,7 +531,7 @@
 
                             // 鏇存柊鏄庣粏鐘舵��
                             BaseDal.Db.Updateable<Dt_DeliveryOrderDetail>()
-                              .SetColumns(d => new Dt_DeliveryOrderDetail { Status = 1,OotDetailStatus="宸插畬鎴�" })
+                              .SetColumns(d => new Dt_DeliveryOrderDetail { Status = 1, OotDetailStatus = "宸插畬鎴�" })
                               .Where(d => d.DeliveryOrderId == order.Id && d.Status == 0)
                               .ExecuteCommand();
 
@@ -1097,6 +1117,273 @@
             }
         }
 
-       
+        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)
+        {
+            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 GetDeliveryOrderDetail(int pageNo, string orderNo, bool isPick)
+        {
+            WebResponseContent content = new WebResponseContent();
+            Dt_DeliveryOrder cabinOrder = new Dt_DeliveryOrder();
+            if (isPick)
+                cabinOrder = Db.Queryable<Dt_DeliveryOrder>().Includes(x => x.Details).First(x => x.Out_no == orderNo && x.Out_type == "3");
+            else
+                cabinOrder = Db.Queryable<Dt_DeliveryOrder>().Includes(x => x.Details).First(x => x.Out_no == orderNo && x.Out_type != "3");
+            List<Dt_DeliveryOrderDetail>? cabinOrderDetails = cabinOrder.Details?.Where(x => x.Reservoirarea == pageNo.ToString()).ToList();
+            content.OK(data: cabinOrderDetails);
+            return content;
+        }
+        public WebResponseContent MatPicking(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($"鐩樼偣鍗曟槑缁嗗凡瀹屾垚");
+                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;
+                if (cabinOrderDetail.Order_Outqty > cabinOrderDetail.Order_qty)
+                    return WebResponseContent.Instance.Error($"瀹炵洏鏁伴噺涓嶅彲瓒呭嚭璐﹂潰鏁伴噺");
+
+                #region 澶勭悊鍑哄簱鍗曪紝璐т綅锛屽簱瀛橈紝搴撳瓨鎵规淇℃伅
+                _unitOfWorkManage.BeginTran();
+
+                #region 鍑哄簱鍗�
+                cabinOrder.OutStatus = "寮�濮�";
+                cabinOrderDetail.OotDetailStatus = "寮�濮�";
+                if (cabinOrderDetail.Order_Outqty == cabinOrderDetail.Order_qty)
+                {
+                    cabinOrderDetail.OotDetailStatus = "宸插畬鎴�";
+                    _deliveryOrderDetailServices.Repository.DeleteAndMoveIntoHty(cabinOrderDetail, OperateTypeEnum.鑷姩瀹屾垚);
+                }
+                else
+                {
+                    _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();
+                if (cabinOrder1.Details == null || cabinOrder1.Details.Count < 1) cabinOrder.OutStatus = "宸插畬鎴�";
+                if (cabinOrder.OutStatus == "宸插畬鎴�")
+                    Repository.DeleteAndMoveIntoHty(cabinOrder, OperateTypeEnum.鑷姩瀹屾垚);
+                else
+                    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);
+                #endregion
+
+                #region 浠诲姟璁板綍
+                Dt_SupplyTask supplyTask = new Dt_SupplyTask()
+                {
+                    WarehouseCode = cabinOrderDetail.Reservoirarea,
+                    BatchNo = inventoryInfo.BatchNo,
+                    MaterielName = inventoryInfo.MaterielName,
+                    MaterielCode = inventoryInfo.MaterielCode,
+                    MaterielSpec = inventoryInfo.MaterielSpec,
+                    TaskType = TaskTypeEnum.OutInventory.ObjToInt(),
+                    TaskStatus = SupplyStatusEnum.CheckFinish.ObjToInt(),
+                    CreateDate = DateTime.Now,
+                    Creater = App.User.UserName,
+                    LocationCode = LocationCode,
+                    OrderNo = cabinOrder.Out_no,
+                    StockQuantity = inventoryInfo.StockQuantity,
+                    SupplyQuantity = Inqty,
+                    Remark = "鐩樼偣"
+                };
+                _supplyTaskService.AddData(supplyTask);
+                #endregion
+
+                #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);
+                }
+                #endregion
+
+                _unitOfWorkManage.CommitTran();
+                #endregion
+
+                content.OK(cabinOrderDetail.Order_Outqty.ToString());
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                content.Error(ex.Message);
+            }
+            return content;
+        }
+        public WebResponseContent FeedbackOut(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($"鍑哄簱鍗曟槑缁嗗凡瀹屾垚");
+                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;
+                if (cabinOrderDetail.Order_Outqty > cabinOrderDetail.Order_qty)
+                    return WebResponseContent.Instance.Error($"鍑哄簱鏁伴噺涓嶅彲瓒呭嚭鍗曟嵁鏁伴噺");
+
+                #region 澶勭悊鍑哄簱鍗曪紝璐т綅锛屽簱瀛橈紝搴撳瓨鎵规淇℃伅
+                _unitOfWorkManage.BeginTran();
+
+                #region 鍑哄簱鍗�
+                cabinOrder.OutStatus = "寮�濮�";
+                cabinOrderDetail.OotDetailStatus = "寮�濮�";
+                if (cabinOrderDetail.Order_Outqty == cabinOrderDetail.Order_qty)
+                {
+                    cabinOrderDetail.OotDetailStatus = "宸插畬鎴�";
+                    _deliveryOrderDetailServices.Repository.DeleteAndMoveIntoHty(cabinOrderDetail, OperateTypeEnum.鑷姩瀹屾垚);
+                }
+                else
+                {
+                    _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();
+                if (cabinOrder1.Details == null || cabinOrder1.Details.Count < 1) cabinOrder.OutStatus = "宸插畬鎴�";
+                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.StockQuantity -= Inqty;
+                if (inventoryInfo.StockQuantity <= 0)
+                    _inventoryInfoService.DeleteData(inventoryInfo);
+                else
+                    _inventoryInfoService.UpdateData(inventoryInfo);
+                #endregion
+
+                #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)
+                {
+                    location.LocationStatus = LocationStatusEnum.Free.ObjToInt();
+                    _basicService.LocationInfoService.UpdateData(location);
+                }
+                #endregion
+
+                #region 浠诲姟璁板綍
+                Dt_SupplyTask supplyTask = new Dt_SupplyTask()
+                {
+                    WarehouseCode = cabinOrderDetail.Reservoirarea,
+                    BatchNo = inventoryInfo.BatchNo,
+                    MaterielName = inventoryInfo.MaterielName,
+                    MaterielCode = inventoryInfo.MaterielCode,
+                    MaterielSpec = inventoryInfo.MaterielSpec,
+                    TaskStatus = SupplyStatusEnum.OutFinish.ObjToInt(),
+                    TaskType = TaskTypeEnum.OutPick.ObjToInt(),
+                    CreateDate = DateTime.Now,
+                    Creater = App.User.UserName,
+                    LocationCode = location.LocationCode,
+                    OrderNo = cabinOrder.Out_no,
+                    StockQuantity = Inqty,
+                    SupplyQuantity = 0,
+                    Remark = "鍑哄簱"
+                };
+                _supplyTaskService.AddData(supplyTask);
+                #endregion
+
+                #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.StockQuantity -= Inqty;
+                    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());
+            }
+            catch (Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                content.Error(ex.Message);
+            }
+            return content;
+        }
     }
 }

--
Gitblit v1.9.3