采购入库代码部分重写,回传bip调整,采购订单接收调整、小件移库到三层货架

This commit is contained in:
2024-09-29 18:10:14 +08:00
parent e6a0066616
commit 6517149d58
9 changed files with 396 additions and 230 deletions

View File

@@ -60,6 +60,7 @@ using Tnb.WarehouseMgr.Entities.Enums;
using Tnb.WarehouseMgr.Interfaces; using Tnb.WarehouseMgr.Interfaces;
using Org.BouncyCastle.Bcpg.OpenPgp; using Org.BouncyCastle.Bcpg.OpenPgp;
using JNPF.Systems.Entitys.Permission; using JNPF.Systems.Entitys.Permission;
using JNPF.Systems.Entitys.System;
namespace Tnb.ProductionMgr namespace Tnb.ProductionMgr
{ {
@@ -716,11 +717,71 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA
return; return;
} }
#region
var carry_mats = await db_YCLInternalTransfer.Queryable<WmsCarryCode>()
.InnerJoin<BasMaterial>((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<List<string>>(row.categorys);
}
var basRegionMats = await db_YCLInternalTransfer.Queryable<BasRegionMat>()
.InnerJoin<DictionaryDataEntity>((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) foreach (WmsCarryH wmsCarryH in items)
{ {
BasLocation startlocation = await db_YCLInternalTransfer.Queryable<BasLocation>().Where(r => r.id == wmsCarryH.location_id).FirstAsync(); BasLocation startlocation = await db_YCLInternalTransfer.Queryable<BasLocation>().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<BasLocation> endLocations = await _wareHouseService.InStockStrategy(inStockStrategyInput); InStockStrategyQuery inStockStrategyInput = null;
List<BasLocation> endLocations = new List<BasLocation>();
// 小件物料入外协存储区
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) if (endLocations.Count() == 0)
{ {
LoggerYCLInternalTransfer.LogWarning($"【YCLInternalTransfer】 当前巷道没有空库位可以入库或者有任务正在执行"); LoggerYCLInternalTransfer.LogWarning($"【YCLInternalTransfer】 当前巷道没有空库位可以入库或者有任务正在执行");
@@ -3636,5 +3697,16 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA
public decimal? codeqty { get; set; } public decimal? codeqty { get; set; }
public string unit_code { 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<string> category_list { get; set; }
}
} }
} }

View File

@@ -144,4 +144,13 @@ public partial class WmsPurchaseOrderD : BaseEntity<string>
/// </summary> /// </summary>
public string? production_unit { get; set; } public string? production_unit { get; set; }
/// <summary>
/// 规格
/// </summary>
public string? material_specification { get; set; }
/// <summary>
/// 型号
/// </summary>
public string? material_standard { get; set; }
} }

View File

@@ -437,7 +437,8 @@ namespace Tnb.WarehouseMgr
if (material != null) if (material != null)
{ {
wmsPurchaseOrderD.matcode_id = material.id; 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; wmsPurchaseOrderD.auxprop_gys = detail.auxprop_gys;
wmsPurchaseOrderDs.Add(wmsPurchaseOrderD); wmsPurchaseOrderDs.Add(wmsPurchaseOrderD);

View File

@@ -318,7 +318,6 @@ namespace Tnb.WarehouseMgr
.AndIF(input.AvoidBusyPassage, it => !busyPassages.Contains(it.passage)) .AndIF(input.AvoidBusyPassage, it => !busyPassages.Contains(it.passage))
.AndIF(!string.IsNullOrEmpty(input.passage), it => it.passage == input.passage) .AndIF(!string.IsNullOrEmpty(input.passage), it => it.passage == input.passage)
.ToExpression(); .ToExpression();
items = await db.Queryable<BasLocation>().Where(whereExp).OrderBy(policy.policy).ToListAsync(); items = await db.Queryable<BasLocation>().Where(whereExp).OrderBy(policy.policy).ToListAsync();
} }
catch (Exception) catch (Exception)
@@ -504,7 +503,7 @@ namespace Tnb.WarehouseMgr
.LeftJoin<BasLocation>((a, b, c) => a.location_id == c.id) .LeftJoin<BasLocation>((a, b, c) => a.location_id == c.id)
.Where(whereExpr) .Where(whereExpr)
//.OrderByIF((a,b,c)=>SqlFunc.IsNullOrEmpty()) //.OrderByIF((a,b,c)=>SqlFunc.IsNullOrEmpty())
.OrderBy("b.codeqty desc") .OrderBy("b.codeqty")
.Select((a, b, c) => new .Select((a, b, c) => new
{ {
WmsCarryH = a, WmsCarryH = a,

View File

@@ -235,14 +235,16 @@ namespace Tnb.WarehouseMgr
if (_wmsCarryCodes.Count > 0) 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: case WmsWareHouseConst.WAREHOUSE_YCL_ID:
{ {
try try
{ {
await _wareHouseService.s_taskExecuteSemaphore_YCLInstock.WaitAsync(); 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 }; InStockStrategyQuery inStockStrategyInput = new() { warehouse_id = "1", Size = 1, AvoidBusyPassage = true, Region_id = WmsWareHouseConst.REGION_YCLCache_ID };
List<BasLocation> endLocations = await _wareHouseService.InStockStrategy(inStockStrategyInput); List<BasLocation> endLocations = await _wareHouseService.InStockStrategy(inStockStrategyInput);
if (endLocations.Count == 0) if (endLocations.Count == 0)

View File

@@ -1808,6 +1808,38 @@ namespace Tnb.WarehouseMgr
await _db.Ado.BeginTranAsync(); await _db.Ado.BeginTranAsync();
await _db.Updateable<OtherOutstockD>().SetColumns(r => r.rk_qty == otherOutstockD_first.rk_qty + input.qty).Where(r => r.id == otherOutstockD_first.id).ExecuteCommandAsync(); await _db.Updateable<OtherOutstockD>().SetColumns(r => r.rk_qty == otherOutstockD_first.rk_qty + input.qty).Where(r => r.id == otherOutstockD_first.id).ExecuteCommandAsync();
//InStockStrategyQuery inStockStrategyInput = null;
//List<BasLocation> endlocations = new List<BasLocation>();
//BasMaterial mat = await _db.Queryable<WmsCarryCode>()
// .InnerJoin<BasMaterial>((a, b) => a.material_id == b.id)
// .Where((a, b) => a.carry_id == wmsCarryH.id).Select((a, b) => b).FirstAsync();
//List<string> categorys = new List<string>();
//if (!string.IsNullOrEmpty(mat.category_id))
//{
// categorys = JsonConvert.DeserializeObject<List<string>>(mat.category_id);
//}
//// 小件物料入外协存储区
//BasRegionMat basRegionMat = await _db.Queryable<BasRegionMat>()
// .InnerJoin<DictionaryDataEntity>((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() InStockStrategyQuery inStockStrategyInput = new()
{ {
warehouse_id = WmsWareHouseConst.WAREHOUSE_YCL_ID, warehouse_id = WmsWareHouseConst.WAREHOUSE_YCL_ID,
@@ -2568,8 +2600,8 @@ namespace Tnb.WarehouseMgr
catch (Exception ex) catch (Exception ex)
{ {
await _db.Ado.RollbackTranAsync(); await _db.Ado.RollbackTranAsync();
Logger.LogWarning("【DistributeSCWToYCL】" + ex.Message); Logger.LogWarning("【DistributeSCWToZCC】" + ex.Message);
Logger.LogWarning("【DistributeSCWToYCL】" + ex.StackTrace); Logger.LogWarning("【DistributeSCWToZCC】" + ex.StackTrace);
return await ToApiResult(HttpStatusCode.InternalServerError, ex.Message); return await ToApiResult(HttpStatusCode.InternalServerError, ex.Message);
} }
finally finally

View File

@@ -144,6 +144,8 @@ namespace Tnb.WarehouseMgr
case WmsWareHouseConst.BIZTYPE_WMSINSTOCK_ID: case WmsWareHouseConst.BIZTYPE_WMSINSTOCK_ID:
{ {
wmsOutinStockDetail.source_detail_id = input.disTask.source_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; wmsOutinStockDetail.source_type = WmsWareHouseConst.BIZTYPE_WMSINSTOCK_ID;
break; break;
} }

View File

@@ -121,71 +121,85 @@ namespace Tnb.WarehouseMgr
create_time = DateTime.Now, create_time = DateTime.Now,
}; };
var instockDs = new List<WmsInstockD>(); var instockDs = new List<WmsInstockD>();
WmsInstockD? instockD = null; var instockCodes = new List<WmsInstockCode>();
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<List<WmsInstockD>>();
List<WmsCarryCode> wmsCarryCodes = await _db.Queryable<WmsCarryCode>().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<List<WmsInstockD>>();
}
}
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(instock).ExecuteCommandAsync();
_ = await _db.Insertable(instockDs).ExecuteCommandAsync(); _ = await _db.Insertable(instockDs).ExecuteCommandAsync();
if (instockCode != null) _ = await _db.Insertable(instockCodes).ExecuteCommandAsync();
{
_ = await _db.Insertable(instockCode).ExecuteCommandAsync();
}
InStockStrategyQuery inStockStrategyInput = new() { warehouse_id = WmsWareHouseConst.WAREHOUSE_CP_ID, Size = 1 }; InStockStrategyQuery inStockStrategyInput = new() { warehouse_id = WmsWareHouseConst.WAREHOUSE_CP_ID, Size = 1 };
@@ -260,21 +274,26 @@ namespace Tnb.WarehouseMgr
return preTask; return preTask;
}).ToList(); }).ToList();
List<WmsPretaskCode> pretaskCodes = new(); List<WmsPretaskCode> pretaskCodes = new();
foreach (WmsPretaskH? pt in preTasks)
foreach (var wmsCarryCode in wmsCarryCodes)
{ {
WmsPretaskCode ptc = pt.Adapt<WmsPretaskCode>(); foreach (WmsPretaskH? pt in preTasks)
ptc.id = SnowflakeIdHelper.NextId(); {
ptc.bill_id = pt.id; WmsPretaskCode ptc = pt.Adapt<WmsPretaskCode>();
ptc.material_id = instockCode.material_id; ptc.id = SnowflakeIdHelper.NextId();
ptc.material_code = instockCode.material_code; ptc.bill_id = pt.id;
ptc.barcode = instockCode.barcode; ptc.material_id = wmsCarryCode.material_id;
ptc.codeqty = instockCode.codeqty; ptc.material_code = wmsCarryCode.material_code;
ptc.material_specification = instockCode.material_specification; ptc.barcode = wmsCarryCode.barcode;
ptc.container_no = instockCode.container_no; ptc.codeqty = wmsCarryCode.codeqty;
ptc.unit_id = instockCode.unit_id; ptc.material_specification = item.material_specification;
ptc.code_batch = instockCode.code_batch; ptc.container_no = item.container_no;
pretaskCodes.Add(ptc); ptc.unit_id = item.unit_id;
ptc.code_batch = wmsCarryCode.code_batch;
pretaskCodes.Add(ptc);
}
} }
bool isOk = await _wareHouseService.GenPreTask(preTasks, pretaskCodes); bool isOk = await _wareHouseService.GenPreTask(preTasks, pretaskCodes);
if (isOk) if (isOk)
{ {
@@ -288,49 +307,49 @@ namespace Tnb.WarehouseMgr
LocationIds = points.Select(x => x.location_id).ToList()! LocationIds = points.Select(x => x.location_id).ToList()!
}; };
//生成操作记录 ////生成操作记录
WmsHandleH handleH = new() //WmsHandleH handleH = new()
{ //{
org_id = _userManager.User == null ? "" : _userManager.User.OrganizeId!, // org_id = _userManager.User == null ? "" : _userManager.User.OrganizeId!,
startlocation_id = loc.id, // startlocation_id = loc.id,
endlocation_id = endLocations![0].id, // endlocation_id = endLocations![0].id,
bill_code = instock.bill_code, // bill_code = instock.bill_code,
biz_type = instock.biz_type, // biz_type = instock.biz_type,
carry_id = carry.id, // carry_id = carry.id,
carry_code = carry.carry_code, // carry_code = carry.carry_code,
require_id = instock.id, // require_id = instock.id,
require_code = instock.bill_code, // require_code = instock.bill_code,
create_id = _userManager.User == null ? "" : _userManager.UserId!, // create_id = _userManager.User == null ? "" : _userManager.UserId!,
create_time = DateTime.Now // create_time = DateTime.Now
}; //};
preTaskUpInput.PreTaskRecord = handleH; //preTaskUpInput.PreTaskRecord = handleH;
//生成操作记录条码表 ////生成操作记录条码表
WmsHandleCode handleCode = instockCode.Adapt<WmsHandleCode>(); //WmsHandleCode handleCode = instockCode.Adapt<WmsHandleCode>();
handleCode.id = SnowflakeIdHelper.NextId(); //handleCode.id = SnowflakeIdHelper.NextId();
handleCode.org_id = _userManager.User == null ? "" : _userManager.User.OrganizeId!; //handleCode.org_id = _userManager.User == null ? "" : _userManager.User.OrganizeId!;
handleCode.bill_id = handleH.id; //handleCode.bill_id = handleH.id;
handleCode.create_id = _userManager.User == null ? "" : _userManager.UserId!; //handleCode.create_id = _userManager.User == null ? "" : _userManager.UserId!;
handleCode.create_time = DateTime.Now; //handleCode.create_time = DateTime.Now;
preTaskUpInput.PreTaskHandleCodes.Add(handleCode); //preTaskUpInput.PreTaskHandleCodes.Add(handleCode);
//生成载具条码表 ////生成载具条码表
WmsCarryCode wmsCarryCode = instockCode.Adapt<WmsCarryCode>(); //WmsCarryCode wmsCarryCode = instockCode.Adapt<WmsCarryCode>();
{ //{
wmsCarryCode.id = SnowflakeIdHelper.NextId(); // wmsCarryCode.id = SnowflakeIdHelper.NextId();
wmsCarryCode.carry_id = carry.id; // wmsCarryCode.carry_id = carry.id;
wmsCarryCode.is_out = 0; // wmsCarryCode.is_out = 0;
wmsCarryCode.location_id = loc.id; // wmsCarryCode.location_id = loc.id;
wmsCarryCode.location_code = loc.location_code; // wmsCarryCode.location_code = loc.location_code;
wmsCarryCode.warehouse_id = instock.warehouse_id; // wmsCarryCode.warehouse_id = instock.warehouse_id;
} //}
_ = await _db.Insertable(wmsCarryCode).ExecuteCommandAsync(); //_ = await _db.Insertable(wmsCarryCode).ExecuteCommandAsync();
//回更状态 //回更状态
await _wareHouseService.GenInStockTaskHandleAfter(preTaskUpInput, 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 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 }); it => new BasLocation { is_lock = 1 });
_ = await _db.Updateable<WmsInstockD>().SetColumns(it => new WmsInstockD { line_status = WmsWareHouseConst.BILLSTATUS_ON_ID }).Where(it => instockCode.bill_d_id == it.id).ExecuteCommandAsync(); _ = await _db.Updateable<WmsInstockD>().SetColumns(it => new WmsInstockD { line_status = WmsWareHouseConst.BILLSTATUS_ON_ID }).Where(it => instock.id == it.bill_id).ExecuteCommandAsync();
_ = await _db.Updateable<WmsInstockH>().SetColumns(it => new WmsInstockH { status = WmsWareHouseConst.BILLSTATUS_ON_ID }).Where(it => it.id == instock!.id).ExecuteCommandAsync(); _ = await _db.Updateable<WmsInstockH>().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 biz_type = WmsWareHouseConst.BIZTYPE_WMSINSTOCK_ID;
string required_type = (await _dbScanInStockByRedis.Queryable<WmsTempCode>().FirstAsync(it => it.barcode == input.data["物料条码"])).required_type; string required_type = (await _dbScanInStockByRedis.Queryable<WmsTempCode>().FirstAsync(it => it.barcode == input.data["物料条码"])).required_type;
string source_id = (await _dbScanInStockByRedis.Queryable<WmsTempCode>().FirstAsync(it => it.barcode == input.data["物料条码"])).require_id; string source_id = (await _dbScanInStockByRedis.Queryable<WmsTempCode>().FirstAsync(it => it.barcode == input.data["物料条码"])).require_id;
string source_main_id = "";
switch (required_type) switch (required_type)
{ {
case WmsWareHouseConst.BILLTYPE_PURCHASE_ID: case WmsWareHouseConst.BILLTYPE_PURCHASE_ID:
{ {
bill_type = WmsWareHouseConst.BILLTYPE_MATERIALINSTOCK_ID; bill_type = WmsWareHouseConst.BILLTYPE_MATERIALINSTOCK_ID;
source_main_id = (await _dbScanInStockByRedis.Queryable<WmsPurchaseD>().FirstAsync(it => it.id == source_id)).bill_id;
break; break;
} }
case WmsWareHouseConst.BILLTYPE_OUTSOURCE_ID: case WmsWareHouseConst.BILLTYPE_OUTSOURCE_ID:
@@ -439,77 +460,90 @@ namespace Tnb.WarehouseMgr
print_status = WmsWareHouseConst.PRINT_STATUS_PRINTCOMPLETE, print_status = WmsWareHouseConst.PRINT_STATUS_PRINTCOMPLETE,
is_check = 1, is_check = 1,
purchase_code = billCode?.ToString() ?? string.Empty, purchase_code = billCode?.ToString() ?? string.Empty,
create_id = _userManager.UserId==null?"": _userManager.UserId, create_id = _userManager.UserId == null ? "" : _userManager.UserId,
create_time = DateTime.Now, create_time = DateTime.Now,
source_id = source_main_id
}; };
var instockDs = new List<WmsInstockD>(); var instockDs = new List<WmsInstockD>();
WmsInstockD? instockD = null; var instockCodes = new List<WmsInstockCode>();
if (mat != null) List<WmsCarryCode> wmsCarryCodes = await _db.Queryable<WmsCarryCode>().Where(r => r.carry_id == carry.id).ToListAsync();
{
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<List<WmsInstockD>>();
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
WmsInstockCode? instockCode = null;
if (mat != null)
{
instockCode = new()
{ {
id = SnowflakeIdHelper.NextId(), if (input.data.ContainsKey("details"))
bill_id = instock.id, {
bill_d_id = instockD?.id ?? string.Empty, instockDs = input.data["details"].Adapt<List<WmsInstockD>>();
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 foreach (var row in list)
code_batch = item.code_batch, {
material_specification = item.material_specification, WmsInstockCode? instockCode = null;
container_no = item.container_no, if (mat != null)
codeqty = item.codeqty, {
is_lock = 0, instockCode = new()
is_end = 0, {
create_id = _userManager.UserId == null ? "" : _userManager.UserId, id = SnowflakeIdHelper.NextId(),
create_time = DateTime.Now, 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(); _ = await _dbScanInStockByRedis.Insertable(instock).ExecuteCommandAsync();
Logger.LogInformation($"【ScanInStockByRedis】插入WmsInstockH {JsonConvert.SerializeObject(instock)}"); Logger.LogInformation($"【ScanInStockByRedis】插入WmsInstockH {JsonConvert.SerializeObject(instock)}");
_ = await _dbScanInStockByRedis.Insertable(instockDs).ExecuteCommandAsync(); _ = await _dbScanInStockByRedis.Insertable(instockDs).ExecuteCommandAsync();
Logger.LogInformation($"【ScanInStockByRedis】插入WmsInstockD {JsonConvert.SerializeObject(instockDs)}"); Logger.LogInformation($"【ScanInStockByRedis】插入WmsInstockD {JsonConvert.SerializeObject(instockDs)}");
if (instockCode != null) if (instockCodes != null)
{ {
_ = await _dbScanInStockByRedis.Insertable(instockCode).ExecuteCommandAsync(); _ = await _dbScanInStockByRedis.Insertable(instockCodes).ExecuteCommandAsync();
Logger.LogInformation($"【ScanInStockByRedis】插入WmsInstockCode {JsonConvert.SerializeObject(instockCode)}"); Logger.LogInformation($"【ScanInStockByRedis】插入WmsInstockCode {JsonConvert.SerializeObject(instockCodes)}");
} }
InStockStrategyQuery inStockStrategyInput = new() { warehouse_id = "1", Size = 1, AvoidBusyPassage = true, Region_id = WmsWareHouseConst.REGION_YCLCache_ID }; 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; return preTask;
}).ToList(); }).ToList();
List<WmsPretaskCode> pretaskCodes = new(); List<WmsPretaskCode> pretaskCodes = new();
foreach (WmsPretaskH? pt in preTasks) foreach (var wmsCarryCode in wmsCarryCodes)
{ {
WmsPretaskCode ptc = pt.Adapt<WmsPretaskCode>(); foreach (WmsPretaskH? pt in preTasks)
ptc.id = SnowflakeIdHelper.NextId(); {
ptc.bill_id = pt.id; WmsPretaskCode ptc = pt.Adapt<WmsPretaskCode>();
ptc.material_id = instockCode.material_id; ptc.id = SnowflakeIdHelper.NextId();
ptc.material_code = instockCode.material_code; ptc.bill_id = pt.id;
ptc.barcode = instockCode.barcode; ptc.material_id = wmsCarryCode.material_id;
ptc.codeqty = instockCode.codeqty; ptc.material_code = wmsCarryCode.material_code;
ptc.material_specification = instockCode.material_specification; ptc.barcode = wmsCarryCode.barcode;
ptc.container_no = instockCode.container_no; ptc.codeqty = wmsCarryCode.codeqty;
ptc.unit_id = instockCode.unit_id; ptc.material_specification = item.material_specification;
ptc.code_batch = instockCode.code_batch; ptc.container_no = item.container_no;
pretaskCodes.Add(ptc); ptc.unit_id = mat.unit_id;
ptc.code_batch = wmsCarryCode.code_batch;
pretaskCodes.Add(ptc);
}
} }
bool isOk = await _wareHouseService.GenPreTask(preTasks, pretaskCodes, _dbScanInStockByRedis); bool isOk = await _wareHouseService.GenPreTask(preTasks, pretaskCodes, _dbScanInStockByRedis);
if (isOk) if (isOk)
@@ -621,37 +658,37 @@ namespace Tnb.WarehouseMgr
LocationIds = points.Select(x => x.location_id).ToList()! LocationIds = points.Select(x => x.location_id).ToList()!
}; };
//生成操作记录 ////生成操作记录
WmsHandleH handleH = new() //WmsHandleH handleH = new()
{ //{
org_id = _userManager.User == null ? "" : _userManager.User.OrganizeId!, // org_id = _userManager.User == null ? "" : _userManager.User.OrganizeId!,
startlocation_id = loc.id, // startlocation_id = loc.id,
endlocation_id = endLocations![0].id, // endlocation_id = endLocations![0].id,
bill_code = instock.bill_code, // bill_code = instock.bill_code,
biz_type = instock.biz_type, // biz_type = instock.biz_type,
carry_id = carry.id, // carry_id = carry.id,
carry_code = carry.carry_code, // carry_code = carry.carry_code,
require_id = instock.id, // require_id = instock.id,
require_code = instock.bill_code, // require_code = instock.bill_code,
create_id = _userManager.User == null ? "" : _userManager.UserId!, // create_id = _userManager.User == null ? "" : _userManager.UserId!,
create_time = DateTime.Now // create_time = DateTime.Now
}; //};
preTaskUpInput.PreTaskRecord = handleH; //preTaskUpInput.PreTaskRecord = handleH;
//生成操作记录条码表 ////生成操作记录条码表
WmsHandleCode handleCode = instockCode.Adapt<WmsHandleCode>(); //WmsHandleCode handleCode = instockCode.Adapt<WmsHandleCode>();
handleCode.id = SnowflakeIdHelper.NextId(); //handleCode.id = SnowflakeIdHelper.NextId();
handleCode.org_id = _userManager.User == null ? "" : _userManager.User.OrganizeId!; //handleCode.org_id = _userManager.User == null ? "" : _userManager.User.OrganizeId!;
handleCode.bill_id = handleH.id; //handleCode.bill_id = handleH.id;
handleCode.create_id = _userManager.User == null ? "" : _userManager.UserId!; //handleCode.create_id = _userManager.User == null ? "" : _userManager.UserId!;
handleCode.create_time = DateTime.Now; //handleCode.create_time = DateTime.Now;
preTaskUpInput.PreTaskHandleCodes.Add(handleCode); //preTaskUpInput.PreTaskHandleCodes.Add(handleCode);
//回更状态 //回更状态
await _wareHouseService.GenInStockTaskHandleAfter(preTaskUpInput, 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 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); it => new BasLocation { is_lock = 1 }, _dbScanInStockByRedis);
_ = await _dbScanInStockByRedis.Updateable<WmsInstockD>().SetColumns(it => new WmsInstockD { line_status = WmsWareHouseConst.BILLSTATUS_ON_ID }).Where(it => instockCode.bill_d_id == it.id).ExecuteCommandAsync(); _ = await _dbScanInStockByRedis.Updateable<WmsInstockD>().SetColumns(it => new WmsInstockD { line_status = WmsWareHouseConst.BILLSTATUS_ON_ID }).Where(it => instock.id == it.bill_id).ExecuteCommandAsync();
_ = await _dbScanInStockByRedis.Updateable<WmsInstockH>().SetColumns(it => new WmsInstockH { status = WmsWareHouseConst.BILLSTATUS_ON_ID }).Where(it => it.id == instock!.id).ExecuteCommandAsync(); _ = await _dbScanInStockByRedis.Updateable<WmsInstockH>().SetColumns(it => new WmsInstockH { status = WmsWareHouseConst.BILLSTATUS_ON_ID }).Where(it => it.id == instock!.id).ExecuteCommandAsync();
} }

View File

@@ -45,6 +45,7 @@ namespace Tnb.WarehouseMgr
private readonly IUserManager _userManager; private readonly IUserManager _userManager;
private readonly IDictionaryDataService _dictionaryDataService; private readonly IDictionaryDataService _dictionaryDataService;
private readonly IThirdApiRecordService _thirdApiRecordService; private readonly IThirdApiRecordService _thirdApiRecordService;
public static SemaphoreSlim s_SaveCheckResult = new(1);
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc(); public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
public WmsPurchaseDService( public WmsPurchaseDService(
@@ -66,13 +67,24 @@ namespace Tnb.WarehouseMgr
{ {
try try
{ {
await s_SaveCheckResult.WaitAsync();
string id = dic["id"]; string id = dic["id"];
string qcRes = dic["qc_res"]; string qcRes = dic["qc_res"];
WmsPurchaseD wmsPurchaseD = await _db.Queryable<WmsPurchaseD>().SingleAsync(x => x.id == id); WmsPurchaseD wmsPurchaseD = await _db.Queryable<WmsPurchaseD>().SingleAsync(x => x.id == id);
string purchaseHId = wmsPurchaseD?.bill_id ?? ""; string purchaseHId = wmsPurchaseD?.bill_id ?? "";
WmsPurchaseH wmsPurchaseH = await _db.Queryable<WmsPurchaseH>().SingleAsync(x => x.id == purchaseHId); WmsPurchaseH wmsPurchaseH = await _db.Queryable<WmsPurchaseH>().SingleAsync(x => x.id == purchaseHId);
#region #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; string? create_id = _userManager.User.Id;
@@ -101,28 +113,24 @@ namespace Tnb.WarehouseMgr
} }
#endregion #endregion
//自制的采购入库 不在质检保存里调用erp接口 //自制的采购入库 不在质检保存里调用erp接口
if (string.IsNullOrEmpty(wmsPurchaseH.erp_bill_code)) if (string.IsNullOrEmpty(wmsPurchaseH.erp_bill_code))
{ {
return "保存成功"; return "保存成功";
} }
List<WmsOutinStockDetail> wmsOutinStockDetails = await _db.Queryable<WmsOutinStockDetail>() // 托盘对应入库单
.Where(x => x.source_detail_id == wmsPurchaseD.id && x.source_type == WmsWareHouseConst.BIZTYPE_WMSINSTOCK_ID) List<WmsInstockH> instock_mains = await _db.Queryable<WmsInstockH>().Where(x => x.source_id == wmsPurchaseD.bill_id).ToListAsync();
.ToListAsync();
List<WmsInstockD> allInstockDetails = await _db.Queryable<WmsInstockD>().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<Dictionary<string, object>> requestData = new List<Dictionary<string, object>>(); List<Dictionary<string, object>> requestData = new List<Dictionary<string, object>>();
List<string> carryIds = wmsOutinStockDetails.Select(x => x.carry_id).ToList(); List<string> carryIds = instock_mains.Select(x => x.carry_id).ToList();
string wmsPurchaseOrderHId = wmsPurchaseH?.erp_bill_code ?? ""; string wmsPurchaseOrderHId = wmsPurchaseH?.erp_bill_code ?? "";
WmsPurchaseOrderH wmsPurchaseOrderH = await _db.Queryable<WmsPurchaseOrderH>().SingleAsync(x => x.id == wmsPurchaseOrderHId); WmsPurchaseOrderH wmsPurchaseOrderH = await _db.Queryable<WmsPurchaseOrderH>().SingleAsync(x => x.id == wmsPurchaseOrderHId);
WmsPurchaseOrderD wmsPurchaseOrderDs = await _db.Queryable<WmsPurchaseOrderD>().FirstAsync(x => x.fk_wms_purchase_order_id == wmsPurchaseOrderHId); WmsPurchaseOrderD wmsPurchaseOrderDs = await _db.Queryable<WmsPurchaseOrderD>().FirstAsync(x => x.fk_wms_purchase_order_id == wmsPurchaseOrderHId);
foreach (var wmsOutinStockDetail in wmsOutinStockDetails)
{ {
WmsDistaskH wmsDistaskH = await _db.Queryable<WmsDistaskH>().FirstAsync(x=>x.bill_code==wmsOutinStockDetail.distask_code);
WmsInstockH instock = await _db.Queryable<WmsInstockH>().SingleAsync(x=>x.id==wmsDistaskH.require_id);
List<WmsInstockD> allInstockDetails = await _db.Queryable<WmsInstockD>().Where(it => it.bill_id == instock.id).ToListAsync();
List<String> materialIds = allInstockDetails.Select(x => x.material_id).Distinct().ToList(); List<String> materialIds = allInstockDetails.Select(x => x.material_id).Distinct().ToList();
List<String> unitCodes = allInstockDetails.Select(x => x.unit_id).Distinct().ToList(); List<String> unitCodes = allInstockDetails.Select(x => x.unit_id).Distinct().ToList();
List<DictionaryDataEntity> unitDatas = await _db.Queryable<DictionaryTypeEntity>() List<DictionaryDataEntity> unitDatas = await _db.Queryable<DictionaryTypeEntity>()
@@ -139,7 +147,7 @@ namespace Tnb.WarehouseMgr
// tableIds.Add(_userManager.UserId); // tableIds.Add(_userManager.UserId);
// tableIds.Add(wmsPurchaseH.create_id); // tableIds.Add(wmsPurchaseH.create_id);
tableIds.Add(WmsWareHouseConst.AdministratorOrgId); tableIds.Add(WmsWareHouseConst.AdministratorOrgId);
tableIds.Add(instock.warehouse_id);// 1001A11000000002OOGU tableIds.Add(instock_mains[0].warehouse_id);// 1001A11000000002OOGU
tableIds.AddRange(materialIds); tableIds.AddRange(materialIds);
tableIds.Add(supplierId); tableIds.Add(supplierId);
tableIds.Add(tranTypeId); tableIds.Add(tranTypeId);
@@ -180,7 +188,7 @@ namespace Tnb.WarehouseMgr
erpRequestData.Add("pk_org", erpOrg.pk_org); erpRequestData.Add("pk_org", erpOrg.pk_org);
erpRequestData.Add("pk_org_v", erpOrg.pk_org_v); erpRequestData.Add("pk_org_v", erpOrg.pk_org_v);
erpRequestData.Add("pk_group", erpOrg.pk_group); 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("vtrantypecode", tranType?.EnCode ?? "");
erpRequestData.Add("csourcebillhid", wmsPurchaseH?.erp_arriveorder_pk ?? ""); 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 ?? "", ["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 ?? "", ["cvendorid"] = erpExtendFields.Find(x => x.table_id == supplierId)?.supplier_id ?? "",
["cvendorvid"] = erpExtendFields.Find(x => x.table_id == supplierId)?.supplier_vid ?? "", ["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, ["nnum"] = item.qty,
["nshouldnum"] = item.pr_qty, ["nshouldnum"] = item.pr_qty,
// ["pk_creqwareid"] = erpExtendFields.Find(x => x.table_id == instock.warehouse_id)?.cotherwhid ?? "", // ["pk_creqwareid"] = erpExtendFields.Find(x => x.table_id == instock.warehouse_id)?.cotherwhid ?? "",
@@ -284,6 +292,10 @@ namespace Tnb.WarehouseMgr
Log.Error(e.Message,e); Log.Error(e.Message,e);
throw Oops.Bah(e.Message); throw Oops.Bah(e.Message);
} }
finally
{
s_SaveCheckResult.Release();
}
return "保存成功"; return "保存成功";
} }