出库申请代码提交
This commit is contained in:
@@ -479,6 +479,7 @@ namespace Tnb.WarehouseMgr
|
||||
|
||||
await _db.Ado.CommitTranAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await _db.Ado.RollbackTranAsync();
|
||||
|
||||
@@ -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<WmsOutstockD> repository, IDictionaryDataService dictionaryDataService)
|
||||
private readonly IRunService _runService;
|
||||
private readonly IVisualDevService _visualDevService;
|
||||
private readonly IWareHouseService _wareHouseService;
|
||||
|
||||
public WmsOutStockService(
|
||||
ISqlSugarRepository<WmsOutstockD> 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<dynamic> 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<List<WmsOutstockD>>();
|
||||
if (outStockDList?.Count > 0)
|
||||
{
|
||||
List<WmsCarryMat> carryMats = new();
|
||||
foreach (var os in outStockDList)
|
||||
{
|
||||
var carryCodes = await _db.Queryable<WmsCarryH>().InnerJoin<WmsCarryCode>((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<WmsCarryCode>()
|
||||
.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<List<WmsCarryMat>>();
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user