This commit is contained in:
qianjiawei
2023-12-21 09:46:21 +08:00
parent e8d9f9af81
commit 024c75356a
7 changed files with 318 additions and 39 deletions

View File

@@ -157,7 +157,7 @@ namespace Tnb.ProductionMgr
//扫码入库
private void ScanInStock(object state)
{
var carry_code = "TestLX0001";//从数采读取
var carry_code = "TestLX0001";//从数采读取载具
WmsCarryH? carry = _repository.AsSugarClient().Queryable<WmsCarryH>().Single(it => it.carry_code == carry_code);
if (carry != null)
{
@@ -176,7 +176,7 @@ namespace Tnb.ProductionMgr
input.data.Add("container_no", WmsCarryCode.container_no!);//箱号
input.data.Add("material_id", WmsCarryCode.material_id);
input.data.Add("id", null);
_wmsPDAScanInStock.ScanInStock(input);
_wmsPDAScanInStock.ScanInStockByRedis(input);
}
}
@@ -191,7 +191,7 @@ namespace Tnb.ProductionMgr
{
// Readtimer = new Timer(GetRedisData, null, TimeSpan.Zero, TimeSpan.FromSeconds(300));
// CheckGettimer = new Timer(CheckGet, null, TimeSpan.Zero, TimeSpan.FromSeconds(300));
// Scantimer = new Timer(ScanInStock, null, TimeSpan.Zero, TimeSpan.FromSeconds(300));
Scantimer = new Timer(ScanInStock, null, TimeSpan.Zero, TimeSpan.FromSeconds(300));
return Task.CompletedTask;
}
public Task StopAsync(CancellationToken cancellationToken)

View File

@@ -10,5 +10,6 @@ namespace Tnb.WarehouseMgr.Interfaces
public interface IWmsPDAScanInStockService
{
Task<dynamic> ScanInStock(VisualDevModelDataCrInput input);
Task<dynamic> ScanInStockByRedis(VisualDevModelDataCrInput input);
}
}

View File

@@ -41,4 +41,8 @@
</None>
</ItemGroup>
<ItemGroup>
<Folder Include="Library\x64\" />
</ItemGroup>
</Project>

View File

@@ -105,10 +105,8 @@ namespace Tnb.WarehouseMgr
if (sPoint != null && ePoint != null)
{
Logger.Information($"sPoint.id={sPoint.id},ePoint.id={ePoint.id}");
List<WmsPointH> points = new List<WmsPointH>();
//中储仓不算路径
if (input.data[nameof(InStockStrategyQuery.warehouse_id)].ToString() != "2")
if (sPoint.area_code != ePoint.area_code)
{
points = await _wareHouseService.PathAlgorithms(sPoint.id, ePoint.id);
if (points.Count <= 2)

View File

@@ -709,24 +709,23 @@ namespace Tnb.WarehouseMgr
if (sPoint != null && ePoint != null)
{
List<WmsPointH> points = new List<WmsPointH>();
try
if (sPoint.area_code != ePoint.area_code)
{
points = await _wareHouseService.PathAlgorithms(sPoint.id, ePoint.id);
points = await _wareHouseService.PathAlgorithms(sPoint.id, ePoint.id);
if (points.Count <= 2)
{
throw new AppFriendlyException("该路径不存在", 500);
}
}
catch (Exception)
else
{
points.Add(sPoint);
points.Add(ePoint);
}
locIds.AddRange(points.Select(x => x.location_id).ToList()!);
//根据获取的路径点生成预任务,生成顺序必须预路径算法返回的起终点的顺序一致(预任务顺序)
if (points?.Count > 0)
{
if (points.Count < 2)
{
throw new AppFriendlyException("该路径不存在", 500);
}
List<WmsPretaskH> curPreTasks = points.Where(it => !it.location_id.IsNullOrEmpty()).GroupBy(g => g.area_code).Select(it =>
{

View File

@@ -117,26 +117,23 @@ namespace Tnb.WarehouseMgr
if (sPoint != null && ePoint != null)
{
List<WmsPointH> points=new List<WmsPointH>();
try
List<WmsPointH> points = new List<WmsPointH>();
if (sPoint.area_code != ePoint.area_code)
{
points = await _wareHouseService!.PathAlgorithms(sPoint.id, ePoint.id);
points = await _wareHouseService.PathAlgorithms(sPoint.id, ePoint.id);
if (points.Count <= 2)
{
throw new AppFriendlyException("该路径不存在", 500);
}
}
catch (Exception)
else
{
points.Add(sPoint);
points.Add(ePoint);
}
//根据获取的路径点生成预任务,生成顺序必须预路径算法返回的起终点的顺序一致(预任务顺序)
if (points?.Count > 0)
{
if (points.Count < 2)
{
throw new AppFriendlyException("该路径不存在", 500);
}
List<WmsPretaskH> preTasks = points.Where(it => !it.location_id.IsNullOrEmpty()).GroupBy(g => g.area_code).Select(it =>
{
WmsPointH? sPoint = it.FirstOrDefault();

View File

@@ -184,6 +184,7 @@ namespace Tnb.WarehouseMgr
InStockStrategyQuery inStockStrategyInput = new() { warehouse_id = WmsWareHouseConst.WAREHOUSE_CP_ID, Size = 1 };
List<BasLocation> endLocations = await _wareHouseService.InStockStrategy(inStockStrategyInput);
WmsPointH sPoint = new();
WmsPointH ePoint = new();
@@ -203,21 +204,20 @@ namespace Tnb.WarehouseMgr
if (sPoint != null && ePoint != null)
{
List<WmsPointH> points=new List<WmsPointH>();
try
List<WmsPointH> points = new List<WmsPointH>();
if (sPoint.area_code != ePoint.area_code)
{
points = await _wareHouseService.PathAlgorithms(sPoint.id, ePoint.id);
if (points.Count <= 2)
{
throw new AppFriendlyException("该路径不存在", 500);
}
}
catch (Exception)
else
{
points.Add(sPoint);
points.Add(ePoint);
}
if (points.Count < 2)
{
throw new AppFriendlyException("该路径不存在", 500);
}
//根据获取的路径点生成预任务,生成顺序必须预路径算法返回的起终点的顺序一致(预任务顺序)
if (points?.Count > 0)
{
@@ -228,7 +228,7 @@ namespace Tnb.WarehouseMgr
WmsPretaskH preTask = new()
{
org_id = _userManager.User.OrganizeId!,
org_id = _userManager.User==null?"": _userManager.User.OrganizeId!,
startlocation_id = sPoint?.location_id!,
startlocation_code = sPoint?.location_code!,
endlocation_id = ePoint?.location_id!,
@@ -249,7 +249,7 @@ namespace Tnb.WarehouseMgr
area_code = it.Key,
require_id = instock.id,
require_code = instock.bill_code,
create_id = _userManager.UserId,
create_id = _userManager.User == null ? "" : _userManager.UserId!,
create_time = DateTime.Now
};
return preTask;
@@ -286,7 +286,7 @@ namespace Tnb.WarehouseMgr
//生成操作记录
WmsHandleH handleH = new()
{
org_id = _userManager.User.OrganizeId,
org_id = _userManager.User == null ? "" : _userManager.User.OrganizeId!,
startlocation_id = loc.id,
endlocation_id = endLocations![0].id,
bill_code = instock.bill_code,
@@ -295,7 +295,7 @@ namespace Tnb.WarehouseMgr
carry_code = carry.carry_code,
require_id = instock.id,
require_code = instock.bill_code,
create_id = _userManager.UserId,
create_id = _userManager.User == null ? "" : _userManager.UserId!,
create_time = DateTime.Now
};
preTaskUpInput.PreTaskRecord = handleH;
@@ -303,9 +303,9 @@ namespace Tnb.WarehouseMgr
//生成操作记录条码表
WmsHandleCode handleCode = instockCode.Adapt<WmsHandleCode>();
handleCode.id = SnowflakeIdHelper.NextId();
handleCode.org_id = _userManager.User.OrganizeId;
handleCode.org_id = _userManager.User == null ? "" : _userManager.User.OrganizeId!;
handleCode.bill_id = handleH.id;
handleCode.create_id = _userManager.UserId;
handleCode.create_id = _userManager.User == null ? "" : _userManager.UserId!;
handleCode.create_time = DateTime.Now;
preTaskUpInput.PreTaskHandleCodes.Add(handleCode);
@@ -344,5 +344,285 @@ namespace Tnb.WarehouseMgr
}
return Task.FromResult(true);
}
public async Task<dynamic> ScanInStockByRedis(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<WmsInstockCode>();
if (item.codeqty == 0)
{
throw new AppFriendlyException("请输入入库数量", 500);
}
carryCode = item.barcode;
carry = await _db.Queryable<WmsCarryH>().FirstAsync(it => it.carry_code == carryCode);
if (carry == null)
{
throw new AppFriendlyException("载具有误", 500);
}
mat = await _db.Queryable<BasMaterial>().FirstAsync(it => it.code == item.material_code);
if (mat == null)
{
throw new AppFriendlyException("物料有误", 500);
}
loc = await _db.Queryable<BasLocation>().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.bill_code)] : 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() ?? "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,
};
var instockDs = new List<WmsInstockD>();
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<List<WmsInstockD>>();
}
}
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,//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,
};
}
_ = await _db.Insertable(instock).ExecuteCommandAsync();
_ = await _db.Insertable(instockDs).ExecuteCommandAsync();
if (instockCode != null)
{
_ = await _db.Insertable(instockCode).ExecuteCommandAsync();
}
InStockStrategyQuery inStockStrategyInput = new() { warehouse_id = "1", Size = 1 };
List<BasLocation> endLocations = await _wareHouseService.InStockStrategy(inStockStrategyInput);
WmsPointH sPoint = new();
WmsPointH ePoint = new();
if (endLocations?.Count > 0)
{
BasLocation eloc = await _db.Queryable<BasLocation>().SingleAsync(it => it.id == endLocations[0].id);
bool isMatch = await IsCarryAndLocationMatchByCarryStd(carry, eloc);
if (!isMatch)
{
throw new AppFriendlyException("库位与载具规格不匹配", 500);
}
ePoint = await _db.Queryable<WmsPointH>().FirstAsync(it => it.location_id == endLocations[0].id);
}
sPoint = await _db.Queryable<WmsPointH>().FirstAsync(it => it.location_id == loc.id);
if (sPoint != null && ePoint != null)
{
List<WmsPointH> points = new List<WmsPointH>();
if (sPoint.area_code != ePoint.area_code)
{
points = await _wareHouseService.PathAlgorithms(sPoint.id, ePoint.id);
if (points.Count <= 2)
{
throw new AppFriendlyException("该路径不存在", 500);
}
}
else
{
points.Add(sPoint);
points.Add(ePoint);
}
//根据获取的路径点生成预任务,生成顺序必须预路径算法返回的起终点的顺序一致(预任务顺序)
if (points?.Count > 0)
{
List<WmsPretaskH> 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<WmsPretaskCode> pretaskCodes = new();
foreach (WmsPretaskH? pt in preTasks)
{
WmsPretaskCode ptc = pt.Adapt<WmsPretaskCode>();
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);
}
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<WmsHandleCode>();
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 });
_ = 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<WmsInstockH>().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);
}
}
}