|
|
@ -36,10 +36,6 @@ namespace LanShengService
|
|
|
|
|
|
|
|
|
|
|
|
Db.CodeFirst.SplitTables().InitTables(typeof(DeviceError));
|
|
|
|
Db.CodeFirst.SplitTables().InitTables(typeof(DeviceError));
|
|
|
|
|
|
|
|
|
|
|
|
Columns1001 = DeviceData1001.GetColumns();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Columns1103 = DeviceData1103.GetColumns();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Logger.LogDebug("加载数据结构");
|
|
|
|
Logger.LogDebug("加载数据结构");
|
|
|
|
|
|
|
|
|
|
|
|
CacheService = services.GetRequiredService<CacheInterface.ICacheService>();
|
|
|
|
CacheService = services.GetRequiredService<CacheInterface.ICacheService>();
|
|
|
@ -69,21 +65,18 @@ namespace LanShengService
|
|
|
|
|
|
|
|
|
|
|
|
private readonly int ValidClearDataLogDo = 1000 * 60 * 60 * 24 * 3;
|
|
|
|
private readonly int ValidClearDataLogDo = 1000 * 60 * 60 * 24 * 3;
|
|
|
|
|
|
|
|
|
|
|
|
private readonly string[] Columns1001;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private readonly string[] Columns1103;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task InsertData(DeviceData deviceData)
|
|
|
|
public async Task InsertData(DeviceData deviceData)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Logger.LogDebug($"设备数据插入队列{JsonSerializer.Serialize(deviceData)}");
|
|
|
|
Logger.LogDebug($"设备数据插入队列{JsonSerializer.Serialize(deviceData)}");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (deviceData.MsgType!.StartsWith("1"))
|
|
|
|
|
|
|
|
{
|
|
|
|
await SetError(deviceData);
|
|
|
|
await SetError(deviceData);
|
|
|
|
|
|
|
|
|
|
|
|
await SetRunCount(deviceData);
|
|
|
|
await SetRunCount(deviceData);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await CacheService.Set($"DeviceData:{deviceData.Id}.{Guid.NewGuid().ToString()}", deviceData, 5);
|
|
|
|
await CacheService.Set($"DeviceData:{deviceData.Id}.{Guid.NewGuid().ToString()}", deviceData, 5);
|
|
|
|
|
|
|
|
|
|
|
|
await CacheService.Set($"CacheData:{deviceData.Id}", deviceData, 5);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task TimerInsertDataDo()
|
|
|
|
public async Task TimerInsertDataDo()
|
|
|
@ -128,7 +121,7 @@ namespace LanShengService
|
|
|
|
await temp.AsInsertable.ExecuteCommandAsync();
|
|
|
|
await temp.AsInsertable.ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
|
|
await temp.AsUpdateable
|
|
|
|
await temp.AsUpdateable
|
|
|
|
.UpdateColumns(Columns1001)
|
|
|
|
.UpdateColumns(Values1001[0].GetNotNullColumns())
|
|
|
|
.ExecuteCommandAsync();
|
|
|
|
.ExecuteCommandAsync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -140,20 +133,34 @@ namespace LanShengService
|
|
|
|
|
|
|
|
|
|
|
|
await temp.AsInsertable.ExecuteCommandAsync();
|
|
|
|
await temp.AsInsertable.ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
|
|
var TempType = typeof(DeviceData);
|
|
|
|
await temp.AsUpdateable
|
|
|
|
|
|
|
|
.UpdateColumns(Values1103[0].GetNotNullColumns())
|
|
|
|
|
|
|
|
.ExecuteCommandAsync();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var TempPropertys = TempType.GetProperties();
|
|
|
|
var Values2001 = DeviceValues.Where(x => x != null && (x.MsgType == "2001" || x.MsgType == "8104")).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
var TempColumns1103 = new List<string>();
|
|
|
|
if (Values2001.Count > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var temp = Db.Storageable(Values2001).ToStorage();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var TempProperty in TempPropertys) {
|
|
|
|
await temp.AsInsertable.ExecuteCommandAsync();
|
|
|
|
if (TempProperty.GetValue(Values1103[0]) != null) {
|
|
|
|
|
|
|
|
TempColumns1103.Add(TempProperty.Name);
|
|
|
|
await temp.AsUpdateable
|
|
|
|
}
|
|
|
|
.UpdateColumns(Values2001[0].GetNotNullColumns())
|
|
|
|
|
|
|
|
.ExecuteCommandAsync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var Values2103 = DeviceValues.Where(x => x != null && x.MsgType == "2103").ToList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Values2103.Count > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var temp = Db.Storageable(Values2103).ToStorage();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await temp.AsInsertable.ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
|
|
await temp.AsUpdateable
|
|
|
|
await temp.AsUpdateable
|
|
|
|
.UpdateColumns(TempColumns1103.ToArray())
|
|
|
|
.UpdateColumns(Values2103[0].GetNotNullColumns())
|
|
|
|
.ExecuteCommandAsync();
|
|
|
|
.ExecuteCommandAsync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -267,22 +274,7 @@ namespace LanShengService
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<List<DeviceData>> GetDeviceData(string[] ids)
|
|
|
|
public async Task<List<DeviceData>> GetDeviceData(string[] ids)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var Result = new List<DeviceData>();
|
|
|
|
var Result = await Db.Queryable<DeviceData>().In("Id", ids)
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
.IgnoreColumns(x => new
|
|
|
|
{
|
|
|
|
{
|
|
|
|
x.Data25_B4,
|
|
|
|
x.Data25_B4,
|
|
|
@ -292,19 +284,7 @@ namespace LanShengService
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.ToListAsync();
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
|
|
Result.AddRange(DbResult.ToList());
|
|
|
|
Result.ForEach(async x =>
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
x.Data6 = x.Data6 / 10;
|
|
|
|
decimal Latitude = 0;
|
|
|
|
decimal Latitude = 0;
|
|
|
@ -313,6 +293,10 @@ namespace LanShengService
|
|
|
|
decimal Longitude = 0;
|
|
|
|
decimal Longitude = 0;
|
|
|
|
Decimal.TryParse(x.Longitude, out Longitude);
|
|
|
|
Decimal.TryParse(x.Longitude, out Longitude);
|
|
|
|
x.Longitude = (Longitude / 1000000).ToString();
|
|
|
|
x.Longitude = (Longitude / 1000000).ToString();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(x.WZGPS)) {
|
|
|
|
|
|
|
|
x.WZ = await Db.Queryable<DeviceData>().FirstAsync(y => y.Id == x.WZGPS);
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
return Result;
|
|
|
@ -1298,7 +1282,8 @@ namespace LanShengService
|
|
|
|
throw new BadRequestException("单元无效");
|
|
|
|
throw new BadRequestException("单元无效");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
if ((report.CompanyIds != null && report.CompanyIds.Count() > 0) || (report.ProjectIds != null && report.ProjectIds.Count() > 0) || (report.DeviceIds != null && report.DeviceIds.Count() > 0)) {
|
|
|
|
if ((report.CompanyIds != null && report.CompanyIds.Count() > 0) || (report.ProjectIds != null && report.ProjectIds.Count() > 0) || (report.DeviceIds != null && report.DeviceIds.Count() > 0))
|
|
|
|
|
|
|
|
{
|
|
|
|
var TempCompanyIds = report.CompanyIds;
|
|
|
|
var TempCompanyIds = report.CompanyIds;
|
|
|
|
var TempProjectIds = report.ProjectIds;
|
|
|
|
var TempProjectIds = report.ProjectIds;
|
|
|
|
var TempDeviceIds = report.DeviceIds;
|
|
|
|
var TempDeviceIds = report.DeviceIds;
|
|
|
@ -1313,13 +1298,15 @@ namespace LanShengService
|
|
|
|
.ToList();
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
var TempGpsIds = new List<string>();
|
|
|
|
var TempGpsIds = new List<string>();
|
|
|
|
TempGpss.ForEach(v => {
|
|
|
|
TempGpss.ForEach(v =>
|
|
|
|
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var tempGps = JsonSerializer.Deserialize<IEnumerable<DeviceGpsDO>>(v!);
|
|
|
|
var tempGps = JsonSerializer.Deserialize<IEnumerable<DeviceGpsDO>>(v!);
|
|
|
|
TempGpsIds.AddRange(tempGps!.Select(x => x.Id!));
|
|
|
|
TempGpsIds.AddRange(tempGps!.Select(x => x.Id!));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch {
|
|
|
|
catch
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -1359,7 +1346,8 @@ namespace LanShengService
|
|
|
|
TempItems.Add(item);
|
|
|
|
TempItems.Add(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (report.Unit.ToLower() == "month") {
|
|
|
|
else if (report.Unit.ToLower() == "month")
|
|
|
|
|
|
|
|
{
|
|
|
|
var TempErrorDate = TempErrors.Select(x => x.Id!.Substring(0, 7)).Distinct();
|
|
|
|
var TempErrorDate = TempErrors.Select(x => x.Id!.Substring(0, 7)).Distinct();
|
|
|
|
foreach (var group in TempErrorGroup)
|
|
|
|
foreach (var group in TempErrorGroup)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -1437,7 +1425,8 @@ namespace LanShengService
|
|
|
|
return Task.FromResult(result);
|
|
|
|
return Task.FromResult(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<DeviceError>> GetErrorList(string search) {
|
|
|
|
public async Task<IEnumerable<DeviceError>> GetErrorList(string search)
|
|
|
|
|
|
|
|
{
|
|
|
|
var _Query = Db.Queryable<DeviceError>()
|
|
|
|
var _Query = Db.Queryable<DeviceError>()
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(search), x => x.ErrCode!.Contains(search) || x.ErrMsg!.Contains(search))
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(search), x => x.ErrCode!.Contains(search) || x.ErrMsg!.Contains(search))
|
|
|
|
.Distinct()
|
|
|
|
.Distinct()
|
|
|
|