fix 优化apilog和设备上传log
This commit is contained in:
@@ -14,6 +14,7 @@ using Kurisu.SqlSugar.Services;
|
||||
using Mapster;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Dlhis.Basic.Device.Services.Implements;
|
||||
|
||||
@@ -247,10 +248,10 @@ public class DeviceService : IDeviceService
|
||||
var offlineNumber = await GetOfflineDevicesCount(devices);
|
||||
|
||||
var res = new DeviceNumberResponse
|
||||
{
|
||||
{
|
||||
OfflineNumber = offlineNumber.Count,
|
||||
TotalNumber = devices.Count,
|
||||
OnlineNumber = devices.Count- offlineNumber.Count
|
||||
OnlineNumber = devices.Count - offlineNumber.Count
|
||||
};
|
||||
return res;
|
||||
}
|
||||
@@ -270,14 +271,14 @@ public class DeviceService : IDeviceService
|
||||
foreach (var device in devices)
|
||||
{
|
||||
var regis = deviceRegistrys.FirstOrDefault(x => x.DeviceUniqueNo == device.UniqueNo);
|
||||
if (regis == null)
|
||||
if (regis == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
TimeSpan timeDifference = DateTime.Now - regis.LastHeartbeatTime;
|
||||
if (timeDifference.TotalSeconds > (device.HeartbeatInterval * 3))
|
||||
{
|
||||
list.Add(device);
|
||||
list.Add(device);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
@@ -307,7 +308,7 @@ public class DeviceService : IDeviceService
|
||||
.ToListAsync();
|
||||
|
||||
//离线
|
||||
var offDevices =await GetOfflineDevicesCount(devices);
|
||||
var offDevices = await GetOfflineDevicesCount(devices);
|
||||
var offids = offDevices.Select(x => x.Id).ToList();
|
||||
|
||||
if (request.IsOnAndOff)
|
||||
@@ -372,28 +373,19 @@ public class DeviceService : IDeviceService
|
||||
};
|
||||
list.Add(res);
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public async Task<Pagination<ApiLogResponse>> GetLogsAsync(ApiLogRequest request)
|
||||
{
|
||||
var level = request.Type.ToString();
|
||||
return await Scoped.Request.Value.CreateAsync(async (sp) =>
|
||||
{
|
||||
var configuration = sp.GetService<IConfiguration>();
|
||||
var logConnectionString = configuration.GetSection("SqlSugarOptions:LogConnectionString").Value;
|
||||
|
||||
//todo 切换连接字符串
|
||||
var dbContext = sp.GetService<IDbContext>();
|
||||
dbContext.Client.CurrentConnectionConfig.ConnectionString = logConnectionString;
|
||||
var logs = await dbContext.Queryable<ApiLogEntity>()
|
||||
.WhereIF(!request.message.IsEmpty(), x => x.Message.Contains(request.message))
|
||||
.WhereIF(!level.IsEmpty(), x => x.Level == level)
|
||||
var logs = await _dbContext.ChangeDb("log").Queryable<ApiLogEntity>()
|
||||
.WhereIF(request.Search.IsPresent(), x => x.Message.Contains(request.Search))
|
||||
.WhereIF(request.Level.HasValue, x => x.Level == request.Level)
|
||||
.Select<ApiLogResponse>()
|
||||
.ToPageListAsync(request);
|
||||
return logs;
|
||||
|
||||
});
|
||||
return logs;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user