|
|
|
@ -36,10 +36,6 @@ namespace LanShengService
|
|
|
|
|
|
|
|
|
|
Db.CodeFirst.SplitTables().InitTables(typeof(DeviceError));
|
|
|
|
|
|
|
|
|
|
Columns1001 = DeviceData1001.GetColumns();
|
|
|
|
|
|
|
|
|
|
Columns1103 = DeviceData1103.GetColumns();
|
|
|
|
|
|
|
|
|
|
Logger.LogDebug("加载数据结构");
|
|
|
|
|
|
|
|
|
|
CacheService = services.GetRequiredService<CacheInterface.ICacheService>();
|
|
|
|
@ -69,21 +65,18 @@ namespace LanShengService
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
if (deviceData.MsgType!.StartsWith("1"))
|
|
|
|
|
{
|
|
|
|
|
await SetError(deviceData);
|
|
|
|
|
|
|
|
|
|
await SetRunCount(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()
|
|
|
|
@ -128,7 +121,7 @@ namespace LanShengService
|
|
|
|
|
await temp.AsInsertable.ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
await temp.AsUpdateable
|
|
|
|
|
.UpdateColumns(Columns1001)
|
|
|
|
|
.UpdateColumns(Values1001[0].GetNotNullColumns())
|
|
|
|
|
.ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -140,20 +133,34 @@ namespace LanShengService
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
if (TempProperty.GetValue(Values1103[0]) != null) {
|
|
|
|
|
TempColumns1103.Add(TempProperty.Name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
await temp.AsInsertable.ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
.UpdateColumns(TempColumns1103.ToArray())
|
|
|
|
|
.UpdateColumns(Values2103[0].GetNotNullColumns())
|
|
|
|
|
.ExecuteCommandAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -267,44 +274,17 @@ namespace LanShengService
|
|
|
|
|
|
|
|
|
|
public async Task<List<DeviceData>> GetDeviceData(string[] ids)
|
|
|
|
|
{
|
|
|
|
|
var Result = new List<DeviceData>();
|
|
|
|
|
|
|
|
|
|
var CacheIds = new List<string>();
|
|
|
|
|
ids.ToList().ForEach((x) =>
|
|
|
|
|
var Result = await Db.Queryable<DeviceData>().In("Id", ids)
|
|
|
|
|
.IgnoreColumns(x => new
|
|
|
|
|
{
|
|
|
|
|
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.Data25_B4,
|
|
|
|
|
x.Data25_B0,
|
|
|
|
|
x.Data26_B4,
|
|
|
|
|
x.Data26_B0
|
|
|
|
|
})
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
Result.ForEach(async x =>
|
|
|
|
|
{
|
|
|
|
|
x.Data6 = x.Data6 / 10;
|
|
|
|
|
decimal Latitude = 0;
|
|
|
|
@ -313,6 +293,10 @@ namespace LanShengService
|
|
|
|
|
decimal Longitude = 0;
|
|
|
|
|
Decimal.TryParse(x.Longitude, out Longitude);
|
|
|
|
|
x.Longitude = (Longitude / 1000000).ToString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(x.WZGPS)) {
|
|
|
|
|
x.WZ = await Db.Queryable<DeviceData>().FirstAsync(y => y.Id == x.WZGPS);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
@ -1298,7 +1282,8 @@ namespace LanShengService
|
|
|
|
|
throw new BadRequestException("单元无效");
|
|
|
|
|
}
|
|
|
|
|
#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 TempProjectIds = report.ProjectIds;
|
|
|
|
|
var TempDeviceIds = report.DeviceIds;
|
|
|
|
@ -1313,17 +1298,19 @@ namespace LanShengService
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
var TempGpsIds = new List<string>();
|
|
|
|
|
TempGpss.ForEach(v => {
|
|
|
|
|
TempGpss.ForEach(v =>
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var tempGps = JsonSerializer.Deserialize<IEnumerable<DeviceGpsDO>>(v!);
|
|
|
|
|
TempGpsIds.AddRange(tempGps!.Select(x => x.Id!));
|
|
|
|
|
}
|
|
|
|
|
catch {
|
|
|
|
|
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
report.GpsIds = report.GpsIds == null? TempGpsIds!: report.GpsIds.Concat(TempGpsIds!);
|
|
|
|
|
report.GpsIds = report.GpsIds == null ? TempGpsIds! : report.GpsIds.Concat(TempGpsIds!);
|
|
|
|
|
}
|
|
|
|
|
var TempErrors = await GetDayError(report);
|
|
|
|
|
var TempErrorGroup = TempErrors.Select(x => x.ErrCode).Distinct();
|
|
|
|
@ -1359,7 +1346,8 @@ namespace LanShengService
|
|
|
|
|
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();
|
|
|
|
|
foreach (var group in TempErrorGroup)
|
|
|
|
|
{
|
|
|
|
@ -1437,7 +1425,8 @@ namespace LanShengService
|
|
|
|
|
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>()
|
|
|
|
|
.WhereIF(!string.IsNullOrWhiteSpace(search), x => x.ErrCode!.Contains(search) || x.ErrMsg!.Contains(search))
|
|
|
|
|
.Distinct()
|
|
|
|
|