feat 获取api日志
This commit is contained in:
@@ -3,6 +3,7 @@ using Dlhis.Basic.Device.Response;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Kurisu.AspNetCore.Scope;
|
||||
using Kurisu.AspNetCore.UnifyResultAndValidation;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
@@ -246,7 +247,7 @@ public class DeviceService : IDeviceService
|
||||
return page;
|
||||
}
|
||||
|
||||
public async Task<Dictionary<string, int>> GetRecentNumbersAsync()
|
||||
public async Task<List<RecentNumberResponse>> GetRecentNumbersAsync()
|
||||
{
|
||||
//获取近30天并转化为"yyyy-MM-dd"集合
|
||||
DateTime currentDate = DateTime.Now;
|
||||
@@ -260,13 +261,39 @@ public class DeviceService : IDeviceService
|
||||
|
||||
var devices = await _dbContext.Queryable<DeviceEntity>().ToListAsync();
|
||||
|
||||
var dic = new Dictionary<string, int>();
|
||||
var list = new List<RecentNumberResponse>();
|
||||
times.ForEach(time =>
|
||||
{
|
||||
var count = devices.Where(x => x.CreateTime.ToString("yyyy-MM-dd") == time).Count();
|
||||
dic[time] = count;
|
||||
var res = new RecentNumberResponse
|
||||
{
|
||||
Date = time,
|
||||
Num = count,
|
||||
};
|
||||
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)
|
||||
.Select<ApiLogResponse>()
|
||||
.ToPageListAsync(request);
|
||||
return logs;
|
||||
|
||||
});
|
||||
return dic;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user