From c2cbdb583fe34643c5dfde10bd1d51573887fb8e Mon Sep 17 00:00:00 2001
From: heshaofeng <heshaofeng@hnkhzn.com>
Date: 星期日, 16 十一月 2025 18:35:34 +0800
Subject: [PATCH] 提交

---
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_InboundService/InboundOrderService.cs |   66 ++++++++++++++++++++++----------
 1 files changed, 45 insertions(+), 21 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_InboundService/InboundOrderService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_InboundService/InboundOrderService.cs"
index 96bb475..d9e296f 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_InboundService/InboundOrderService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_InboundService/InboundOrderService.cs"
@@ -19,6 +19,7 @@
 using WIDESEA_IRecordService;
 using WIDESEA_IStockService;
 using WIDESEA_Model.Models;
+using WIDESEA_Model.Models.Basic;
 
 namespace WIDESEA_InboundService
 {
@@ -35,9 +36,11 @@
         private readonly IRepository<Dt_InboundOrderDetail> _inboundOrderDetailRepository;
         private readonly IRepository<Dt_StockInfoDetail> _stockDetailRepository;
         private readonly IRepository<Dt_InboundOrder> _inboundOrderRepository;
+        private readonly IRepository<Dt_WarehouseArea> _warehouseAreaRepository;
+        private readonly IRepository<Dt_StockInfo> _stockRepository;
         public IRepository<Dt_InboundOrder> Repository => BaseDal;
 
-        public InboundOrderService(IRepository<Dt_InboundOrder> BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_InboundOrderDetail> inboundOrderDetailRepository, IRepository<Dt_Task> taskRepository, IStockService stockService, IInboundOrderDetailService inboundOrderDetailService, IMaterialUnitService materialUnitService,IRepository<Dt_StockInfoDetail> stockDetailRepository,IRepository<Dt_InboundOrder> inboundOrderRepository) : base(BaseDal)
+        public InboundOrderService(IRepository<Dt_InboundOrder> BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_InboundOrderDetail> inboundOrderDetailRepository, IRepository<Dt_Task> taskRepository, IStockService stockService, IInboundOrderDetailService inboundOrderDetailService, IMaterialUnitService materialUnitService, IRepository<Dt_StockInfoDetail> stockDetailRepository, IRepository<Dt_InboundOrder> inboundOrderRepository, IRepository<Dt_WarehouseArea> warehouseAreaRepository,IRepository<Dt_StockInfo> stockRepository) : base(BaseDal)
         {
             _mapper = mapper;
             _unitOfWorkManage = unitOfWorkManage;
@@ -48,6 +51,8 @@
             _materialUnitService = materialUnitService;
             _stockDetailRepository = stockDetailRepository;
             _inboundOrderRepository = inboundOrderRepository;
+            _warehouseAreaRepository = warehouseAreaRepository;
+            _stockRepository = stockRepository;
         }
 
         public async Task<WebResponseContent> ReceiveInboundOrder(List<Dt_InboundOrder> models, int operateType)
@@ -56,7 +61,7 @@
             {
                 return operateType switch
                 {
-                    1 =>await AddInboundOrder(models),
+                    1 => await AddInboundOrder(models),
                     2 => await UpdateInboundOrder(models),
                     3 => DeleteInboundOrder(models),
 
@@ -86,8 +91,8 @@
                     foreach (var item in model.Details)
                     {
                         var purchaseToStockResult = await _materialUnitService.ConvertPurchaseToStockAsync(item.MaterielCode, item.BarcodeQty);
-                        item.Unit= purchaseToStockResult.Unit;  
-                        item.OrderQuantity=purchaseToStockResult.Quantity;  
+                        item.Unit = purchaseToStockResult.Unit;
+                        item.OrderQuantity = purchaseToStockResult.Quantity;
                     }
 
                     model.InboundOrderNo = CreateCodeByRule(nameof(RuleCodeEnum.InboundOrderRule));
@@ -317,6 +322,14 @@
                 (bool, string, object?) result2 = ModelValidate.ValidateModelData(materielGroupDTO);
                 if (!result2.Item1) return content = WebResponseContent.Instance.Error(result2.Item2);
 
+                //  materielGroupDTO.WarehouseCode
+                var code = _warehouseAreaRepository.Db.Queryable<Dt_WarehouseArea>().Where(x => x.Code == materielGroupDTO.WarehouseType).Select(x=>x.Code).First();
+                if(string.IsNullOrEmpty(code))
+                {
+                    return content = WebResponseContent.Instance.Error($"浠撳簱涓病鏈夎{materielGroupDTO.WarehouseType}缂栧彿銆�");
+                }
+                
+
                 Dt_InboundOrder inboundOrder = GetInboundOrder(materielGroupDTO.OrderNo);
 
                 var dbinboundOrderDetails = _inboundOrderDetailService.GetByBarcode(materielGroupDTO.Barcodes);
@@ -337,11 +350,10 @@
 
                 if (stockInfo == null)
                 {
-                    stockInfo = new Dt_StockInfo() { PalletType = (int)PalletTypeEnum.None };
+                    stockInfo = new Dt_StockInfo() { PalletType = (int)PalletTypeEnum.None,LocationType=materielGroupDTO.locationType.ObjToInt() };
                     stockInfo.Details = new List<Dt_StockInfoDetail>();
                 }
-
-
+               
                 foreach (var item in dbinboundOrderDetails)
                 {
                     stockInfo.Details.Add(new Dt_StockInfoDetail
@@ -353,15 +365,17 @@
                         Unit = item.Unit,
                         InboundOrderRowNo = item.lineNo,
                         SupplyCode = item.SupplyCode,
-                        WarehouseCode = item.WarehouseCode,
+                        WarehouseCode = materielGroupDTO.WarehouseType,
                         StockQuantity = item.OrderQuantity,
-                        Status = 0,
+                        Status = 0,                         
                         OrderNo = inboundOrder.InboundOrderNo,
                         BusinessType = inboundOrder.BusinessType,
+                        ProductionDate = DateTime.Now.ToString("yyyy-mm-dd HH:mm:ss")
                     });
-
+                   
                     item.ReceiptQuantity = item.BarcodeQty;
                     item.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
+                    item.WarehouseCode = materielGroupDTO.WarehouseType;
                 }
 
                 if (stockInfo.Id == 0)
@@ -376,7 +390,7 @@
                 {
                     inboundOrder.OrderStatus = InOrderStatusEnum.鍏ュ簱涓�.ObjToInt();
                 }
-
+                inboundOrder.Operator = App.User.UserName;
                 content = MaterielGroupUpdateData(inboundOrder, dbinboundOrderDetails, stockInfo);
                 if (content.Status)
                 {
@@ -405,10 +419,19 @@
 
             WebResponseContent content = new WebResponseContent();
             try
-            {
+            {                                           
                 (bool, string, object?) result2 = ModelValidate.ValidateModelData(materielGroupDTO);
                 if (!result2.Item1) return content = WebResponseContent.Instance.Error(result2.Item2);
 
+                bool code = _warehouseAreaRepository.Db.Queryable<Dt_WarehouseArea>().Where(x => x.Id == materielGroupDTO.WarehouseCode).Any();
+                if (!code)
+                {
+                    return content = WebResponseContent.Instance.Error($"浠撳簱涓病鏈夎{materielGroupDTO.WarehouseCode}缂栧彿銆�");
+                }
+
+                if(_stockRepository.QueryFirst(x=>x.PalletCode == materielGroupDTO.PalletCode)!=null){
+                    return WebResponseContent.Instance.Error("璇ユ墭鐩樺凡缁忕粍杩囩洏");
+                }
 
                 Dt_StockInfo? stockInfo = _stockService.StockInfoService.GetStockByPalletCode(materielGroupDTO.PalletCode);
                 if (stockInfo != null && !string.IsNullOrEmpty(stockInfo.LocationCode) && stockInfo.StockStatus != StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt())
@@ -425,7 +448,7 @@
                 {
                     if (stockInfo == null)
                     {
-                        stockInfo = new Dt_StockInfo() { PalletType = PalletTypeEnum.Empty.ObjToInt(), StockStatus = StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt(), PalletCode = materielGroupDTO.PalletCode };
+                        stockInfo = new Dt_StockInfo() { PalletType = PalletTypeEnum.Empty.ObjToInt(), StockStatus = StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt(), PalletCode = materielGroupDTO.PalletCode,LocationType= materielGroupDTO.WarehouseCode.ObjToInt() };
                         stockInfo.Details = new List<Dt_StockInfoDetail>();
                     }
                     else
@@ -559,21 +582,21 @@
             {
                 StockSumQuantity = 0,
                 StockCount = 0,
-                UniqueUnit=""
+                UniqueUnit = ""
             };
             WebResponseContent content = new WebResponseContent();
             try
             {
                 if (string.IsNullOrWhiteSpace(orderNo))
                 {
-                  return content.Error("浼犲叆鐨勮鍗曞彿orderNo涓虹┖鎴栫┖鐧�");
+                    return content.Error("浼犲叆鐨勮鍗曞彿orderNo涓虹┖鎴栫┖鐧�");
                 }
                 var orderDetail = _inboundOrderRepository.Db.Queryable<Dt_InboundOrder>().Includes(x => x.Details).Where(s => s.InboundOrderNo == orderNo).First();
                 if (orderDetail == null)
                 {
-                   return content.Error("鏈壘鍒板崟鎹�");
+                    return content.Error("鏈壘鍒板崟鎹�");
                 }
-               var unitGroups = orderDetail.Details.GroupBy(d => d.Unit).ToList();
+                var unitGroups = orderDetail.Details.GroupBy(d => d.Unit).ToList();
                 if (unitGroups.Count == 1)
                 {
                     resultDTO.UniqueUnit = unitGroups.First().Key;
@@ -585,18 +608,19 @@
                 var validDetails = _stockDetailRepository.Db.Queryable<Dt_StockInfoDetail>().Where(s => s.OrderNo == orderNo).ToList();
                 resultDTO.StockSumQuantity = orderDetail.Details.Sum(d => d.OrderQuantity);
                 resultDTO.StockCount = orderDetail.Details.Count;
-                if(validDetails.Any())
+                if (validDetails.Any())
                 {
-                     resultDTO.StockSumQuantity -= validDetails.Sum(d => d.StockQuantity);
+                    resultDTO.StockSumQuantity -= validDetails.Sum(d => d.StockQuantity);
                     // 鏄庣粏璁板綍鏁帮細绗﹀悎鏉′欢鐨勬湁鏁堣褰曟潯鏁�
                     resultDTO.StockCount -= validDetails.Count;
                 }
-                return content.OK("",resultDTO);
+                return content.OK("", resultDTO);
             }
             catch (Exception ex)
             {
-              return content.Error("SumQuantity 缁熻搴撳瓨鏁伴噺澶辫触锛岃鍗曞彿锛歿OrderNo}");
+                return content.Error("SumQuantity 缁熻搴撳瓨鏁伴噺澶辫触锛岃鍗曞彿锛歿OrderNo}");
             }
         }
+
     }
 }

--
Gitblit v1.9.3