From d87de78f54ef7b9950b20a81429f394537cee210 Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 20 Jun 2023 09:15:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=BA=E5=BA=93=E7=94=B3=E8=AF=B7=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Tnb.WarehouseMgr/WareHouseService.cs | 1 + .../Tnb.WarehouseMgr/WmsOutStockService.cs | 68 ++++++++++++++++++- 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs index 52b0f055..ebf0852b 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs @@ -479,6 +479,7 @@ namespace Tnb.WarehouseMgr await _db.Ado.CommitTranAsync(); } + } catch (Exception ex) { await _db.Ado.RollbackTranAsync(); diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsOutStockService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsOutStockService.cs index da26eca2..ed96f2c6 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsOutStockService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsOutStockService.cs @@ -4,12 +4,19 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using JNPF.Common.Dtos.VisualDev; +using JNPF.Common.Extension; +using JNPF.Common.Security; +using JNPF.FriendlyException; using JNPF.Systems.Interfaces.System; using JNPF.VisualDev; +using JNPF.VisualDev.Entitys; +using JNPF.VisualDev.Interfaces; +using Mapster; using Microsoft.AspNetCore.Mvc; using SqlSugar; using Tnb.WarehouseMgr.Entities; using Tnb.WarehouseMgr.Entities.Consts; +using Tnb.WarehouseMgr.Entities.Enums; using Tnb.WarehouseMgr.Interfaces; namespace Tnb.WarehouseMgr @@ -22,16 +29,75 @@ namespace Tnb.WarehouseMgr { private readonly ISqlSugarClient _db; private readonly IDictionaryDataService _dictionaryDataService; - public WmsOutStockService(ISqlSugarRepository repository, IDictionaryDataService dictionaryDataService) + private readonly IRunService _runService; + private readonly IVisualDevService _visualDevService; + private readonly IWareHouseService _wareHouseService; + + public WmsOutStockService( + ISqlSugarRepository repository, + IDictionaryDataService dictionaryDataService, + IRunService runService, + IVisualDevService visualDevService, + IWareHouseService wareHouseService) { _db = repository.AsSugarClient(); _dictionaryDataService = dictionaryDataService; + _runService = runService; + _visualDevService = visualDevService; + _wareHouseService = wareHouseService; OverideFuncs.CreateAsync = OutStockApplyFor; } private async Task OutStockApplyFor(VisualDevModelDataCrInput input) { + VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleConsts.MODULE_WMSOUTSTOCK_ID, true); + await _runService.Create(templateEntity, input); + + //tablefield120 出库物料明细 + if (input.data.ContainsKey("tablefield120") && input.data["tablefield120"].IsNotEmptyOrNull()) + { + var outStockDList = input.data["tablefield120"].ToObject>(); + if (outStockDList?.Count > 0) + { + List carryMats = new(); + foreach (var os in outStockDList) + { + var carryCodes = await _db.Queryable().InnerJoin((a, b) => a.id == b.carry_id) + .Where((a, b) => b.material_id == os.material_id && b.code_batch == os.code_batch && a.is_lock == 0 && + !string.IsNullOrEmpty(a.location_id) && a.status == (int)EnumCarryStatus.占用) + .Select() + .ToListAsync(); + if (carryCodes?.Count > 0) + { + var codeQty = carryCodes.Sum(x => x.codeqty); + if (codeQty < os.pr_qty) + { + throw new AppFriendlyException($"需要出库[{os.pr_qty}],实际库存{codeQty},数量不足", 500); + } + var partCarryMats = carryCodes.Adapt>(); + partCarryMats.ForEach(x => + { + x.need_qty = (int)os.pr_qty; + x.real_qty = codeQty; + }); + carryMats.AddRange(partCarryMats); + } + } + if (carryMats.Count > 0) + { + carryMats.ForEach(x => x.id = SnowflakeIdHelper.NextId()); + carryMats = carryMats.OrderBy(o => o.create_time).GroupBy(g => new { g.carry_id, g.material_id, g.code_batch }) + .Select(x => + { + WmsCarryMat carryMat = x.FirstOrDefault()!; + carryMat.real_qty = x.Sum(d => d.real_qty); + return carryMat; + }) + .ToList(); + } + } + } return Task.FromResult(0); }