121 lines
5.2 KiB
C#
121 lines
5.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
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
|
|
{
|
|
/// <summary>
|
|
/// 出库申请业务类
|
|
/// </summary>
|
|
[OverideVisualDev(ModuleConsts.MODULE_WMSOUTSTOCK_ID)]
|
|
public class WmsOutStockService : BaseWareHouseService, IWmsOutStockService
|
|
{
|
|
private readonly ISqlSugarClient _db;
|
|
private readonly 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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据出库申请单ID获取申请单明细信息
|
|
/// </summary>
|
|
/// <param name="billId"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
public async Task<dynamic> GetInStockDetailsListById([FromRoute] string billId)
|
|
{
|
|
var dic = await _dictionaryDataService.GetDictionaryByTypeId(WmsWareHouseConst.WMS_INSTOCK_D_BILL_STATUS_TYPEID);
|
|
var items = await _db.Queryable<WmsOutstockD>().Where(it => it.bill_id == billId).ToListAsync();
|
|
_db.ThenMapper(items,
|
|
it => it.line_status = dic.ContainsKey(it.line_status) ? dic[it.line_status]?.ToString()! : "");
|
|
return items;
|
|
}
|
|
}
|
|
}
|