修改日志保存机制

main
潘建东 7 months ago
parent 6ea71e8b30
commit 9a94fb43b0

@ -1 +1 @@
start "lansheng" cmd /k docker build -f Lansheng\LanShengAPI\Dockerfile -t lansheng:latest .
start "lansheng" cmd /k docker build -f Lansheng\LanShengAPI\Dockerfile -t lansheng:1.0.2 .

@ -5,6 +5,9 @@
"Microsoft.AspNetCore": "Warning"
}
},
"ConnectionStrings": {
"Default": "Data Source=124.71.176.44;database=lsdb;User Id=root;Pwd=root;charset=utf8;pooling=true;"
},
"DotNetty": {
"Use": "Y",
"ThreadPool": 8,

@ -9,6 +9,7 @@ namespace LanShengModel
{
[SugarTable("LS_TcpDataLog_{year}{month}{day}")]
[SplitTable(SplitType.Day)]
[SugarIndex("TcpDataLog_DTU_INDEX",nameof(TcpDataLog.DTU_ID),OrderByType.Asc,nameof(TcpDataLog.CreateDate),OrderByType.Desc)]
public class TcpDataLog
{
@ -40,6 +41,7 @@ namespace LanShengModel
[SugarTable("LS_TcpDataLog_{year}{month}{day}")]
[SplitTable(SplitType.Day)]
[SugarIndex("TcpDataLog_DTU_INDEX", nameof(TcpDataLog.DTU_ID), OrderByType.Asc, nameof(TcpDataLog.CreateDate), OrderByType.Desc)]
public class TcpDataLog<T>
{

@ -47,6 +47,8 @@ namespace LanShengService
Logger.LogDebug("加载设备故障表");
Logger.LogDebug("创建设备服务");
ClearDataLogDo();
}
private readonly IServiceProvider Services;
@ -232,7 +234,15 @@ namespace LanShengService
public async Task ClearDataLogDo()
{
await Db.Deleteable<TcpDataLog>().Where(x => x.CreateDate < DateTime.Now.AddMilliseconds(-ValidClearDataLogDo)).SplitTable(tas => tas.Take(10)).ExecuteCommandAsync();
while (true)
{
var _Deletes = Db.SplitHelper<TcpDataLog>().GetTables().Where(x => x.Date < DateTime.Now.AddDays(-5));
foreach (var _Table in _Deletes)
{
Db.DbMaintenance.DropTable(_Table.TableName);
}
await Task.Delay(1000 * 60 * 6 * 10);
}
}
public async Task Offline(string id = "")
@ -294,7 +304,8 @@ namespace LanShengService
Decimal.TryParse(x.Longitude, out Longitude);
x.Longitude = (Longitude / 1000000).ToString();
if (!string.IsNullOrEmpty(x.WZGPS)) {
if (!string.IsNullOrEmpty(x.WZGPS))
{
x.WZ = await Db.Queryable<DeviceData>().FirstAsync(y => y.Id == x.WZGPS);
}
});
@ -336,181 +347,181 @@ namespace LanShengService
#endregion
#region 自定义故障
int TempTime = 12;
//int TempTime = 12;
//进料门限位保护
if (string.IsNullOrEmpty(deviceData.ErrCode) && string.IsNullOrEmpty(deviceData.ErrMsg))
{
var Data3_B7_Date = CacheService.Get<DateTime>($"Data3_B7_Date:{deviceData.Id}").Result;
if (Data3_B7_Date == default)
{
CacheService.Set<DateTime>($"Data3_B7_Date:{deviceData.Id}", DateTime.Now).Wait();
CacheService.Set<int?>($"Data3_B7:{deviceData.Id}", deviceData.Data3_B7).Wait();
}
else
{
var Data3_B7 = CacheService.Get<int?>($"Data3_B7:{deviceData.Id}").Result;
if (Data3_B7 == deviceData.Data3_B7)
{
TimeSpan span = DateTime.Now - Data3_B7_Date;
if (span.TotalHours > TempTime)
{
deviceData.ErrCode = "LS001";
deviceData.ErrMsg = "进料门限位长时间未动作";
}
}
else
{
CacheService.Set<DateTime>($"Data3_B7_Date:{deviceData.Id}", DateTime.Now).Wait();
CacheService.Set<int?>($"Data3_B7:{deviceData.Id}", deviceData.Data3_B7).Wait();
}
}
}
//if (string.IsNullOrEmpty(deviceData.ErrCode) && string.IsNullOrEmpty(deviceData.ErrMsg))
//{
// var Data3_B7_Date = CacheService.Get<DateTime>($"Data3_B7_Date:{deviceData.Id}").Result;
// if (Data3_B7_Date == default)
// {
// CacheService.Set<DateTime>($"Data3_B7_Date:{deviceData.Id}", DateTime.Now).Wait();
// CacheService.Set<int?>($"Data3_B7:{deviceData.Id}", deviceData.Data3_B7).Wait();
// }
// else
// {
// var Data3_B7 = CacheService.Get<int?>($"Data3_B7:{deviceData.Id}").Result;
// if (Data3_B7 == deviceData.Data3_B7)
// {
// TimeSpan span = DateTime.Now - Data3_B7_Date;
// if (span.TotalHours > TempTime)
// {
// deviceData.ErrCode = "LS001";
// deviceData.ErrMsg = "进料门限位长时间未动作";
// }
// }
// else
// {
// CacheService.Set<DateTime>($"Data3_B7_Date:{deviceData.Id}", DateTime.Now).Wait();
// CacheService.Set<int?>($"Data3_B7:{deviceData.Id}", deviceData.Data3_B7).Wait();
// }
// }
//}
//出料门限位保护
if (string.IsNullOrEmpty(deviceData.ErrCode) && string.IsNullOrEmpty(deviceData.ErrMsg))
{
var Data3_B6_Date = CacheService.Get<DateTime>($"Data3_B6_Date:{deviceData.Id}").Result;
if (Data3_B6_Date == default)
{
CacheService.Set<DateTime>($"Data3_B6_Date:{deviceData.Id}", DateTime.Now).Wait();
CacheService.Set<int?>($"Data3_B6:{deviceData.Id}", deviceData.Data3_B6).Wait();
}
else
{
var Data3_B6 = CacheService.Get<int?>($"Data3_B6:{deviceData.Id}").Result;
if (Data3_B6 == deviceData.Data3_B6)
{
TimeSpan span = DateTime.Now - Data3_B6_Date;
if (span.TotalHours > TempTime)
{
deviceData.ErrCode = "LS002";
deviceData.ErrMsg = "出料门限位长时间未动作";
}
}
else
{
CacheService.Set<DateTime>($"Data3_B6_Date:{deviceData.Id}", DateTime.Now).Wait();
CacheService.Set<int?>($"Data3_B6:{deviceData.Id}", deviceData.Data3_B6).Wait();
}
}
}
//if (string.IsNullOrEmpty(deviceData.ErrCode) && string.IsNullOrEmpty(deviceData.ErrMsg))
//{
// var Data3_B6_Date = CacheService.Get<DateTime>($"Data3_B6_Date:{deviceData.Id}").Result;
// if (Data3_B6_Date == default)
// {
// CacheService.Set<DateTime>($"Data3_B6_Date:{deviceData.Id}", DateTime.Now).Wait();
// CacheService.Set<int?>($"Data3_B6:{deviceData.Id}", deviceData.Data3_B6).Wait();
// }
// else
// {
// var Data3_B6 = CacheService.Get<int?>($"Data3_B6:{deviceData.Id}").Result;
// if (Data3_B6 == deviceData.Data3_B6)
// {
// TimeSpan span = DateTime.Now - Data3_B6_Date;
// if (span.TotalHours > TempTime)
// {
// deviceData.ErrCode = "LS002";
// deviceData.ErrMsg = "出料门限位长时间未动作";
// }
// }
// else
// {
// CacheService.Set<DateTime>($"Data3_B6_Date:{deviceData.Id}", DateTime.Now).Wait();
// CacheService.Set<int?>($"Data3_B6:{deviceData.Id}", deviceData.Data3_B6).Wait();
// }
// }
//}
//进料门上限位保护
if (string.IsNullOrEmpty(deviceData.ErrCode) && string.IsNullOrEmpty(deviceData.ErrMsg))
{
var Data15_B3_Date = CacheService.Get<DateTime>($"Data15_B3_Date:{deviceData.Id}").Result;
if (Data15_B3_Date == default)
{
CacheService.Set<DateTime>($"Data15_B3_Date:{deviceData.Id}", DateTime.Now).Wait();
CacheService.Set<int?>($"Data15_B3:{deviceData.Id}", deviceData.Data15_B3).Wait();
}
else
{
var Data15_B3 = CacheService.Get<int?>($"Data15_B3:{deviceData.Id}").Result;
if (Data15_B3 == deviceData.Data15_B3)
{
TimeSpan span = DateTime.Now - Data15_B3_Date;
if (span.TotalHours > TempTime)
{
deviceData.ErrCode = "LS003";
deviceData.ErrMsg = "进料门上限位长时间未动作";
}
}
else
{
CacheService.Set<DateTime>($"Data15_B3_Date:{deviceData.Id}", DateTime.Now).Wait();
CacheService.Set<int?>($"Data15_B3:{deviceData.Id}", deviceData.Data3_B6).Wait();
}
}
}
//if (string.IsNullOrEmpty(deviceData.ErrCode) && string.IsNullOrEmpty(deviceData.ErrMsg))
//{
// var Data15_B3_Date = CacheService.Get<DateTime>($"Data15_B3_Date:{deviceData.Id}").Result;
// if (Data15_B3_Date == default)
// {
// CacheService.Set<DateTime>($"Data15_B3_Date:{deviceData.Id}", DateTime.Now).Wait();
// CacheService.Set<int?>($"Data15_B3:{deviceData.Id}", deviceData.Data15_B3).Wait();
// }
// else
// {
// var Data15_B3 = CacheService.Get<int?>($"Data15_B3:{deviceData.Id}").Result;
// if (Data15_B3 == deviceData.Data15_B3)
// {
// TimeSpan span = DateTime.Now - Data15_B3_Date;
// if (span.TotalHours > TempTime)
// {
// deviceData.ErrCode = "LS003";
// deviceData.ErrMsg = "进料门上限位长时间未动作";
// }
// }
// else
// {
// CacheService.Set<DateTime>($"Data15_B3_Date:{deviceData.Id}", DateTime.Now).Wait();
// CacheService.Set<int?>($"Data15_B3:{deviceData.Id}", deviceData.Data3_B6).Wait();
// }
// }
//}
//进料门下限位保护
if (string.IsNullOrEmpty(deviceData.ErrCode) && string.IsNullOrEmpty(deviceData.ErrMsg))
{
var Data15_B2_Date = CacheService.Get<DateTime>($"Data15_B2_Date:{deviceData.Id}").Result;
if (Data15_B2_Date == default)
{
CacheService.Set<DateTime>($"Data15_B2_Date:{deviceData.Id}", DateTime.Now).Wait();
CacheService.Set<int?>($"Data15_B2:{deviceData.Id}", deviceData.Data15_B2).Wait();
}
else
{
var Data15_B2 = CacheService.Get<int?>($"Data15_B2:{deviceData.Id}").Result;
if (Data15_B2 == deviceData.Data15_B2)
{
TimeSpan span = DateTime.Now - Data15_B2_Date;
if (span.TotalHours > TempTime)
{
deviceData.ErrCode = "LS004";
deviceData.ErrMsg = "进料门下限位长时间未动作";
}
}
else
{
CacheService.Set<DateTime>($"Data15_B2_Date:{deviceData.Id}", DateTime.Now).Wait();
CacheService.Set<int?>($"Data15_B2:{deviceData.Id}", deviceData.Data15_B2).Wait();
}
}
}
//if (string.IsNullOrEmpty(deviceData.ErrCode) && string.IsNullOrEmpty(deviceData.ErrMsg))
//{
// var Data15_B2_Date = CacheService.Get<DateTime>($"Data15_B2_Date:{deviceData.Id}").Result;
// if (Data15_B2_Date == default)
// {
// CacheService.Set<DateTime>($"Data15_B2_Date:{deviceData.Id}", DateTime.Now).Wait();
// CacheService.Set<int?>($"Data15_B2:{deviceData.Id}", deviceData.Data15_B2).Wait();
// }
// else
// {
// var Data15_B2 = CacheService.Get<int?>($"Data15_B2:{deviceData.Id}").Result;
// if (Data15_B2 == deviceData.Data15_B2)
// {
// TimeSpan span = DateTime.Now - Data15_B2_Date;
// if (span.TotalHours > TempTime)
// {
// deviceData.ErrCode = "LS004";
// deviceData.ErrMsg = "进料门下限位长时间未动作";
// }
// }
// else
// {
// CacheService.Set<DateTime>($"Data15_B2_Date:{deviceData.Id}", DateTime.Now).Wait();
// CacheService.Set<int?>($"Data15_B2:{deviceData.Id}", deviceData.Data15_B2).Wait();
// }
// }
//}
//出料门上限位保护
if (string.IsNullOrEmpty(deviceData.ErrCode) && string.IsNullOrEmpty(deviceData.ErrMsg))
{
var Data15_B1_Date = CacheService.Get<DateTime>($"Data15_B1_Date:{deviceData.Id}").Result;
if (Data15_B1_Date == default)
{
CacheService.Set<DateTime>($"Data15_B1_Date:{deviceData.Id}", DateTime.Now).Wait();
CacheService.Set<int?>($"Data15_B1:{deviceData.Id}", deviceData.Data15_B1).Wait();
}
else
{
var Data15_B1 = CacheService.Get<int?>($"Data15_B1:{deviceData.Id}").Result;
if (Data15_B1 == deviceData.Data15_B1)
{
TimeSpan span = DateTime.Now - Data15_B1_Date;
if (span.TotalHours > TempTime)
{
deviceData.ErrCode = "LS005";
deviceData.ErrMsg = "出料门上限位长时间未动作";
}
}
else
{
CacheService.Set<DateTime>($"Data15_B1_Date:{deviceData.Id}", DateTime.Now).Wait();
CacheService.Set<int?>($"Data15_B1:{deviceData.Id}", deviceData.Data15_B1).Wait();
}
}
}
//if (string.IsNullOrEmpty(deviceData.ErrCode) && string.IsNullOrEmpty(deviceData.ErrMsg))
//{
// var Data15_B1_Date = CacheService.Get<DateTime>($"Data15_B1_Date:{deviceData.Id}").Result;
// if (Data15_B1_Date == default)
// {
// CacheService.Set<DateTime>($"Data15_B1_Date:{deviceData.Id}", DateTime.Now).Wait();
// CacheService.Set<int?>($"Data15_B1:{deviceData.Id}", deviceData.Data15_B1).Wait();
// }
// else
// {
// var Data15_B1 = CacheService.Get<int?>($"Data15_B1:{deviceData.Id}").Result;
// if (Data15_B1 == deviceData.Data15_B1)
// {
// TimeSpan span = DateTime.Now - Data15_B1_Date;
// if (span.TotalHours > TempTime)
// {
// deviceData.ErrCode = "LS005";
// deviceData.ErrMsg = "出料门上限位长时间未动作";
// }
// }
// else
// {
// CacheService.Set<DateTime>($"Data15_B1_Date:{deviceData.Id}", DateTime.Now).Wait();
// CacheService.Set<int?>($"Data15_B1:{deviceData.Id}", deviceData.Data15_B1).Wait();
// }
// }
//}
//出料门下限位保护
if (string.IsNullOrEmpty(deviceData.ErrCode) && string.IsNullOrEmpty(deviceData.ErrMsg))
{
var Data15_B0_Date = CacheService.Get<DateTime>($"Data15_B0_Date:{deviceData.Id}").Result;
if (Data15_B0_Date == default)
{
CacheService.Set<DateTime>($"Data15_B0_Date:{deviceData.Id}", DateTime.Now).Wait();
CacheService.Set<int?>($"Data15_B0:{deviceData.Id}", deviceData.Data15_B0).Wait();
}
else
{
var Data15_B0 = CacheService.Get<int?>($"Data15_B0:{deviceData.Id}").Result;
if (Data15_B0 == deviceData.Data15_B0)
{
TimeSpan span = DateTime.Now - Data15_B0_Date;
if (span.TotalHours > TempTime)
{
deviceData.ErrCode = "LS007";
deviceData.ErrMsg = "出料门下限位长时间未动作";
}
}
else
{
CacheService.Set<DateTime>($"Data15_B0_Date:{deviceData.Id}", DateTime.Now).Wait();
CacheService.Set<int?>($"Data15_B0:{deviceData.Id}", deviceData.Data15_B0).Wait();
}
}
}
//if (string.IsNullOrEmpty(deviceData.ErrCode) && string.IsNullOrEmpty(deviceData.ErrMsg))
//{
// var Data15_B0_Date = CacheService.Get<DateTime>($"Data15_B0_Date:{deviceData.Id}").Result;
// if (Data15_B0_Date == default)
// {
// CacheService.Set<DateTime>($"Data15_B0_Date:{deviceData.Id}", DateTime.Now).Wait();
// CacheService.Set<int?>($"Data15_B0:{deviceData.Id}", deviceData.Data15_B0).Wait();
// }
// else
// {
// var Data15_B0 = CacheService.Get<int?>($"Data15_B0:{deviceData.Id}").Result;
// if (Data15_B0 == deviceData.Data15_B0)
// {
// TimeSpan span = DateTime.Now - Data15_B0_Date;
// if (span.TotalHours > TempTime)
// {
// deviceData.ErrCode = "LS007";
// deviceData.ErrMsg = "出料门下限位长时间未动作";
// }
// }
// else
// {
// CacheService.Set<DateTime>($"Data15_B0_Date:{deviceData.Id}", DateTime.Now).Wait();
// CacheService.Set<int?>($"Data15_B0:{deviceData.Id}", deviceData.Data15_B0).Wait();
// }
// }
//}
//人数摄像头保护
if (string.IsNullOrEmpty(deviceData.ErrCode) && string.IsNullOrEmpty(deviceData.ErrMsg))

Loading…
Cancel
Save