From a1238dc822fbd0fb2a1dfb16a7c4b7425eb5a5ab Mon Sep 17 00:00:00 2001
From: heshaofeng <heshaofeng@hnkhzn.com>
Date: 星期五, 07 十一月 2025 10:56:38 +0800
Subject: [PATCH] Merge branch 'master' of http://115.159.85.185:8098/r/ZhongRui/ALDbanyunxiangmu
---
项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_StockService/StockInfoService.cs | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 102 insertions(+), 1 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_StockService/StockInfoService.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_StockService/StockInfoService.cs"
index 3ed0705..c047a3e 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_StockService/StockInfoService.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_StockService/StockInfoService.cs"
@@ -2,6 +2,7 @@
using WIDESEA_Common.StockEnum;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.BaseServices;
+using WIDESEA_IBasicService;
using WIDESEA_IRecordService;
using WIDESEA_IStockService;
using WIDESEA_Model.Models;
@@ -15,11 +16,14 @@
private readonly IRecordService _recordService;
public IRepository<Dt_StockInfo> Repository => BaseDal;
private readonly IRepository<Dt_StockInfoDetail> _stockInfoDetailRepository;
- public StockInfoService(IRepository<Dt_StockInfo> BaseDal, IMapper mapper, IRepository<Dt_StockInfoDetail> stockInfoDetailRepository, IRecordService recordService) : base(BaseDal)
+
+ private readonly ILocationInfoService _locationInfoService;
+ public StockInfoService(IRepository<Dt_StockInfo> BaseDal, IMapper mapper, IRepository<Dt_StockInfoDetail> stockInfoDetailRepository, IRecordService recordService, ILocationInfoService locationInfoService) : base(BaseDal)
{
_mapper = mapper;
_stockInfoDetailRepository = stockInfoDetailRepository;
_recordService = recordService;
+ _locationInfoService = locationInfoService;
}
/// <summary>
@@ -72,5 +76,102 @@
_recordService.StockQuantityChangeRecordService.AddStockChangeRecord(stockInfo, stockInfo.Details, beforeQuantity, stockInfo.Details.Sum(x => x.StockQuantity) + beforeQuantity, WIDESEA_Common.StockEnum.StockChangeType.MaterielGroup);
}
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="stockInfos"></param>
+ /// <param name="materielCode"></param>
+ /// <param name="needQuantity"></param>
+ /// <param name="residueQuantity"></param>
+ /// <returns></returns>
+ public List<Dt_StockInfo> GetOutboundStocks(List<Dt_StockInfo> stockInfos, string materielCode, decimal needQuantity, out decimal residueQuantity)
+ {
+ List<Dt_StockInfo> outStocks = new List<Dt_StockInfo>();
+ var stockTotalQuantity = stockInfos.Select(x => x.Details.Sum(v => v.StockQuantity - v.OutboundQuantity)).Sum(x => x);
+ //stockInfos = stockInfos.OrderBy(x => x.Id).ToList();
+ if (stockTotalQuantity >= needQuantity)//搴撳瓨澶�
+ {
+ int index = 0;
+ while (needQuantity > 0)
+ {
+ Dt_StockInfo stockInfo = stockInfos[index];
+ // 璁$畻鍙敤搴撳瓨鏃惰浆鎹负decimal
+ decimal useableStockQuantity = stockInfo.Details
+ .Where(x => x.MaterielCode == materielCode)
+ .Sum(x => (decimal)x.StockQuantity - (decimal)x.OutboundQuantity);
+
+ // 灏唍eedQuantity杞崲涓篸ecimal杩涜姣旇緝
+ if (useableStockQuantity < (decimal)needQuantity && useableStockQuantity > 0)
+ {
+ stockInfo.Details.ForEach(x =>
+ x.OutboundQuantity = x.StockQuantity);
+
+ // 浣跨敤decimal杩涜璁$畻鍚庡啀杞洖float
+ needQuantity = needQuantity - useableStockQuantity;
+ }
+ else
+ {
+ stockInfo.Details.ForEach(x =>
+ {
+ if (x.StockQuantity > x.OutboundQuantity && x.MaterielCode == materielCode)
+ {
+ // 灏嗙浉鍏冲�艰浆鎹负decimal杩涜绮剧‘璁$畻
+ decimal currentStock = (decimal)x.StockQuantity;
+ decimal currentOutbound = (decimal)x.OutboundQuantity;
+ decimal currentNeed = (decimal)needQuantity;
+ decimal available = currentStock - currentOutbound;
+
+ if (available >= currentNeed)
+ {
+ x.OutboundQuantity = currentOutbound + currentNeed;
+ needQuantity = 0;
+ }
+ else
+ {
+ needQuantity =currentNeed - available;
+ x.OutboundQuantity = x.StockQuantity;
+ }
+ }
+ });
+ }
+ outStocks.Add(stockInfo);
+ index++;
+ }
+
+ }
+ else
+ {
+ throw new Exception("搴撳瓨涓嶈冻");
+ }
+ residueQuantity = needQuantity;
+ return outStocks;
+ }
+
+ public List<Dt_StockInfo> GetStockInfos(string materielCode, string lotNo, List<string> locationCodes)
+ {
+ List<Dt_StockInfo> stockInfos = null;
+ if (!string.IsNullOrEmpty(lotNo))
+ {
+ var stockSort = Db.Queryable<Dt_StockInfo>().Where(x => locationCodes.Contains(x.LocationCode)).Includes(x => x.Details).Where(x => x.Details.Any(v => v.MaterielCode == materielCode && v.BatchNo == lotNo)).ToList();
+ stockInfos = stockSort.OrderBy(x => x.Details.FirstOrDefault()?.EffectiveDate).ThenBy(x => x.Details.Sum(v => v.StockQuantity)).ToList();
+ }
+ else
+ {
+ var stockSort = Db.Queryable<Dt_StockInfo>().Where(x => locationCodes.Contains(x.LocationCode)).Includes(x => x.Details).Where(x => x.Details.Any(v => v.MaterielCode == materielCode)).ToList();
+ stockInfos = stockSort.OrderBy(x => x.Details.FirstOrDefault()?.EffectiveDate).ThenBy(x => x.Details.Sum(v => v.StockQuantity)).ToList();
+ }
+
+ return stockInfos;
+ //ISugarQueryable<Dt_LocationInfo> sugarQueryable = Db.Queryable<Dt_LocationInfo>().Where(x => locationCodes.Contains(x.LocationCode));
+ //ISugarQueryable<Dt_StockInfo> sugarQueryable1 = Db.Queryable<Dt_StockInfo>().Includes(x => x.Details).Where(x => x.Details.Any(v => v.MaterielCode == materielCode));
+ //return sugarQueryable.InnerJoin(sugarQueryable1, (a, b) => a.LocationCode == b.LocationCode).Select((a, b) => b).OrderBy(a => a.CreateDate).Includes(a => a.Details).ToList();
+ }
+
+ public List<Dt_StockInfo> GetUseableStocks(string materielCode, string batchNo)
+ {
+ List<string> locationCodes = _locationInfoService.GetCanOutLocationCodes();
+
+ return GetStockInfos(materielCode, batchNo, locationCodes);
+ }
}
}
--
Gitblit v1.9.3