完善日志 bug处理

This commit is contained in:
2024-06-21 15:14:30 +08:00
parent c9ad81052e
commit 0095ebec24
40 changed files with 470 additions and 254 deletions

View File

@@ -90,7 +90,7 @@ namespace Tnb.ProductionMgr
private StackExRedisHelper _redisData;
private readonly IPrdInstockService _prdInstockService;
private readonly ISqlSugarRepository<RedisReadConfig> _repository;
private readonly ISqlSugarClient db_Scantimer;
private ISqlSugarClient db_Scantimer;
private readonly ISqlSugarClient db_CheckGettimer;
private readonly ISqlSugarClient db_SSXcodetimer;
private readonly ISqlSugarClient db_BGWCarrySupplementtimer;
@@ -188,23 +188,23 @@ namespace Tnb.ProductionMgr
{
continue;
}
Logger.LogInformation($@"【定时任务CheckGet】 成功取到{strs[2]}值:{coderesult}");
LoggerSSX.LogInformation($@"【定时任务CheckGet】 成功取到{strs[2]}值:{coderesult}");
//using (var _db = _repository.AsSugarClient().CopyNew())
//{
var DistaskH = db_CheckGettimer.Queryable<WmsDistaskH>().Where(p => p.carry_code == coderesult && p.status == WmsWareHouseConst.TASK_BILL_STATUS_YXD_ID && string.IsNullOrEmpty(p.extras)).First();
if (DistaskH != null)
{
Logger.LogInformation($@"【定时任务CheckGet】 成功找到载具:{coderesult} 对应的任务执行单{DistaskH.bill_code}");
LoggerSSX.LogInformation($@"【定时任务CheckGet】 成功找到载具:{coderesult} 对应的任务执行单{DistaskH.bill_code}");
dynamic reqBody = new ExpandoObject();
reqBody.taskCode = DistaskH.bill_code;
reqBody.slotCode = key;
reqBody.containerCode = coderesult;
CancellationTokenSource Ctu = new();
Logger.LogInformation($"【定时任务CheckGet】 开始发送请求到 http://192.168.11.104:1880/wcs/notify/cargo 载具:{coderesult}");
LoggerSSX.LogInformation($"【定时任务CheckGet】 开始发送请求到 http://192.168.11.104:1880/wcs/notify/cargo 载具:{coderesult}");
dynamic respBody = HttpClientHelper.PostStreamAsync("http://192.168.11.104:1880/wcs/notify/cargo", reqBody, Ctu.Token).Result;
Logger.LogInformation($"【定时任务CheckGet】 接收请求 http://192.168.11.104:1880/wcs/notify/cargo 结果 {respBody} ");
LoggerSSX.LogInformation($"【定时任务CheckGet】 接收请求 http://192.168.11.104:1880/wcs/notify/cargo 结果 {respBody} ");
DistaskH.extras = respBody;
db_CheckGettimer.Updateable(DistaskH).ExecuteCommand();
Ctu.Dispose();
@@ -351,7 +351,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA
if (result)
{
Logger.LogInformation($"【ScanInStock】 八工位 {key} {strs[1]}采集到 {result}");
LoggerBGWCarrySupplement.LogInformation($"【ScanInStock】 八工位 {key} {strs[1]}采集到 {result}");
Dictionary<string, string> dicCommand = new(StringComparer.OrdinalIgnoreCase)
{
@@ -360,23 +360,23 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA
["TagName"] = strs[3],
["Value"] = strs[4],
};
Logger.LogInformation($"【ScanInStock】 八工位 {key} 发送PutDoneEmptyBox指令 {_eleCtlCfg.WriteTagUrl} {JsonConvert.SerializeObject(dicCommand)}");
LoggerBGWCarrySupplement.LogInformation($"【ScanInStock】 八工位 {key} 发送PutDoneEmptyBox指令 {_eleCtlCfg.WriteTagUrl} {JsonConvert.SerializeObject(dicCommand)}");
HttpClientHelper.GetRequestAsync(_eleCtlCfg.WriteTagUrl, dicCommand).Wait();
string coderesult = await GetStringTag(strs[0], strs[2]);
Logger.LogInformation($"【ScanInStock】 八工位 {key} 获取到扫码信息: {coderesult}");
LoggerBGWCarrySupplement.LogInformation($"【ScanInStock】 八工位 {key} 获取到扫码信息: {coderesult}");
//using (var _db = _repository.AsSugarClient().CopyNew())
{
WmsCarryH? carry = db_Scantimer.Queryable<WmsCarryH>().Single(it => it.carry_code == coderesult);
Logger.LogInformation($"【ScanInStock】 八工位 {key} 查找{coderesult}绑定的托盘: {JsonConvert.SerializeObject(carry)}");
LoggerBGWCarrySupplement.LogInformation($"【ScanInStock】 八工位 {key} 查找{coderesult}绑定的托盘: {JsonConvert.SerializeObject(carry)}");
if (carry != null)
{
if (db_Scantimer.Queryable<WmsDistaskH>().Where(p => p.carry_id == carry.id && p.status != WmsWareHouseConst.TASK_BILL_STATUS_COMPLE_ID).Any())
if (db_Scantimer.Queryable<WmsDistaskH>().Where(p => p.carry_id == carry.id && p.status != WmsWareHouseConst.TASK_BILL_STATUS_COMPLE_ID && p.status != WmsWareHouseConst.TASK_BILL_STATUS_CANCEL_ID).Any())
{
Logger.LogInformation($"【ScanInStock】 八工位 {key} 托盘 {carry.carry_code} 对应的执行任务状态(status)不是26126860808229(已完成),此时不能执行入库");
LoggerBGWCarrySupplement.LogInformation($"【ScanInStock】 八工位 {key} 托盘 {carry.carry_code} 找到了执行任务状态(status)不是26126860808229(已完成)或26126863175461(已取消)的历史任务,此时不能执行入库");
continue;
}
@@ -385,7 +385,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA
if (WmsCarryCode != null)
{
Logger.LogInformation($"【ScanInStock】 八工位 {key} 查找到托盘{carry.carry_code}在WmsCarryCode中存在");
LoggerBGWCarrySupplement.LogInformation($"【ScanInStock】 八工位 {key} 查找到托盘{carry.carry_code}在WmsCarryCode中存在");
VisualDevModelDataCrInput input = new VisualDevModelDataCrInput();
input.data = new Dictionary<string, object>();
@@ -404,7 +404,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA
}
else
{
Logger.LogInformation($"【ScanInStock】 八工位 {key} 托盘 {carry.carry_code} 未绑定物料条码!");
LoggerBGWCarrySupplement.LogInformation($"【ScanInStock】 八工位 {key} 托盘 {carry.carry_code} 未绑定物料条码!");
}
}
}
@@ -414,7 +414,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA
catch (Exception ex)
{
Console.WriteLine("【ScanInStock】" + ex.Message);
Logger.LogInformation($"【ScanInStock】 八工位扫到码发送入库请求发生异常:{ex}");
LoggerBGWCarrySupplement.LogInformation($"【ScanInStock】 八工位扫到码发送入库请求发生异常:{ex}");
}
finally
{
@@ -751,7 +751,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA
var DistaskH = db_SSXcodetimer.Queryable<WmsDistaskH>().Where(p => p.carry_code == result && p.status != WmsWareHouseConst.TASK_BILL_STATUS_COMPLE_ID).OrderByDescending(p => p.create_time).First();
if (DistaskH != null)
{
Logger.LogInformation($"【定时任务SSXcode】DistaskH != null putdic.Keys.Contains(DistaskH.startlocation_code):{putdic.Keys.Contains(DistaskH.startlocation_code)} {result}");
LoggerSSX.LogInformation($"【定时任务SSXcode】DistaskH != null putdic.Keys.Contains(DistaskH.startlocation_code):{putdic.Keys.Contains(DistaskH.startlocation_code)} {result}");
Dictionary<string, string> dicCommand2 = new(StringComparer.OrdinalIgnoreCase)
{
@@ -772,7 +772,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA
}
else
{
Logger.LogInformation($"【定时任务SSXcode】DistaskH == null ");
LoggerSSX.LogInformation($"【定时任务SSXcode】DistaskH == null ");
Dictionary<string, string> dicCommand2 = new(StringComparer.OrdinalIgnoreCase)
{
["DevName"] = key,
@@ -796,7 +796,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA
catch (Exception ex)
{
Console.WriteLine("【SSXcode】" + ex.Message);
Logger.LogInformation($"【定时任务SSXcode】发生异常 {ex}");
LoggerSSX.LogInformation($"【定时任务SSXcode】发生异常 {ex}");
}
finally
{
@@ -861,7 +861,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA
if (WmsMaterialTransfers.Count() == 0)
{
LoggerFloor2UpDownMachine.LogWarning($@"【上升降机】未找到条码{barcode}的输送线为9、10的转库单");
LoggerFloor2UpDownMachine.LogWarning($@"【上升降机】未找到条码{barcode}的输送线为9、10的转库单,可能是出入仓库选择有误或者此载具在中储仓发生了错乱");
return;
}
// 转库单
@@ -1050,7 +1050,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA
db_Floor2timer送空托到上升降区.Queryable<BasLocation>()
.InnerJoin<WmsCarryH>((a, b) => a.id == b.location_id)
.LeftJoin<WmsCarryD>((a, b, c) => b.id == c.carry_id)
.Where((a, b, c) => a.wh_id == "33780009364245" && a.is_use == "1" && a.is_lock == 0 && string.IsNullOrEmpty(c.id)
.Where((a, b, c) => a.wh_id == "33780009364245" && a.is_use == "1" && a.is_lock == 0 && a.is_type == "0" && string.IsNullOrEmpty(c.id)
&& b.carrystd_id == WmsWareHouseConst.CARRY_LJSTD_ID).OrderBy(a => a.id).Take(1);
if (rackStartLocations.Count() == 0)
@@ -1174,7 +1174,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA
.InnerJoin<WmsCarryH>((a, b) => a.id == b.location_id)
.LeftJoin<WmsCarryD>((a, b, c) => b.id == c.carry_id) // 有料箱
.LeftJoin<WmsCarryCode>((a, b, c, d) => c.membercarry_id == d.carry_id)
.Where((a, b, c, d) => a.wh_id == "33780009364245" && a.is_use == "1" && a.is_lock == 0 && !string.IsNullOrEmpty(c.id)
.Where((a, b, c, d) => a.wh_id == "33780009364245" && a.is_use == "1" && a.is_lock == 0 && a.is_type == "0" && !string.IsNullOrEmpty(c.id)
&& b.carrystd_id == WmsWareHouseConst.CARRY_LJSTD_ID).OrderBy((a, b, c, d) => d.id).Select((a, b, c, d) => new // 关联载具物料明细表
{
basLocation = a,
@@ -1200,7 +1200,16 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA
if (rackStartLocations.Count() == 0)
{
//LoggerFloor2RackDelivery.LogWarning($"【送满托到下升降区】 暂存仓中没有可用的满料架 {rackStartLocations.ToSqlString()}");
//LoggerFloor2RackDelivery.LogWarning($"【送满托到下升降区】 暂存仓中没有可用的满料架 {db_Floor2timer送满托到下升降区.Queryable<BasLocation>()
//.InnerJoin<WmsCarryH>((a, b) => a.id == b.location_id)
//.LeftJoin<WmsCarryD>((a, b, c) => b.id == c.carry_id) // 有料箱
//.LeftJoin<WmsCarryCode>((a, b, c, d) => c.membercarry_id == d.carry_id)
//.Where((a, b, c, d) => a.wh_id == "33780009364245" && a.is_use == "1" && a.is_lock == 0 && a.is_type == "0" && !string.IsNullOrEmpty(c.id)
//&& b.carrystd_id == WmsWareHouseConst.CARRY_LJSTD_ID).OrderBy((a, b, c, d) => d.id).Select((a, b, c, d) => new // 关联载具物料明细表
//{
// basLocation = a,
// WmsCarryCode_id = d.id
//}).ToSqlString()}");
continue;
}
LoggerFloor2RackDelivery.LogInformation($"【送满托到下升降区】 即将补充料架区{wmsMechanicalArmH.name}");
@@ -1317,7 +1326,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA
// 找到未占用且未锁定的库位
ISugarQueryable<BasLocation> rackEndLocations =
db_Floor2timer移走上升降区未生成预任务且满托的料架.Queryable<BasLocation>()
.Where(r => r.wh_id == "33780009364245" && r.is_use == "0" && r.is_lock == 0).OrderBy(a => a.id).Take(1);
.Where(r => r.wh_id == "33780009364245" && r.is_use == "0" && r.is_lock == 0 && r.is_type == "0").OrderBy(a => a.id).Take(1);
if (rackEndLocations.Count() == 0)
{
@@ -1419,7 +1428,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA
// 找到未占用且未锁定的库位
ISugarQueryable<BasLocation> rackEndLocations =
db_Floor2timer移走下升降区未生成预任务且空托的料架.Queryable<BasLocation>()
.Where(r => r.wh_id == "33780009364245" && r.is_use == "0" && r.is_lock == 0).OrderBy(a => a.id).Take(1);
.Where(r => r.wh_id == "33780009364245" && r.is_use == "0" && r.is_lock == 0 && r.is_type == "0").OrderBy(a => a.id).Take(1);
if (rackEndLocations.Count() == 0)
{
@@ -1673,41 +1682,6 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA
[LogLevel.Error] = "ERR",
};
protected string _LoggerFileName = "";
protected ILogger _Logger;
protected ILogger Logger
{
get
{
string newFileName = $"{AppContext.BaseDirectory}/logs/custom{DateTime.Now:yyyyMMdd}.log";
if (_LoggerFileName != newFileName)
{
ILoggerFactory loggerFactory = LoggerFactory.Create(builder => builder.AddFile(newFileName, cfgOpts =>
{
//cfgOpts.DateFormat = "yyyy-MM-dd HH:mm:ss.fff";
cfgOpts.MessageFormat = (logMsg) =>
{
var logLevel = s_logLevelMap[logMsg.LogLevel];
var sb = new StringBuilder();
_ = sb.Append($"[{logLevel}] ");
_ = sb.Append($"{logMsg.LogName} ");
_ = sb.Append($"{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff} ");
_ = sb.Append($"#{logMsg.EventId.Id} ");
_ = sb.Append(logMsg.Message + " ");
_ = sb.Append(logMsg.Exception?.ToString());
return sb.ToString();
};
}));
_Logger = loggerFactory.CreateLogger(this.GetType());
_LoggerFileName = newFileName;
}
return _Logger;
}
}
protected string _LoggerBGWFileName = "";
protected ILogger _LoggerBGW;
protected ILogger LoggerBGW
@@ -1715,7 +1689,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA
get
{
string newFileName = $"{AppContext.BaseDirectory}/logs/customBGW{DateTime.Now:yyyyMMdd}.log";
if (_LoggerFileName != newFileName)
if (_LoggerBGWFileName != newFileName)
{
ILoggerFactory loggerFactory = LoggerFactory.Create(builder => builder.AddFile(newFileName, cfgOpts =>
{
@@ -1736,7 +1710,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA
}));
_LoggerBGW = loggerFactory.CreateLogger(this.GetType());
_LoggerFileName = newFileName;
_LoggerBGWFileName = newFileName;
}
return _LoggerBGW;
}
@@ -1750,7 +1724,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA
get
{
string newFileName = $"{AppContext.BaseDirectory}/logs/customSSX{DateTime.Now:yyyyMMdd}.log";
if (_LoggerFileName != newFileName)
if (_LoggerSSXFileName != newFileName)
{
ILoggerFactory loggerFactory = LoggerFactory.Create(builder => builder.AddFile(newFileName, cfgOpts =>
{
@@ -1771,7 +1745,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA
}));
_LoggerSSX = loggerFactory.CreateLogger(this.GetType());
_LoggerFileName = newFileName;
_LoggerSSXFileName = newFileName;
}
return _LoggerSSX;
}
@@ -1785,7 +1759,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA
get
{
string newFileName = $"{AppContext.BaseDirectory}/logs/customFloor2UpDownMachine{DateTime.Now:yyyyMMdd}.log";
if (_LoggerFileName != newFileName)
if (_LoggerFloor2UpDownMachineFileName != newFileName)
{
ILoggerFactory loggerFactory = LoggerFactory.Create(builder => builder.AddFile(newFileName, cfgOpts =>
{
@@ -1806,7 +1780,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA
}));
_LoggerFloor2UpDownMachine = loggerFactory.CreateLogger(this.GetType());
_LoggerFileName = newFileName;
_LoggerFloor2UpDownMachineFileName = newFileName;
}
return _LoggerFloor2UpDownMachine;
}
@@ -1820,7 +1794,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA
get
{
string newFileName = $"{AppContext.BaseDirectory}/logs/customFloor2RackDelivery{DateTime.Now:yyyyMMdd}.log";
if (_LoggerFileName != newFileName)
if (_LoggerFloor2RackDeliveryFileName != newFileName)
{
ILoggerFactory loggerFactory = LoggerFactory.Create(builder => builder.AddFile(newFileName, cfgOpts =>
{
@@ -1841,7 +1815,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA
}));
_LoggerFloor2RackDelivery = loggerFactory.CreateLogger(this.GetType());
_LoggerFileName = newFileName;
_LoggerFloor2RackDeliveryFileName = newFileName;
}
return _LoggerFloor2RackDelivery;
}
@@ -1855,7 +1829,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA
get
{
string newFileName = $"{AppContext.BaseDirectory}/logs/customBGWCarrySupplement{DateTime.Now:yyyyMMdd}.log";
if (_LoggerFileName != newFileName)
if (_LoggerBGWCarrySupplementFileName != newFileName)
{
ILoggerFactory loggerFactory = LoggerFactory.Create(builder => builder.AddFile(newFileName, cfgOpts =>
{
@@ -1876,49 +1850,12 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA
}));
_LoggerBGWCarrySupplement = loggerFactory.CreateLogger(this.GetType());
_LoggerFileName = newFileName;
_LoggerBGWCarrySupplementFileName = newFileName;
}
return _LoggerBGWCarrySupplement;
}
}
protected string _LoggerSSX7SupplementtimerFileName = "";
protected ILogger _LoggerSSX7Supplementtimer;
protected ILogger LoggerSSX7Supplementtimer
{
get
{
string newFileName = $"{AppContext.BaseDirectory}/logs/customSSX7Supplementtimer{DateTime.Now:yyyyMMdd}.log";
if (_LoggerFileName != newFileName)
{
ILoggerFactory loggerFactory = LoggerFactory.Create(builder => builder.AddFile(newFileName, cfgOpts =>
{
//cfgOpts.DateFormat = "yyyy-MM-dd HH:mm:ss.fff";
cfgOpts.MessageFormat = (logMsg) =>
{
var logLevel = s_logLevelMap[logMsg.LogLevel];
var sb = new StringBuilder();
_ = sb.Append($"[{logLevel}] ");
_ = sb.Append($"{logMsg.LogName} ");
_ = sb.Append($"{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff} ");
_ = sb.Append($"#{logMsg.EventId.Id} ");
_ = sb.Append(logMsg.Message + " ");
_ = sb.Append(logMsg.Exception?.ToString());
return sb.ToString();
};
}));
_LoggerSSX7Supplementtimer = loggerFactory.CreateLogger(this.GetType());
_LoggerFileName = newFileName;
}
return _LoggerSSX7Supplementtimer;
}
}
protected string _LoggerYCLGLDPJInstockFileName = "";
protected ILogger _LoggerYCLGLDPJInstock;
protected ILogger LoggerYCLGLDPJInstock
@@ -1926,7 +1863,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA
get
{
string newFileName = $"{AppContext.BaseDirectory}/logs/customYCLGLDPJInstock{DateTime.Now:yyyyMMdd}.log";
if (_LoggerFileName != newFileName)
if (_LoggerYCLGLDPJInstockFileName != newFileName)
{
ILoggerFactory loggerFactory = LoggerFactory.Create(builder => builder.AddFile(newFileName, cfgOpts =>
{
@@ -1947,7 +1884,7 @@ where carry_code = '{coderesult}' and status = '{WmsWareHouseConst.TASK_BILL_STA
}));
_LoggerYCLGLDPJInstock = loggerFactory.CreateLogger(this.GetType());
_LoggerFileName = newFileName;
_LoggerYCLGLDPJInstockFileName = newFileName;
}
return _LoggerYCLGLDPJInstock;
}