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

@@ -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