diff --git a/be/Hosts/WmsPda.Host/Win_in.Sfs.Wms.Pda.Host/Controllers/Inventories/BalanceController.cs b/be/Hosts/WmsPda.Host/Win_in.Sfs.Wms.Pda.Host/Controllers/Inventories/BalanceController.cs index 2b466b511..830f91326 100644 --- a/be/Hosts/WmsPda.Host/Win_in.Sfs.Wms.Pda.Host/Controllers/Inventories/BalanceController.cs +++ b/be/Hosts/WmsPda.Host/Win_in.Sfs.Wms.Pda.Host/Controllers/Inventories/BalanceController.cs @@ -1,9 +1,14 @@ +using DocumentFormat.OpenXml.Drawing.Charts; +using Volo.Abp.AutoMapper; + namespace Win_in.Sfs.Wms.Pda.Controllers.Inventories; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using AutoMapper; +using Castle.Components.DictionaryAdapter; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using Volo.Abp; @@ -26,12 +31,11 @@ using JsonSerializer = System.Text.Json.JsonSerializer; public class BalanceController : AbpController { private readonly IBalanceAppService _balanceAppService; - private readonly IItemBasicAppService _itemBasicAppService; - private readonly ILocationAppService _locationAppService; - private readonly IExpectOutAppService _expectOutAppService; + private readonly IProductionLineItemAppService _productionLineItemAppService; + private IMapper _mapper; /// /// @@ -43,11 +47,12 @@ public class BalanceController : AbpController public BalanceController( IBalanceAppService balanceAppService, IItemBasicAppService itemBasicAppService, - ILocationAppService locationAppService, IExpectOutAppService expectOutAppService) + ILocationAppService locationAppService, IExpectOutAppService expectOutAppService, IProductionLineItemAppService productionLineItemAppService) { this._balanceAppService = balanceAppService; this._locationAppService = locationAppService; _expectOutAppService = expectOutAppService; + _productionLineItemAppService = productionLineItemAppService; this._itemBasicAppService = itemBasicAppService; } @@ -482,6 +487,77 @@ public class BalanceController : AbpController return await this._balanceAppService.GetPagedListByFilterAsync(input, false).ConfigureAwait(false); } + /// + /// + /// + /// + /// + /// + [HttpPost("get-recommend-balance")] + public async Task> GetRecommendBalance(string itemCode,string productLine) + { + var productionLineItemDto = await _productionLineItemAppService.GetByProductLineCodeAndItemCodeAsync(productLine, itemCode).ConfigureAwait(false); + + //获取可用库存 + var input = new RecommendBalanceRequestInput + { + ItemCode = itemCode, + Qty = decimal.MaxValue, + Statuses = new EditableList { EnumInventoryStatus.OK }, + Locations = + JsonSerializer.Deserialize>(productionLineItemDto.RawLocationCodeListJson), + IsPackingCode = true + }; + + var usableList = await _balanceAppService.GetUsableListAsync(input).ConfigureAwait(false); + return await SortByFifoAsync(usableList).ConfigureAwait(false); + } + + /// + /// 排序规则 1.批次正序 2.底层 3.到货日期正序 4.数量倒序(整箱优先) 5.库位正序 6.箱码正序 + /// + /// + /// + private async Task> SortByFifoAsync(List balances) + { + var sortBalances = new List(); + var config = new MapperConfiguration(cfg => + { + cfg.CreateMap() + .Ignore(x => x.LocationRow); + }); + _mapper = new Mapper(config); + + var resultBalances = _mapper.Map, List>(balances); + foreach (var resultBalance in resultBalances) + { + var locationDto = await _locationAppService.GetByCodeAsync(resultBalance.LocationCode).ConfigureAwait(false); + resultBalance.LocationRow = locationDto.RowCode; + } + + resultBalances + .OrderBy(p => p.Lot) + .ThenBy(p => p.LocationRow) + .ThenBy(p => p.PutInTime) + .ThenBy(p => p.Qty)//2023-9-14 苑静雯 从小数开始发料 + .ThenBy(p => p.LocationCode) + .ThenBy(p => p.PackingCode) + .ToList(); + + return resultBalances; + } + + /// + /// + /// + public class SortBalance : BalanceDTO + { + /// + /// + /// + public int LocationRow { get; set; } + } + /* /// /// 查询库余额 diff --git a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/KittingIssueRequestEventHandler.cs b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/KittingIssueRequestEventHandler.cs index 1ccb8b4f3..17528e307 100644 --- a/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/KittingIssueRequestEventHandler.cs +++ b/be/Modules/Store/src/Win_in.Sfs.Wms.Store.Event/Requests/KittingIssueRequestEventHandler.cs @@ -690,7 +690,7 @@ public class KittingIssueRequestEventHandler resultBalances .OrderBy(p => p.Lot) - .OrderBy(p=>p.LocationRow) + .ThenBy(p=>p.LocationRow) .ThenBy(p => p.PutInTime) .ThenBy(p => p.Qty)//2023-9-14 苑静雯 从小数开始发料 .ThenBy(p => p.LocationCode)