This commit is contained in:
qianjiawei
2023-12-15 09:49:44 +08:00
3 changed files with 131 additions and 105 deletions

View File

@@ -10,5 +10,11 @@ namespace Tnb.WarehouseMgr.Entities.Dto.Inputs
public class CheckPutInput
{
public string point_code { get; set; }
public int type { get; set; }
}
public enum exectype
{
= 0,
= 1
}
}

View File

@@ -243,12 +243,25 @@ namespace Tnb.WarehouseMgr
[HttpPost]
public async Task CheckPut(CheckPutInput input)
{
Dictionary<string, string[]> dic = new Dictionary<string, string[]>();
dic.Add("5号输送线点位", new string[] { "TY4C-ZHUSU1", "weighDone_5" });
dic.Add("6号输送线点位", new string[] { "TY4C-ZHUSU1", "weighDone_6" });
if (!dic.ContainsKey(input.point_code))
throw new AppFriendlyException("点位" + input.point_code + "不存在", 500);
var strs = dic.Where(p => p.Key == input.point_code).First().Value;
Dictionary<string, string[]> putdic = new Dictionary<string, string[]>();
putdic.Add("SSX-021-005", new string[] { "CS05", "ConveyorAllowPutEmptyBox" });
putdic.Add("SSX-021-006", new string[] { "CS06", "ConveyorAllowPutEmptyBox" });
Dictionary<string, string[]> getdic = new Dictionary<string, string[]>();
getdic.Add("SSX-021-005", new string[] { "CS05", "FullBoxAllowGet" });
getdic.Add("SSX-021-006", new string[] { "CS06", "FullBoxAllowGet" });
var strs = new string[] { };
if (input.type == (int)exectype.)
{
if (!putdic.ContainsKey(input.point_code))
throw new AppFriendlyException("点位" + input.point_code + "不存在", 500);
strs = putdic.Where(p => p.Key == input.point_code).First().Value;
}
else if (input.type == (int)exectype.)
{
if (!getdic.ContainsKey(input.point_code))
throw new AppFriendlyException("点位" + input.point_code + "不存在", 500);
strs = getdic.Where(p => p.Key == input.point_code).First().Value;
}
bool flag = await _redisData.HashExist(strs[0], strs[1]);
if (!flag)
{
@@ -316,7 +329,7 @@ namespace Tnb.WarehouseMgr
//it.area_code.Contains("ELE", StringComparison.OrdinalIgnoreCase)
var elePreTasks = preTasks.Where(it => it.area_code.Contains("ELE", StringComparison.OrdinalIgnoreCase)).ToList();
var normalPreTasks = preTasks.Where(it => !agvElevatorTasks.Concat(elePreTasks).Select(x => x.endlocation_code).Contains(it.endlocation_code)).ToList();
var normalPreTasks = preTasks.Where(it =>it.area_code!="B"&& !agvElevatorTasks.Concat(elePreTasks).Select(x => x.endlocation_code).Contains(it.endlocation_code)).ToList();
IEnumerable<WmsPretaskH?> firstEleGrp = agvElevatorTasks.GroupBy(g => g.endlocation_code).Select(t => t.OrderBy(o => o.bill_code).FirstOrDefault());
agvElevatorTasks = firstEleGrp?.ToList() ?? Enumerable.Empty<WmsPretaskH>().ToList()!;
@@ -534,7 +547,6 @@ namespace Tnb.WarehouseMgr
try
{
var db = _db.CopyNew();
Logger.Information("进入CTUTaskExecute");
List<WmsPretaskH> CTUTasks = await db.Queryable<WmsPretaskH>()
.InnerJoin<WmsAreaH>((a, b) => a.area_id == b.id)
.Where(a => a.status == WmsWareHouseConst.PRETASK_BILL_STATUS_DXF_ID)
@@ -659,11 +671,14 @@ namespace Tnb.WarehouseMgr
//判断
if (DistaskHs.Where(p => p.status == WmsWareHouseConst.TASK_BILL_STATUS_DZX_ID).Any())
{
timer = new Timer(TimerExec, null, TimeSpan.Zero, TimeSpan.FromMinutes(10));
var time =int.Parse( db.Queryable<BasFactoryConfig>().Where(P => P.key == "getinterval").First().value);
timer = new Timer(TimerExec, null, TimeSpan.FromMinutes(time), TimeSpan.FromMinutes(time));
}
if (inCtuExec.Count > 0)
{
//呼叫ctu入库
await db.Updateable<WmsDistaskH>().SetColumns(it => new WmsDistaskH { status = WmsWareHouseConst.TASK_BILL_STATUS_RUNING_ID }).Where(it => inCtuExec.Select(p => p.id).ToList().Contains(it.id)).ExecuteCommandAsync();
await db.Updateable<WmsPretaskH>().SetColumns(it => new WmsPretaskH { status = WmsWareHouseConst.PRETASK_BILL_STATUS_START_ID }).Where(it => inCtuExec.Select(x => x.pretask_id).ToList().Contains(it.id)).ExecuteCommandAsync();
CancellationTokenSource Ctu = new();
await CallingCTU(inCtuExec, Ctu.Token, 1);
Ctu.Dispose();
@@ -671,6 +686,8 @@ namespace Tnb.WarehouseMgr
if (outCtuExec.Count > 0)
{
//呼叫ctu出库
await db.Updateable<WmsDistaskH>().SetColumns(it => new WmsDistaskH { status = WmsWareHouseConst.TASK_BILL_STATUS_RUNING_ID }).Where(it => outCtuExec.Select(p => p.id).ToList().Contains(it.id)).ExecuteCommandAsync();
await db.Updateable<WmsPretaskH>().SetColumns(it => new WmsPretaskH { status = WmsWareHouseConst.PRETASK_BILL_STATUS_START_ID }).Where(it => outCtuExec.Select(x => x.pretask_id).ToList().Contains(it.id)).ExecuteCommandAsync();
CancellationTokenSource Ctu = new();
await CallingCTU(outCtuExec, Ctu.Token, 0);
Ctu.Dispose();
@@ -678,7 +695,6 @@ namespace Tnb.WarehouseMgr
}
catch(Exception ex)
{
Logger.Information("CTUTaskExecute方法报错"+ex.Message);
}
}
//判断生成bill_code
@@ -689,7 +705,7 @@ namespace Tnb.WarehouseMgr
if (distaskH.task_type == WmsWareHouseConst.WMS_PRETASK_INSTOCK_TYPE_ID)
{
var orgdistaskHs = OriginDistaskH.Where(p => p.status == WmsWareHouseConst.TASK_BILL_STATUS_DZX_ID && p.task_type == WmsWareHouseConst.WMS_PRETASK_INSTOCK_TYPE_ID && p.startpoint_id == distaskH.startpoint_id).ToList();
var newdistaskHs = NewdistaskHs = OriginDistaskH.Where(p => p.status == WmsWareHouseConst.TASK_BILL_STATUS_DZX_ID && p.task_type == WmsWareHouseConst.WMS_PRETASK_INSTOCK_TYPE_ID && p.startpoint_id == distaskH.startpoint_id).ToList();
var newdistaskHs = NewdistaskHs.Where(p => p.status == WmsWareHouseConst.TASK_BILL_STATUS_DZX_ID && p.task_type == WmsWareHouseConst.WMS_PRETASK_INSTOCK_TYPE_ID && p.startpoint_id == distaskH.startpoint_id).ToList();
if ((orgdistaskHs.Count + newdistaskHs.Count) == 0)
{
var groups = _billRullService.GetBillNumber(WmsWareHouseConst.WMS_TASK_EXECUTE_ENCODE).Result;
@@ -723,7 +739,6 @@ namespace Tnb.WarehouseMgr
{
try
{
Logger.Information("CTU任务执行TimerExec");
SqlSugarClient db = _db.CopyNew();
var list = db.Queryable<WmsDistaskH>().InnerJoin<WmsAreaH>((a, b) => a.area_id == b.id)
.Where((a, b) => b.code == "B" && a.status == WmsWareHouseConst.TASK_BILL_STATUS_DZX_ID)
@@ -736,13 +751,14 @@ namespace Tnb.WarehouseMgr
}).ToList();
var date = DateTime.Now;
var time = int.Parse(db.Queryable<BasFactoryConfig>().Where(P => P.key == "getinterval").First().value);
foreach (var item in data)
{
if (date.Subtract(item.time).Minutes >= 10)
if (date.Subtract(item.time).Minutes >= time)
{
var execlist = list.Where(p => p.groups == item.groups).ToList();
await db.Updateable<WmsDistaskH>().SetColumns(it => new WmsDistaskH { status = WmsWareHouseConst.TASK_BILL_STATUS_YXD_ID }).Where(it => execlist.Select(p => p.id).ToList().Contains(it.id)).ExecuteCommandAsync();
await db.Updateable<WmsPretaskH>().SetColumns(it => new WmsPretaskH { status = WmsWareHouseConst.PRETASK_BILL_STATUS_YXF_ID }).Where(it => execlist.Select(x => x.pretask_id).ToList().Contains(it.id)).ExecuteCommandAsync();
await db.Updateable<WmsDistaskH>().SetColumns(it => new WmsDistaskH { status = WmsWareHouseConst.TASK_BILL_STATUS_RUNING_ID }).Where(it => execlist.Select(p => p.id).ToList().Contains(it.id)).ExecuteCommandAsync();
await db.Updateable<WmsPretaskH>().SetColumns(it => new WmsPretaskH { status = WmsWareHouseConst.PRETASK_BILL_STATUS_START_ID }).Where(it => execlist.Select(x => x.pretask_id).ToList().Contains(it.id)).ExecuteCommandAsync();
CancellationTokenSource Ctu = new();
int type = execlist.First().task_type == WmsWareHouseConst.WMS_PRETASK_INSTOCK_TYPE_ID ? 1 : 0;
await CallingCTU(execlist, Ctu.Token, type);
@@ -752,7 +768,6 @@ namespace Tnb.WarehouseMgr
}
catch (Exception ex)
{
Logger.Information("CTU任务执行TimerExec报错" + ex.Message);
}
finally
{
@@ -762,7 +777,6 @@ namespace Tnb.WarehouseMgr
}
private async Task CallingCTU(List<WmsDistaskH> distaskHs, CancellationToken token,int type)
{
Logger.Information("CTU任务执行请求第三方接口");
try
{
AgvRequestConfig requestCfg = App.Configuration.Build<AgvRequestConfig>();
@@ -775,7 +789,6 @@ namespace Tnb.WarehouseMgr
targetName = it.endpoint_code,
containerCode = it.carry_code,
}));
foreach ((string k, object v) in taskChainCodeDic)
{
dynamic reqBody = new ExpandoObject();
@@ -785,14 +798,11 @@ namespace Tnb.WarehouseMgr
reqBody.taskChainPriority = 0;
reqBody.taskList = v;
reqBody.inOut = type;
Logger.Information($"请求参数:{JsonConvert.SerializeObject(reqBody)}");
dynamic respBody = await HttpClientHelper.PostStreamAsync(url, reqBody, token);
Logger.Information($"调用Agv接口响应结果:{respBody}");
}
}
catch (Exception ex)
{
Logger.Information("CTU任务执行请求第三方接口报错"+ex.Message);
}
}
#endregion

View File

@@ -76,8 +76,8 @@ namespace Tnb.WarehouseMgr
//入库取终点
InStockStrategyQuery inStockStrategyInput = new() { warehouse_id = input.data[nameof(InStockStrategyQuery.warehouse_id)].ToString()!, Size = 1 };
//test
BasLocation llll = await _db.Queryable<BasLocation>().FirstAsync(it=>it.location_code == _configuration["TestLocation"]);
List<BasLocation> endLocations = new() { llll }; //await _wareHouseService.InStockStrategy(inStockStrategyInput);
BasLocation llll = await _db.Queryable<BasLocation>().FirstAsync(it => it.location_code == _configuration["TestLocation"]);
List<BasLocation> endLocations = await _wareHouseService.InStockStrategy(inStockStrategyInput);
WmsPointH? sPoint = null;
WmsPointH? ePoint = null;
if (input.data.ContainsKey(nameof(WmsPointH.location_id)))
@@ -106,94 +106,104 @@ namespace Tnb.WarehouseMgr
if (sPoint != null && ePoint != null)
{
Logger.Information($"sPoint.id={sPoint.id},ePoint.id={ePoint.id}");
List<WmsPointH> points = await _wareHouseService.PathAlgorithms(sPoint.id, ePoint.id);
if (points.Count <= 2)
List<WmsPointH> points = new List<WmsPointH>();
//中储仓不算路径
if (input.data[nameof(InStockStrategyQuery.warehouse_id)].ToString() != "2")
{
throw new AppFriendlyException("该路径不存在", 500);
points = await _wareHouseService.PathAlgorithms(sPoint.id, ePoint.id);
if (points.Count <= 2)
{
throw new AppFriendlyException("该路径不存在", 500);
}
}
//根据获取的路径点生成预任务,生成顺序必须预路径算法返回的起终点的顺序一致(预任务顺序)
else
{
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.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_WMSEMPTYINSTOCK_ID,
task_type = WmsWareHouseConst.WMS_PRETASK_INSTOCK_TYPE_ID,
carry_id = input.data[nameof(preTask.carry_id)]?.ToString()!,
carry_code = input.data[nameof(preTask.carry_code)]?.ToString()!,
area_id = sPoint?.area_id!,
area_code = it.Key,
require_id = input.data["ReturnIdentity"].ToString(),
require_code = input.data[nameof(preTask.bill_code)]?.ToString()!,
create_id = _userManager.UserId,
create_time = DateTime.Now,
};
return preTask;
}).ToList();
bool isOk = await _wareHouseService.GenPreTask(preTasks, null!);
if (isOk)
{
GenPreTaskUpInput preTaskUpInput = new()
{
RquireId = input.data["ReturnIdentity"].ToString()!,
CarryId = input.data[nameof(WmsCarryD.carry_id)]?.ToString()!,
CarryStartLocationId = points.FirstOrDefault()!.location_id!,
CarryStartLocationCode = points.FirstOrDefault()!.location_code!,
LocationIds = points.Select(x => x.location_id).ToList()!,
PreTaskRecords = preTasks.Adapt<List<WmsHandleH>>()
};
preTaskUpInput.PreTaskRecords.ForEach(x => x.id = SnowflakeIdHelper.NextId());
WmsHandleH handleH = new()
{
org_id = _userManager.User.OrganizeId,
startlocation_id = input.data[nameof(WmsPointH.location_id)]?.ToString()!,
endlocation_id = endLocations![0].id,
bill_code = input.data[nameof(WmsHandleH.bill_code)]?.ToString()!,
biz_type = input.data[nameof(WmsHandleH.biz_type)]?.ToString()!,
carry_id = input.data[nameof(WmsHandleH.carry_id)]?.ToString()!,
carry_code = input.data[nameof(WmsHandleH.carry_code)]?.ToString()!,
require_id = input.data["ReturnIdentity"].ToString(),
require_code = input.data[nameof(WmsHandleH.bill_code)]?.ToString()!,
create_id = _userManager.UserId,
create_time = DateTime.Now
};
preTaskUpInput.PreTaskRecord = handleH;
//根据空载具入库Id回更单据状态
_ = await _db.Updateable<WmsEmptyInstock>().SetColumns(it => new WmsEmptyInstock { status = WmsWareHouseConst.BILLSTATUS_ON_ID }).Where(it => it.id == preTaskUpInput.RquireId).ExecuteCommandAsync();
await _wareHouseService.GenInStockTaskHandleAfter(preTaskUpInput,
it => new WmsCarryH { is_lock = 1, location_id = preTaskUpInput.CarryStartLocationId, location_code = preTaskUpInput.CarryStartLocationCode },
it => new BasLocation { is_lock = 1 });
}
else
{
throw new AppFriendlyException("预任务生成失败,路径或者设备相关配置错误", 500);
}
points.Add(sPoint);
points.Add(ePoint);
}
//根据获取的路径点生成预任务,生成顺序必须预路径算法返回的起终点的顺序一致(预任务顺序)
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.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_WMSEMPTYINSTOCK_ID,
task_type = WmsWareHouseConst.WMS_PRETASK_INSTOCK_TYPE_ID,
carry_id = input.data[nameof(preTask.carry_id)]?.ToString()!,
carry_code = input.data[nameof(preTask.carry_code)]?.ToString()!,
area_id = sPoint?.area_id!,
area_code = it.Key,
require_id = input.data["ReturnIdentity"].ToString(),
require_code = input.data[nameof(preTask.bill_code)]?.ToString()!,
create_id = _userManager.UserId,
create_time = DateTime.Now,
};
return preTask;
}).ToList();
bool isOk = await _wareHouseService.GenPreTask(preTasks, null!);
if (isOk)
{
GenPreTaskUpInput preTaskUpInput = new()
{
RquireId = input.data["ReturnIdentity"].ToString()!,
CarryId = input.data[nameof(WmsCarryD.carry_id)]?.ToString()!,
CarryStartLocationId = points.FirstOrDefault()!.location_id!,
CarryStartLocationCode = points.FirstOrDefault()!.location_code!,
LocationIds = points.Select(x => x.location_id).ToList()!,
PreTaskRecords = preTasks.Adapt<List<WmsHandleH>>()
};
preTaskUpInput.PreTaskRecords.ForEach(x => x.id = SnowflakeIdHelper.NextId());
WmsHandleH handleH = new()
{
org_id = _userManager.User.OrganizeId,
startlocation_id = input.data[nameof(WmsPointH.location_id)]?.ToString()!,
endlocation_id = endLocations![0].id,
bill_code = input.data[nameof(WmsHandleH.bill_code)]?.ToString()!,
biz_type = input.data[nameof(WmsHandleH.biz_type)]?.ToString()!,
carry_id = input.data[nameof(WmsHandleH.carry_id)]?.ToString()!,
carry_code = input.data[nameof(WmsHandleH.carry_code)]?.ToString()!,
require_id = input.data["ReturnIdentity"].ToString(),
require_code = input.data[nameof(WmsHandleH.bill_code)]?.ToString()!,
create_id = _userManager.UserId,
create_time = DateTime.Now
};
preTaskUpInput.PreTaskRecord = handleH;
//根据空载具入库Id回更单据状态
_ = await _db.Updateable<WmsEmptyInstock>().SetColumns(it => new WmsEmptyInstock { status = WmsWareHouseConst.BILLSTATUS_ON_ID }).Where(it => it.id == preTaskUpInput.RquireId).ExecuteCommandAsync();
await _wareHouseService.GenInStockTaskHandleAfter(preTaskUpInput,
it => new WmsCarryH { is_lock = 1, location_id = preTaskUpInput.CarryStartLocationId, location_code = preTaskUpInput.CarryStartLocationCode },
it => new BasLocation { is_lock = 1 });
}
else
{
throw new AppFriendlyException("预任务生成失败,路径或者设备相关配置错误", 500);
}
}
else
{