using System.Linq.Expressions;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using Tnb.BasicData.Entities;
using Tnb.WarehouseMgr.Entities;
using Tnb.WarehouseMgr.Entities.Consts;
using Tnb.WarehouseMgr.Entities.Dto;
using Tnb.WarehouseMgr.Interfaces;
namespace Tnb.WarehouseMgr
{
///
/// 投料记录
///
public class WmsFeedingService : BaseWareHouseService, IWmsFeedingService
{
private readonly ISqlSugarClient _db;
private static Dictionary dicMaterial = new();
public WmsFeedingService(ISqlSugarRepository repository)
{
_db = repository.AsSugarClient();
}
///
/// 根据载具Id获取载具条码记录
///
///
///
[HttpGet]
public async Task GetCarryCodeList([FromRoute] string carryId)
{
if (dicMaterial.Count < 1)
{
dicMaterial = await _db.Queryable().ToDictionaryAsync(x => x.id, x => x.name);
}
WmsCarryH carry = await _db.Queryable().SingleAsync(it => it.id == carryId);
List carryMIds = new();
if (carry.carrystd_id == WmsWareHouseConst.CARRY_LJSTD_ID)
{
List carryDs = await _db.Queryable().Where(it => it.carry_id == carryId).ToListAsync();
carryMIds = carryDs.Select(x => x.membercarry_id).ToList();
}
Expression> whereExp = carryMIds?.Count > 0 ? a => carryMIds.Contains(a.carry_id) : a => a.carry_id == carryId;
List items = await _db.Queryable().Where(whereExp)
.Select()
.Mapper(it => it.material_name = (it.material_id != null && dicMaterial.ContainsKey(it.material_id)) ? dicMaterial[it.material_id].ToString() : "")
.ToListAsync();
return items ?? Enumerable.Empty();
}
}
}