From 43fba3aeb0fbbd48fb2f6a859418ab5c9e9d9241 Mon Sep 17 00:00:00 2001
From: 647556386 <647556386@qq.com>
Date: 星期五, 19 十二月 2025 14:51:56 +0800
Subject: [PATCH] Merge branch 'htq20251215' of http://115.159.85.185:8098/r/ZhongRui/ALDbanyunxiangmu into htq20251215

---
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundOrderDetailService.cs |  144 ++++++++++++++++++++++++++++++-----------------
 1 files changed, 92 insertions(+), 52 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_OutboundService/OutboundOrderDetailService.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_OutboundService/OutboundOrderDetailService.cs"
index 664827c..848271c 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_OutboundService/OutboundOrderDetailService.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_OutboundService/OutboundOrderDetailService.cs"
@@ -27,17 +27,15 @@
 
         private readonly IOutStockLockInfoService _outStockLockInfoService;
         private readonly ILocationInfoService _locationInfoService;
-        private readonly IBasicService _basicService;
         private readonly IRecordService _recordService;
         private readonly IOutboundOrderService _outboundOrderService;
         private readonly ILocationStatusChangeRecordService _locationStatusChangeRecordService;
         private readonly ILogger<OutboundOrderDetailService> _logger;
-        public OutboundOrderDetailService(IRepository<Dt_OutboundOrderDetail> BaseDal, IUnitOfWorkManage unitOfWorkManage, IStockService stockService, IOutStockLockInfoService outStockLockInfoService, IBasicService basicService, IRecordService recordService, ILocationInfoService locationInfoService, ILocationStatusChangeRecordService locationStatusChangeRecordService, IOutboundOrderService outboundOrderService, ILogger<OutboundOrderDetailService> logger) : base(BaseDal)
+        public OutboundOrderDetailService(IRepository<Dt_OutboundOrderDetail> BaseDal, IUnitOfWorkManage unitOfWorkManage, IStockService stockService, IOutStockLockInfoService outStockLockInfoService, IRecordService recordService, ILocationInfoService locationInfoService, ILocationStatusChangeRecordService locationStatusChangeRecordService, IOutboundOrderService outboundOrderService, ILogger<OutboundOrderDetailService> logger) : base(BaseDal)
         {
             _unitOfWorkManage = unitOfWorkManage;
             _stockService = stockService;
             _outStockLockInfoService = outStockLockInfoService;
-            _basicService = basicService;
             _recordService = recordService;
             _locationInfoService = locationInfoService;
             _locationStatusChangeRecordService = locationStatusChangeRecordService;
@@ -46,8 +44,6 @@
 
         }
 
-
-        /// <summary>
         /// 鍒嗛厤鍑哄簱搴撳瓨  鎸夊厛杩涘厛鍑哄師鍒欏垎閰�
         /// </summary>
         public (List<Dt_StockInfo>, List<Dt_OutboundOrderDetail>, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>)
@@ -78,14 +74,14 @@
 
             // 鎸夌墿鏂欏拰鎵规鍒嗙粍澶勭悊
             var groupDetails = outboundOrderDetails
-                .GroupBy(x => new { x.MaterielCode, x.BatchNo, x.SupplyCode,x.WarehouseCode })
+                .GroupBy(x => new { x.MaterielCode, x.BatchNo, x.SupplyCode, x.WarehouseCode })
                 .Select(x => new
                 {
                     MaterielCode = x.Key.MaterielCode,
                     BatchNo = x.Key.BatchNo,
                     SupplyCode = x.Key.SupplyCode,
                     Details = x.ToList(),
-                    WarehouseCode=x.Key.WarehouseCode,
+                    WarehouseCode = x.Key.WarehouseCode,
                     TotalNeedQuantity = CalculateReassignNeedQuantity(x.ToList())
                 })
                 .Where(x => x.TotalNeedQuantity > 0)
@@ -94,9 +90,9 @@
             foreach (var item in groupDetails)
             {
                 var needQuantity = item.TotalNeedQuantity;
-                 
+
                 // 鑾峰彇鍙敤搴撳瓨锛堟寜鍏堣繘鍏堝嚭鎺掑簭锛�
-                List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseableStocks(item.MaterielCode, item.BatchNo, item.SupplyCode,item.WarehouseCode, outboundOrder.FactoryArea);
+                List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseableStocks(item.MaterielCode, item.BatchNo, item.SupplyCode, item.WarehouseCode, outboundOrder.FactoryArea);
 
                 if (!stockInfos.Any())
                 {
@@ -128,7 +124,7 @@
 
 
                 // 鏇存柊搴撳瓨鍜屾墭鐩樼姸鎬�
-               UpdateNormalStocksAndPalletsStatus(autoAssignStocks, stockAllocations);
+                UpdateNormalStocksAndPalletsStatus(autoAssignStocks, stockAllocations);
             }
 
             if (outStocks.Any())
@@ -150,13 +146,13 @@
                 if (stockAllocations.TryGetValue(stockDetail.Id, out decimal allocatedQty) && allocatedQty > 0)
                 {
 
-                      _stockService.StockInfoService.Db.Updateable<Dt_StockInfo>()
-                        .SetColumns(x => new Dt_StockInfo
-                        {
-                            StockStatus = (int)StockStatusEmun.鍑哄簱閿佸畾,
-                        })
-                        .Where(x => x.Id == stock.Id)
-                        .ExecuteCommand();
+                    _stockService.StockInfoService.Db.Updateable<Dt_StockInfo>()
+                      .SetColumns(x => new Dt_StockInfo
+                      {
+                          StockStatus = (int)StockStatusEmun.鍑哄簱閿佸畾,
+                      })
+                      .Where(x => x.Id == stock.Id)
+                      .ExecuteCommand();
                 }
             }
         }
@@ -312,13 +308,13 @@
 
             // 鎸夌墿鏂欏拰鎵规鍒嗙粍澶勭悊锛堣繖閲屽彧鏈変竴涓槑缁嗭級
             var groupDetails = new List<Dt_OutboundOrderDetail> { orderDetail }
-                .GroupBy(x => new { x.MaterielCode, x.BatchNo, x.SupplyCode ,x.WarehouseCode})
+                .GroupBy(x => new { x.MaterielCode, x.BatchNo, x.SupplyCode, x.WarehouseCode })
                 .Select(x => new
                 {
                     MaterielCode = x.Key.MaterielCode,
                     BatchNo = x.Key.BatchNo,
                     SupplyCode = x.Key.SupplyCode,
-                    WarehouseCode=x.Key.WarehouseCode,
+                    WarehouseCode = x.Key.WarehouseCode,
                     Details = x.ToList(),
                     TotalNeedQuantity = batchQuantity  // 浣跨敤鍒嗘壒鏁伴噺
                 })
@@ -330,7 +326,7 @@
                 var needQuantity = item.TotalNeedQuantity;
 
                 // 鑾峰彇鍙敤搴撳瓨锛堟寜鍏堣繘鍏堝嚭鎺掑簭锛�
-                List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseableStocks(item.MaterielCode, item.BatchNo, item.SupplyCode,item.WarehouseCode,outboundOrder.FactoryArea);
+                List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseableStocks(item.MaterielCode, item.BatchNo, item.SupplyCode, item.WarehouseCode, outboundOrder.FactoryArea);
                 if (!stockInfos.Any())
                 {
                     throw new Exception($"鐗╂枡[{item.MaterielCode}]鎵规[{item.BatchNo}]鏈壘鍒板彲鍒嗛厤搴撳瓨");
@@ -383,11 +379,11 @@
                 var stockDetail = stock.Details.First();
                 if (stockAllocations.TryGetValue(stockDetail.Id, out decimal allocatedQty) && allocatedQty > 0)
                 {
-              
+
                     await _stockService.StockInfoService.Db.Updateable<Dt_StockInfo>()
                         .SetColumns(x => new Dt_StockInfo
                         {
-                            StockStatus = (int)StockStatusEmun.鍑哄簱閿佸畾, 
+                            StockStatus = (int)StockStatusEmun.鍑哄簱閿佸畾,
                         })
                         .Where(x => x.Id == stock.Id)
                         .ExecuteCommandAsync();
@@ -581,34 +577,78 @@
 
         public override PageGridData<Dt_OutboundOrderDetail> GetPageData(PageDataOptions options)
         {
-            //var  pageGridData = base.GetPageData(options);
+            return base.GetPageData(options);
 
-            ISugarQueryable<Dt_OutboundOrderDetail> sugarQueryable1 = BaseDal.Db.Queryable<Dt_OutboundOrderDetail>();
-            if (!string.IsNullOrEmpty(options.Wheres))
-            {
+            //ISugarQueryable<Dt_OutboundOrderDetail> sugarQueryable1 = BaseDal.Db.Queryable<Dt_OutboundOrderDetail>();
+            //if (!string.IsNullOrEmpty(options.Wheres))
+            //{
 
-                List<SearchParameters> searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>();
-                int totalCount = 0;
-                if (searchParametersList.Count > 0)
-                {
-                    {
-                        SearchParameters? searchParameters = searchParametersList.FirstOrDefault(x => x.Name == nameof(Dt_InboundOrderDetail.OrderId).FirstLetterToLower());
-                        if (searchParameters != null)
-                        {
-                            sugarQueryable1 = sugarQueryable1.Where(x => x.OrderId == searchParameters.Value.ObjToInt());
-                            var dataList = sugarQueryable1.ToPageList(options.Page, options.Rows, ref totalCount);
-                            return new PageGridData<Dt_OutboundOrderDetail>(totalCount, dataList);
-                        }
-                    }
-
-
-                }
-            }
+            //    List<SearchParameters> searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>();
+            //    int totalCount = 0;
+            //    if (searchParametersList.Count > 0)
+            //    {
+            //        {
+            //            SearchParameters? searchParameters = searchParametersList.FirstOrDefault(x => x.Name == nameof(Dt_InboundOrderDetail.OrderId).FirstLetterToLower());
+            //            if (searchParameters != null)
+            //            {
+            //                Dt_OutboundOrder outboundOrder = _outboundOrderService.Repository.QueryFirst(x => x.Id == searchParameters.Value.ObjToInt());
+            //                if (outboundOrder != null)
+            //                {
+            //                    if (outboundOrder.IsBatch == 0)
+            //                    {
+            //                        sugarQueryable1 = sugarQueryable1.Where(x => x.OrderId == searchParameters.Value.ObjToInt());
+            //                        var dataList = sugarQueryable1.ToPageList(options.Page, options.Rows, ref totalCount);
+            //                        return new PageGridData<Dt_OutboundOrderDetail>(totalCount, dataList);
+            //                    }
+            //                    else
+            //                    {
+            //                        sugarQueryable1 = sugarQueryable1.Where(x => x.OrderId == searchParameters.Value.ObjToInt());
+            //                        sugarQueryable1.GroupBy(x => new { x.MaterielCode, x.MaterielName, x.BatchNo, x.SupplyCode, x.WarehouseCode }).Select(s => new Dt_OutboundOrderDetail
+            //                        {
+            //                            WarehouseCode = s.WarehouseCode,
+            //                            SupplyCode = s.SupplyCode,
+            //                            BatchNo = s.BatchNo,
+            //                            MaterielName = s.MaterielName,
+            //                            MaterielCode = s.MaterielCode,
+            //                            AllocatedQuantity = SqlFunc.AggregateSum(s.AllocatedQuantity),
+            //                            OrderQuantity = SqlFunc.AggregateSum(s.OrderQuantity),
+            //                            PickedQty = SqlFunc.AggregateSum(s.PickedQty),
+            //                            OverOutQuantity = SqlFunc.AggregateSum(s.OverOutQuantity),
+            //                            MoveQty = SqlFunc.AggregateSum(s.MoveQty),
+            //                            NoStockOutQty = SqlFunc.AggregateSum(s.NoStockOutQty),
+            //                            LockQuantity = SqlFunc.AggregateSum(s.LockQuantity),
+            //                            BarcodeMoveQty = SqlFunc.AggregateSum(s.BarcodeMoveQty),
+            //                            BarcodeQty =SqlFunc.AggregateMin( s.BarcodeQty),
+            //                            BarcodeUnit = SqlFunc.AggregateMin(s.BarcodeUnit),
+            //                            BatchAllocateStatus = SqlFunc.AggregateMin(s.BatchAllocateStatus),
+            //                            CreateDate = SqlFunc.AggregateMin(s.CreateDate),
+            //                            Creater = SqlFunc.AggregateMin(s.Creater),
+            //                            documentsNO = SqlFunc.AggregateMin(s.documentsNO),
+            //                            Id = SqlFunc.AggregateMin(s.Id),
+            //                            lineNo = SqlFunc.AggregateMin(s.lineNo),
+            //                            Modifier = SqlFunc.AggregateMin(s.Modifier),
+            //                            ModifyDate = SqlFunc.AggregateMin(s.ModifyDate),
+            //                            OrderDetailStatus = SqlFunc.AggregateMin(s.OrderDetailStatus),
+            //                            OrderId = SqlFunc.AggregateMin(s.OrderId),
+            //                            Remark = SqlFunc.AggregateMin(s.Remark),
+            //                            ReturnJsonData = SqlFunc.AggregateMin(s.ReturnJsonData),
+            //                            ReturnToMESStatus = SqlFunc.AggregateMin(s.ReturnToMESStatus),
+            //                            RowNo = SqlFunc.AggregateMin(s.RowNo),
+            //                            Unit = SqlFunc.AggregateMin(s.Unit)
+            //                        });
+            //                        var dataList = sugarQueryable1.ToPageList(options.Page, options.Rows, ref totalCount);
+            //                        return new PageGridData<Dt_OutboundOrderDetail>(totalCount, dataList);
+            //                    }
+            //                }
+            //            }
+            //        }
+            //    }
+            //}
             return new PageGridData<Dt_OutboundOrderDetail>();
         }
 
 
-        public (List<Dt_StockInfo>, Dt_OutboundOrderDetail, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>)AssignStockOutbound(Dt_OutboundOrderDetail outboundOrderDetail, List<StockSelectViewDTO> stockSelectViews)
+        public (List<Dt_StockInfo>, Dt_OutboundOrderDetail, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) AssignStockOutbound(Dt_OutboundOrderDetail outboundOrderDetail, List<StockSelectViewDTO> stockSelectViews)
         {
             // 楠岃瘉鐢ㄦ埛閫夋嫨
             (bool, string) checkResult = CheckSelectStockDeital(outboundOrderDetail, stockSelectViews);
@@ -668,10 +708,10 @@
             }
 
             // 濡傛灉鐢ㄦ埛閫夋嫨鐨勫簱瀛樹笉澶燂紝鑷姩鍒嗛厤鍓╀綑閮ㄥ垎
-          
+
             if (remainingNeedQuantity > 0)
             {
-                
+
             }
 
             // 鏇存柊閿佸畾鏁伴噺
@@ -724,7 +764,7 @@
                 .Where(d => d.MaterielCode == detail.MaterielCode &&
                            (d.StockQuantity - d.OutboundQuantity) > 0 &&
                            d.Barcode == barcode); // 鍙垎閰嶆寚瀹氭潯鐮�
-           
+
             query = query.Where(x => x.WarehouseCode == detail.WarehouseCode);
 
             if (!string.IsNullOrEmpty(detail.BatchNo))
@@ -761,7 +801,7 @@
             var query = stock.Details.AsQueryable()
                 .Where(d => d.MaterielCode == detail.MaterielCode &&
                            (d.StockQuantity - d.OutboundQuantity) > 0);
-               // .OrderBy(d => d.CreateDate);             
+            // .OrderBy(d => d.CreateDate);             
 
             if (!string.IsNullOrEmpty(detail.BatchNo))
             {
@@ -772,7 +812,7 @@
             {
                 query = query.Where(d => d.SupplyCode == detail.SupplyCode);
             }
-            var sortedDetails= query.ToList().OrderBy(d => d.CreateDate);
+            var sortedDetails = query.ToList().OrderBy(d => d.CreateDate);
 
 
             foreach (var stockDetail in sortedDetails)
@@ -795,9 +835,9 @@
         }
 
         private Dt_OutStockLockInfo CreateOutStockLockInfo(Dt_OutboundOrder outboundOrder, Dt_OutboundOrderDetail detail,
-            Dt_StockInfo stock, decimal quantity,string barcode="")
+            Dt_StockInfo stock, decimal quantity, string barcode = "")
         {
-            
+
 
             return _outStockLockInfoService.GetOutStockLockInfo(outboundOrder, detail, stock, quantity, barcode);
         }
@@ -862,7 +902,7 @@
                 }
 
                 var available = CalculateAvailableQuantityByBarcode(stock, outboundOrderDetail.MaterielCode,
-                    outboundOrderDetail.BatchNo, outboundOrderDetail.SupplyCode,selection.Barcode);
+                    outboundOrderDetail.BatchNo, outboundOrderDetail.SupplyCode, selection.Barcode);
 
                 if (available <= 0)
                 {

--
Gitblit v1.9.3