You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1364 lines
55 KiB
C#
1364 lines
55 KiB
C#
using CommonModel;
|
|
using Dapr.Client;
|
|
using LanShengInterface;
|
|
using LanShengModel;
|
|
using Microsoft.Data.SqlClient;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
using NewLife.Reflection;
|
|
using SqlSugar;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace LanShengService
|
|
{
|
|
public class DeviceService : IDeviceService
|
|
{
|
|
public DeviceService(IServiceProvider services)
|
|
{
|
|
Services = services;
|
|
|
|
Logger = services.GetRequiredService<ILogger<DeviceService>>();
|
|
|
|
Db = services.GetRequiredService<ISqlSugarClient>();
|
|
|
|
Db.CodeFirst.InitTables(typeof(DeviceData));
|
|
|
|
Db.CodeFirst.SplitTables().InitTables(typeof(TcpDataLog<DeviceData>));
|
|
|
|
Db.CodeFirst.SplitTables().InitTables(typeof(DeviceError));
|
|
|
|
Columns1001 = DeviceData1001.GetColumns();
|
|
|
|
Columns1103 = DeviceData1103.GetColumns();
|
|
|
|
Logger.LogDebug("加载数据结构");
|
|
|
|
CacheService = services.GetRequiredService<CacheInterface.ICacheService>();
|
|
|
|
Logger.LogDebug("加载缓存服务");
|
|
|
|
InitDeviceError();
|
|
|
|
Logger.LogDebug("加载设备故障表");
|
|
|
|
Logger.LogDebug("创建设备服务");
|
|
}
|
|
|
|
private readonly IServiceProvider Services;
|
|
|
|
private readonly ILogger Logger;
|
|
|
|
private readonly ISqlSugarClient Db;
|
|
|
|
private readonly CacheInterface.ICacheService CacheService;
|
|
|
|
private readonly int TicketInsertDataDo = 1000;
|
|
|
|
private readonly int TicketInsertDataLogDo = 5000;
|
|
|
|
private readonly int TicketClearDataLogDo = 1000 * 60 * 60 * 24;
|
|
|
|
private readonly int ValidClearDataLogDo = 1000 * 60 * 60 * 24 * 3;
|
|
|
|
private readonly string[] Columns1001;
|
|
|
|
private readonly string[] Columns1103;
|
|
|
|
public async Task InsertData(DeviceData deviceData)
|
|
{
|
|
Logger.LogDebug($"设备数据插入队列{JsonSerializer.Serialize(deviceData)}");
|
|
|
|
await SetError(deviceData);
|
|
|
|
await SetRunCount(deviceData);
|
|
|
|
await CacheService.Set($"DeviceData:{deviceData.Id}.{Guid.NewGuid().ToString()}", deviceData, 5);
|
|
|
|
await CacheService.Set($"CacheData:{deviceData.Id}", deviceData, 5);
|
|
}
|
|
|
|
public async Task TimerInsertDataDo()
|
|
{
|
|
Logger.LogDebug($"启动设备数据定时任务");
|
|
|
|
await Task.Factory.StartNew(async () =>
|
|
{
|
|
while (true)
|
|
{
|
|
try
|
|
{
|
|
await InsertDataDo();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.LogError(ex.ToString());
|
|
}
|
|
finally
|
|
{
|
|
Thread.Sleep(TicketInsertDataDo);
|
|
}
|
|
}
|
|
}, TaskCreationOptions.LongRunning);
|
|
}
|
|
|
|
public async Task InsertDataDo()
|
|
{
|
|
var Devices = await CacheService.Query<DeviceData>("DeviceData:");
|
|
await CacheService.BatchDelete(Devices.Keys.ToArray());
|
|
Logger.LogDebug($"执行设备数据队列插入{JsonSerializer.Serialize(Devices)}");
|
|
if (Devices.Count > 0)
|
|
{
|
|
var DeviceValues = Devices.Values.GroupBy(x => x == null ? null : x.Id).Select(x => x.First());
|
|
|
|
var Values1001 = DeviceValues.Where(x => x != null && (x.MsgType == "1001" || x.MsgType == "9104")).ToList();
|
|
|
|
if (Values1001.Count > 0)
|
|
{
|
|
var temp = Db.Storageable(Values1001).ToStorage();
|
|
|
|
await temp.AsInsertable.ExecuteCommandAsync();
|
|
|
|
await temp.AsUpdateable
|
|
.UpdateColumns(Columns1001)
|
|
.ExecuteCommandAsync();
|
|
}
|
|
|
|
var Values1103 = DeviceValues.Where(x => x != null && x.MsgType == "1103").ToList();
|
|
|
|
if (Values1103.Count > 0)
|
|
{
|
|
var temp = Db.Storageable(Values1103).ToStorage();
|
|
|
|
await temp.AsInsertable.ExecuteCommandAsync();
|
|
|
|
await temp.AsUpdateable
|
|
.UpdateColumns(Columns1103)
|
|
.ExecuteCommandAsync();
|
|
}
|
|
}
|
|
}
|
|
|
|
public async Task InsertDataLog(TcpDataLog<DeviceData> dataLog)
|
|
{
|
|
Logger.LogDebug($"日志插入队列{JsonSerializer.Serialize(dataLog)}");
|
|
|
|
await CacheService.Set($"TcpDataLog:{dataLog.DTU_ID}.{Guid.NewGuid().ToString()}", dataLog, 30);
|
|
}
|
|
|
|
public async Task TimerInsertDataLogDo()
|
|
{
|
|
Logger.LogDebug($"启动设备日志定时任务");
|
|
await Task.Factory.StartNew(async () =>
|
|
{
|
|
while (true)
|
|
{
|
|
try
|
|
{
|
|
await InsertDataLogDo();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.LogError(ex.ToString());
|
|
}
|
|
finally
|
|
{
|
|
Thread.Sleep(TicketInsertDataLogDo);
|
|
}
|
|
}
|
|
}, TaskCreationOptions.LongRunning);
|
|
}
|
|
|
|
public async Task TimerClearDataLogDo()
|
|
{
|
|
Logger.LogDebug($"启动设备日志定时清理任务");
|
|
await Task.Factory.StartNew(async () =>
|
|
{
|
|
while (true)
|
|
{
|
|
try
|
|
{
|
|
await ClearDataLogDo();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.LogError(ex.ToString());
|
|
}
|
|
finally
|
|
{
|
|
Thread.Sleep(TicketClearDataLogDo);
|
|
}
|
|
}
|
|
}, TaskCreationOptions.LongRunning);
|
|
}
|
|
|
|
public async Task InsertDataLogDo()
|
|
{
|
|
var Logs = await CacheService.Query<TcpDataLog<DeviceData>>("TcpDataLog:");
|
|
await CacheService.BatchDelete(Logs.Keys.ToArray());
|
|
Logger.LogDebug($"执行日志队列插入{JsonSerializer.Serialize(Logs)}");
|
|
if (Logs.Count > 0)
|
|
{
|
|
await Db.Insertable(Logs.Values.ToList()).SplitTable().ExecuteCommandAsync();
|
|
}
|
|
}
|
|
|
|
public async Task ClearDataLogDo()
|
|
{
|
|
await Db.Deleteable<TcpDataLog>().Where(x => x.CreateDate < DateTime.Now.AddMilliseconds(-ValidClearDataLogDo)).SplitTable(tas => tas.Take(10)).ExecuteCommandAsync();
|
|
}
|
|
|
|
public async Task Offline(string id = "")
|
|
{
|
|
Logger.LogDebug($"设备离线{id}");
|
|
if (string.IsNullOrEmpty(id))
|
|
{
|
|
await Db.Updateable<DeviceData>().SetColumns(x => x.Status == "offline").SetColumns(x => x.ErrCode == "").SetColumns(x => x.ErrMsg == "").SetColumns(x => x.OfflineDate == DateTime.Now).Where(x => 1 == 1).ExecuteCommandAsync();
|
|
}
|
|
else
|
|
{
|
|
await Db.Updateable<DeviceData>().SetColumns(x => x.Status == "offline").SetColumns(x => x.ErrCode == "").SetColumns(x => x.ErrMsg == "").SetColumns(x => x.OfflineDate == DateTime.Now).Where(x => x.Id == id).ExecuteCommandAsync();
|
|
}
|
|
}
|
|
|
|
public async Task ResetRunCount(string id = "")
|
|
{
|
|
Logger.LogDebug($"重置运行次数{id}");
|
|
if (!string.IsNullOrEmpty(id))
|
|
{
|
|
await Db.Updateable<DeviceData>().SetColumns(x => x.RunCount == 0).Where(x => x.Id == id).ExecuteCommandAsync();
|
|
|
|
await CacheService.Set<int>($"{id}_RunCount", 0);
|
|
}
|
|
}
|
|
|
|
public async Task<DeviceData> GetDeviceData(string id)
|
|
{
|
|
var Result = await GetDeviceData(new string[] { id });
|
|
if (Result.Count > 0)
|
|
{
|
|
return Result[0];
|
|
}
|
|
else
|
|
{
|
|
throw new BadRequestException("设备编号不存在");
|
|
}
|
|
}
|
|
|
|
public async Task<List<DeviceData>> GetDeviceData(string[] ids)
|
|
{
|
|
var Result = new List<DeviceData>();
|
|
|
|
var CacheIds = new List<string>();
|
|
ids.ToList().ForEach((x) =>
|
|
{
|
|
CacheIds.Add($"CacheData:{x}");
|
|
});
|
|
var CacheResult = await CacheService.BatchGet<DeviceData>(CacheIds);
|
|
|
|
Result.AddRange(CacheResult.Where(x => x.Value != null).Select(x => x.Value));
|
|
|
|
var NotCacheIds = CacheResult.Where(x => x.Value == null).Select(x => x.Key.Remove(0, 10)).ToList();
|
|
|
|
if (NotCacheIds.Count() > 0)
|
|
{
|
|
var DbResult = await Db.Queryable<DeviceData>().In("Id", NotCacheIds)
|
|
.IgnoreColumns(x => new
|
|
{
|
|
x.Data25_B4,
|
|
x.Data25_B0,
|
|
x.Data26_B4,
|
|
x.Data26_B0
|
|
})
|
|
.ToListAsync();
|
|
|
|
Result.AddRange(DbResult.ToList());
|
|
|
|
var DbCache = new Dictionary<string, DeviceData>();
|
|
|
|
foreach (var Item in DbResult)
|
|
{
|
|
DbCache.Add($"CacheData:{Item.Id}", Item);
|
|
}
|
|
|
|
await CacheService.BatchSet<DeviceData>(DbCache, 60);
|
|
}
|
|
Result = JsonSerializer.Deserialize<List<DeviceData>>(JsonSerializer.Serialize(Result))!;
|
|
Result.ForEach(x =>
|
|
{
|
|
x.Data6 = x.Data6 / 10;
|
|
decimal Latitude = 0;
|
|
Decimal.TryParse(x.Latitude, out Latitude);
|
|
x.Latitude = (Latitude / 1000000).ToString();
|
|
decimal Longitude = 0;
|
|
Decimal.TryParse(x.Longitude, out Longitude);
|
|
x.Longitude = (Longitude / 1000000).ToString();
|
|
});
|
|
|
|
return Result;
|
|
}
|
|
|
|
private Task SetError(DeviceData deviceData)
|
|
{
|
|
deviceData.ErrCode = "";
|
|
deviceData.ErrMsg = "";
|
|
|
|
#region 一体机驱动故障
|
|
if (string.IsNullOrEmpty(deviceData.ErrCode) && string.IsNullOrEmpty(deviceData.ErrMsg))
|
|
{
|
|
SetData4Error(deviceData);
|
|
}
|
|
#endregion
|
|
|
|
#region 一体机逻辑故障
|
|
if (string.IsNullOrEmpty(deviceData.ErrCode) && string.IsNullOrEmpty(deviceData.ErrMsg))
|
|
{
|
|
SetData5Error(deviceData);
|
|
}
|
|
#endregion
|
|
|
|
#region 门机故障
|
|
if (string.IsNullOrEmpty(deviceData.ErrCode) && string.IsNullOrEmpty(deviceData.ErrMsg))
|
|
{
|
|
SetData17Error(deviceData);
|
|
}
|
|
#endregion
|
|
|
|
#region 语音码故障
|
|
if (string.IsNullOrEmpty(deviceData.ErrCode) && string.IsNullOrEmpty(deviceData.ErrMsg))
|
|
{
|
|
SeteData22Error(deviceData);
|
|
}
|
|
#endregion
|
|
|
|
#region 自定义故障
|
|
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_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_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_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))
|
|
{
|
|
if (deviceData.Data16_B4 == 0)
|
|
{
|
|
deviceData.ErrCode = "LS008";
|
|
deviceData.ErrMsg = "人数摄像头通讯异常";
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 故障记录
|
|
DeviceError tempErr = CacheService.Get<DeviceError>($"DeviceError:{deviceData.Id}").Result;
|
|
if (!string.IsNullOrEmpty(deviceData.ErrCode))
|
|
{
|
|
if (tempErr == null || (tempErr != null && tempErr.ErrCode != deviceData.ErrCode))
|
|
{
|
|
if (tempErr != null)
|
|
{
|
|
tempErr.EndDate = DateTime.Now;
|
|
Db.Updateable<DeviceError>(tempErr).UpdateColumns(x => x.EndDate).SplitTable().ExecuteCommand();
|
|
}
|
|
tempErr = new DeviceError()
|
|
{
|
|
Id = Guid.NewGuid().ToString(),
|
|
ErrCode = deviceData.ErrCode,
|
|
ErrMsg = deviceData.ErrMsg,
|
|
DeviceId = deviceData.Id,
|
|
CreateDate = DateTime.Now
|
|
};
|
|
Db.Insertable<DeviceError>(tempErr).SplitTable().ExecuteCommand();
|
|
|
|
CacheService.Set<DeviceError>($"DeviceError:{deviceData.Id}", tempErr);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (tempErr != null)
|
|
{
|
|
tempErr.EndDate = DateTime.Now;
|
|
Db.Updateable<DeviceError>(tempErr).UpdateColumns(x => x.EndDate).SplitTable().ExecuteCommand();
|
|
CacheService.Delete($"DeviceError:{deviceData.Id}");
|
|
}
|
|
}
|
|
#endregion
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
private void InitDeviceError()
|
|
{
|
|
Db.Updateable<DeviceData>().SetColumns(x => x.ErrCode == "").SetColumns(x => x.ErrMsg == "").Where(x => 1 == 1).ExecuteCommand();
|
|
Db.Updateable<DeviceError>().SetColumns(x => x.EndDate == DateTime.Now).Where(x => x.EndDate == null).SplitTable(tas => tas.Take(2)).ExecuteCommand();
|
|
}
|
|
|
|
public async Task<PageData<DeviceError>> GetDeviceErrorPage(PageYearSearch<DeviceError> search)
|
|
{
|
|
RefAsync<int> _Total = 0;
|
|
var Data = await Db.Queryable<DeviceError>()
|
|
.WhereIF(!string.IsNullOrEmpty(search.Search), x => x.Id!.Contains(search.Search!) || x.DeviceId!.Contains(search.Search!) || x.ErrCode!.Contains(search.Search!) || x.ErrMsg!.Contains(search.Search!))
|
|
.WhereIF(search.Mode != null && !string.IsNullOrEmpty(search.Mode.Id), x => x.Id == search.Mode!.Id)
|
|
.WhereIF(search.Mode != null && !string.IsNullOrEmpty(search.Mode.DeviceId), x => x.DeviceId == search.Mode!.DeviceId)
|
|
.WhereIF(search.Mode != null && !string.IsNullOrEmpty(search.Mode.ErrCode), x => x.ErrCode == search.Mode!.ErrCode)
|
|
.WhereIF(search.Mode != null && !string.IsNullOrEmpty(search.Mode.ErrMsg), x => x.ErrMsg!.Contains(search.Mode!.ErrMsg!))
|
|
.SplitTable((DateTime)search.StartDate!, (DateTime)search.EndDate!)
|
|
.OrderByDescending(x => x.CreateDate)
|
|
.ToPageListAsync(search.Index, search.Size, _Total);
|
|
return new PageData<DeviceError> { Total = _Total.Value, Data = Data };
|
|
}
|
|
|
|
private void SeteData22Error(DeviceData deviceData)
|
|
{
|
|
#region 创安处理逻辑
|
|
if (deviceData.Id!.IndexOf("CASSH") >= 0)
|
|
{
|
|
//修复默认值传1的问题
|
|
if (deviceData.Data22 == 1)
|
|
{
|
|
deviceData.Data22 = 0;
|
|
}
|
|
|
|
if (deviceData.Data3_B5 == 0)
|
|
{
|
|
deviceData.Data22 = 1;
|
|
}
|
|
if (deviceData.Data15_B0 == 0 && deviceData.Data3_B6 == 0)
|
|
{
|
|
deviceData.Data22 = 2;
|
|
}
|
|
if (deviceData.Data15_B2 == 0 && deviceData.Data3_B7 == 0)
|
|
{
|
|
deviceData.Data22 = 3;
|
|
}
|
|
if (deviceData.Data3_B4 == 0)
|
|
{
|
|
deviceData.Data22 = 4;
|
|
}
|
|
//if (deviceData.Data3_B3 == 0)
|
|
//{
|
|
// deviceData.Data22 = 5;
|
|
//}
|
|
if (deviceData.Data2_B3 == 0)
|
|
{
|
|
deviceData.Data22 = 6;
|
|
}
|
|
if (deviceData.Data2_B2 == 0)
|
|
{
|
|
deviceData.Data22 = 7;
|
|
}
|
|
if (deviceData.Data2_B1 == 0)
|
|
{
|
|
deviceData.Data22 = 8;
|
|
}
|
|
if (deviceData.Data27_B7 == 1)
|
|
{
|
|
deviceData.Data22 = 9;
|
|
}
|
|
if (deviceData.Data27_B6 == 1)
|
|
{
|
|
deviceData.Data22 = 10;
|
|
}
|
|
if (deviceData.Data2_B5 == 0)
|
|
{
|
|
deviceData.Data22 = 11;
|
|
}
|
|
if (deviceData.Data2_B4 == 0)
|
|
{
|
|
deviceData.Data22 = 12;
|
|
}
|
|
if (deviceData.Data2_B6 == 0)
|
|
{
|
|
deviceData.Data22 = 13;
|
|
}
|
|
if (deviceData.Data16_B1 == 0)
|
|
{
|
|
var ticks = CacheService.Get<long>($"{deviceData.Id}_Data16_B1").Result;
|
|
if (ticks != 0)
|
|
{
|
|
var time = new TimeSpan(DateTime.Now.Ticks).Subtract(new TimeSpan(ticks));
|
|
if (time.TotalSeconds > 10 && time.TotalMinutes <= 5)
|
|
{
|
|
deviceData.Data22 = 101;
|
|
}
|
|
else if (time.TotalMinutes > 5)
|
|
{
|
|
deviceData.Data22 = 102;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
CacheService.Set<long>($"{deviceData.Id}_Data16_B1", DateTime.Now.Ticks);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
CacheService.Delete($"{deviceData.Id}_Data16_B1");
|
|
}
|
|
if (deviceData.Data16_B0 == 0)
|
|
{
|
|
var ticks = CacheService.Get<long>($"{deviceData.Id}_Data16_B0").Result;
|
|
if (ticks != 0)
|
|
{
|
|
var time = new TimeSpan(DateTime.Now.Ticks).Subtract(new TimeSpan(ticks));
|
|
if (time.TotalSeconds > 10 && time.TotalMinutes <= 5)
|
|
{
|
|
deviceData.Data22 = 103;
|
|
}
|
|
else if (time.TotalMinutes > 5)
|
|
{
|
|
deviceData.Data22 = 104;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
CacheService.Set<long>($"{deviceData.Id}_Data16_B0", DateTime.Now.Ticks);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
CacheService.Delete($"{deviceData.Id}_Data16_B0");
|
|
}
|
|
if (deviceData.Data15_B3 == 0 && deviceData.Data15_B2 == 0)
|
|
{
|
|
deviceData.Data22 = 37;
|
|
}
|
|
if (deviceData.Data15_B1 == 0 && deviceData.Data15_B0 == 0)
|
|
{
|
|
deviceData.Data22 = 38;
|
|
}
|
|
}
|
|
if (deviceData.Data23 == 0)
|
|
{
|
|
deviceData.Data22 = 100;
|
|
}
|
|
#endregion
|
|
if (deviceData.Data22 != null && deviceData.Data22 > 0)
|
|
{
|
|
switch (deviceData.Data22)
|
|
{
|
|
case 1:
|
|
deviceData.ErrCode = "YY001";
|
|
deviceData.ErrMsg = "天窗门未关好";
|
|
break;
|
|
case 2:
|
|
deviceData.ErrCode = "YY002";
|
|
deviceData.ErrMsg = "双开门未关好";
|
|
break;
|
|
case 3:
|
|
deviceData.ErrCode = "YY003";
|
|
deviceData.ErrMsg = "单开门未关好";
|
|
break;
|
|
case 4:
|
|
deviceData.ErrCode = "YY004";
|
|
deviceData.ErrMsg = "上限位已断开";
|
|
break;
|
|
case 5:
|
|
deviceData.ErrCode = "YY005";
|
|
deviceData.ErrMsg = "下限位已断开";
|
|
break;
|
|
case 6:
|
|
deviceData.ErrCode = "YY006";
|
|
deviceData.ErrMsg = "请注意防坠器限位已断开";
|
|
break;
|
|
case 7:
|
|
deviceData.ErrCode = "YY007";
|
|
deviceData.ErrMsg = "请注意防冲顶限位已断开";
|
|
break;
|
|
case 8:
|
|
deviceData.ErrCode = "YY008";
|
|
deviceData.ErrMsg = "请注意备用限位已断开";
|
|
break;
|
|
case 9:
|
|
deviceData.ErrCode = "YY009";
|
|
deviceData.ErrMsg = "电梯控制远程限速";
|
|
break;
|
|
case 10:
|
|
deviceData.ErrCode = "YY010";
|
|
deviceData.ErrMsg = "电梯控制远程锁机";
|
|
break;
|
|
case 11:
|
|
deviceData.ErrCode = "YY011";
|
|
deviceData.ErrMsg = "急停按钮已被按下";
|
|
break;
|
|
case 12:
|
|
deviceData.ErrCode = "YY012";
|
|
deviceData.ErrMsg = "笼顶急停按钮已被按下";
|
|
break;
|
|
case 13:
|
|
deviceData.ErrCode = "YY013";
|
|
deviceData.ErrMsg = "电锁或者IC卡未插好";
|
|
break;
|
|
case 14:
|
|
deviceData.ErrCode = "YY014";
|
|
deviceData.ErrMsg = "请注意编码器脉冲值异常";
|
|
break;
|
|
case 15:
|
|
deviceData.ErrCode = "YY015";
|
|
deviceData.ErrMsg = "请注意电梯发生逆变单元保护故障";
|
|
break;
|
|
case 16:
|
|
deviceData.ErrCode = "YY016";
|
|
deviceData.ErrMsg = "请注意电梯发生过流故障";
|
|
break;
|
|
case 17:
|
|
deviceData.ErrCode = "YY017";
|
|
deviceData.ErrMsg = "请注意电梯发生过压故障";
|
|
break;
|
|
case 18:
|
|
deviceData.ErrCode = "YY018";
|
|
deviceData.ErrMsg = "请注意电梯发生欠压故障";
|
|
break;
|
|
case 19:
|
|
deviceData.ErrCode = "YY019";
|
|
deviceData.ErrMsg = "请注意电梯发生驱动器过载故障";
|
|
break;
|
|
case 20:
|
|
deviceData.ErrCode = "YY020";
|
|
deviceData.ErrMsg = "请注意电梯发生模块过热故障";
|
|
break;
|
|
case 21:
|
|
deviceData.ErrCode = "YY021";
|
|
deviceData.ErrMsg = "请注意电梯发生对地短路故障";
|
|
break;
|
|
case 22:
|
|
deviceData.ErrCode = "YY022";
|
|
deviceData.ErrMsg = "请注意电梯发生输入缺相故障";
|
|
break;
|
|
case 23:
|
|
deviceData.ErrCode = "YY023";
|
|
deviceData.ErrMsg = "请注意电梯发生输出缺相故障";
|
|
break;
|
|
case 24:
|
|
deviceData.ErrCode = "YY024";
|
|
deviceData.ErrMsg = "请注意电梯自检异常";
|
|
break;
|
|
case 25:
|
|
deviceData.ErrCode = "YY025";
|
|
deviceData.ErrMsg = "请注意电梯已超载";
|
|
break;
|
|
case 26:
|
|
deviceData.ErrCode = "YY026";
|
|
deviceData.ErrMsg = "请注意编码器故障";
|
|
break;
|
|
case 27:
|
|
deviceData.ErrCode = "YY027";
|
|
deviceData.ErrMsg = "请注意刹车电流过大";
|
|
break;
|
|
case 28:
|
|
deviceData.ErrCode = "YY028";
|
|
deviceData.ErrMsg = "请注意刹车信号故障";
|
|
break;
|
|
case 29:
|
|
deviceData.ErrCode = "YY029";
|
|
deviceData.ErrMsg = "请注意刹车电流较小";
|
|
break;
|
|
case 30:
|
|
deviceData.ErrCode = "YY030";
|
|
deviceData.ErrMsg = "请注意刹车片磨损严重";
|
|
break;
|
|
case 31:
|
|
deviceData.ErrCode = "YY031";
|
|
deviceData.ErrMsg = "请注意电梯超速";
|
|
break;
|
|
case 32:
|
|
deviceData.ErrCode = "YY032";
|
|
deviceData.ErrMsg = "进料门有异物卡住";
|
|
break;
|
|
case 33:
|
|
deviceData.ErrCode = "YY033";
|
|
deviceData.ErrMsg = "出料门有异物卡住";
|
|
break;
|
|
case 34:
|
|
deviceData.ErrCode = "YY034";
|
|
deviceData.ErrMsg = "门机发生故障";
|
|
break;
|
|
case 35:
|
|
deviceData.ErrCode = "YY035";
|
|
deviceData.ErrMsg = "人数超载请自觉退出";
|
|
break;
|
|
case 36:
|
|
deviceData.ErrCode = "WR036";
|
|
deviceData.ErrMsg = "请勿遮挡光幕";
|
|
break;
|
|
case 37:
|
|
deviceData.ErrCode = "YY037";
|
|
deviceData.ErrMsg = "进料门上下限位异常";
|
|
break;
|
|
case 38:
|
|
deviceData.ErrCode = "YY038";
|
|
deviceData.ErrMsg = "出料门上下限位异常";
|
|
break;
|
|
case 39:
|
|
deviceData.ErrCode = "YY039";
|
|
deviceData.ErrMsg = "请勿遮挡光幕";
|
|
break;
|
|
case 40:
|
|
deviceData.ErrCode = "YY040";
|
|
deviceData.ErrMsg = "上行通道限位断开";
|
|
break;
|
|
case 41:
|
|
deviceData.ErrCode = "YY041";
|
|
deviceData.ErrMsg = "下行通道限位断开";
|
|
break;
|
|
case 100:
|
|
deviceData.ErrCode = "YY100";
|
|
deviceData.ErrMsg = "请打开自动平层开关";
|
|
break;
|
|
case 101:
|
|
deviceData.ErrCode = "WR101";
|
|
deviceData.ErrMsg = "请勿遮挡进料门光幕";
|
|
break;
|
|
case 102:
|
|
deviceData.ErrCode = "YY102";
|
|
deviceData.ErrMsg = "请勿遮挡进料门光幕";
|
|
break;
|
|
case 103:
|
|
deviceData.ErrCode = "WR103";
|
|
deviceData.ErrMsg = "请勿遮挡出料门光幕";
|
|
break;
|
|
case 104:
|
|
deviceData.ErrCode = "YY104";
|
|
deviceData.ErrMsg = "请勿遮挡出料门光幕";
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void SetData17Error(DeviceData deviceData)
|
|
{
|
|
switch (deviceData.Data17)
|
|
{
|
|
case 2:
|
|
deviceData.ErrCode = "门机故障";
|
|
deviceData.ErrMsg = "加速过电流";
|
|
break;
|
|
case 3:
|
|
deviceData.ErrCode = "门机故障";
|
|
deviceData.ErrMsg = "减速过电流";
|
|
break;
|
|
case 4:
|
|
deviceData.ErrCode = "门机故障";
|
|
deviceData.ErrMsg = "恒速过电流";
|
|
break;
|
|
case 5:
|
|
deviceData.ErrCode = "门机故障";
|
|
deviceData.ErrMsg = "加速过电压";
|
|
break;
|
|
case 6:
|
|
deviceData.ErrCode = "门机故障";
|
|
deviceData.ErrMsg = "减速过电压";
|
|
break;
|
|
case 7:
|
|
deviceData.ErrCode = "门机故障";
|
|
deviceData.ErrMsg = "恒速过电压";
|
|
break;
|
|
case 8:
|
|
deviceData.ErrCode = "门机故障";
|
|
deviceData.ErrMsg = "控制电源异常";
|
|
break;
|
|
case 9:
|
|
deviceData.ErrCode = "门机故障";
|
|
deviceData.ErrMsg = "欠电压";
|
|
break;
|
|
case 10:
|
|
deviceData.ErrCode = "门机故障";
|
|
deviceData.ErrMsg = "变频器过载";
|
|
break;
|
|
case 11:
|
|
deviceData.ErrCode = "门机故障";
|
|
deviceData.ErrMsg = "电机过载";
|
|
break;
|
|
case 12:
|
|
deviceData.ErrCode = "门机故障";
|
|
deviceData.ErrMsg = "输入缺相";
|
|
break;
|
|
case 13:
|
|
deviceData.ErrCode = "门机故障";
|
|
deviceData.ErrMsg = "输出缺相";
|
|
break;
|
|
case 14:
|
|
deviceData.ErrCode = "门机故障";
|
|
deviceData.ErrMsg = "模块过热";
|
|
break;
|
|
case 15:
|
|
deviceData.ErrCode = "门机故障";
|
|
deviceData.ErrMsg = "外部故障";
|
|
break;
|
|
case 16:
|
|
deviceData.ErrCode = "门机故障";
|
|
deviceData.ErrMsg = "通讯异常";
|
|
break;
|
|
case 17:
|
|
deviceData.ErrCode = "门机故障";
|
|
deviceData.ErrMsg = "接触器异常";
|
|
break;
|
|
case 18:
|
|
deviceData.ErrCode = "门机故障";
|
|
deviceData.ErrMsg = "电流检测异常";
|
|
break;
|
|
case 19:
|
|
deviceData.ErrCode = "门机故障";
|
|
deviceData.ErrMsg = "电机调谐异常";
|
|
break;
|
|
case 20:
|
|
deviceData.ErrCode = "门机故障";
|
|
deviceData.ErrMsg = "编码器/PG卡异常";
|
|
break;
|
|
case 21:
|
|
deviceData.ErrCode = "门机故障";
|
|
deviceData.ErrMsg = "EPPROM读写异常";
|
|
break;
|
|
case 22:
|
|
deviceData.ErrCode = "门机故障";
|
|
deviceData.ErrMsg = "变频器硬件故障";
|
|
break;
|
|
case 23:
|
|
deviceData.ErrCode = "门机故障";
|
|
deviceData.ErrMsg = "电机对地短路";
|
|
break;
|
|
case 26:
|
|
deviceData.ErrCode = "门机故障";
|
|
deviceData.ErrMsg = "累计运行时间到达";
|
|
break;
|
|
case 29:
|
|
deviceData.ErrCode = "门机故障";
|
|
deviceData.ErrMsg = "累计上电时间到达";
|
|
break;
|
|
case 30:
|
|
deviceData.ErrCode = "门机故障";
|
|
deviceData.ErrMsg = "掉载";
|
|
break;
|
|
case 31:
|
|
deviceData.ErrCode = "门机故障";
|
|
deviceData.ErrMsg = "运行时PID反馈丢失";
|
|
break;
|
|
case 40:
|
|
deviceData.ErrCode = "门机故障";
|
|
deviceData.ErrMsg = "CBC限流保护";
|
|
break;
|
|
case 42:
|
|
deviceData.ErrCode = "门机故障";
|
|
deviceData.ErrMsg = "速度偏差过大";
|
|
break;
|
|
case 43:
|
|
deviceData.ErrCode = "门机故障";
|
|
deviceData.ErrMsg = "过速度";
|
|
break;
|
|
case 45:
|
|
deviceData.ErrCode = "门机故障";
|
|
deviceData.ErrMsg = "电机过热";
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void SetData5Error(DeviceData deviceData)
|
|
{
|
|
switch (deviceData.Data5)
|
|
{
|
|
case 1:
|
|
deviceData.ErrCode = "Pb01";
|
|
deviceData.ErrMsg = "超载";
|
|
break;
|
|
case 2:
|
|
deviceData.ErrCode = "Pb02";
|
|
deviceData.ErrMsg = "超载报警";
|
|
break;
|
|
case 3:
|
|
deviceData.ErrCode = "Pb03";
|
|
deviceData.ErrMsg = "EEPROM 存储故障";
|
|
break;
|
|
case 4:
|
|
deviceData.ErrCode = "Pb04";
|
|
deviceData.ErrMsg = "编码器故障";
|
|
break;
|
|
case 5:
|
|
deviceData.ErrCode = "Pb05";
|
|
deviceData.ErrMsg = "刹车电流过大";
|
|
break;
|
|
case 6:
|
|
deviceData.ErrCode = "Pb06";
|
|
deviceData.ErrMsg = "刹车信号故障";
|
|
break;
|
|
case 7:
|
|
deviceData.ErrCode = "Pb07";
|
|
deviceData.ErrMsg = "运行时抱闸未及时打开";
|
|
break;
|
|
case 8:
|
|
deviceData.ErrCode = "Pb08";
|
|
deviceData.ErrMsg = "停机时抱闸未及时断开";
|
|
break;
|
|
case 9:
|
|
deviceData.ErrCode = "Pb09";
|
|
deviceData.ErrMsg = "刹车片磨损较大";
|
|
break;
|
|
case 10:
|
|
deviceData.ErrCode = "Pb10";
|
|
deviceData.ErrMsg = "变频器通讯故障";
|
|
break;
|
|
case 11:
|
|
deviceData.ErrCode = "Pb11";
|
|
deviceData.ErrMsg = "运行超速故障";
|
|
break;
|
|
case 13:
|
|
deviceData.ErrCode = "Pb13";
|
|
deviceData.ErrMsg = "输入缺相";
|
|
break;
|
|
case 41:
|
|
deviceData.ErrCode = "Pb41";
|
|
deviceData.ErrMsg = "工频输出接触器未吸合";
|
|
break;
|
|
case 42:
|
|
deviceData.ErrCode = "Pb42";
|
|
deviceData.ErrMsg = "工频输出接触器异常吸合";
|
|
break;
|
|
case 43:
|
|
deviceData.ErrCode = "Pb43";
|
|
deviceData.ErrMsg = "工频输入电源相序错误";
|
|
break;
|
|
case 44:
|
|
deviceData.ErrCode = "Pb44";
|
|
deviceData.ErrMsg = "工频上升接触器黏连";
|
|
break;
|
|
case 45:
|
|
deviceData.ErrCode = "Pb45";
|
|
deviceData.ErrMsg = "工频下降接触器黏连";
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void SetData4Error(DeviceData deviceData)
|
|
{
|
|
switch (deviceData.Data4)
|
|
{
|
|
case 1:
|
|
deviceData.ErrCode = "ERR01";
|
|
deviceData.ErrMsg = "逆变单元保护";
|
|
break;
|
|
case 2:
|
|
deviceData.ErrCode = "ERR02";
|
|
deviceData.ErrMsg = "硬件过流";
|
|
break;
|
|
case 3:
|
|
deviceData.ErrCode = "ERR03";
|
|
deviceData.ErrMsg = "硬件过压";
|
|
break;
|
|
case 4:
|
|
deviceData.ErrCode = "ERR04";
|
|
deviceData.ErrMsg = "加速过电流";
|
|
break;
|
|
case 5:
|
|
deviceData.ErrCode = "ERR05";
|
|
deviceData.ErrMsg = "减速过电流";
|
|
break;
|
|
case 6:
|
|
deviceData.ErrCode = "ERR06";
|
|
deviceData.ErrMsg = "恒速过电流";
|
|
break;
|
|
case 7:
|
|
deviceData.ErrCode = "ERR07";
|
|
deviceData.ErrMsg = "停止过电流";
|
|
break;
|
|
case 8:
|
|
deviceData.ErrCode = "ERR08";
|
|
deviceData.ErrMsg = "加速过电压";
|
|
break;
|
|
case 9:
|
|
deviceData.ErrCode = "ERR09";
|
|
deviceData.ErrMsg = "减速过电压";
|
|
break;
|
|
case 10:
|
|
deviceData.ErrCode = "ERR10";
|
|
deviceData.ErrMsg = "恒速过电压";
|
|
break;
|
|
case 11:
|
|
deviceData.ErrCode = "ERR11";
|
|
deviceData.ErrMsg = "停止过电压";
|
|
break;
|
|
case 12:
|
|
deviceData.ErrCode = "ERR12";
|
|
deviceData.ErrMsg = "欠压故障";
|
|
break;
|
|
case 13:
|
|
deviceData.ErrCode = "ERR13";
|
|
deviceData.ErrMsg = "驱动器过载";
|
|
break;
|
|
case 14:
|
|
deviceData.ErrCode = "ERR14";
|
|
deviceData.ErrMsg = "电机过载";
|
|
break;
|
|
case 15:
|
|
deviceData.ErrCode = "ERR15";
|
|
deviceData.ErrMsg = "模块过热";
|
|
break;
|
|
case 16:
|
|
deviceData.ErrCode = "ERR16";
|
|
deviceData.ErrMsg = "AD转换故障";
|
|
break;
|
|
case 17:
|
|
deviceData.ErrCode = "ERR17";
|
|
deviceData.ErrMsg = "IU电流检测故障";
|
|
break;
|
|
case 18:
|
|
deviceData.ErrCode = "ERR18";
|
|
deviceData.ErrMsg = "IV电流检测故障";
|
|
break;
|
|
case 19:
|
|
deviceData.ErrCode = "ERR19";
|
|
deviceData.ErrMsg = "IW电流检测故障";
|
|
break;
|
|
case 20:
|
|
deviceData.ErrCode = "ERR20";
|
|
deviceData.ErrMsg = "对地短路故障";
|
|
break;
|
|
case 21:
|
|
deviceData.ErrCode = "ERR21";
|
|
deviceData.ErrMsg = "电机参数调谐故障";
|
|
break;
|
|
case 23:
|
|
deviceData.ErrCode = "ERR23";
|
|
deviceData.ErrMsg = "输入缺相";
|
|
break;
|
|
case 24:
|
|
deviceData.ErrCode = "ERR24";
|
|
deviceData.ErrMsg = "输出缺相";
|
|
break;
|
|
case 25:
|
|
deviceData.ErrCode = "ERR25";
|
|
deviceData.ErrMsg = "存储器故障";
|
|
break;
|
|
case 26:
|
|
deviceData.ErrCode = "ERR26";
|
|
deviceData.ErrMsg = "密码输入错误超过3次";
|
|
break;
|
|
case 27:
|
|
deviceData.ErrCode = "ERR27";
|
|
deviceData.ErrMsg = "通信故障";
|
|
break;
|
|
case 28:
|
|
deviceData.ErrCode = "ERR28";
|
|
deviceData.ErrMsg = "外部故障";
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
private Task SetRunCount(DeviceData deviceData)
|
|
{
|
|
deviceData.RunCount = CacheService.Get<int>($"{deviceData.Id}_RunCount").Result;
|
|
if (deviceData.RunCount == 0)
|
|
{
|
|
var temp = Db.Queryable<DeviceData>().Single(x => x.Id == deviceData.Id);
|
|
deviceData.RunCount = temp == null ? 0 : temp.RunCount;
|
|
if (deviceData.RunCount != null)
|
|
{
|
|
CacheService.Set<int>($"{deviceData.Id}_RunCount", (int)deviceData.RunCount!);
|
|
}
|
|
}
|
|
|
|
if (deviceData.MsgType == "1103" && deviceData.Data11 == 1)
|
|
{
|
|
|
|
var OldData11 = CacheService.Get<int>($"{deviceData.Id}_Data11").Result;
|
|
|
|
if (OldData11 > 1)
|
|
{
|
|
Db.Updateable<DeviceData>().SetColumns(x => x.RunCount == x.RunCount + 1).Where(x => x.Id == deviceData.Id).ExecuteCommand();
|
|
deviceData.RunCount = Db.Queryable<DeviceData>().Single(x => x.Id == deviceData.Id).RunCount;
|
|
if (deviceData.RunCount != null)
|
|
{
|
|
CacheService.Set<int>($"{deviceData.Id}_RunCount", (int)deviceData.RunCount!);
|
|
}
|
|
}
|
|
}
|
|
if (deviceData.Data11 != null)
|
|
{
|
|
CacheService.Set<int>($"{deviceData.Id}_Data11", (int)deviceData.Data11!);
|
|
}
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
#region 故障统计
|
|
/// <summary>
|
|
/// 获取设备故障报表
|
|
/// </summary>
|
|
/// <param name="report">报表筛选</param>
|
|
/// <returns></returns>
|
|
public async Task<DeviceErrorReport> GetDeviceErrorReport(DeviceErrorReport report)
|
|
{
|
|
#region 有效校验
|
|
var TempDate = DateTime.Now;
|
|
if (report.StartDate == null)
|
|
{
|
|
report.StartDate = TempDate.AddDays(-TempDate.Day);
|
|
}
|
|
if (report.EndDate == null)
|
|
{
|
|
report.EndDate = TempDate;
|
|
}
|
|
var TempUnits = new string[] { "year", "month", "day" };
|
|
if (!string.IsNullOrEmpty(report.Unit) && !TempUnits.Any(x => x == report.Unit.ToLower()))
|
|
{
|
|
throw new BadRequestException("单元无效");
|
|
}
|
|
#endregion
|
|
var TempQuery = Db.Queryable<DeviceError>()
|
|
.WhereIF(report.ErrCodes != null, x => report.ErrCodes!.Any(q => q == x.ErrCode))
|
|
.WhereIF(report.DeviceIds != null, x => report.DeviceIds!.Any(q => q == x.DeviceId))
|
|
.Where(x => x.CreateDate >= report.StartDate && x.CreateDate <= report.EndDate);
|
|
DateTime TempStart = (DateTime)report.StartDate!;
|
|
DateTime TempEnd = (DateTime)report.EndDate!;
|
|
if (string.IsNullOrEmpty(report.Unit))
|
|
{
|
|
report.Items = await TempQuery
|
|
.GroupBy(x => new { x.ErrCode, x.ErrMsg })
|
|
.Select(x => new DeviceError
|
|
{
|
|
ErrCode = x.ErrCode,
|
|
ErrMsg = x.ErrMsg,
|
|
Count = SqlFunc.AggregateCount(x.ErrCode)
|
|
})
|
|
.SplitTable(TempStart, TempEnd)
|
|
.ToListAsync();
|
|
}
|
|
else if (report.Unit.ToLower() == "year")
|
|
{
|
|
var TempYears = TempEnd.Year - TempStart.Year + 1;
|
|
var TempYearArray = Enumerable.Range(0, TempYears).Select(x => Convert.ToDateTime(TempStart.AddYears(x).ToString("yyyy-MM-dd"))).ToList();
|
|
var TempQueryYear = Db.Reportable(TempYearArray).ToQueryable<DateTime>();
|
|
report.Items = TempQueryYear
|
|
.LeftJoin(TempQuery.SplitTable(TempStart, TempEnd), (x, y) => x.ColumnName.ToString("yyyy") == ((DateTime)y.CreateDate!).ToString("yyyy"))
|
|
.GroupBy((x, y) => new { x.ColumnName, y.ErrCode, y.ErrMsg })
|
|
.Select((x, y) => new DeviceError
|
|
{
|
|
ErrCode = y.ErrCode,
|
|
ErrMsg = y.ErrMsg,
|
|
Count = SqlFunc.AggregateCount(y.ErrCode),
|
|
Id = x.ColumnName.ToString("yyyy"),
|
|
CreateDate = x.ColumnName
|
|
})
|
|
.ToList().OrderBy(x => x.Id);
|
|
}
|
|
else if (report.Unit.ToLower() == "month")
|
|
{
|
|
var TempMonths = (TempEnd.Year - TempStart.Year) * 12 + (TempEnd.Month - TempStart.Month + 1);
|
|
var TempMonthArray = Enumerable.Range(0, TempMonths).Select(x => Convert.ToDateTime(TempStart.AddMonths(x).ToString("yyyy-MM-dd"))).ToList();
|
|
var TempQueryMonth = Db.Reportable(TempMonthArray).ToQueryable<DateTime>();
|
|
report.Items = TempQueryMonth
|
|
.LeftJoin(TempQuery.SplitTable(TempStart, TempEnd), (x, y) => x.ColumnName.ToString("yyyy-MM") == ((DateTime)y.CreateDate!).ToString("yyyy-MM"))
|
|
.GroupBy((x, y) => new { x.ColumnName, y.ErrCode, y.ErrMsg })
|
|
.Select((x, y) => new DeviceError
|
|
{
|
|
ErrCode = y.ErrCode,
|
|
ErrMsg = y.ErrMsg,
|
|
Count = SqlFunc.AggregateCount(y.ErrCode),
|
|
Id = x.ColumnName.ToString("yyyy-MM"),
|
|
CreateDate = x.ColumnName
|
|
})
|
|
.ToList().OrderBy(x => x.Id);
|
|
}
|
|
else if (report.Unit.ToLower() == "day")
|
|
{
|
|
var TempDays = (TempEnd - TempStart).TotalDays.ToInt();
|
|
var TempDayArray = Enumerable.Range(0, TempDays).Select(x => Convert.ToDateTime(TempStart.AddDays(x).ToString("yyyy-MM-dd"))).ToList();
|
|
var TempQueryDay = Db.Reportable(TempDayArray).ToQueryable<DateTime>();
|
|
report.Items = TempQueryDay
|
|
.LeftJoin(TempQuery.SplitTable(TempStart, TempEnd), (x, y) => x.ColumnName.ToString("yyyy-MM-dd") == ((DateTime)y.CreateDate!).ToString("yyyy-MM-dd"))
|
|
.GroupBy((x, y) => new { x.ColumnName, y.ErrCode, y.ErrMsg })
|
|
.Select((x, y) => new DeviceError
|
|
{
|
|
ErrCode = y.ErrCode,
|
|
ErrMsg = y.ErrMsg,
|
|
Count = SqlFunc.AggregateCount(y.ErrCode),
|
|
Id = x.ColumnName.ToString("yyyy-MM-dd"),
|
|
CreateDate = x.ColumnName
|
|
})
|
|
.ToList().OrderBy(x => x.Id);
|
|
}
|
|
return report;
|
|
}
|
|
#endregion
|
|
}
|
|
}
|