using JNPF.Common.Core.Manager; using JNPF.Common.Dtos.VisualDev; using JNPF.Common.Extension; using JNPF.Common.Security; using JNPF.EventBus; using JNPF.FriendlyException; using JNPF.Systems.Interfaces.System; using JNPF.VisualDev; using Mapster; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using SqlSugar; using Tnb.BasicData.Entities; using Tnb.ProductionMgr.Interfaces; using Tnb.WarehouseMgr.Entities; using Tnb.WarehouseMgr.Entities.Attributes; using Tnb.WarehouseMgr.Entities.Consts; using Tnb.WarehouseMgr.Entities.Dto; using Tnb.WarehouseMgr.Entities.Enums; using Tnb.WarehouseMgr.Interfaces; namespace Tnb.WarehouseMgr { /// /// PDA扫码入库模块 /// [OverideVisualDev(ModuleConsts.MODULE_WMSSCANCODEINSTOCKPDA_ID)] [ServiceModule(BizTypeId)] public class WmsPDAScanInStockService : BaseWareHouseService, IWmsPDAScanInStockService, IPdaStroage { private const string BizTypeId = "26191496816421"; private readonly ISqlSugarClient _db; private ISqlSugarClient _dbScanInStockByRedis; private readonly IDictionaryDataService _dictionaryDataService; private readonly IUserManager _userManager; private readonly IWareHouseService _wareHouseService; private readonly IBillRullService _billRullService; private readonly IPrdInstockService _prdInstockService; public WmsPDAScanInStockService( ISqlSugarRepository repository, IDictionaryDataService dictionaryDataService, IUserManager userManager, IBillRullService billRullService, IWareHouseService wareHouseService, IPrdInstockService prdInstockService, IEventPublisher eventPublisher ) { _db = repository.AsSugarClient(); _dbScanInStockByRedis = repository.AsSugarClient(); _dictionaryDataService = dictionaryDataService; _userManager = userManager; _billRullService = billRullService; _wareHouseService = wareHouseService; _prdInstockService = prdInstockService; OverideFuncs.CreateAsync = ScanInStock; } public async Task ScanInStock(VisualDevModelDataCrInput input) { try { await _db.Ado.BeginTranAsync(); WmsInstockCode? item = null; BasMaterial? mat = null; WmsCarryH? carry = null; BasLocation? loc = null; string? carryCode = null; if (input.data.ContainsKey(nameof(WmsInstockCode.barcode))) { item = input.data.Adapt(); if (item.codeqty == 0) { throw new AppFriendlyException("请输入入库数量", 500); } carryCode = item.barcode; carry = await _db.Queryable().FirstAsync(it => it.carry_code == carryCode); if (carry == null) { throw new AppFriendlyException("载具有误", 500); } mat = await _db.Queryable().FirstAsync(it => it.code == item.material_code); if (mat == null) { throw new AppFriendlyException("物料有误", 500); } loc = await _db.Queryable().FirstAsync(it => it.location_code == item.extras); if (loc == null) { throw new AppFriendlyException("库位有误", 500); } } var whId = input.data.ContainsKey(nameof(WmsPurchaseH.warehouse_id)) ? input.data[nameof(WmsPurchaseH.warehouse_id)] : null; var billCode = input.data.ContainsKey(nameof(WmsPurchaseH.bill_code)) ? input.data[nameof(WmsPurchaseH.warehouse_id)] : null; WmsInstockH instock = new() { id = SnowflakeIdHelper.NextId(), org_id = _userManager.UserId, carry_code = carryCode, carry_id = carry?.id ?? string.Empty, location_id = loc?.id ?? string.Empty, bill_code = _billRullService.GetBillNumber(WmsWareHouseConst.WMS_INSTOCK_ENCODE).GetAwaiter().GetResult(), bill_type = WmsWareHouseConst.BILLTYPE_MATERIALINSTOCK_ID, biz_type = WmsWareHouseConst.BIZTYPE_WMSINSTOCK_ID, bill_date = DateTime.Today, warehouse_id = whId?.ToString() ?? WmsWareHouseConst.WAREHOUSE_CP_ID, status = WmsWareHouseConst.BILLSTATUS_ADD_ID, generate_type = "0", sync_status = WmsWareHouseConst.SYNC_STATUS_NONEEDSYNC, print_status = WmsWareHouseConst.PRINT_STATUS_PRINTCOMPLETE, is_check = 1, purchase_code = billCode?.ToString() ?? string.Empty, create_id = _userManager.UserId, create_time = DateTime.Now, }; var instockDs = new List(); var instockCodes = new List(); List wmsCarryCodes = await _db.Queryable().Where(r => r.carry_id == carry.id).ToListAsync(); wmsCarryCodes.GroupBy(g => new { g.material_id, g.code_batch }).Select( r => { var list = r.ToList(); decimal qty = list.Sum(x=>x.codeqty); WmsInstockD? instockD = null; if (mat != null) { instockD = new() { id = SnowflakeIdHelper.NextId(), bill_id = instock.id, line_status = WmsWareHouseConst.BILLSTATUS_ADD_ID, material_id = mat.id, material_code = mat.code, unit_id = mat.unit_id, pr_qty = qty, qty = 0, code_batch = r.Key.code_batch, material_specification = item.material_specification, container_no = item.container_no, warehouse_id = WmsWareHouseConst.WAREHOUSE_CP_ID, print_qty = qty, scan_qty = qty, print_id = "", create_id = _userManager.UserId, create_time = DateTime.Now, }; instockDs.Add(instockD); } else { if (input.data.ContainsKey("details")) { instockDs = input.data["details"].Adapt>(); } } foreach (var row in list) { WmsInstockCode? instockCode = null; if (mat != null) { instockCode = new() { id = SnowflakeIdHelper.NextId(), bill_id = instock.id, bill_d_id = instockD?.id ?? string.Empty, line_status = WmsWareHouseConst.BILLSTATUS_ADD_ID, material_id = mat.id, material_code = mat.code, unit_id = mat.unit_id, barcode = row.barcode, code_batch = row.code_batch, material_specification = item.material_specification, container_no = item.container_no, codeqty = row.codeqty, is_lock = 0, is_end = 0, create_id = _userManager.UserId, create_time = DateTime.Now, }; instockCodes.Add(instockCode); } } return r; } ); _ = await _db.Insertable(instock).ExecuteCommandAsync(); _ = await _db.Insertable(instockDs).ExecuteCommandAsync(); _ = await _db.Insertable(instockCodes).ExecuteCommandAsync(); InStockStrategyQuery inStockStrategyInput = new() { warehouse_id = WmsWareHouseConst.WAREHOUSE_CP_ID, Size = 1 }; List endLocations = await _wareHouseService.InStockStrategy(inStockStrategyInput); WmsPointH sPoint = new(); WmsPointH ePoint = new(); if (endLocations?.Count > 0) { BasLocation eloc = await _db.Queryable().SingleAsync(it => it.id == endLocations[0].id); bool isMatch = await IsCarryAndLocationMatchByCarryStd(carry, eloc); if (!isMatch) { throw new AppFriendlyException("库位与载具规格不匹配", 500); } ePoint = await _db.Queryable().FirstAsync(it => it.location_id == endLocations[0].id); } sPoint = await _db.Queryable().FirstAsync(it => it.location_id == loc.id); if (sPoint != null && ePoint != null) { List points = new List(); if (sPoint.area_code != ePoint.area_code) { points = await _wareHouseService.PathAlgorithms(sPoint.id, ePoint.id); if (points.Count <= 2) { throw new AppFriendlyException($"sPoint {sPoint.point_code} ePoint{ePoint.point_code}该路径不存在", 500); } } else { points.Add(sPoint); points.Add(ePoint); } //根据获取的路径点生成预任务,生成顺序必须预路径算法返回的起终点的顺序一致(预任务顺序) if (points?.Count > 0) { List preTasks = points.Where(it => !it.location_id.IsNullOrEmpty()).GroupBy(g => g.area_code).Select(it => { WmsPointH? sPoint = it.FirstOrDefault(); WmsPointH? ePoint = it.LastOrDefault(); WmsPretaskH preTask = new() { org_id = _userManager.User==null?"": _userManager.User.OrganizeId!, startlocation_id = sPoint?.location_id!, startlocation_code = sPoint?.location_code!, endlocation_id = ePoint?.location_id!, endlocation_code = ePoint?.location_code!, start_floor = sPoint?.floor.ToString(), end_floor = ePoint?.floor.ToString(), startpoint_id = sPoint?.id!, startpoint_code = sPoint?.point_code!, endpoint_id = ePoint?.id!, endpoint_code = ePoint?.point_code!, bill_code = _billRullService.GetBillNumber(WmsWareHouseConst.WMS_PRETASK_H_ENCODE).GetAwaiter().GetResult(), status = WmsWareHouseConst.PRETASK_BILL_STATUS_DXF_ID, biz_type = WmsWareHouseConst.BIZTYPE_WMSINSTOCK_ID, task_type = WmsWareHouseConst.WMS_PRETASK_INSTOCK_TYPE_ID, carry_id = carry.id, carry_code = carry.carry_code, area_id = sPoint?.area_id!, area_code = it.Key, require_id = instock.id, require_code = instock.bill_code, create_id = _userManager.User == null ? "" : _userManager.UserId!, create_time = DateTime.Now }; return preTask; }).ToList(); List pretaskCodes = new(); foreach (var wmsCarryCode in wmsCarryCodes) { foreach (WmsPretaskH? pt in preTasks) { WmsPretaskCode ptc = pt.Adapt(); ptc.id = SnowflakeIdHelper.NextId(); ptc.bill_id = pt.id; ptc.material_id = wmsCarryCode.material_id; ptc.material_code = wmsCarryCode.material_code; ptc.barcode = wmsCarryCode.barcode; ptc.codeqty = wmsCarryCode.codeqty; ptc.material_specification = item.material_specification; ptc.container_no = item.container_no; ptc.unit_id = item.unit_id; ptc.code_batch = wmsCarryCode.code_batch; pretaskCodes.Add(ptc); } } bool isOk = await _wareHouseService.GenPreTask(preTasks, pretaskCodes); if (isOk) { GenPreTaskUpInput preTaskUpInput = new() { RquireId = instock.id, CarryId = carry.id, CarryStartLocationId = points.FirstOrDefault()!.location_id!, CarryStartLocationCode = points.FirstOrDefault()!.location_code!, LocationIds = points.Select(x => x.location_id).ToList()! }; ////生成操作记录 //WmsHandleH handleH = new() //{ // org_id = _userManager.User == null ? "" : _userManager.User.OrganizeId!, // startlocation_id = loc.id, // endlocation_id = endLocations![0].id, // bill_code = instock.bill_code, // biz_type = instock.biz_type, // carry_id = carry.id, // carry_code = carry.carry_code, // require_id = instock.id, // require_code = instock.bill_code, // create_id = _userManager.User == null ? "" : _userManager.UserId!, // create_time = DateTime.Now //}; //preTaskUpInput.PreTaskRecord = handleH; ////生成操作记录条码表 //WmsHandleCode handleCode = instockCode.Adapt(); //handleCode.id = SnowflakeIdHelper.NextId(); //handleCode.org_id = _userManager.User == null ? "" : _userManager.User.OrganizeId!; //handleCode.bill_id = handleH.id; //handleCode.create_id = _userManager.User == null ? "" : _userManager.UserId!; //handleCode.create_time = DateTime.Now; //preTaskUpInput.PreTaskHandleCodes.Add(handleCode); ////生成载具条码表 //WmsCarryCode wmsCarryCode = instockCode.Adapt(); //{ // wmsCarryCode.id = SnowflakeIdHelper.NextId(); // wmsCarryCode.carry_id = carry.id; // wmsCarryCode.is_out = 0; // wmsCarryCode.location_id = loc.id; // wmsCarryCode.location_code = loc.location_code; // wmsCarryCode.warehouse_id = instock.warehouse_id; //} //_ = await _db.Insertable(wmsCarryCode).ExecuteCommandAsync(); //回更状态 await _wareHouseService.GenInStockTaskHandleAfter(preTaskUpInput, it => new WmsCarryH { carry_code = instock!.carry_code!, is_lock = 1, carry_status = ((int)EnumCarryStatus.占用).ToString(), location_id = preTaskUpInput.CarryStartLocationId, location_code = preTaskUpInput.CarryStartLocationCode }, it => new BasLocation { is_lock = 1 }); _ = await _db.Updateable().SetColumns(it => new WmsInstockD { line_status = WmsWareHouseConst.BILLSTATUS_ON_ID }).Where(it => instock.id == it.bill_id).ExecuteCommandAsync(); _ = await _db.Updateable().SetColumns(it => new WmsInstockH { status = WmsWareHouseConst.BILLSTATUS_ON_ID }).Where(it => it.id == instock!.id).ExecuteCommandAsync(); } } } await _db.Ado.CommitTranAsync(); } catch (Exception) { await _db.Ado.RollbackTranAsync(); throw; } finally { _ = InvokeGenPretaskExcute(); } return Task.FromResult(true); } public async Task ScanInStockByRedis(VisualDevModelDataCrInput input, ISqlSugarClient dbConn = null) { var db = _dbScanInStockByRedis; if (dbConn != null) db = dbConn; Logger.LogInformation($"【ScanInStockByRedis】执行入库 {JsonConvert.SerializeObject(input)}"); try { await _dbScanInStockByRedis.Ado.BeginTranAsync(); WmsInstockCode? item = null; BasMaterial? mat = null; WmsCarryH? carry = null; BasLocation? loc = null; string? carryCode = null; if (input.data.ContainsKey(nameof(WmsInstockCode.barcode))) { item = input.data.Adapt(); if (item.codeqty == 0) { throw new AppFriendlyException("请输入入库数量", 500); } carryCode = item.barcode; carry = await _dbScanInStockByRedis.Queryable().FirstAsync(it => it.carry_code == carryCode); if (carry == null) { throw new AppFriendlyException("载具有误", 500); } mat = await _dbScanInStockByRedis.Queryable().FirstAsync(it => it.code == item.material_code); if (mat == null) { throw new AppFriendlyException("物料有误", 500); } loc = await _dbScanInStockByRedis.Queryable().FirstAsync(it => it.location_code == item.extras); if (loc == null) { throw new AppFriendlyException("库位有误", 500); } } var whId = input.data.ContainsKey(nameof(WmsPurchaseH.warehouse_id)) ? input.data[nameof(WmsPurchaseH.warehouse_id)] : "1"; var billCode = input.data.ContainsKey(nameof(WmsPurchaseH.bill_code)) ? input.data[nameof(WmsPurchaseH.bill_code)] : null; string bill_type = ""; string biz_type = WmsWareHouseConst.BIZTYPE_WMSINSTOCK_ID; string required_type = (await _dbScanInStockByRedis.Queryable().FirstAsync(it => it.barcode == input.data["物料条码"])).required_type; string source_id = (await _dbScanInStockByRedis.Queryable().FirstAsync(it => it.barcode == input.data["物料条码"])).require_id; string source_main_id = ""; switch (required_type) { case WmsWareHouseConst.BILLTYPE_PURCHASE_ID: { bill_type = WmsWareHouseConst.BILLTYPE_MATERIALINSTOCK_ID; source_main_id = (await _dbScanInStockByRedis.Queryable().FirstAsync(it => it.id == source_id)).bill_id; break; } case WmsWareHouseConst.BILLTYPE_OUTSOURCE_ID: { bill_type = WmsWareHouseConst.BILLTYPE_OUTSOURCEINSTOCK_ID; source_main_id = (await _dbScanInStockByRedis.Queryable().FirstAsync(it => it.id == source_id)).erp_outsource_order_d_pk; break; } case WmsWareHouseConst.BILLTYPE_RAWMATTRANSFERINSTOCK_ID: { bill_type = WmsWareHouseConst.BILLTYPE_RAWMATTRANSFERINSTOCK_ID; biz_type = WmsWareHouseConst.BIZTYPE_RAWMATTRANSFERINSTOCK_ID; break; } } WmsInstockH instock = new() { id = SnowflakeIdHelper.NextId(), org_id = _userManager.UserId, carry_code = carryCode, carry_id = carry?.id ?? string.Empty, location_id = loc?.id ?? string.Empty, bill_code = _billRullService.GetBillNumber(WmsWareHouseConst.WMS_INSTOCK_ENCODE).GetAwaiter().GetResult(), bill_type = bill_type, biz_type = WmsWareHouseConst.BIZTYPE_WMSINSTOCK_ID, bill_date = DateTime.Today, warehouse_id = whId?.ToString() ?? "1", status = WmsWareHouseConst.BILLSTATUS_ADD_ID, generate_type = "0", sync_status = WmsWareHouseConst.SYNC_STATUS_NONEEDSYNC, print_status = WmsWareHouseConst.PRINT_STATUS_PRINTCOMPLETE, is_check = 1, purchase_code = billCode?.ToString() ?? string.Empty, create_id = _userManager.UserId == null ? "" : _userManager.UserId, create_time = DateTime.Now, source_id = source_main_id }; var instockDs = new List(); var instockCodes = new List(); List wmsCarryCodes = await _dbScanInStockByRedis.Queryable().Where(r => r.carry_id == carry.id).ToListAsync(); foreach (var r in wmsCarryCodes.GroupBy(g => new { g.material_id, g.code_batch })) { var list = r.ToList(); decimal qty = list.Sum(x => x.codeqty); WmsInstockD? instockD = null; if (mat != null) { instockD = new() { id = SnowflakeIdHelper.NextId(), bill_id = instock.id, line_status = WmsWareHouseConst.BILLSTATUS_ADD_ID, material_id = mat.id, material_code = mat.code, unit_id = mat.unit_id, pr_qty = qty, qty = 0, code_batch = r.Key.code_batch, material_specification = item.material_specification, container_no = item.container_no, warehouse_id = WmsWareHouseConst.WAREHOUSE_CP_ID, print_qty = qty, scan_qty = qty, print_id = "", create_id = _userManager.UserId, create_time = DateTime.Now, }; instockDs.Add(instockD); } else { if (input.data.ContainsKey("details")) { instockDs = input.data["details"].Adapt>(); } } foreach (var row in list) { WmsInstockCode? instockCode = null; if (mat != null) { instockCode = new() { id = SnowflakeIdHelper.NextId(), bill_id = instock.id, bill_d_id = instockD?.id ?? string.Empty, line_status = WmsWareHouseConst.BILLSTATUS_ADD_ID, material_id = mat.id, material_code = mat.code, unit_id = mat.unit_id, barcode = row.barcode, code_batch = row.code_batch, material_specification = item.material_specification, container_no = item.container_no, codeqty = row.codeqty, is_lock = 0, is_end = 0, create_id = _userManager.UserId, create_time = DateTime.Now, }; instockCodes.Add(instockCode); } } } _ = await _dbScanInStockByRedis.Insertable(instock).ExecuteCommandAsync(); Logger.LogInformation($"【ScanInStockByRedis】插入WmsInstockH {JsonConvert.SerializeObject(instock)}"); _ = await _dbScanInStockByRedis.Insertable(instockDs).ExecuteCommandAsync(); Logger.LogInformation($"【ScanInStockByRedis】插入WmsInstockD {JsonConvert.SerializeObject(instockDs)}"); if (instockCodes != null) { _ = await _dbScanInStockByRedis.Insertable(instockCodes).ExecuteCommandAsync(); Logger.LogInformation($"【ScanInStockByRedis】插入WmsInstockCode {JsonConvert.SerializeObject(instockCodes)}"); } InStockStrategyQuery inStockStrategyInput = new() { warehouse_id = "1", Size = 1, AvoidBusyPassage = true, Region_id = WmsWareHouseConst.REGION_YCLCache_ID }; List endLocations = await _wareHouseService.InStockStrategy(inStockStrategyInput); WmsPointH sPoint = new(); WmsPointH ePoint = new(); if (endLocations?.Count > 0) { BasLocation eloc = await _dbScanInStockByRedis.Queryable().SingleAsync(it => it.id == endLocations[0].id); bool isMatch = await IsCarryAndLocationMatchByCarryStd(carry, eloc); if (!isMatch) { throw new AppFriendlyException("库位与载具规格不匹配", 500); } ePoint = await _dbScanInStockByRedis.Queryable().FirstAsync(it => it.location_id == endLocations[0].id); } else { throw new AppFriendlyException("没有可以入库的库位", 500); } sPoint = await _dbScanInStockByRedis.Queryable().FirstAsync(it => it.location_id == loc.id); Logger.LogInformation($"【ScanInStockByRedis】sPoint:{JsonConvert.SerializeObject(sPoint)} ePoint:{JsonConvert.SerializeObject(ePoint)}"); if (sPoint != null && ePoint != null) { List points = new List(); if (sPoint.area_code != ePoint.area_code) { points = await _wareHouseService.PathAlgorithms(sPoint.id, ePoint.id); Logger.LogInformation($"【ScanInStockByRedis】 路径点数量为:{points.Count}"); if (points.Count <= 2) { throw new AppFriendlyException($"sPoint {sPoint.point_code} ePoint{ePoint.point_code}该路径不存在", 500); } } else { points.Add(sPoint); points.Add(ePoint); } //根据获取的路径点生成预任务,生成顺序必须预路径算法返回的起终点的顺序一致(预任务顺序) if (points?.Count > 0) { List preTasks = points.Where(it => !it.location_id.IsNullOrEmpty()).GroupBy(g => g.area_code).Select(it => { WmsPointH? sPoint = it.FirstOrDefault(); WmsPointH? ePoint = it.LastOrDefault(); WmsPretaskH preTask = new() { org_id = _userManager.User == null ? "" : _userManager.User.OrganizeId!, startlocation_id = sPoint?.location_id!, startlocation_code = sPoint?.location_code!, endlocation_id = ePoint?.location_id!, endlocation_code = ePoint?.location_code!, start_floor = sPoint?.floor.ToString(), end_floor = ePoint?.floor.ToString(), startpoint_id = sPoint?.id!, startpoint_code = sPoint?.point_code!, endpoint_id = ePoint?.id!, endpoint_code = ePoint?.point_code!, bill_code = _billRullService.GetBillNumber(WmsWareHouseConst.WMS_PRETASK_H_ENCODE).GetAwaiter().GetResult(), status = WmsWareHouseConst.PRETASK_BILL_STATUS_DXF_ID, biz_type = biz_type, task_type = WmsWareHouseConst.WMS_PRETASK_INSTOCK_TYPE_ID, carry_id = carry.id, carry_code = carry.carry_code, area_id = sPoint?.area_id!, area_code = it.Key, require_id = instock.id, require_code = instock.bill_code, source_id = source_id, create_id = _userManager.User == null ? "" : _userManager.UserId!, create_time = DateTime.Now, priority = WmsWareHouseConst.priority_instock }; return preTask; }).ToList(); List pretaskCodes = new(); foreach (var wmsCarryCode in wmsCarryCodes) { foreach (WmsPretaskH? pt in preTasks) { WmsPretaskCode ptc = pt.Adapt(); ptc.id = SnowflakeIdHelper.NextId(); ptc.bill_id = pt.id; ptc.material_id = wmsCarryCode.material_id; ptc.material_code = wmsCarryCode.material_code; ptc.barcode = wmsCarryCode.barcode; ptc.codeqty = wmsCarryCode.codeqty; ptc.material_specification = item.material_specification; ptc.container_no = item.container_no; ptc.unit_id = mat.unit_id; ptc.code_batch = wmsCarryCode.code_batch; pretaskCodes.Add(ptc); } } bool isOk = await _wareHouseService.GenPreTask(preTasks, pretaskCodes, _dbScanInStockByRedis); if (isOk) { GenPreTaskUpInput preTaskUpInput = new() { RquireId = instock.id, CarryId = carry.id, CarryStartLocationId = points.FirstOrDefault()!.location_id!, CarryStartLocationCode = points.FirstOrDefault()!.location_code!, LocationIds = points.Select(x => x.location_id).ToList()! }; ////生成操作记录 //WmsHandleH handleH = new() //{ // org_id = _userManager.User == null ? "" : _userManager.User.OrganizeId!, // startlocation_id = loc.id, // endlocation_id = endLocations![0].id, // bill_code = instock.bill_code, // biz_type = instock.biz_type, // carry_id = carry.id, // carry_code = carry.carry_code, // require_id = instock.id, // require_code = instock.bill_code, // create_id = _userManager.User == null ? "" : _userManager.UserId!, // create_time = DateTime.Now //}; //preTaskUpInput.PreTaskRecord = handleH; ////生成操作记录条码表 //WmsHandleCode handleCode = instockCode.Adapt(); //handleCode.id = SnowflakeIdHelper.NextId(); //handleCode.org_id = _userManager.User == null ? "" : _userManager.User.OrganizeId!; //handleCode.bill_id = handleH.id; //handleCode.create_id = _userManager.User == null ? "" : _userManager.UserId!; //handleCode.create_time = DateTime.Now; //preTaskUpInput.PreTaskHandleCodes.Add(handleCode); //回更状态 await _wareHouseService.GenInStockTaskHandleAfter(preTaskUpInput, it => new WmsCarryH { carry_code = instock!.carry_code!, is_lock = 1, carry_status = ((int)EnumCarryStatus.占用).ToString(), location_id = preTaskUpInput.CarryStartLocationId, location_code = preTaskUpInput.CarryStartLocationCode }, it => new BasLocation { is_lock = 1 }, _dbScanInStockByRedis); _ = await _dbScanInStockByRedis.Updateable().SetColumns(it => new WmsInstockD { line_status = WmsWareHouseConst.BILLSTATUS_ON_ID }).Where(it => instock.id == it.bill_id).ExecuteCommandAsync(); _ = await _dbScanInStockByRedis.Updateable().SetColumns(it => new WmsInstockH { status = WmsWareHouseConst.BILLSTATUS_ON_ID }).Where(it => it.id == instock!.id).ExecuteCommandAsync(); } } } await _dbScanInStockByRedis.Ado.CommitTranAsync(); } // 测试代码 后期删 catch (AggregateException ex) { Console.WriteLine("【ScanInStockByRedis】 AggregateException" + ex.Message); Logger.LogInformation($"【ScanInStockByRedis】 AggregateException" + ex.Message); _dbScanInStockByRedis = _dbScanInStockByRedis.CopyNew(); await _dbScanInStockByRedis.Ado.RollbackTranAsync(); throw; } catch (Exception ex) { Logger.LogInformation($"【ScanInStockByRedis】 八工位扫到码发送入库请求发生异常:{ex.Message}"); // 测试代码 后期删 if (ex.Message.Contains("Connection is busy")) _dbScanInStockByRedis = _dbScanInStockByRedis.CopyNew(); await _dbScanInStockByRedis.Ado.RollbackTranAsync(); throw; } finally { _ = InvokeGenPretaskExcute(); } return Task.FromResult(true); } [HttpPost] public async Task test(string code) { var carry_code = code;//从数采读取载具 WmsCarryH? carry = _db.Queryable().Single(it => it.carry_code == carry_code); if (carry != null) { var WmsCarryCode = _db.Queryable().Single(it => it.carry_id == carry.id); var loc= _db.Queryable().Single(it => it.id == carry.location_id); VisualDevModelDataCrInput input = new VisualDevModelDataCrInput(); input.data = new Dictionary(); input.data.Add("barcode", carry_code); input.data.Add("codeqty", WmsCarryCode.codeqty);//条码数量 input.data.Add("material_code", WmsCarryCode.material_code); input.data.Add("extras", loc.location_code!);//location_code input.data.Add("warehouse_id", WmsCarryCode.warehouse_id!); input.data.Add("bill_code", "");//采购收货单号 input.data.Add("code_batch", WmsCarryCode.code_batch!);//批次 input.data.Add("material_specification", WmsCarryCode.material_specification!);//规格型号 input.data.Add("container_no", WmsCarryCode.container_no!);//箱号 input.data.Add("material_id", WmsCarryCode.material_id); input.data.Add("id", null); await ScanInStockByRedis(input); } } } }