From 70aa9b5ca249a84e5867912d551cdafbec76e54e Mon Sep 17 00:00:00 2001
From: 647556386 <647556386@qq.com>
Date: 星期五, 05 十二月 2025 09:45:17 +0800
Subject: [PATCH] Merge branch 'master' of http://115.159.85.185:8098/r/ZhongRui/ALDbanyunxiangmu
---
项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundOrderDetailService.cs | 464 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 405 insertions(+), 59 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 121a74e..bf49e91 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"
@@ -1,4 +1,5 @@
-锘縰sing Microsoft.Extensions.Logging;
+锘縰sing Autofac.Core;
+using Microsoft.Extensions.Logging;
using SqlSugar;
using WIDESEA_Common.LocationEnum;
using WIDESEA_Common.OrderEnum;
@@ -66,6 +67,11 @@
var outboundOrder = _outboundOrderService.Db.Queryable<Dt_OutboundOrder>()
.First(x => x.Id == orderId);
+ if (!CanReassignOrder(outboundOrder))
+ {
+ throw new Exception($"璁㈠崟{outboundOrder.OrderNo}鐘舵�佷笉鍏佽閲嶆柊鍒嗛厤搴撳瓨");
+ }
+
List<Dt_StockInfo> outStocks = new List<Dt_StockInfo>();
List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>();
List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>();
@@ -79,7 +85,7 @@
BatchNo = x.Key.BatchNo,
SupplyCode = x.Key.SupplyCode,
Details = x.ToList(),
- TotalNeedQuantity = x.Sum(v => v.OrderQuantity - v.OverOutQuantity - v.LockQuantity - v.MoveQty)
+ TotalNeedQuantity = CalculateReassignNeedQuantity(x.ToList())
})
.Where(x => x.TotalNeedQuantity > 0)
.ToList();
@@ -93,7 +99,7 @@
if (!stockInfos.Any())
{
- throw new Exception($"鐗╂枡[{item.MaterielCode}]鎵规[{item.BatchNo}]鏈壘鍒板彲鍒嗛厤搴撳瓨");
+ throw new Exception($"鐗╂枡[{item.MaterielCode}]鎵规[{item.BatchNo}]渚涘簲鍟哰{item.SupplyCode}]鏈壘鍒板彲鍒嗛厤搴撳瓨");
}
// 鍒嗛厤搴撳瓨锛堟寜鍏堣繘鍏堝嚭锛�
@@ -118,6 +124,10 @@
// 鏇存柊鍑哄簱鍗曟槑缁嗙姸鎬�
UpdateOrderDetailStatus(item.Details, allocatedQuantity, needQuantity);
+
+
+ // 鏇存柊搴撳瓨鍜屾墭鐩樼姸鎬�
+ UpdateNormalStocksAndPalletsStatus(autoAssignStocks, stockAllocations);
}
if (outStocks.Any())
@@ -127,6 +137,59 @@
}
return (outStocks, outboundOrderDetails, outStockLockInfos, locationInfos);
+ }
+ /// <summary>
+ /// 鏇存柊搴撳瓨鍜屾墭鐩樼姸鎬�
+ /// </summary>
+ private void UpdateNormalStocksAndPalletsStatus(List<Dt_StockInfo> stocks, Dictionary<int, decimal> stockAllocations)
+ {
+ foreach (var stock in stocks)
+ {
+ var stockDetail = stock.Details.First();
+ 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();
+ }
+ }
+ }
+ /// <summary>
+ /// 妫�鏌ヨ鍗曟槸鍚﹀厑璁搁噸鏂板垎閰�
+ /// </summary>
+ private bool CanReassignOrder(Dt_OutboundOrder outboundOrder)
+ {
+ // 鍏佽閲嶆柊鍒嗛厤鐨勭姸鎬�
+ var allowedStatus = new[] { OutOrderStatusEnum.鏈紑濮�, OutOrderStatusEnum.鍑哄簱涓�, OutOrderStatusEnum.閮ㄥ垎瀹屾垚 };
+
+ return allowedStatus.Contains((OutOrderStatusEnum)outboundOrder.OrderStatus);
+ }
+
+ /// <summary>
+ /// 閲嶆柊璁$畻闇�姹傛暟閲忥紙鑰冭檻閲嶆柊鍒嗛厤鐨勫満鏅級
+ /// </summary>
+ private decimal CalculateReassignNeedQuantity(List<Dt_OutboundOrderDetail> details)
+ {
+ decimal totalNeed = 0;
+
+ foreach (var detail in details)
+ {
+ // 鍏抽敭淇敼锛氶噸鏂板垎閰嶆椂锛屽彧鑰冭檻鏈嚭搴撶殑閮ㄥ垎锛屽拷鐣ラ攣瀹氭暟閲�
+ // 鍥犱负閿佸畾鏁伴噺鍦ㄥ洖搴撴椂宸茬粡琚噸缃�
+ decimal remainingNeed = detail.OrderQuantity - detail.OverOutQuantity - detail.MoveQty;
+
+ if (remainingNeed > 0)
+ {
+ totalNeed += remainingNeed;
+ }
+ }
+
+ return totalNeed;
}
private (bool success, string message) DistributeLockQuantityByFIFO(
List<Dt_OutboundOrderDetail> details,
@@ -226,6 +289,213 @@
return (true, "鍒嗛厤鎴愬姛");
}
+
+
+ /// <summary>
+ /// 涓哄垎鎵瑰垎閰嶅簱瀛�
+ /// </summary>
+ public async Task<(List<Dt_StockInfo>, List<Dt_OutboundOrderDetail>, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>)>
+ AssignStockForBatch(Dt_OutboundOrderDetail orderDetail, decimal batchQuantity, string batchNo)
+ {
+ if (orderDetail == null)
+ {
+ throw new Exception("鏈壘鍒板嚭搴撳崟鏄庣粏淇℃伅");
+ }
+
+ var outboundOrder = await _outboundOrderService.Db.Queryable<Dt_OutboundOrder>()
+ .FirstAsync(x => x.Id == orderDetail.OrderId);
+
+ List<Dt_StockInfo> outStocks = new List<Dt_StockInfo>();
+ List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>();
+ List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>();
+
+ // 鎸夌墿鏂欏拰鎵规鍒嗙粍澶勭悊锛堣繖閲屽彧鏈変竴涓槑缁嗭級
+ var groupDetails = new List<Dt_OutboundOrderDetail> { orderDetail }
+ .GroupBy(x => new { x.MaterielCode, x.BatchNo, x.SupplyCode })
+ .Select(x => new
+ {
+ MaterielCode = x.Key.MaterielCode,
+ BatchNo = x.Key.BatchNo,
+ SupplyCode = x.Key.SupplyCode,
+ Details = x.ToList(),
+ TotalNeedQuantity = batchQuantity // 浣跨敤鍒嗘壒鏁伴噺
+ })
+ .Where(x => x.TotalNeedQuantity > 0)
+ .ToList();
+
+ foreach (var item in groupDetails)
+ {
+ var needQuantity = item.TotalNeedQuantity;
+
+ // 鑾峰彇鍙敤搴撳瓨锛堟寜鍏堣繘鍏堝嚭鎺掑簭锛�
+ List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseableStocks(item.MaterielCode, item.BatchNo, item.SupplyCode);
+ if (!stockInfos.Any())
+ {
+ throw new Exception($"鐗╂枡[{item.MaterielCode}]鎵规[{item.BatchNo}]鏈壘鍒板彲鍒嗛厤搴撳瓨");
+ }
+
+ // 鍒嗛厤搴撳瓨锛堟寜鍏堣繘鍏堝嚭锛�
+ var (autoAssignStocks, stockAllocations) = _stockService.StockInfoService.GetOutboundStocks(stockInfos, item.MaterielCode, needQuantity, out decimal residueQuantity);
+
+ // 妫�鏌ュ垎閰嶇粨鏋�
+ decimal allocatedQuantity = needQuantity - residueQuantity;
+ if (allocatedQuantity <= 0)
+ {
+ throw new Exception($"鐗╂枡[{item.MaterielCode}]鎵规[{item.BatchNo}]搴撳瓨涓嶈冻锛岄渶瑕亄needQuantity}锛屼絾鏃犳硶鍒嗛厤浠讳綍搴撳瓨");
+ }
+
+ outStocks.AddRange(autoAssignStocks);
+
+ // 鎸夊厛杩涘厛鍑哄師鍒欏垎閰嶉攣瀹氭暟閲忓埌鍚勪釜鏄庣粏
+ var distributionResult = DistributeLockQuantityByFIFO(item.Details, autoAssignStocks, stockAllocations, outStockLockInfos, outboundOrder, batchNo);
+
+ if (!distributionResult.success)
+ {
+ throw new Exception(distributionResult.message);
+ }
+
+ // 鏇存柊鍑哄簱鍗曟槑缁嗙姸鎬�
+ UpdateOrderDetailStatus(item.Details, allocatedQuantity, needQuantity);
+
+ // 鏇存柊搴撳瓨鍜屾墭鐩樼姸鎬佷负鍑哄簱閿佸畾
+ await UpdateStocksAndPalletsStatus(autoAssignStocks, stockAllocations);
+ }
+
+ if (outStocks.Any())
+ {
+ locationInfos.AddRange(_locationInfoService.GetLocationInfos(
+ outStocks.Select(x => x.LocationCode).Distinct().ToList()));
+
+
+ }
+
+ return (outStocks, groupDetails.SelectMany(x => x.Details).ToList(), outStockLockInfos, locationInfos);
+ }
+ /// <summary>
+ /// 鏇存柊搴撳瓨鍜屾墭鐩樼姸鎬�
+ /// </summary>
+ private async Task UpdateStocksAndPalletsStatus(List<Dt_StockInfo> stocks, Dictionary<int, decimal> stockAllocations)
+ {
+ foreach (var stock in stocks)
+ {
+ 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.鍑哄簱閿佸畾,
+ })
+ .Where(x => x.Id == stock.Id)
+ .ExecuteCommandAsync();
+ }
+ }
+ }
+ /// <summary>
+ /// 鎸夊厛杩涘厛鍑哄師鍒欏垎閰嶉攣瀹氭暟閲�
+ /// </summary>
+ private (bool success, string message) DistributeLockQuantityByFIFO(
+ List<Dt_OutboundOrderDetail> details,
+ List<Dt_StockInfo> assignStocks,
+ Dictionary<int, decimal> stockAllocations,
+ List<Dt_OutStockLockInfo> outStockLockInfos,
+ Dt_OutboundOrder outboundOrder,
+ string batchNo)
+ {
+ var sortedDetails = details
+ .Where(d => d.OrderQuantity - d.OverOutQuantity - d.AllocatedQuantity > 0)
+ .OrderBy(x => x.Id)
+ .ToList();
+
+ if (!sortedDetails.Any())
+ return (true, "鏃犻渶鍒嗛厤");
+
+ // 鑾峰彇鎵�鏈夊垎閰嶄簡搴撳瓨鐨勬槑缁嗭紝鎸夊厛杩涘厛鍑烘帓搴�
+ var allocatedStockDetails = assignStocks
+ .SelectMany(x => x.Details)
+ .Where(x => stockAllocations.ContainsKey(x.Id) && stockAllocations[x.Id] > 0)
+ .OrderBy(x => x.CreateDate)
+ .ThenBy(x => x.StockId)
+ .ToList();
+
+ if (!allocatedStockDetails.Any())
+ {
+ return (false, "娌℃湁鍙垎閰嶇殑搴撳瓨鏄庣粏");
+ }
+
+ decimal totalNeedQuantity = sortedDetails.Sum(d =>
+ d.OrderQuantity - d.OverOutQuantity - d.AllocatedQuantity);
+ decimal allocatedQuantity = 0;
+
+ // 涓烘瘡涓簱瀛樻槑缁嗗垱寤哄垎閰嶈褰�
+ foreach (var stockDetail in allocatedStockDetails)
+ {
+ if (!stockAllocations.TryGetValue(stockDetail.Id, out decimal allocatedQuantityForStock))
+ continue;
+
+ if (allocatedQuantityForStock <= 0) continue;
+
+ var stockInfo = assignStocks.First(x => x.Id == stockDetail.StockId);
+ decimal remainingAllocate = allocatedQuantityForStock;
+
+ // 鎸夐『搴忓垎閰嶇粰鍚勪釜鍑哄簱鍗曟槑缁�
+ foreach (var detail in sortedDetails)
+ {
+ if (remainingAllocate <= 0) break;
+
+ // 璁$畻杩欎釜鏄庣粏杩橀渶瑕佸垎閰嶇殑鏁伴噺
+ var detailNeed = detail.OrderQuantity - detail.OverOutQuantity - detail.AllocatedQuantity;
+ if (detailNeed <= 0) continue;
+
+ // 鍒嗛厤鏁伴噺
+ var assignQuantity = Math.Min(remainingAllocate, detailNeed);
+
+ // 楠岃瘉鏉$爜鏄惁瀛樺湪
+ if (string.IsNullOrEmpty(stockDetail.Barcode))
+ {
+ return (false, $"搴撳瓨鏄庣粏ID[{stockDetail.Id}]鐨勬潯鐮佷负绌�");
+ }
+
+
+ // 鍒涘缓鍑哄簱閿佸畾淇℃伅
+ var lockInfo = _outStockLockInfoService.GetOutStockLockInfo(
+ outboundOrder, detail, stockInfo, assignQuantity, stockDetail.Barcode, batchNo);
+ outStockLockInfos.Add(lockInfo);
+
+ // 鏇存柊鏄庣粏鐨勫凡鍒嗛厤鏁伴噺
+ detail.AllocatedQuantity += assignQuantity;
+ detail.LockQuantity = detail.AllocatedQuantity;
+ remainingAllocate -= assignQuantity;
+ allocatedQuantity += assignQuantity;
+ }
+
+ // 濡傛灉杩樻湁鍓╀綑鍒嗛厤鏁伴噺锛岃褰曡鍛�
+ if (remainingAllocate > 0)
+ {
+ _logger.LogWarning($"搴撳瓨鍒嗛厤鍚庝粛鏈夊墿浣欐暟閲忔湭鍒嗛厤: {remainingAllocate}, 鏉$爜: {stockDetail.Barcode}");
+ }
+ }
+
+ // 楠岃瘉鏄惁鑷冲皯鍒嗛厤浜嗕竴閮ㄥ垎
+ if (allocatedQuantity <= 0)
+ {
+ return (false, "搴撳瓨鍒嗛厤澶辫触锛屾棤娉曞垎閰嶄换浣曟暟閲�");
+ }
+
+ // 璁板綍鍒嗛厤缁撴灉
+ if (allocatedQuantity < totalNeedQuantity)
+ {
+ _logger.LogWarning($"搴撳瓨閮ㄥ垎鍒嗛厤锛岄渶瑕亄totalNeedQuantity}锛屽疄闄呭垎閰峽allocatedQuantity}");
+ }
+ else
+ {
+ _logger.LogInformation($"搴撳瓨瀹屽叏鍒嗛厤锛屽垎閰嶆暟閲弡allocatedQuantity}");
+ }
+
+ return (true, "鍒嗛厤鎴愬姛");
+ }
+
private void UpdateOrderDetailStatus(List<Dt_OutboundOrderDetail> details,
decimal allocatedQuantity, decimal needQuantity)
@@ -336,8 +606,7 @@
}
- 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);
@@ -353,12 +622,9 @@
decimal totalAssignedFromUserSelection = 0;
// 鎸夊厛杩涘厛鍑烘帓搴忕敤鎴烽�夋嫨鐨勫簱瀛�
- var userSelectedStocks = _stockService.StockInfoService.GetStockInfosByPalletCodes(
- stockSelectViews.Select(x => x.PalletCode).ToList());
+ var userSelectedStocks = _stockService.StockInfoService.GetStockInfosByPalletCodes(stockSelectViews.Select(x => x.PalletCode).ToList());
- var sortedUserSelectedStocks = userSelectedStocks
- .OrderBy(x => x.CreateDate)
- .ToList();
+ var sortedUserSelectedStocks = userSelectedStocks.OrderBy(x => x.CreateDate).ToList();
// 鍒嗛厤鐢ㄦ埛閫夋嫨鐨勫簱瀛�
foreach (var stock in sortedUserSelectedStocks)
@@ -370,26 +636,25 @@
if (userSelection == null) continue;
// 璁$畻璇ユ墭鐩樺疄闄呭彲鐢ㄦ暟閲�
- var availableQuantity = CalculateAvailableQuantity(stock, outboundOrderDetail.MaterielCode,
- outboundOrderDetail.BatchNo, outboundOrderDetail.SupplyCode);
+ var availableQuantity = CalculateAvailableQuantityByBarcode(stock, outboundOrderDetail.MaterielCode,
+ outboundOrderDetail.BatchNo, outboundOrderDetail.SupplyCode, userSelection.Barcode);
// 纭畾鍒嗛厤鏁伴噺锛氬彇鐢ㄦ埛閫夋嫨鏁伴噺銆佸彲鐢ㄦ暟閲忓拰鍓╀綑闇�姹傜殑鏈�灏忓��
- var assignQuantity = Math.Min(
- Math.Min(userSelection.UseableQuantity, availableQuantity),
- remainingNeedQuantity);
+ var assignQuantity = Math.Min(Math.Min(userSelection.UseableQuantity, availableQuantity), remainingNeedQuantity);
if (assignQuantity <= 0) continue;
- // 鎵ц鍒嗛厤
- var actualAssigned = AssignStockQuantity(stock, outboundOrderDetail, assignQuantity);
+ // 鎵ц鍒嗛厤锛屼娇鐢ㄧ敤鎴烽�夋嫨鐨勬潯鐮�
+ var actualAssigned = AssignStockQuantity(stock, outboundOrderDetail, assignQuantity, userSelection.Barcode);
+
if (actualAssigned > 0)
{
outStocks.Add(stock);
totalAssignedFromUserSelection += actualAssigned;
remainingNeedQuantity -= actualAssigned;
- // 鍒涘缓閿佸畾璁板綍
- var lockInfo = CreateOutStockLockInfo(outboundOrder, outboundOrderDetail, stock, actualAssigned);
+ // 鍒涘缓閿佸畾璁板綍锛屼娇鐢ㄧ敤鎴烽�夋嫨鐨勬潯鐮�
+ var lockInfo = CreateOutStockLockInfo(outboundOrder, outboundOrderDetail, stock, actualAssigned, userSelection.Barcode);
outStockLockInfos.Add(lockInfo);
}
}
@@ -401,48 +666,81 @@
}
// 濡傛灉鐢ㄦ埛閫夋嫨鐨勫簱瀛樹笉澶燂紝鑷姩鍒嗛厤鍓╀綑閮ㄥ垎
- decimal autoAssignedQuantity = 0;
+
if (remainingNeedQuantity > 0)
{
- List<Dt_StockInfo> autoStocks = _stockService.StockInfoService.GetUseableStocks(
- outboundOrderDetail.MaterielCode, outboundOrderDetail.BatchNo, "");
+ //// 鍙�夛細杩欓噷鍙互鏍规嵁涓氬姟闇�姹傚喅瀹氭槸鍚﹀厑璁歌嚜鍔ㄥ垎閰�
+ //// 濡傛灉瑕佹眰涓ユ牸鎸夌敤鎴烽�夋嫨鍑哄簱锛屽彲浠ユ姏鍑哄紓甯�
+ //// throw new Exception($"鐢ㄦ埛閫夋嫨鐨勫簱瀛樻暟閲忎笉瓒筹紝杩橀渶{remainingNeedQuantity}锛岃閲嶆柊閫夋嫨");
- // 鎺掗櫎鐢ㄦ埛宸查�夋嫨鐨勬墭鐩�
- autoStocks = autoStocks
- .Where(x => !stockSelectViews.Select(v => v.PalletCode).Contains(x.PalletCode))
- .ToList();
+ //// 濡傛灉闇�瑕佽嚜鍔ㄥ垎閰嶏紝璁板綍鏃ュ織
+ //_logger.LogInformation($"鐢ㄦ埛閫夋嫨鐨勫簱瀛樻暟閲忎笉瓒筹紝杩橀渶{remainingNeedQuantity}锛岀郴缁熷皢鑷姩鍒嗛厤");
- var (autoAssignStocks, stockAllocations) = _stockService.StockInfoService.GetOutboundStocks(
- autoStocks, outboundOrderDetail.MaterielCode, remainingNeedQuantity, out decimal residueQuantity);
+ //List<Dt_StockInfo> autoStocks = _stockService.StockInfoService.GetUseableStocks(
+ // outboundOrderDetail.MaterielCode,
+ // outboundOrderDetail.BatchNo,
+ // "");
- // 妫�鏌ヨ嚜鍔ㄥ垎閰嶇粨鏋�
- autoAssignedQuantity = remainingNeedQuantity - residueQuantity;
- if (autoAssignedQuantity <= 0 && remainingNeedQuantity > 0)
- {
- // 閮ㄥ垎鍒嗛厤鏄彲浠ユ帴鍙楃殑锛岃褰曡鍛婁絾涓嶆姤閿�
- _logger.LogWarning($"鑷姩鍒嗛厤澶辫触锛屽墿浣欓渶姹倇remainingNeedQuantity}鏃犳硶婊¤冻");
- }
- else if (autoAssignedQuantity > 0)
- {
- outStocks.AddRange(autoAssignStocks);
+ //// 鎺掗櫎鐢ㄦ埛宸查�夋嫨涓斿凡鍒嗛厤鐨勬墭鐩�
+ //var assignedPalletCodes = outStocks.Select(x => x.PalletCode).ToList();
+ //autoStocks = autoStocks
+ // .Where(x => !assignedPalletCodes.Contains(x.PalletCode))
+ // .ToList();
- // 涓鸿嚜鍔ㄥ垎閰嶇殑搴撳瓨鍒涘缓閿佸畾璁板綍
- var autoLockInfos = CreateLockInfosForAutoAssign(outboundOrder, outboundOrderDetail, autoAssignStocks, stockAllocations);
- outStockLockInfos.AddRange(autoLockInfos);
- }
+ //var (autoAssignStocks, stockAllocations) = _stockService.StockInfoService.GetOutboundStocks(
+ // autoStocks,
+ // outboundOrderDetail.MaterielCode,
+ // remainingNeedQuantity,
+ // out decimal residueQuantity);
+
+ //if (autoAssignStocks != null && autoAssignStocks.Any())
+ //{
+ // outStocks.AddRange(autoAssignStocks);
+
+ // // 涓鸿嚜鍔ㄥ垎閰嶇殑搴撳瓨鍒涘缓閿佸畾璁板綍
+ // var autoLockInfos = CreateLockInfosForAutoAssign(outboundOrder, outboundOrderDetail, autoAssignStocks, stockAllocations);
+ // outStockLockInfos.AddRange(autoLockInfos);
+
+ // // 鏇存柊宸插垎閰嶆暟閲�
+ // decimal autoAssignedQuantity = remainingNeedQuantity - residueQuantity;
+ // totalAssignedFromUserSelection += autoAssignedQuantity;
+ // remainingNeedQuantity = residueQuantity; // 鏇存柊鍓╀綑闇�姹�
+ //}
+ //else if (remainingNeedQuantity > 0)
+ //{
+ // _logger.LogWarning($"鑷姩鍒嗛厤澶辫触锛屽墿浣欓渶姹倇remainingNeedQuantity}鏃犳硶婊¤冻");
+ //}
}
// 鏇存柊閿佸畾鏁伴噺
- outboundOrderDetail.LockQuantity += totalAssignedFromUserSelection + autoAssignedQuantity;
+ outboundOrderDetail.LockQuantity += totalAssignedFromUserSelection;
// 鏇存柊鐘舵��
- UpdateOrderDetailStatus(outboundOrderDetail, remainingNeedQuantity - autoAssignedQuantity);
+ UpdateOrderDetailStatus(outboundOrderDetail, remainingNeedQuantity);
List<Dt_LocationInfo> locationInfos = _locationInfoService.GetLocationInfos(outStocks.Select(x => x.LocationCode).ToList());
return (outStocks, outboundOrderDetail, outStockLockInfos, locationInfos);
}
+ private decimal CalculateAvailableQuantityByBarcode(Dt_StockInfo stock, string materielCode, string batchNo, string supplyCode, string barcode)
+ {
+ var query = stock.Details.AsQueryable()
+ .Where(d => d.MaterielCode == materielCode &&
+ (d.StockQuantity - d.OutboundQuantity) > 0 &&
+ d.Barcode == barcode);
+ if (!string.IsNullOrEmpty(batchNo))
+ {
+ query = query.Where(x => x.BatchNo == batchNo);
+ }
+
+ if (!string.IsNullOrEmpty(supplyCode))
+ {
+ query = query.Where(d => d.SupplyCode == supplyCode);
+ }
+
+ return query.Sum(d => d.StockQuantity - d.OutboundQuantity);
+ }
// 杈呭姪鏂规硶
private decimal CalculateAvailableQuantity(Dt_StockInfo stock, string materielCode, string batchNo, string supplyCode)
{
@@ -455,17 +753,26 @@
return relevantDetails.Sum(d => d.StockQuantity - d.OutboundQuantity);
}
- private decimal AssignStockQuantity(Dt_StockInfo stock, Dt_OutboundOrderDetail detail, decimal assignQuantity)
+ private decimal AssignStockQuantity(Dt_StockInfo stock, Dt_OutboundOrderDetail detail, decimal assignQuantity, string barcode)
{
decimal remainingAssign = assignQuantity;
- // 鎸夊厛杩涘厛鍑哄垎閰嶅簱瀛樻槑缁�
- var sortedDetails = stock.Details
+ // 鎸夊厛杩涘厛鍑哄垎閰嶆寚瀹氭潯鐮佺殑搴撳瓨鏄庣粏
+ var query = stock.Details.AsQueryable()
.Where(d => d.MaterielCode == detail.MaterielCode &&
- d.BatchNo == detail.BatchNo &&
- (d.StockQuantity - d.OutboundQuantity) > 0)
- .OrderBy(d => d.CreateDate)
- .ToList();
+ (d.StockQuantity - d.OutboundQuantity) > 0 &&
+ d.Barcode == barcode); // 鍙垎閰嶆寚瀹氭潯鐮�
+
+ if (!string.IsNullOrEmpty(detail.BatchNo))
+ {
+ query = query.Where(x => x.BatchNo == detail.BatchNo);
+ }
+ // 濡傛灉鍑哄簱鍗曟湁渚涘簲鍟嗚姹傦紝鎸変緵搴斿晢杩囨护
+ if (!string.IsNullOrEmpty(detail.SupplyCode))
+ {
+ query = query.Where(d => d.SupplyCode == detail.SupplyCode);
+ }
+ var sortedDetails = query.ToList().OrderBy(d => d.CreateDate);
foreach (var stockDetail in sortedDetails)
{
@@ -481,13 +788,52 @@
return assignQuantity - remainingAssign; // 杩斿洖瀹為檯鍒嗛厤鏁伴噺
}
- private Dt_OutStockLockInfo CreateOutStockLockInfo(Dt_OutboundOrder outboundOrder, Dt_OutboundOrderDetail detail,
- Dt_StockInfo stock, decimal quantity)
+ private (decimal assignedQuantity, string barcode) AssignStockQuantity(Dt_StockInfo stock, Dt_OutboundOrderDetail detail, decimal assignQuantity)
{
- var barcode = stock.Details
- .Where(d => !string.IsNullOrEmpty(d.Barcode))
- .Select(d => d.Barcode)
- .FirstOrDefault();
+ decimal remainingAssign = assignQuantity;
+ string assignedBarcode = string.Empty;
+
+ // 鎸夊厛杩涘厛鍑哄垎閰嶅簱瀛樻槑缁�
+ var query = stock.Details.AsQueryable()
+ .Where(d => d.MaterielCode == detail.MaterielCode &&
+ (d.StockQuantity - d.OutboundQuantity) > 0);
+ // .OrderBy(d => d.CreateDate);
+
+ if (!string.IsNullOrEmpty(detail.BatchNo))
+ {
+ query = query.Where(x => x.BatchNo == detail.BatchNo);
+ }
+ // 濡傛灉鍑哄簱鍗曟湁渚涘簲鍟嗚姹傦紝鎸変緵搴斿晢杩囨护
+ if (!string.IsNullOrEmpty(detail.SupplyCode))
+ {
+ query = query.Where(d => d.SupplyCode == detail.SupplyCode);
+ }
+ var sortedDetails= query.ToList().OrderBy(d => d.CreateDate);
+
+
+ foreach (var stockDetail in sortedDetails)
+ {
+ if (remainingAssign <= 0) break;
+
+ var available = stockDetail.StockQuantity - stockDetail.OutboundQuantity;
+ var assign = Math.Min(available, remainingAssign);
+
+ stockDetail.OutboundQuantity += assign;
+ remainingAssign -= assign;
+ if (string.IsNullOrEmpty(assignedBarcode) && assign > 0)
+ {
+ assignedBarcode = stockDetail.Barcode;
+ }
+ }
+
+
+ return (assignQuantity - remainingAssign, assignedBarcode);
+ }
+
+ private Dt_OutStockLockInfo CreateOutStockLockInfo(Dt_OutboundOrder outboundOrder, Dt_OutboundOrderDetail detail,
+ Dt_StockInfo stock, decimal quantity,string barcode="")
+ {
+
return _outStockLockInfoService.GetOutStockLockInfo(outboundOrder, detail, stock, quantity, barcode);
}
@@ -551,8 +897,8 @@
return (false, $"鎵樼洏[{selection.PalletCode}]涓嶅瓨鍦�");
}
- var available = CalculateAvailableQuantity(stock, outboundOrderDetail.MaterielCode,
- outboundOrderDetail.BatchNo, outboundOrderDetail.SupplyCode);
+ var available = CalculateAvailableQuantityByBarcode(stock, outboundOrderDetail.MaterielCode,
+ outboundOrderDetail.BatchNo, outboundOrderDetail.SupplyCode,selection.Barcode);
if (available <= 0)
{
--
Gitblit v1.9.3