From 728f8d9084b15f8a347d62199ee6c3eead004e66 Mon Sep 17 00:00:00 2001
From: heshaofeng <heshaofeng@hnkhzn.com>
Date: 星期四, 29 一月 2026 10:48:29 +0800
Subject: [PATCH] 优化调拨查询

---
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_InboundService/InboundService.cs |   46 +++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 43 insertions(+), 3 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/InboundService.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/InboundService.cs"
index d678648..430bdb3 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/InboundService.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/InboundService.cs"
@@ -18,6 +18,7 @@
 using WIDESEA_Common.CommonEnum;
 using WIDESEA_Common.OrderEnum;
 using WIDESEA_Common.StockEnum;
+using WIDESEA_Common.WareHouseEnum;
 using WIDESEA_Core;
 using WIDESEA_Core.BaseRepository;
 using WIDESEA_Core.Helper;
@@ -172,6 +173,11 @@
                 {
                     return content.Error($"涓�涓噰璐崟鎹噷闈笉鍏佽缁勭洏涓や釜浠撳簱锛岃閲嶆柊閫夋嫨浠撳簱锛屼笂涓�涓粍鐩樹粨搴撲负{isWarehouse.WarehouseCode}");
                 }
+
+                if (inboundOrder.BusinessType == "11" && inboundOrder.IsTestMaterials == 1 && (palletDto.WarehouseType != "1076" || palletDto.WarehouseType != "5057"))
+                {
+                    return content.Error($"璇ュ崟鎹负璇曚骇鐗╂枡锛岄渶瑕佸叆搴撳埌璇曚骇浠擄紝璇烽噸鏂版牴鎹巶鍖洪�夋嫨璇曚骇浠撳簱杩涜缁勭洏鍏ュ簱");
+                }
                 if (!_locationInfoService.QueryLocationCount(Convert.ToInt32(palletDto.locationType)))
                 {
                     return content.Error($"璇ュ簱鍖簕palletDto.locationType}涓嶅瓨鍦ㄧ┖闂插簱浣�");
@@ -181,6 +187,11 @@
                 if (nullpallet != null)
                 {
                     return content.Error($"璇ユ墭鐩榹palletDto.PalletCode}宸茬粡杩涜绌烘墭缁勭洏,涓嶈兘鍦ㄨ繘琛岀粍鐩�");
+                }
+               var outbundPallet = _stockInfoRepository.QueryFirst(x => x.StockStatus == (int)StockStatusEmun.鍑哄簱瀹屾垚 && x.PalletCode == palletDto.PalletCode);
+                if (outbundPallet != null)
+                {
+                    return content.Error($"璇ユ墭鐩榹palletDto.PalletCode}鏈繘琛屽彇绌虹,涓嶈兘杩涜缁勭洏");
                 }
 
                 foreach (var item in details)
@@ -440,13 +451,24 @@
                     //}
                 }
                 _mesReturnRecord.UpdateData(returnRecords);
+                //閲嶆柊鍥炶皟瀹屾垚鐨勫崟鎹紝鏇存柊搴撳瓨鐘舵��
+                foreach (var returnRecord in returnRecords)
+                {
+                    if (returnRecord.ReturnStatus == 1)
+                    {
+                        _stockInfoRepository.Db.Updateable<Dt_StockInfoDetail>().SetColumns(it => new Dt_StockInfoDetail
+                        {
+                            Status = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt()
+                        }).Where(it => it.OrderNo == returnRecord.OrderNo && returnRecord.RequestData.Contains(it.Barcode)).ExecuteCommand();
+                    }
+                }
 
                 var inboundOrderDetail = _inboundOrderRepository.Db.Queryable<Dt_InboundOrderDetail>()
-                                        .Where(x => x.OrderId == inboundOrder.Id && x.OrderDetailStatus==(int)OrderDetailStatusEnum.Over && x.ReturnToMESStatus == 0)
+                                        .Where(x => x.OrderId == inboundOrder.Id && x.OrderDetailStatus == (int)OrderDetailStatusEnum.Over && x.ReturnToMESStatus == 0)
                                         .ToList();
 
                 var stocks = _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.StockStatus == (int)StockStatusEmun.鍏ュ簱瀹屾垚)
-                                            .Where(it => SqlFunc.Subqueryable<Dt_StockInfoDetail>().Where(s => s.StockId == it.Id && s.OrderNo == inboundOrder.InboundOrderNo).Any())
+                                            .Where(it => SqlFunc.Subqueryable<Dt_StockInfoDetail>().Where(s => s.StockId == it.Id && s.OrderNo == inboundOrder.InboundOrderNo && s.Status == StockStatusEmun.鍏ュ簱纭.ObjToInt()).Any())
                                             .ToList();
 
                 var stockIds = stocks.Select(s => s.Id).ToList();
@@ -467,6 +489,13 @@
                                     inbound => inbound.Barcode,
                                     stockdetail => stockdetail.Barcode,
                                     (inbound, stockdetail) => inbound.Id)
+                                .ToList();
+
+                var inbounddetailBarcode = inboundOrderDetail
+                                .Join(allDetailsData,
+                                    inbound => inbound.Barcode,
+                                    stockdetail => stockdetail.Barcode,
+                                    (inbound, stockdetail) => stockdetail.Barcode)
                                 .ToList();
 
                 var detail = allDetailsData.Where(x => matchedData.Contains(x.Barcode)).ToList();
@@ -512,6 +541,11 @@
                     {
                         _inboundOrderRepository.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 1 })
                         .Where(it => it.OrderId == inboundOrder.Id && inbounddetailID.Contains(it.Id)).ExecuteCommand();
+
+                        _stockInfoRepository.Db.Updateable<Dt_StockInfoDetail>().SetColumns(it => new Dt_StockInfoDetail
+                        {
+                            Status = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt()
+                        }).Where(it => it.OrderNo == inboundOrder.InboundOrderNo && inbounddetailBarcode.Contains(it.Barcode)).ExecuteCommand();
                     }
                     else
                     {
@@ -535,7 +569,7 @@
                         details = FeedbackInboundDetailsModelDto(detail)
                     };
 
-                    if (feedmodel.details.Count<=0)
+                    if (feedmodel.details.Count <= 0)
                     {
                         if (returnRecords.Count() == returnRecords.Count(x => x.ReturnStatus == 1))
                         {
@@ -558,6 +592,11 @@
                     {
                         _inboundOrderRepository.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 1 })
                         .Where(it => inbounddetailID.Contains(it.Id)).ExecuteCommand();
+
+                        _stockInfoRepository.Db.Updateable<Dt_StockInfoDetail>().SetColumns(it => new Dt_StockInfoDetail
+                        {
+                            Status = StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt()
+                        }).Where(it => it.OrderNo == inboundOrder.InboundOrderNo && inbounddetailBarcode.Contains(it.Barcode)).ExecuteCommand();
                     }
                     else
                     {
@@ -575,6 +614,7 @@
             }
         }
 
+
         public List<AllocateDtoDetail> GetAllocateDtoDetails(List<Dt_StockInfoDetail> stockInfoDetails)
         {
             var groupedData = stockInfoDetails.GroupBy(item => new { item.MaterielCode, item.InboundOrderRowNo, item.BarcodeUnit, item.WarehouseCode })

--
Gitblit v1.9.3