From 696edbff3c8812e4b820f624d66a02ae6ddb1a06 Mon Sep 17 00:00:00 2001
From: 647556386 <647556386@qq.com>
Date: 星期四, 16 四月 2026 13:40:18 +0800
Subject: [PATCH] Merge branch 'htq20251215' of http://115.159.85.185:8098/r/ZhongRui/ALDbanyunxiangmu into htq20251215

---
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_InboundService/InboundOrderService.cs |   69 +++++++++++++++++++++++++++++-----
 1 files changed, 59 insertions(+), 10 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 f3ea18d..418c05f 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"
@@ -50,9 +50,10 @@
         private readonly IBasicService _basicService;
         private readonly IRepository<Dt_AllocateOrder> _allocateOrderRepository;
         private readonly IRepository<Dt_OutboundOrder> _outboundOrderRepository;
+        private readonly IRepository<Dt_OutboundOrderDetail> _outboundOrderDetailRepository;
         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, IRepository<Dt_WarehouseArea> warehouseAreaRepository, IRepository<Dt_StockInfo> stockRepository, IRepository<Dt_LocationType> locationTypeRepository, IMaterielInfoService materielInfoService, IBasicService basicService, IRepository<Dt_LocationInfo> locationInfoRepository, IRepository<Dt_AllocateOrder> allocateOrderRepository, IRepository<Dt_OutboundOrder> outboundOrderRepository) : 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, IRepository<Dt_LocationType> locationTypeRepository, IMaterielInfoService materielInfoService, IBasicService basicService, IRepository<Dt_LocationInfo> locationInfoRepository, IRepository<Dt_AllocateOrder> allocateOrderRepository, IRepository<Dt_OutboundOrder> outboundOrderRepository, IRepository<Dt_OutboundOrderDetail> outboundOrderDetailRepository) : base(BaseDal)
         {
             _mapper = mapper;
             _unitOfWorkManage = unitOfWorkManage;
@@ -71,6 +72,7 @@
             _locationInfoRepository = locationInfoRepository;
             _allocateOrderRepository = allocateOrderRepository;
             _outboundOrderRepository = outboundOrderRepository;
+            _outboundOrderDetailRepository = outboundOrderDetailRepository;
         }
 
         public async Task<WebResponseContent> ReceiveInboundOrder(List<Dt_InboundOrder> models, int operateType)
@@ -703,9 +705,10 @@
             {
                 _unitOfWorkManage.BeginTran();
 
-                // 鏅鸿兘璇嗗埆杈撳叆绫诲瀷
+              
                 string palletCode = null;
                 string barcode = null;
+                int stockStatus = 0; 
 
                 // 1. 鍏堝皾璇曟寜鎵樼洏鍙锋煡璇�
                 var stockByPallet = _stockRepository.Db.Queryable<Dt_StockInfo>()
@@ -718,10 +721,17 @@
                 {
                     // 璇嗗埆涓烘墭鐩樺彿
                     palletCode = code;
-                    var task =_taskRepository.Db.Queryable<Dt_Task>().Where(t => t.PalletCode == palletCode).ToList();
-                    if(task!=null && task.Any())
+                    stockStatus = stockByPallet.StockStatus; 
+
+                    var task = _taskRepository.Db.Queryable<Dt_Task>().Where(t => t.PalletCode == palletCode).ToList();
+                    if (task != null && task.Any())
                     {
                         return WebResponseContent.Instance.Error($"鎵樼洏鍙� {palletCode} 瀛樺湪鏈畬鎴愮殑浠诲姟锛屾棤娉曟挙閿�");
+                    }
+
+                    if (stockStatus == StockStatusEmun.鍏ュ簱纭.ObjToInt())
+                    {
+                        return WebResponseContent.Instance.Error($"鎵樼洏鍙� {palletCode} 澶勪簬鍏ュ簱纭鐘舵�侊紝绂佹鏁存墭鐩樻挙閿�锛岃鍗曠嫭鎾ら攢鏉$爜");
                     }
                 }
                 else
@@ -732,13 +742,14 @@
                     {
                         var stockInfo = _stockRepository
                             .Db.Queryable<Dt_StockInfo>()
-                            .Where(s => s.Id == detail.StockId&& (s.StockStatus == (int)StockStatusEmun.缁勭洏鏆傚瓨 || s.StockStatus == StockStatusEmun.鍏ュ簱纭.ObjToInt()))
+                            .Where(s => s.Id == detail.StockId && (s.StockStatus == (int)StockStatusEmun.缁勭洏鏆傚瓨 || s.StockStatus == StockStatusEmun.鍏ュ簱纭.ObjToInt()))
                             .First();
 
                         if (stockInfo != null)
                         {
                             barcode = code;
                             palletCode = stockInfo.PalletCode;
+                            stockStatus = stockInfo.StockStatus; 
                         }
                     }
                     else
@@ -771,6 +782,16 @@
                         return WebResponseContent.Instance.Error($"鎵樼洏 {palletCode} 涓嬫湭鎵惧埌鏉$爜 {barcode} 鐨勬槑缁嗚褰�");
                     }
 
+                    if (stockStatus == StockStatusEmun.鍏ュ簱纭.ObjToInt())
+                    {
+                        var totalDetails = stock.Details?.Count ?? 0;
+                        if (totalDetails <= 1)
+                        {
+                            _unitOfWorkManage.RollbackTran();
+                            return WebResponseContent.Instance.Error($"鎵樼洏 {palletCode} 澶勪簬鍏ュ簱纭鐘舵�侊紝褰撳墠浠呭墿浣欐渶鍚�1鏉℃槑缁嗭紝绂佹鎾ら攢锛堝繀椤讳繚鐣欒嚦灏�1鏉″簱瀛樻槑缁嗭級");
+                        }
+                    }
+
                     ResetInboundOrderStatus(new List<string> { targetDetail.OrderNo }, new List<string> { targetDetail.Barcode });
                     _stockDetailRepository.DeleteData(targetDetail);
 
@@ -780,10 +801,13 @@
 
                     if (!remainingDetails.Any())
                     {
-                        ResetInboundOrderStatus(stock.Details.Select(d => d.OrderNo).Distinct().ToList());
-                        _stockRepository.DeleteData(stock);
+                        if (stockStatus == (int)StockStatusEmun.缁勭洏鏆傚瓨)
+                        {
+                            ResetInboundOrderStatus(stock.Details.Select(d => d.OrderNo).Distinct().ToList());
+                            _stockRepository.DeleteData(stock);
+                        }
                         _unitOfWorkManage.CommitTran();
-                        return WebResponseContent.Instance.OK($"鏉$爜 {barcode} 鎾ら攢鎴愬姛锛屾墭鐩樻棤鍓╀綑鏄庣粏锛屽凡鍒犻櫎鎵樼洏骞堕噸缃叧鑱斿叆搴撳崟鐘舵��");
+                        return WebResponseContent.Instance.OK($"鏉$爜 {barcode} 鎾ら攢鎴愬姛锛屾墭鐩樻棤鍓╀綑鏄庣粏锛屽凡閲嶇疆鍏宠仈鍏ュ簱鍗曠姸鎬�");
                     }
 
                     _unitOfWorkManage.CommitTran();
@@ -791,7 +815,6 @@
                 }
                 else
                 {
-                    // ===== 鎾ら攢鏁翠釜鎵樼洏 =====
                     var stock = _stockRepository.Db.Queryable<Dt_StockInfo>()
                         .Includes(o => o.Details)
                         .First(x => x.PalletCode == palletCode
@@ -924,6 +947,7 @@
                             sugarQueryable1 = sugarQueryable1.Where(x => x.Details.Any(d => d.MaterielCode.Contains(materielCode)));
 
                         }
+
                         //var dataList = sugarQueryable1.ToPageList(options.Page, options.Rows, ref totalCount);
                         //return new PageGridData<Dt_InboundOrder>(totalCount, dataList);
                     }
@@ -986,6 +1010,18 @@
             return content.OK(data: details);
         }
 
+        public WebResponseContent GetLocationType(string code)
+        {
+           var warehouseAreaName = _warehouseAreaRepository.QueryFirst(x => x.Code == code);
+            if(string.IsNullOrWhiteSpace(warehouseAreaName.ToString()))
+            {
+                return WebResponseContent.Instance.Error("鏈壘鍒颁粨搴撳悕绉�");
+            }
+            var locationTypeDesc = _locationTypeRepository.Db.Queryable<Dt_LocationType>().Where(x => string.Equals(x.LocationTypeDesc, warehouseAreaName.Name, StringComparison.OrdinalIgnoreCase)).First();
+
+            return WebResponseContent.Instance.OK(data:locationTypeDesc.LocationType);
+        }
+
         public WebResponseContent HandCloseOrder(List<string> orderNos)
         {
             try
@@ -1018,10 +1054,23 @@
                     }
                     else if (outbound != null)
                     {
-                        if(outbound.OrderStatus !=(int)OutOrderStatusEnum.鏈紑濮� && outbound.OrderStatus != (int)OutOrderStatusEnum.鍑哄簱涓�)
+                        if(outbound.OrderStatus ==(int)OutOrderStatusEnum.鍑哄簱瀹屾垚)
                         {
                             return WebResponseContent.Instance.Error($"璇ュ崟鎹姸鎬佷笉鍙互鍏抽棴");
                         }
+                        if(outbound.OrderStatus == (int)OutOrderStatusEnum.鍑哄簱涓�)
+                        {
+                           var outboundDetails = _outboundOrderDetailRepository.QueryData(x => x.OrderId == outbound.Id);
+                            if (outboundDetails == null)
+                            {
+                                return WebResponseContent.Instance.Error("璇ュ崟鎹姸鎬佷笉鑳藉叧闂�");
+                            }
+                            var detailStatus = outboundDetails.All(x => x.LockQuantity == x.OverOutQuantity);
+                            if (!detailStatus)
+                            {
+                                return WebResponseContent.Instance.Error("璇ュ崟鎹湁姝e湪鍑哄簱鐨勭墿鏂欙紝涓嶈兘鍏抽棴");
+                            }
+                        }
                         outbound.OrderStatus = (int)OutOrderStatusEnum.鍏抽棴;
                         outbound.Operator = App.User.UserName;
                         _outboundOrderRepository.UpdateData(outbound);

--
Gitblit v1.9.3