From 8dc2427e1c5e5e349bce2d72759034c406eb0848 Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期五, 13 三月 2026 01:15:27 +0800
Subject: [PATCH] 合并
---
项目代码/WMS/WMSServices/WIDESEA_OutboundService/OutSGOrderDetailService.cs | 163 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 162 insertions(+), 1 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_OutboundService/OutSGOrderDetailService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_OutboundService/OutSGOrderDetailService.cs"
index e6ae397..907c163 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_OutboundService/OutSGOrderDetailService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WMSServices/WIDESEA_OutboundService/OutSGOrderDetailService.cs"
@@ -4,7 +4,11 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using WIDESEA_Common.LocationEnum;
+using WIDESEA_Common.StockEnum;
+using WIDESEA_Core;
using WIDESEA_Core.BaseServices;
+using WIDESEA_Core.Helper;
using WIDESEA_IBasicRepository;
using WIDESEA_IBasicService;
using WIDESEA_IOutboundRepository;
@@ -12,6 +16,7 @@
using WIDESEA_IRecordService;
using WIDESEA_IStockService;
using WIDESEA_Model.Models;
+using WIDESEA_OutboundRepository;
namespace WIDESEA_OutboundService
{
@@ -24,8 +29,9 @@
private IBasicService _basicService;
private ILocationStatusChangeRecordService _locationStatusChangeRecordService;
private readonly IMapper _mapper;
+ private readonly IOutboundRepository _outboundRepository;
- public OutSGOrderDetailService(IOutSGOrderDetailRepository BaseDal, IBasicRepository basicRepository, IStockService stockService, IOutStockLockInfoService outStockLockInfoService, IBasicService basicService, ILocationStatusChangeRecordService locationStatusChangeRecordService, IMapper mapper) : base(BaseDal)
+ public OutSGOrderDetailService(IOutSGOrderDetailRepository BaseDal, IBasicRepository basicRepository, IStockService stockService, IOutStockLockInfoService outStockLockInfoService, IBasicService basicService, ILocationStatusChangeRecordService locationStatusChangeRecordService, IMapper mapper, IOutboundRepository outboundRepository) : base(BaseDal)
{
_basicRepository = basicRepository;
_stockService = stockService;
@@ -33,6 +39,161 @@
_basicService = basicService;
_locationStatusChangeRecordService = locationStatusChangeRecordService;
_mapper = mapper;
+ _outboundRepository = outboundRepository;
+ }
+
+ /// <summary>
+ /// 鍒嗛厤搴撳瓨
+ /// </summary>
+ public (List<Dt_StockInfo>, List<Dt_OutSGOrderDetail>, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>,string) AssignStockOutbound(List<Dt_OutSGOrderDetail> outboundOrderDetails)
+ {
+ if (!outboundOrderDetails.Any())
+ {
+ throw new Exception($"鏈壘鍒板嚭搴撳崟鏄庣粏淇℃伅");
+ }
+ string message = "";
+ //鑾峰彇鎵�鏈夋帓绋嬩富琛�
+ List<Dt_OutSGOrder> outBSTOrders = _outboundRepository.OutSGOrderRepository.QueryData(x => outboundOrderDetails.Select(x=>x.OutSGOrderId).Distinct().Contains(x.Id));
+ List<Dt_StockInfo> outStocks = new List<Dt_StockInfo>();
+ //瀵瑰嚭搴撶墿鏂欒繘琛屽垎缁�
+ List<Dt_OutSGOrderDetail> groupDetails = outboundOrderDetails.GroupBy(x => new { x.MaterialNo, x.Width, x.MachineName }).Select(x =>
+ new Dt_OutSGOrderDetail
+ {
+ XqLen = x.Sum(v => v.XqLen),
+ MaterialNo = x.Key.MaterialNo,
+ Width = x.Key.Width,
+ MachineName = x.Key.MachineName
+ }
+ ).ToList();
+ Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseId == outBSTOrders.FirstOrDefault().WarehouseId);
+ //鍑哄簱璇︽儏
+ List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>();
+ //璐т綅瀛樺偍
+ List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>();
+
+ foreach (var item in groupDetails)
+ {
+ decimal needQuantity = item.XqLen;
+ //鑾峰彇鎵�鏈夋潯鐮�
+ List<string> palletCodes = outStocks.Select(x => x.PalletCode).ToList();
+ //鑾峰彇鑰佸巶缂撳瓨鍙敤搴撳瓨
+ List<Dt_StockInfo> stockInfos = _stockService.StockInfoService.GetUseOldCacheStocks(item.MaterialNo, item.Width).Where(x => !palletCodes.Contains(x.PalletCode)).ToList() ?? new List<Dt_StockInfo>();
+ //鑾峰彇绔嬪簱鍙敤搴撳瓨
+ stockInfos.AddRange(_stockService.StockInfoService.GetUseableStocks(item.MaterialNo, item.Width, outBSTOrders.FirstOrDefault().WarehouseId).Where(x=>!palletCodes.Contains(x.PalletCode)).ToList());
+ if (!stockInfos.Any())
+ {
+ message += $"鐗╂枡锛歿item.MaterialNo},骞呭锛歿item.Width}鏃犲簱瀛橈紱";
+ continue;
+ }
+
+ //鍒嗛厤瀹為檯搴撳瓨
+ List<Dt_StockInfo> autoAssignStocks = _stockService.StockInfoService.GetOutOldStocks(stockInfos, needQuantity).ToList();
+ //娣诲姞搴撳瓨鍒嗛厤
+ outStocks.AddRange(autoAssignStocks);
+ //鑾峰彇鎵�鏈夎鐗╂枡鍗曟嵁
+ List<Dt_OutSGOrderDetail> details = outboundOrderDetails.Where(x => x.MaterialNo == item.MaterialNo && x.Width == item.Width && x.MachineName == item.MachineName).ToList();
+ autoAssignStocks.ForEach(x =>
+ {
+ x.StockOutLength = 0;
+ });
+ for (int i = 0; i < details.Count; i++)
+ {
+ ////璁㈠崟鏁伴噺
+ //if ((details.Count-1) == i)
+ //{
+
+ //}
+ decimal orderQuantity = details[i].XqLen;
+ bool assignStop = true;
+ while (assignStop)
+ {
+ //鍑哄簱璁㈠崟鏄庣粏宸插垎閰嶆暟閲�
+ decimal detailAssignQuantity = outStockLockInfos.Where(x => x.OrderDetailId == details[i].Id).Sum(x => x.AssignQuantity);
+
+ decimal orderDetailNeedQuantity = details[i].XqLen - detailAssignQuantity;
+
+ if (autoAssignStocks.Count==0)
+ {
+ break;
+ }
+
+ decimal useStockLength = autoAssignStocks[0].StockLength- autoAssignStocks[0].StockOutLength;
+ Dt_OutSGOrder? sGOrder = outBSTOrders.FirstOrDefault(x => x.Id == details[i].OutSGOrderId);
+ if (orderDetailNeedQuantity > useStockLength)
+ {
+ //鐢熸垚璇︽儏
+ Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(sGOrder, details[i], autoAssignStocks[0], useStockLength);
+ outStockLockInfos.Add(outStockLockInfo);
+ details[i].AssignTotalUsage += useStockLength;
+ autoAssignStocks.Remove(autoAssignStocks[0]);
+ }
+ else
+ {
+ //鐢熸垚璇︽儏
+ Dt_OutStockLockInfo outStockLockInfo = _outStockLockInfoService.GetOutStockLockInfo(sGOrder, details[i], autoAssignStocks[0], orderDetailNeedQuantity);
+ outStockLockInfos.Add(outStockLockInfo);
+ details[i].AssignTotalUsage = orderQuantity;
+ autoAssignStocks[0].StockOutLength+= orderDetailNeedQuantity;
+ if (autoAssignStocks[0].StockOutLength== autoAssignStocks[0].StockLength)
+ {
+ autoAssignStocks.Remove(autoAssignStocks[0]);
+ }
+ assignStop =false;
+ }
+ }
+
+ }
+
+ locationInfos.AddRange(_basicRepository.LocationInfoRepository.GetLocationInfos(outStocks.Where(x=>!x.LocationCode.IsNullOrEmpty() && !locationInfos.Select(x=>x.LocationCode).Contains(x.LocationCode)).Select(x => x.LocationCode).ToList()));
+ }
+
+ return (outStocks, outboundOrderDetails, outStockLockInfos, locationInfos, message);
+ }
+ /// <summary>
+ /// 鍑哄簱搴撳瓨鍒嗛厤鍚庯紝鏇存柊鏁版嵁搴撴暟鎹�
+ /// </summary>
+ public WebResponseContent LockOutboundStockDataUpdate(List<Dt_StockInfo> stockInfos, List<Dt_OutSGOrderDetail> outboundOrderDetails, List<Dt_OutStockLockInfo> outStockLockInfos, List<Dt_LocationInfo> locationInfos, LocationStatusEnum locationStatus = LocationStatusEnum.Lock, List<Dt_Task>? tasks = null)
+ {
+ try
+ {
+ stockInfos.Where(x => x.LocationCode.IsNullOrEmpty()).ToList().ForEach(x =>
+ {
+ x.StockStatus = StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt();
+ });
+ _stockService.StockInfoService.Repository.UpdateData(stockInfos);
+ BaseDal.UpdateData(outboundOrderDetails);
+
+ List<Dt_OutStockLockInfo> addOutStockLockInfos = outStockLockInfos.Where(x => x.Id == 0).ToList();
+ if (addOutStockLockInfos != null && addOutStockLockInfos.Any())
+ {
+ if (tasks != null)
+ {
+ addOutStockLockInfos.ForEach(x =>
+ {
+ x.TaskNum = tasks.FirstOrDefault(v => v.PalletCode == x.PalletCode)?.TaskNum;
+ });
+ }
+
+ _outStockLockInfoService.Repository.AddData(addOutStockLockInfos);
+ List<Dt_OutStockLockInfo> addOutCacheInfos = addOutStockLockInfos.Where(x => x.LocationCode.Contains("鑰佸巶缂撳瓨鍖�")).ToList();
+ List<Dt_OutLineView> outLineViewsAdd = addOutCacheInfos.Select(x => _mapper.Map<Dt_OutLineView>(x)).ToList();
+ _outboundRepository.OutLineViewRepository.AddData(outLineViewsAdd);
+ }
+ List<Dt_OutStockLockInfo> updateOutStockLockInfos = outStockLockInfos.Where(x => x.Id > 0).ToList();
+ if (updateOutStockLockInfos != null && updateOutStockLockInfos.Any())
+ {
+ _outStockLockInfoService.Repository.UpdateData(updateOutStockLockInfos);
+ }
+ //娣诲姞璐т綅鐘舵��
+ _locationStatusChangeRecordService.AddLocationStatusChangeRecord(locationInfos, locationStatus, LocationChangeType.OutboundAssignLocation, "", tasks?.Select(x => x.TaskNum).ToList());
+ //鎵归噺鏇存柊璐т綅鐘舵��
+ _basicService.LocationInfoService.Repository.UpdateLocationStatus(locationInfos, locationStatus);
+ return WebResponseContent.Instance.OK();
+ }
+ catch (Exception ex)
+ {
+ return WebResponseContent.Instance.Error(ex.Message);
+ }
}
}
}
--
Gitblit v1.9.3