From 5d7175c98f5e06883ca8d2724b7a32c4463e7d56 Mon Sep 17 00:00:00 2001 From: alex Date: Wed, 6 Sep 2023 17:09:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=87=BA=E5=BA=93=E7=94=B3?= =?UTF-8?q?=E8=AF=B7=EF=BC=8C=E6=A0=B9=E6=8D=AE=E5=B7=A5=E4=BD=8D=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=8C=B9=E9=85=8D=E7=BB=88=E6=AD=A2=E5=BA=93=E4=BD=8D?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Tnb.WarehouseMgr/WmsOutStockService.cs | 113 +++++++++++------- 1 file changed, 73 insertions(+), 40 deletions(-) diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsOutStockService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsOutStockService.cs index ba6e9562..d2bd6152 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsOutStockService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsOutStockService.cs @@ -19,6 +19,7 @@ using JNPF.VisualDev.Interfaces; using Mapster; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json.Linq; +using NPOI.SS.Formula.Functions; using SqlSugar; using SqlSugar.DbConvert; using Tnb.BasicData.Entities; @@ -76,14 +77,63 @@ namespace Tnb.WarehouseMgr OverideFuncs.CreateAsync = OutStockApplyFor; } - private async Task OutStockApplyFor(VisualDevModelDataCrInput input) { try { await _db.Ado.BeginTranAsync(); //判断目标库位是否自动签收 - var loc = await _db.Queryable().SingleAsync(it => it.id == input.data[nameof(WmsPointH.location_id)].ToString()); + BasLocation? loc = null; + if (input.data.ContainsKey(nameof(WmsPointH.location_id)) && input.data[nameof(WmsPointH.location_id)].IsNotEmptyOrNull()) + { + loc = await _db.Queryable().SingleAsync(it => it.id == input.data[nameof(WmsPointH.location_id)].ToString()); + } + else if (input.data.ContainsKey(nameof(WmsOutstockH.station_id)) && input.data[nameof(WmsOutstockH.station_id)].IsNotEmptyOrNull()) + { + //多个投料库位 + /* + * 天益 + * 2、不管库位是否为空, 获取到所有库位 A B + * 2.1 根据这些库位去查任务执行 目的库位是这些库位的未完成任务数。 A 10 B 9 + * 2.2 哪个最少给哪个 + */ + var org = await _db.Queryable().FirstAsync(it => it.Id == input.data[nameof(WmsOutstockH.station_id)].ToString()); + if (!org?.FeedingLocationId.IsNullOrWhiteSpace() ?? false) + { + var fLocIds = JArray.Parse(org.FeedingLocationId).Values().ToList(); + var minTaskNumLocs = await _db.Queryable().Where(it => it.status != WmsWareHouseConst.PRETASK_BILL_STATUS_COMPLE_ID && fLocIds.Contains(it.endlocation_id)) + .GroupBy(it => it.endlocation_id) + .Select(it => new + { + it.endlocation_id, + count = SqlFunc.AggregateCount(it.endlocation_id) + }) + .MergeTable() + .OrderBy(it => it.count) + .ToListAsync(); + if (minTaskNumLocs?.Count > 0) + { + var freeLocIds = fLocIds.Except(minTaskNumLocs.Select(x => x.endlocation_id)).ToList(); + if (freeLocIds?.Count > 0) + { + var rIdx = new Random().Next(0, freeLocIds.Count); + loc = await _db.Queryable().SingleAsync(it => it.id == freeLocIds[rIdx]); + } + else + { + var firstLocId = minTaskNumLocs.FirstOrDefault().endlocation_id; + loc = await _db.Queryable().SingleAsync(it => it.id == firstLocId); + } + } + else if (minTaskNumLocs?.Count < 1) + { + var rIdx = new Random().Next(0, fLocIds.Count); + loc = await _db.Queryable().SingleAsync(it => it.id == fLocIds[rIdx]); + } + input.data[nameof(WmsOutstockH.location_id)] = loc.id; + } + } + var carryIds = new List(); //tablefield120 出库物料明细 @@ -98,20 +148,20 @@ namespace Tnb.WarehouseMgr { var OutStockStrategyInput = new OutStockStrategyQuery { - carry_id = input.data[nameof(OutStockStrategyQuery.carry_id)].ToString(), - warehouse_id = input.data[nameof(WmsOutstockH.warehouse_id)].ToString(), + carry_id = input.data[nameof(OutStockStrategyQuery.carry_id)]?.ToString() ?? string.Empty, + warehouse_id = input.data[nameof(WmsOutstockH.warehouse_id)]?.ToString() ?? string.Empty, material_id = os.material_id, code_batch = os.code_batch, }; var outStkCarrys = await _wareHouseService.OutStockStrategy(OutStockStrategyInput); - Expression> whereExp = input.data.ContainsKey(nameof(WmsOutstockH.carry_id)) + Expression> whereExp = input.data.ContainsKey(nameof(WmsOutstockH.carry_id)) && input.data[nameof(WmsOutstockH.carry_id)].IsNotEmptyOrNull() ? (a, b) => a.id == input.data[nameof(WmsOutstockH.carry_id)].ToString() : (a, b) => outStkCarrys.Select(x => x.id).Contains(b.carry_id); List? carryCodesPart = await _db.Queryable().InnerJoin((a, b) => a.id == b.carry_id).InnerJoin((a, b, c) => a.location_id == c.id) .Where(whereExp) .Select() - .ToListAsync(); + .ToListAsync(); if (carryCodesPart?.Count > 0) { @@ -177,8 +227,20 @@ namespace Tnb.WarehouseMgr } } carryIds = allOutIds.Concat(sortingOutIds).ToList(); - await _db.Updateable().SetColumns(it => new WmsCarryH { out_status = ((int)EnumOutStatus.全部出).ToString(), source_id = input.data[nameof(WmsOutstockH.source_id)].ToString(), source_code = input.data[nameof(WmsOutstockH.source_code)].ToString() }).Where(it => allOutIds.Contains(it.id)).ExecuteCommandAsync(); - await _db.Updateable().SetColumns(it => new WmsCarryH { out_status = ((int)EnumOutStatus.分拣出).ToString(), source_id = input.data[nameof(WmsOutstockH.source_id)].ToString(), source_code = input.data[nameof(WmsOutstockH.source_code)].ToString() }).Where(it => sortingOutIds.Contains(it.id)).ExecuteCommandAsync(); + var carryH = new WmsCarryH + { + out_status = ((int)EnumOutStatus.全部出).ToString(), + source_id = input.data.ContainsKey(nameof(WmsOutstockH.source_id)) ? input.data[nameof(WmsOutstockH.source_id)]?.ToString() ?? string.Empty : string.Empty, + source_code = input.data.ContainsKey(nameof(WmsOutstockH.source_code)) ? input.data[nameof(WmsOutstockH.source_code)]?.ToString() ?? string.Empty : string.Empty, + }; + await _db.Updateable(carryH) + .UpdateColumns(it => new { it.out_status, it.source_id, it.source_code }) + .Where(it => allOutIds.Contains(it.id)) + .ExecuteCommandAsync(); + carryH.out_status = ((int)EnumOutStatus.分拣出).ToString(); + await _db.Updateable(carryH) + .UpdateColumns(it => new { it.out_status, it.source_id, it.source_code }) + .ExecuteCommandAsync(); } @@ -205,37 +267,7 @@ namespace Tnb.WarehouseMgr } if (input.data.ContainsKey(nameof(WmsPointH.location_id)) && input.data[nameof(WmsPointH.location_id)].IsNotEmptyOrNull()) { - ePoint = await _db.Queryable().FirstAsync(it => it.location_id == input.data[nameof(WmsPointH.location_id)].ToString()); - } - else if (input.data.ContainsKey(nameof(WmsOutstockH.station_id))) - { - //多个投料库位 - /* - * 潍柴 - * 1、那个库位状态是空的出那个 - * 1.1、没有空位直接抛异常 - * - * 天益 - * 2、不管库位是否为空, 获取到所有库位 A B - * 2.1 根据这些库位去查任务执行 目的库位是这些库位的未完成任务数。 A 10 B 9 - * 2.2 哪个最少给哪个 - */ - var org = await _db.Queryable().FirstAsync(it => it.Id == input.data[nameof(WmsOutstockH.station_id)].ToString()); - if (!org?.FeedingLocationId.IsNullOrWhiteSpace() ?? false) - { - var fLocIds = JArray.Parse(org.FeedingLocationId).Values(); - var minTaskNumLoc = await _db.Queryable().Where(it => it.status != WmsWareHouseConst.PRETASK_BILL_STATUS_COMPLE_ID && fLocIds.Contains(it.endlocation_id)) - .GroupBy(it => it.endlocation_id) - .Select(it => new - { - it.endlocation_id, - count = SqlFunc.AggregateCount(it.endlocation_id) - }) - .MergeTable() - .OrderBy(it => it.count) - .FirstAsync(); - ePoint = await _db.Queryable().FirstAsync(it => it.location_id == minTaskNumLoc.endlocation_id); - } + ePoint = await _db.Queryable().FirstAsync(it => it.location_id == loc.id); } if (sPoint != null && ePoint != null) @@ -323,8 +355,9 @@ namespace Tnb.WarehouseMgr await _db.Ado.CommitTranAsync(); } - catch (Exception) + catch (Exception ex) { + JNPF.Logging.Log.Error(ex.ToString()); await _db.Ado.RollbackTranAsync(); throw; }