fix 优化apilog和设备上传log
This commit is contained in:
@@ -1,14 +1,13 @@
|
||||
using Dlhis.Entity.Basic.Enums;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Dlhis.Basic.Device.Request
|
||||
{
|
||||
public class ApiLogRequest :PageDto
|
||||
{
|
||||
public string message { get; set; }
|
||||
namespace Dlhis.Basic.Device.Request;
|
||||
|
||||
[EnumDataType(typeof(ApiLogEnumType)),]
|
||||
public ApiLogEnumType? Type { get; set; }
|
||||
}
|
||||
public class ApiLogRequest : PageDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 日志级别 LogLevel
|
||||
/// </summary>
|
||||
[EnumDataType(typeof(LogLevel))]
|
||||
public LogLevel? Level { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,42 +1,56 @@
|
||||
using SqlSugar;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Dlhis.Basic.Device.Response
|
||||
namespace Dlhis.Basic.Device.Response;
|
||||
|
||||
public class ApiLogResponse
|
||||
{
|
||||
public class ApiLogResponse
|
||||
/// <summary>
|
||||
/// 时间UTC
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public string Timestamp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 产生时间
|
||||
/// </summary>
|
||||
public DateTime RaiseTime
|
||||
{
|
||||
/// <summary>
|
||||
/// 时间
|
||||
/// </summary>
|
||||
public string Timestamp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 级别
|
||||
/// </summary>
|
||||
public string Level { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 模板
|
||||
/// </summary>
|
||||
public string Template { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 消息内容
|
||||
/// </summary>
|
||||
public string Message { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 异常内容
|
||||
/// </summary>
|
||||
public string Exception { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 属性
|
||||
/// </summary>
|
||||
public string Properties { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 时间
|
||||
/// </summary>
|
||||
public DateTime _ts { get; set; }
|
||||
get
|
||||
{
|
||||
return DateTime.Parse(Timestamp).ToLocalTime();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 级别
|
||||
/// </summary>
|
||||
public string Level { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 模板
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public string Template { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 消息内容
|
||||
/// </summary>
|
||||
public string Message { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 异常内容
|
||||
/// </summary>
|
||||
public string Exception { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 属性
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public string Properties { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 时间
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public DateTime _TS { get; set; }
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Kurisu.AspNetCore;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Kurisu.AspNetCore;
|
||||
using Kurisu.AspNetCore.Startup;
|
||||
using Kurisu.Core.DataAccess.Entity;
|
||||
using Kurisu.SqlSugar.Extensions;
|
||||
@@ -14,26 +15,58 @@ public class SqlSugarPack : BaseAppPack
|
||||
|
||||
public override void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddSqlSugar();
|
||||
services.AddSqlSugar(sp =>
|
||||
{
|
||||
var configuration = sp.GetService<IConfiguration>();
|
||||
|
||||
return new List<ConnectionConfig>
|
||||
{
|
||||
new ConnectionConfig
|
||||
{
|
||||
ConfigId = "face",
|
||||
|
||||
ConnectionString = configuration.GetSection("SqlSugarOptions:FaceConnectionString").Value,
|
||||
DbType = DbType.MySql,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
IsAutoCloseConnection = true,
|
||||
|
||||
MoreSettings = new ConnMoreSettings
|
||||
{
|
||||
DisableNvarchar = true,
|
||||
}
|
||||
},
|
||||
new ConnectionConfig
|
||||
{
|
||||
ConfigId = "log",
|
||||
|
||||
ConnectionString = configuration.GetSection("SqlSugarOptions:LogConnectionString").Value,
|
||||
DbType = DbType.MySql,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
IsAutoCloseConnection = true,
|
||||
|
||||
MoreSettings = new ConnMoreSettings
|
||||
{
|
||||
DisableNvarchar = true,
|
||||
}
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
public override void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
using var scope = app.ApplicationServices.CreateScope();
|
||||
var db = scope.ServiceProvider.GetService<ISqlSugarClient>();
|
||||
var db = scope.ServiceProvider.GetService<IDbContext>();
|
||||
var tables = App.ActiveTyps.Where(x => x.IsDefined(typeof(SugarTable), false))
|
||||
.Where(x => !x.IsDefined(typeof(SkipScanAttribute), false))
|
||||
.ToArray();
|
||||
|
||||
db.DbMaintenance.CreateDatabase();
|
||||
db.CodeFirst.InitTables(tables);
|
||||
db.Client.DbMaintenance.CreateDatabase();
|
||||
db.Client.CodeFirst.InitTables(tables);
|
||||
|
||||
//using var scopeFace = app.ApplicationServices.CreateScope();
|
||||
//var dbFace = scopeFace.ServiceProvider.GetService<ISqlSugarClient>();
|
||||
//var faceConnectionString = Configuration.GetSection("SqlSugarOptions:FaceConnectionString").Value;
|
||||
//dbFace.CurrentConnectionConfig.ConnectionString = faceConnectionString;
|
||||
//dbFace.DbMaintenance.CreateDatabase();
|
||||
//dbFace.CodeFirst.InitTables<GainfoFaceEntity>();
|
||||
var faceDb = db.ChangeDb("face");
|
||||
faceDb.DbMaintenance.CreateDatabase();
|
||||
faceDb.CodeFirst.InitTables<GainfoFaceEntity>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user