diff --git a/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs b/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs index 00d25d31..d16dd24d 100644 --- a/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs +++ b/ProductionMgr/Tnb.ProductionMgr/RedisBackGround.cs @@ -60,6 +60,7 @@ using Tnb.WarehouseMgr.Entities.Enums; using Tnb.WarehouseMgr.Interfaces; using Org.BouncyCastle.Bcpg.OpenPgp; using JNPF.Systems.Entitys.Permission; +using JNPF.Systems.Entitys.System; namespace Tnb.ProductionMgr { @@ -716,11 +717,71 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA return; } + #region 小件物料入外协存储区 + var carry_mats = await db_YCLInternalTransfer.Queryable() + .InnerJoin((a, b) => a.material_id == b.id) + .Where((a, b) => items.Select(r => r.id).Contains(a.carry_id)).Select((a, b) => new carry_matEntity + { + carry_id = a.carry_id, + material_code = b.code, + categorys = b.category_id + }).ToListAsync(); + + foreach (var row in carry_mats) + { + row.category_list = JsonConvert.DeserializeObject>(row.categorys); + } + + var basRegionMats = await db_YCLInternalTransfer.Queryable() + .InnerJoin((a, b) => a.material_type == b.Id).Select((a, b) => new + { + region_id = a.region_id, + region_code = a.region_code, + category = b.EnCode + }).ToListAsync(); + + for (int carry_mat_index = 0; carry_mat_index < carry_mats.Count; carry_mat_index++) + { + var carry_mat = carry_mats[carry_mat_index]; + foreach (var basRegionMat in basRegionMats) + { + if (!carry_mat.category_list.Contains(basRegionMat.category)) + { + carry_mats.RemoveAt(carry_mat_index); carry_mat_index--; + } + else + { + carry_mat.category = basRegionMat.category; + carry_mat.region_id = basRegionMat.region_id; + carry_mat.region_code = basRegionMat.region_code; + } + } + } + #endregion + foreach (WmsCarryH wmsCarryH in items) { BasLocation startlocation = await db_YCLInternalTransfer.Queryable().Where(r => r.id == wmsCarryH.location_id).FirstAsync(); - InStockStrategyQuery inStockStrategyInput = new() { warehouse_id = "1", Size = 1, passage = startlocation.passage, AvoidBusyPassage = true, Region_id = WmsWareHouseConst.REGION_Purchase_ID, PolicyCode = WmsWareHouseConst.POLICY_YCLINSTOCK }; - List endLocations = await _wareHouseService.InStockStrategy(inStockStrategyInput); + + InStockStrategyQuery inStockStrategyInput = null; + List endLocations = new List(); + + // 小件物料入外协存储区 + var carry_mat = carry_mats.Where(r => r.carry_id == wmsCarryH.id).First(); + if (carry_mat != null && !string.IsNullOrEmpty(carry_mat.category)) + { + inStockStrategyInput = new() { warehouse_id = "1", Size = 1, passage = startlocation.passage, AvoidBusyPassage = true, Region_id = carry_mat.region_id, PolicyCode = WmsWareHouseConst.POLICY_YCLINSTOCK }; + endLocations = await _wareHouseService.InStockStrategy(inStockStrategyInput); + LoggerYCLInternalTransfer.LogInformation($"【ScanInStockByRedis】托盘物料{carry_mat.material_code} 物料类型为{carry_mat.category} 配置的入库区域为{carry_mat.region_code} 巷道{startlocation.passage} 托盘{wmsCarryH.carry_code}在检查外协存储区库存时找到可入库位数量为{endLocations.Count}"); + } + + if (endLocations?.Count == 0) + { + inStockStrategyInput = new() { warehouse_id = "1", Size = 1, passage = startlocation.passage, AvoidBusyPassage = true, Region_id = WmsWareHouseConst.REGION_Purchase_ID, PolicyCode = WmsWareHouseConst.POLICY_YCLINSTOCK }; + endLocations = await _wareHouseService.InStockStrategy(inStockStrategyInput); + LoggerYCLInternalTransfer.LogInformation($"【ScanInStockByRedis】托盘{wmsCarryH.carry_code} 巷道{startlocation.passage} 在检查采购存储区库存时找到可入库位数量为{endLocations.Count}"); + } + if (endLocations.Count() == 0) { LoggerYCLInternalTransfer.LogWarning($"【YCLInternalTransfer】 当前巷道没有空库位可以入库或者有任务正在执行"); @@ -3636,5 +3697,16 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA public decimal? codeqty { get; set; } public string unit_code { get; set; } } + + public class carry_matEntity + { + public string carry_id { get; set; } + public string material_code { get; set; } + public string region_id { get; set; } + public string region_code { get; set; } + public string categorys { get; set; } + public string category { get; set; } + public List category_list { get; set; } + } } } \ No newline at end of file diff --git a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsPurchaseOrderD.cs b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsPurchaseOrderD.cs index b9f03a6e..ccf0a0e9 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsPurchaseOrderD.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr.Entities/Entity/WmsPurchaseOrderD.cs @@ -144,4 +144,13 @@ public partial class WmsPurchaseOrderD : BaseEntity /// public string? production_unit { get; set; } + /// + /// 规格 + /// + public string? material_specification { get; set; } + + /// + /// 型号 + /// + public string? material_standard { get; set; } } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/ErpToWmsService.cs b/WarehouseMgr/Tnb.WarehouseMgr/ErpToWmsService.cs index 97b0a74e..a5297b70 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/ErpToWmsService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/ErpToWmsService.cs @@ -437,7 +437,8 @@ namespace Tnb.WarehouseMgr if (material != null) { wmsPurchaseOrderD.matcode_id = material.id; - wmsPurchaseOrderD.matspecification = material.material_specification; + wmsPurchaseOrderD.material_specification = material.material_specification; + wmsPurchaseOrderD.material_standard = material.material_standard; } wmsPurchaseOrderD.auxprop_gys = detail.auxprop_gys; wmsPurchaseOrderDs.Add(wmsPurchaseOrderD); diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs index a63c07bb..f0f08d19 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WareHouseService.cs @@ -318,7 +318,6 @@ namespace Tnb.WarehouseMgr .AndIF(input.AvoidBusyPassage, it => !busyPassages.Contains(it.passage)) .AndIF(!string.IsNullOrEmpty(input.passage), it => it.passage == input.passage) .ToExpression(); - items = await db.Queryable().Where(whereExp).OrderBy(policy.policy).ToListAsync(); } catch (Exception) @@ -504,7 +503,7 @@ namespace Tnb.WarehouseMgr .LeftJoin((a, b, c) => a.location_id == c.id) .Where(whereExpr) //.OrderByIF((a,b,c)=>SqlFunc.IsNullOrEmpty()) - .OrderBy("b.codeqty desc") + .OrderBy("b.codeqty") .Select((a, b, c) => new { WmsCarryH = a, diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsMaterialSignHService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsMaterialSignHService.cs index 7591be10..a6810897 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsMaterialSignHService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsMaterialSignHService.cs @@ -235,14 +235,16 @@ namespace Tnb.WarehouseMgr if (_wmsCarryCodes.Count > 0) { - switch (carryLoc.wh_id) + // 没其他情况 先默认原材料 + wmsMaterialSignH.warehouse_instock_id = WmsWareHouseConst.WAREHOUSE_YCL_ID; + switch (wmsMaterialSignH.warehouse_instock_id) { case WmsWareHouseConst.WAREHOUSE_YCL_ID: { try { await _wareHouseService.s_taskExecuteSemaphore_YCLInstock.WaitAsync(); - wmsMaterialSignH.warehouse_instock_id = WmsWareHouseConst.WAREHOUSE_YCL_ID; + InStockStrategyQuery inStockStrategyInput = new() { warehouse_id = "1", Size = 1, AvoidBusyPassage = true, Region_id = WmsWareHouseConst.REGION_YCLCache_ID }; List endLocations = await _wareHouseService.InStockStrategy(inStockStrategyInput); if (endLocations.Count == 0) diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsMaterialTransferService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsMaterialTransferService.cs index a23463ed..e4097509 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsMaterialTransferService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsMaterialTransferService.cs @@ -1808,6 +1808,38 @@ namespace Tnb.WarehouseMgr await _db.Ado.BeginTranAsync(); await _db.Updateable().SetColumns(r => r.rk_qty == otherOutstockD_first.rk_qty + input.qty).Where(r => r.id == otherOutstockD_first.id).ExecuteCommandAsync(); + + //InStockStrategyQuery inStockStrategyInput = null; + //List endlocations = new List(); + + //BasMaterial mat = await _db.Queryable() + // .InnerJoin((a, b) => a.material_id == b.id) + // .Where((a, b) => a.carry_id == wmsCarryH.id).Select((a, b) => b).FirstAsync(); + + //List categorys = new List(); + //if (!string.IsNullOrEmpty(mat.category_id)) + //{ + // categorys = JsonConvert.DeserializeObject>(mat.category_id); + //} + //// 小件物料入外协存储区 + //BasRegionMat basRegionMat = await _db.Queryable() + // .InnerJoin((a, b) => a.material_type == b.Id) + // .Where((a, b) => categorys.Contains(b.EnCode)).FirstAsync(); + //if (basRegionMat != null) + //{ + // inStockStrategyInput = new() { warehouse_id = "1", Size = 1, AvoidBusyPassage = true, Region_id = basRegionMat.region_id }; + // endlocations = await _wareHouseService.InStockStrategy(inStockStrategyInput); + // Logger.LogInformation($"【ScanInStockByRedis】托盘物料{mat.code} 物料类型id为{basRegionMat.material_type} 配置的入库区域为{basRegionMat.region_code} 托盘{wmsCarryH.carry_code}在检查外协存储区库存时找到可入库位数量为{endlocations.Count}"); + //} + + //if (endlocations?.Count == 0) + //{ + // inStockStrategyInput = new() { warehouse_id = "1", Size = 1, AvoidBusyPassage = true, Region_id = WmsWareHouseConst.REGION_YCLCache_ID }; + // endlocations = await _wareHouseService.InStockStrategy(inStockStrategyInput); + // Logger.LogInformation($"【ScanInStockByRedis】托盘{wmsCarryH.carry_code}在检查采购存储区库存时找到可入库位数量为{endlocations.Count}"); + //} + + InStockStrategyQuery inStockStrategyInput = new() { warehouse_id = WmsWareHouseConst.WAREHOUSE_YCL_ID, @@ -2568,8 +2600,8 @@ namespace Tnb.WarehouseMgr catch (Exception ex) { await _db.Ado.RollbackTranAsync(); - Logger.LogWarning("【DistributeSCWToYCL】" + ex.Message); - Logger.LogWarning("【DistributeSCWToYCL】" + ex.StackTrace); + Logger.LogWarning("【DistributeSCWToZCC】" + ex.Message); + Logger.LogWarning("【DistributeSCWToZCC】" + ex.StackTrace); return await ToApiResult(HttpStatusCode.InternalServerError, ex.Message); } finally diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsOutinStockDetailService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsOutinStockDetailService.cs index 15ca5715..a91faafb 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsOutinStockDetailService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsOutinStockDetailService.cs @@ -144,6 +144,8 @@ namespace Tnb.WarehouseMgr case WmsWareHouseConst.BIZTYPE_WMSINSTOCK_ID: { wmsOutinStockDetail.source_detail_id = input.disTask.source_id; + wmsOutinStockDetail.source_id = input.disTask.require_id; + wmsOutinStockDetail.source_code = input.disTask.require_code; wmsOutinStockDetail.source_type = WmsWareHouseConst.BIZTYPE_WMSINSTOCK_ID; break; } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAScanInStockService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAScanInStockService.cs index a7240ff2..4ffa668a 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAScanInStockService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsPDAScanInStockService.cs @@ -121,71 +121,85 @@ namespace Tnb.WarehouseMgr create_time = DateTime.Now, }; var instockDs = new List(); - 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 = item.codeqty, - qty = 0, - code_batch = item.code_batch, - material_specification = item.material_specification, - container_no = item.container_no, - warehouse_id = WmsWareHouseConst.WAREHOUSE_CP_ID, - print_qty = item.codeqty, - scan_qty = item.codeqty, - print_id = "", - create_id = _userManager.UserId, - create_time = DateTime.Now, - }; - instockDs.Add(instockD); - } - else - { - if (input.data.ContainsKey("details")) - { - instockDs = input.data["details"].Adapt>(); + 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; } - } - - - 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 = carryCode, - code_batch = item.code_batch, - material_specification = item.material_specification, - container_no = item.container_no, - codeqty = item.codeqty, - is_lock = 0, - is_end = 0, - create_id = _userManager.UserId, - create_time = DateTime.Now, - }; - } - + ); + _ = await _db.Insertable(instock).ExecuteCommandAsync(); _ = await _db.Insertable(instockDs).ExecuteCommandAsync(); - if (instockCode != null) - { - _ = await _db.Insertable(instockCode).ExecuteCommandAsync(); - } + _ = await _db.Insertable(instockCodes).ExecuteCommandAsync(); InStockStrategyQuery inStockStrategyInput = new() { warehouse_id = WmsWareHouseConst.WAREHOUSE_CP_ID, Size = 1 }; @@ -260,21 +274,26 @@ namespace Tnb.WarehouseMgr return preTask; }).ToList(); List pretaskCodes = new(); - foreach (WmsPretaskH? pt in preTasks) + + foreach (var wmsCarryCode in wmsCarryCodes) { - WmsPretaskCode ptc = pt.Adapt(); - ptc.id = SnowflakeIdHelper.NextId(); - ptc.bill_id = pt.id; - ptc.material_id = instockCode.material_id; - ptc.material_code = instockCode.material_code; - ptc.barcode = instockCode.barcode; - ptc.codeqty = instockCode.codeqty; - ptc.material_specification = instockCode.material_specification; - ptc.container_no = instockCode.container_no; - ptc.unit_id = instockCode.unit_id; - ptc.code_batch = instockCode.code_batch; - pretaskCodes.Add(ptc); + 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) { @@ -288,49 +307,49 @@ namespace Tnb.WarehouseMgr 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; + ////生成操作记录 + //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); + ////生成操作记录条码表 + //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(); + ////生成载具条码表 + //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 => instockCode.bill_d_id == it.id).ExecuteCommandAsync(); + _ = 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(); } @@ -399,11 +418,13 @@ namespace Tnb.WarehouseMgr 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: @@ -439,77 +460,90 @@ namespace Tnb.WarehouseMgr print_status = WmsWareHouseConst.PRINT_STATUS_PRINTCOMPLETE, is_check = 1, purchase_code = billCode?.ToString() ?? string.Empty, - create_id = _userManager.UserId==null?"": _userManager.UserId, + create_id = _userManager.UserId == null ? "" : _userManager.UserId, create_time = DateTime.Now, + source_id = source_main_id }; var instockDs = new List(); - 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 = item.codeqty, - qty = 0, - code_batch = item.code_batch, - material_specification = item.material_specification, - container_no = item.container_no, - warehouse_id = whId?.ToString() ?? "1", - print_qty = item.codeqty, - scan_qty = item.codeqty, - print_id = "", - create_id = _userManager.UserId == null ? "" : _userManager.UserId, - create_time = DateTime.Now, - }; - instockDs.Add(instockD); - } - else - { - if (input.data.ContainsKey("details")) - { - instockDs = input.data["details"].Adapt>(); + var instockCodes = new List(); + List wmsCarryCodes = await _db.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); } - } - - - WmsInstockCode? instockCode = null; - if (mat != null) - { - instockCode = new() + else { - 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 = carryCode,//carry code bar_code - code_batch = item.code_batch, - material_specification = item.material_specification, - container_no = item.container_no, - codeqty = item.codeqty, - is_lock = 0, - is_end = 0, - create_id = _userManager.UserId == null ? "" : _userManager.UserId, - create_time = DateTime.Now, - }; + 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 (instockCode != null) + if (instockCodes != null) { - _ = await _dbScanInStockByRedis.Insertable(instockCode).ExecuteCommandAsync(); - Logger.LogInformation($"【ScanInStockByRedis】插入WmsInstockCode {JsonConvert.SerializeObject(instockCode)}"); + _ = 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 }; @@ -593,20 +627,23 @@ namespace Tnb.WarehouseMgr return preTask; }).ToList(); List pretaskCodes = new(); - foreach (WmsPretaskH? pt in preTasks) + foreach (var wmsCarryCode in wmsCarryCodes) { - WmsPretaskCode ptc = pt.Adapt(); - ptc.id = SnowflakeIdHelper.NextId(); - ptc.bill_id = pt.id; - ptc.material_id = instockCode.material_id; - ptc.material_code = instockCode.material_code; - ptc.barcode = instockCode.barcode; - ptc.codeqty = instockCode.codeqty; - ptc.material_specification = instockCode.material_specification; - ptc.container_no = instockCode.container_no; - ptc.unit_id = instockCode.unit_id; - ptc.code_batch = instockCode.code_batch; - pretaskCodes.Add(ptc); + 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) @@ -621,37 +658,37 @@ namespace Tnb.WarehouseMgr 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; + ////生成操作记录 + //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); + ////生成操作记录条码表 + //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 => instockCode.bill_d_id == it.id).ExecuteCommandAsync(); + _ = 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(); } diff --git a/WarehouseMgr/Tnb.WarehouseMgr/WmsPurchaseDService.cs b/WarehouseMgr/Tnb.WarehouseMgr/WmsPurchaseDService.cs index a967d1d9..61d2dd49 100644 --- a/WarehouseMgr/Tnb.WarehouseMgr/WmsPurchaseDService.cs +++ b/WarehouseMgr/Tnb.WarehouseMgr/WmsPurchaseDService.cs @@ -45,6 +45,7 @@ namespace Tnb.WarehouseMgr private readonly IUserManager _userManager; private readonly IDictionaryDataService _dictionaryDataService; private readonly IThirdApiRecordService _thirdApiRecordService; + public static SemaphoreSlim s_SaveCheckResult = new(1); public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc(); public WmsPurchaseDService( @@ -66,13 +67,24 @@ namespace Tnb.WarehouseMgr { try { + await s_SaveCheckResult.WaitAsync(); string id = dic["id"]; string qcRes = dic["qc_res"]; WmsPurchaseD wmsPurchaseD = await _db.Queryable().SingleAsync(x => x.id == id); string purchaseHId = wmsPurchaseD?.bill_id ?? ""; WmsPurchaseH wmsPurchaseH = await _db.Queryable().SingleAsync(x => x.id == purchaseHId); - + #region 插入质检记录 + if (!string.IsNullOrEmpty(wmsPurchaseD.qc_res) && wmsPurchaseD.qc_res != "await") + { + throw Oops.Bah("当前收货明细行已操作过质检"); + } + // 待检 + if (string.IsNullOrEmpty(qcRes) || qcRes == "await") + { + return "保存成功"; + } + string? create_id = _userManager.User.Id; @@ -101,28 +113,24 @@ namespace Tnb.WarehouseMgr } #endregion - //自制的采购入库 不在质检保存里调用erp接口 if (string.IsNullOrEmpty(wmsPurchaseH.erp_bill_code)) { return "保存成功"; } - - List wmsOutinStockDetails = await _db.Queryable() - .Where(x => x.source_detail_id == wmsPurchaseD.id && x.source_type == WmsWareHouseConst.BIZTYPE_WMSINSTOCK_ID) - .ToListAsync(); + + // 托盘对应入库单 + List instock_mains = await _db.Queryable().Where(x => x.source_id == wmsPurchaseD.bill_id).ToListAsync(); + + List allInstockDetails = await _db.Queryable().Where(it => instock_mains.Select(r => r.id).Contains(it.bill_id) && it.material_id == wmsPurchaseD.material_id && it.code_batch == wmsPurchaseD.code_batch).ToListAsync(); + List> requestData = new List>(); - List carryIds = wmsOutinStockDetails.Select(x => x.carry_id).ToList(); + List carryIds = instock_mains.Select(x => x.carry_id).ToList(); string wmsPurchaseOrderHId = wmsPurchaseH?.erp_bill_code ?? ""; WmsPurchaseOrderH wmsPurchaseOrderH = await _db.Queryable().SingleAsync(x => x.id == wmsPurchaseOrderHId); WmsPurchaseOrderD wmsPurchaseOrderDs = await _db.Queryable().FirstAsync(x => x.fk_wms_purchase_order_id == wmsPurchaseOrderHId); - foreach (var wmsOutinStockDetail in wmsOutinStockDetails) { - WmsDistaskH wmsDistaskH = await _db.Queryable().FirstAsync(x=>x.bill_code==wmsOutinStockDetail.distask_code); - WmsInstockH instock = await _db.Queryable().SingleAsync(x=>x.id==wmsDistaskH.require_id); - List allInstockDetails = await _db.Queryable().Where(it => it.bill_id == instock.id).ToListAsync(); - List materialIds = allInstockDetails.Select(x => x.material_id).Distinct().ToList(); List unitCodes = allInstockDetails.Select(x => x.unit_id).Distinct().ToList(); List unitDatas = await _db.Queryable() @@ -139,7 +147,7 @@ namespace Tnb.WarehouseMgr // tableIds.Add(_userManager.UserId); // tableIds.Add(wmsPurchaseH.create_id); tableIds.Add(WmsWareHouseConst.AdministratorOrgId); - tableIds.Add(instock.warehouse_id);// 1001A11000000002OOGU + tableIds.Add(instock_mains[0].warehouse_id);// 1001A11000000002OOGU tableIds.AddRange(materialIds); tableIds.Add(supplierId); tableIds.Add(tranTypeId); @@ -180,7 +188,7 @@ namespace Tnb.WarehouseMgr erpRequestData.Add("pk_org", erpOrg.pk_org); erpRequestData.Add("pk_org_v", erpOrg.pk_org_v); erpRequestData.Add("pk_group", erpOrg.pk_group); - erpRequestData.Add("vbillcode", instock.bill_code); + erpRequestData.Add("vbillcode", wmsPurchaseH.bill_code); erpRequestData.Add("vtrantypecode", tranType?.EnCode ?? ""); erpRequestData.Add("csourcebillhid", wmsPurchaseH?.erp_arriveorder_pk ?? ""); @@ -205,7 +213,7 @@ namespace Tnb.WarehouseMgr ["cunitid"] = erpExtendFields.Find(x => x.table_id == (unitDatas.Find(x => x.EnCode == item.unit_id)?.Id ?? ""))?.cunitid ?? "", ["cvendorid"] = erpExtendFields.Find(x => x.table_id == supplierId)?.supplier_id ?? "", ["cvendorvid"] = erpExtendFields.Find(x => x.table_id == supplierId)?.supplier_vid ?? "", - ["dbizdate"] = instock.create_time.ToString("yyyy-MM-dd HH:mm:ss"), + ["dbizdate"] = wmsPurchaseH.create_time.ToString("yyyy-MM-dd HH:mm:ss"), ["nnum"] = item.qty, ["nshouldnum"] = item.pr_qty, // ["pk_creqwareid"] = erpExtendFields.Find(x => x.table_id == instock.warehouse_id)?.cotherwhid ?? "", @@ -284,6 +292,10 @@ namespace Tnb.WarehouseMgr Log.Error(e.Message,e); throw Oops.Bah(e.Message); } + finally + { + s_SaveCheckResult.Release(); + } return "保存成功"; }