122 lines
4.9 KiB
C#
122 lines
4.9 KiB
C#
using System.Linq.Expressions;
|
|
using JNPF.Common.Extension;
|
|
using JNPF.FriendlyException;
|
|
using Mapster;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Senparc.Weixin.MP.AdvancedAPIs.Semantic;
|
|
using SqlSugar;
|
|
using Tnb.BasicData.Entities;
|
|
using Tnb.WarehouseMgr.Entities;
|
|
using Tnb.WarehouseMgr.Entities.Consts;
|
|
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
|
|
using Tnb.WarehouseMgr.Entities.Dto.Outputs;
|
|
using Tnb.WarehouseMgr.Interfaces;
|
|
|
|
namespace Tnb.WarehouseMgr
|
|
{
|
|
public class WmsCarryQueryService : BaseWareHouseService, IWmsCarryQueryService
|
|
{
|
|
private readonly ISqlSugarClient _db;
|
|
private static Dictionary<string, object> s_materialMap = new();
|
|
public WmsCarryQueryService(ISqlSugarRepository<WmsCarryH> repository)
|
|
{
|
|
_db = repository.AsSugarClient();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 载具查询接口
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
|
|
public async Task<dynamic> MESCarryQuery(MESCarryQueryInput input)
|
|
{
|
|
if (input.IsNull())
|
|
{
|
|
throw new ArgumentNullException("input");
|
|
}
|
|
|
|
List<CarryQueryOutput> data = new();
|
|
try
|
|
{
|
|
List<WmsCarryH> carrys = await _db.Queryable<WmsCarryH>()
|
|
.InnerJoin<WmsCollocationSchemeH>((a, b) => a.collocation_scheme_id == b.id)
|
|
.Where((a, b) => a.carry_code.Contains(input.carry_code) || b.bill_name.Contains(input.collocation_scheme_name))
|
|
.ToListAsync();
|
|
|
|
data = carrys.Adapt<List<CarryQueryOutput>>();
|
|
|
|
}
|
|
catch (Exception)
|
|
{
|
|
await _db.Ado.RollbackTranAsync();
|
|
}
|
|
return data;
|
|
}
|
|
/// <summary>
|
|
/// 载具查询返回接口
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
//[NonUnify]
|
|
public async Task<dynamic> MESCarryQueryResult(MESCarryQueryResultInput input)
|
|
{
|
|
if (input.IsNull())
|
|
{
|
|
throw new ArgumentNullException("input");
|
|
}
|
|
|
|
if (s_materialMap.Count < 1)
|
|
{
|
|
s_materialMap = await _db.Queryable<BasMaterial>().ToDictionaryAsync(x => x.id, x => x.name);
|
|
}
|
|
|
|
CarryQueryOutput data = new();
|
|
WmsCarryH carry = await _db.Queryable<WmsCarryH>().FirstAsync(a => a.carry_code == input.carry_code && a.status == 1);
|
|
if (carry.IsNull())
|
|
{
|
|
throw new AppFriendlyException($"编号{input.carry_code},对应载具不存在或被禁用", 500);
|
|
}
|
|
|
|
Dictionary<string, object> mCarryIdDic = await _db.Queryable<WmsCarryD>().Where(it => it.carry_id == carry.id).ToDictionaryAsync(x => x.membercarry_id, x => x.membercarry_code);
|
|
Expression<Func<WmsCarryCode, bool>> whereExp = carry.carrystd_id == WmsWareHouseConst.CARRY_LJSTD_ID && mCarryIdDic.Keys?.Count > 0
|
|
? a => mCarryIdDic.Keys.Contains(a.carry_id)
|
|
: a => a.carry_id == carry.id;
|
|
|
|
List<WmsCarryCode> carryCodes = await _db.Queryable<WmsCarryCode>().InnerJoin<WmsCarryH>((a, b) => a.carry_id == b.id).LeftJoin<WmsInstockH>((a, b, c) => a.carry_id == c.carry_id)
|
|
.Where(whereExp)
|
|
.Select((a, b, c) => new WmsCarryCode
|
|
{
|
|
check_conclusion = SqlFunc.IsNull(b.check_conclusion, 1),
|
|
instock_time = b.create_time,
|
|
}, true)
|
|
.ToListAsync();
|
|
|
|
if (carry.carrystd_id == WmsWareHouseConst.CARRY_LJSTD_ID && mCarryIdDic?.Count > 0)
|
|
{
|
|
if (carryCodes.Count < mCarryIdDic.Keys?.Count)
|
|
{
|
|
throw new AppFriendlyException("载具条码数据异常,有料箱为空", 500);
|
|
}
|
|
|
|
int i = 0;
|
|
foreach ((string mCarryId, object v) in mCarryIdDic)
|
|
{
|
|
carryCodes[i].member_carrycode = v?.ToString() ?? string.Empty;
|
|
var carryCode = carryCodes.Find(x => x.carry_id == mCarryId);
|
|
if (carryCode != null)
|
|
{
|
|
carryCodes[i].material_name = s_materialMap.ContainsKey(carryCode.material_id) ? s_materialMap[carryCode.material_id]?.ToString() ?? "" : "";
|
|
}
|
|
i++;
|
|
}
|
|
}
|
|
data = carry.Adapt<CarryQueryOutput>();
|
|
data.wmsCarryCodes = carryCodes.Adapt<List<CarryCodeQueryOutput>>();
|
|
return data;
|
|
}
|
|
}
|
|
}
|