134 lines
5.5 KiB
C#
134 lines
5.5 KiB
C#
using JNPF.Common.Core.Manager;
|
|
using JNPF.Common.Extension;
|
|
using JNPF.Common.Security;
|
|
using JNPF.FriendlyException;
|
|
using JNPF.VisualDev;
|
|
using JNPF.VisualDev.Entitys.Dto.VisualDev;
|
|
using JNPF.VisualDev.Interfaces;
|
|
using Mapster;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using SqlSugar;
|
|
using Tnb.BasicData.Entities;
|
|
using Tnb.ProductionMgr.Entities.Enums;
|
|
using Tnb.WarehouseMgr.Entities;
|
|
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
|
|
using Tnb.WarehouseMgr.Entities.Enums;
|
|
using Tnb.WarehouseMgr.Interfaces;
|
|
|
|
namespace Tnb.WarehouseMgr
|
|
{
|
|
/// <summary>
|
|
/// 载具台账服务
|
|
/// </summary>
|
|
[OverideVisualDev(ModuleConsts.MODULE_WMSCARRY_ID)]
|
|
public class WmsCarryLedgerService : BaseWareHouseService, IWmsCarryLedgerService
|
|
{
|
|
private const string ModuleId = "";
|
|
private readonly ISqlSugarClient _db;
|
|
private readonly IRunService _runService;
|
|
private readonly IVisualDevService _visualDevService;
|
|
private readonly IUserManager _userManager;
|
|
public WmsCarryLedgerService(ISqlSugarRepository<WmsCarryH> repository, IRunService runService, IVisualDevService visualDevService, IUserManager userManager)
|
|
{
|
|
_db = repository.AsSugarClient();
|
|
_runService = runService;
|
|
_visualDevService = visualDevService;
|
|
_userManager = userManager;
|
|
OverideFuncs.ImportDataAsync = DataImport;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 载具导入
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private async Task<dynamic> DataImport(VisualDevImportDataInput input)
|
|
{
|
|
int row = 0;
|
|
try
|
|
{
|
|
List<Dictionary<string, object>> dics = input.list;
|
|
List<WmsCarryH> carrys = new();
|
|
Dictionary<string, object>? locs = null;
|
|
List<string> locCodes = new();
|
|
List<string> cStdCodes = new();
|
|
WmsCarryH carryH = new();
|
|
//遍历字典,找出需要查询数据库拿的相关字段
|
|
foreach (Dictionary<string, object> d in dics)
|
|
{
|
|
string cStdCode = d["carrystd_id"].ToString() ?? string.Empty;
|
|
locCodes.Add(d["location_code"].ToString() ?? string.Empty);
|
|
cStdCodes.Add(cStdCode);
|
|
d["create_time"] = DateTime.Now;
|
|
_ = d.Remove("modify_time");
|
|
carryH = d.Adapt<WmsCarryH>();
|
|
carrys.Add(carryH);
|
|
}
|
|
Dictionary<string, object> carryStdDic = await _db.Queryable<WmsCarrystd>().Where(it => cStdCodes.Contains(it.carrystd_code)).ToDictionaryAsync(x => x.carrystd_code, x => x.id);
|
|
if (locCodes?.Count > 0)
|
|
{
|
|
locs = await _db.Queryable<BasLocation>().Where(it => locCodes.Contains(it.location_code)).ToDictionaryAsync(x => x.location_code, x => x.id);
|
|
}
|
|
|
|
carrys.ForEach(x =>
|
|
{
|
|
if (!carryStdDic.Keys.Contains(x.carrystd_id))
|
|
{
|
|
throw new AppFriendlyException($"第{carrys.IndexOf(x) + 1}个数据的载具规格有误", 500);
|
|
}
|
|
|
|
x.id = SnowflakeIdHelper.NextId();
|
|
x.org_id = _userManager.User.OrganizeId;
|
|
x.status = 1;
|
|
x.is_lock = 0;
|
|
x.carrystd_id = carryStdDic[x.carrystd_id].ToString() ?? throw new AppFriendlyException($"第{carrys.IndexOf(x) + 1}个数据的载具规格有误", 500);
|
|
x.carry_status = ((int)EnumCarryStatus.空闲).ToString();
|
|
if (locs != null && x.location_code != null && x.location_code != string.Empty)
|
|
{
|
|
x.location_id = locs[x.location_code].ToString() ?? throw new AppFriendlyException($"第{carrys.IndexOf(x) + 1}个数据的库位编号有误", 500);
|
|
}
|
|
|
|
x.out_status = ((int)EnumOutStatus.正常).ToString();
|
|
x.is_check = EnumCheckConclusion.待检.ParseToInt().ToString();
|
|
x.create_id = _userManager.UserId;
|
|
x.modify_id = null;
|
|
x.modify_time = null;
|
|
});
|
|
if (carrys.Count > 1000)
|
|
{
|
|
_ = await _db.Fastest<WmsCarryH>().BulkCopyAsync(carrys);
|
|
}
|
|
else if (carrys.Count > 400)
|
|
{
|
|
_db.Utilities.PageEach(carrys, 100, async pageList =>
|
|
{
|
|
_ = await _db.Insertable(pageList).ExecuteCommandAsync();
|
|
});
|
|
}
|
|
else
|
|
{
|
|
row = await _db.Insertable(carrys).ExecuteCommandAsync();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw Oops.Bah(ex.Message);
|
|
}
|
|
return row > 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 载具条码打印
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <exception cref="ArgumentNullException"></exception>
|
|
[HttpPost]
|
|
public void CarryBarCodePrint(CarryBarCodeInput input)
|
|
{
|
|
if (input == null || input.barCodes.Count < 1) throw new ArgumentNullException(nameof(input));
|
|
var ip = _db.Queryable<BasFactoryConfig>().Where(p => p.key == "carrybarcodeprinterip").FirstAsync().Result.value;
|
|
base.CarryPrint(input.barCodes, input.copies, ip);
|
|
}
|
|
}
|
|
}
|
|
|