feat 获取api日志
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
using Dlhis.Basic.Device.Request;
|
using Dlhis.Basic.Device.Request;
|
||||||
using Dlhis.Basic.Device.Response;
|
using Dlhis.Basic.Device.Response;
|
||||||
using Dlhis.Basic.Device.Services;
|
using Dlhis.Basic.Device.Services;
|
||||||
|
using Dlhis.Entity.Basic.Entity;
|
||||||
using Kurisu.Core.DataAccess.Dto;
|
using Kurisu.Core.DataAccess.Dto;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
@@ -198,8 +199,18 @@ public class DevicesController : ControllerBase
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet("recentnumbers")]
|
[HttpGet("recentnumbers")]
|
||||||
public async Task<Dictionary<string, int>> GetRecentNumbersAsync()
|
public async Task<List<RecentNumberResponse>> GetRecentNumbersAsync()
|
||||||
{
|
{
|
||||||
return await _deviceService.GetRecentNumbersAsync();
|
return await _deviceService.GetRecentNumbersAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取api日志
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("logs")]
|
||||||
|
public async Task<Pagination<ApiLogResponse>> GetLogsAsync([FromQuery]ApiLogRequest request)
|
||||||
|
{
|
||||||
|
return await _deviceService.GetLogsAsync(request);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
14
Src/Dlhis.Basic/Device/Request/ApiLogRequest.cs
Normal file
14
Src/Dlhis.Basic/Device/Request/ApiLogRequest.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using Dlhis.Entity.Basic.Enums;
|
||||||
|
using Kurisu.Core.DataAccess.Dto;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace Dlhis.Basic.Device.Request
|
||||||
|
{
|
||||||
|
public class ApiLogRequest :PageDto
|
||||||
|
{
|
||||||
|
public string message { get; set; }
|
||||||
|
|
||||||
|
[EnumDataType(typeof(ApiLogEnumType)),]
|
||||||
|
public ApiLogEnumType? Type { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
49
Src/Dlhis.Basic/Device/Response/ApiLogResponse.cs
Normal file
49
Src/Dlhis.Basic/Device/Response/ApiLogResponse.cs
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
using SqlSugar;
|
||||||
|
|
||||||
|
namespace Dlhis.Basic.Device.Response
|
||||||
|
{
|
||||||
|
public class ApiLogResponse
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 时间
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(ColumnDescription = "时间")]
|
||||||
|
public string Timestamp { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 级别
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(ColumnDescription = "级别")]
|
||||||
|
public string Level { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 模板
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(ColumnDescription = "模板")]
|
||||||
|
public string Template { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 消息内容
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(ColumnDescription = "消息内容")]
|
||||||
|
public string Message { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 异常内容
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(ColumnDescription = "异常内容")]
|
||||||
|
public string Exception { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 属性
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(ColumnDescription = "属性")]
|
||||||
|
public string Properties { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 时间
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(ColumnDescription = "时间")]
|
||||||
|
public DateTime _ts { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
9
Src/Dlhis.Basic/Device/Response/RecentNumberResponse.cs
Normal file
9
Src/Dlhis.Basic/Device/Response/RecentNumberResponse.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
namespace Dlhis.Basic.Device.Response
|
||||||
|
{
|
||||||
|
public class RecentNumberResponse
|
||||||
|
{
|
||||||
|
public string Date { get; set; }
|
||||||
|
|
||||||
|
public int Num { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using Dlhis.Basic.Device.Request;
|
using Dlhis.Basic.Device.Request;
|
||||||
using Dlhis.Basic.Device.Response;
|
using Dlhis.Basic.Device.Response;
|
||||||
|
using Dlhis.Entity.Basic.Entity;
|
||||||
using Kurisu.Core.DataAccess.Dto;
|
using Kurisu.Core.DataAccess.Dto;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
@@ -23,5 +24,7 @@ public interface IDeviceService : IScopeDependency
|
|||||||
|
|
||||||
Task<Pagination<DevicePageResponse>> GetAttendanceOfflineAsync(DeviceOnlineAndofflineRequest request);
|
Task<Pagination<DevicePageResponse>> GetAttendanceOfflineAsync(DeviceOnlineAndofflineRequest request);
|
||||||
|
|
||||||
Task<Dictionary<string, int>> GetRecentNumbersAsync();
|
Task<List<RecentNumberResponse>> GetRecentNumbersAsync();
|
||||||
|
|
||||||
|
Task<Pagination<ApiLogResponse>> GetLogsAsync(ApiLogRequest request);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using Dlhis.Basic.Device.Response;
|
|||||||
using Dlhis.Entity.Basic.Entity;
|
using Dlhis.Entity.Basic.Entity;
|
||||||
using Dlhis.Entity.Device.Entities;
|
using Dlhis.Entity.Device.Entities;
|
||||||
using Dlhis.Entity.Device.Enums;
|
using Dlhis.Entity.Device.Enums;
|
||||||
|
using Kurisu.AspNetCore.Scope;
|
||||||
using Kurisu.AspNetCore.UnifyResultAndValidation;
|
using Kurisu.AspNetCore.UnifyResultAndValidation;
|
||||||
using Kurisu.AspNetCore.Utils.Extensions;
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
using Kurisu.Core.DataAccess.Dto;
|
using Kurisu.Core.DataAccess.Dto;
|
||||||
@@ -246,7 +247,7 @@ public class DeviceService : IDeviceService
|
|||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Dictionary<string, int>> GetRecentNumbersAsync()
|
public async Task<List<RecentNumberResponse>> GetRecentNumbersAsync()
|
||||||
{
|
{
|
||||||
//获取近30天并转化为"yyyy-MM-dd"集合
|
//获取近30天并转化为"yyyy-MM-dd"集合
|
||||||
DateTime currentDate = DateTime.Now;
|
DateTime currentDate = DateTime.Now;
|
||||||
@@ -260,13 +261,39 @@ public class DeviceService : IDeviceService
|
|||||||
|
|
||||||
var devices = await _dbContext.Queryable<DeviceEntity>().ToListAsync();
|
var devices = await _dbContext.Queryable<DeviceEntity>().ToListAsync();
|
||||||
|
|
||||||
var dic = new Dictionary<string, int>();
|
var list = new List<RecentNumberResponse>();
|
||||||
times.ForEach(time =>
|
times.ForEach(time =>
|
||||||
{
|
{
|
||||||
var count = devices.Where(x => x.CreateTime.ToString("yyyy-MM-dd") == time).Count();
|
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,9 +24,9 @@ public class Startup : DefaultStartup
|
|||||||
base.ConfigureServices(services);
|
base.ConfigureServices(services);
|
||||||
|
|
||||||
//todo
|
//todo
|
||||||
var redis = ConnectionMultiplexer.Connect($"10.27.21.15:30050,defaultDatabase:1,password=dlhis123");
|
/*var redis = ConnectionMultiplexer.Connect($"10.27.21.15:30050,defaultDatabase:1,password=dlhis123");
|
||||||
services.AddDataProtection()
|
services.AddDataProtection()
|
||||||
.SetApplicationName("basic")
|
.SetApplicationName("basic")
|
||||||
.PersistKeysToStackExchangeRedis(redis, "DataProtection-Keys");
|
.PersistKeysToStackExchangeRedis(redis, "DataProtection-Keys");*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
"DefaultConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=yikatong;charset=utf8mb4;",
|
"DefaultConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=yikatong;charset=utf8mb4;",
|
||||||
"SlaveConnectionString": [],
|
"SlaveConnectionString": [],
|
||||||
"FaceConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=face;charset=utf8mb4;",
|
"FaceConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=face;charset=utf8mb4;",
|
||||||
|
"LogConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=log;charset=utf8mb4;",
|
||||||
"Timeout": 30,
|
"Timeout": 30,
|
||||||
"SlowSqlTime": 1,
|
"SlowSqlTime": 1,
|
||||||
"EnableSqlLog": false
|
"EnableSqlLog": false
|
||||||
|
|||||||
61
Src/Dlhis.Entity/Basic/Entity/ApiLogEntity.cs
Normal file
61
Src/Dlhis.Entity/Basic/Entity/ApiLogEntity.cs
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
using Kurisu.Core.DataAccess.Entity;
|
||||||
|
using Kurisu.SqlSugar;
|
||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Dlhis.Entity.Basic.Entity
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// api日志表
|
||||||
|
/// </summary>
|
||||||
|
[SugarTable(TableName = "Logs", TableDescription = "api日志表")]
|
||||||
|
public class ApiLogEntity
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 时间
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(ColumnDescription = "时间")]
|
||||||
|
public string Timestamp { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 级别
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(ColumnDescription = "级别")]
|
||||||
|
public string Level { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 模板
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(ColumnDescription = "模板")]
|
||||||
|
public string Template { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 消息内容
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(ColumnDescription = "消息内容")]
|
||||||
|
public string Message { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 异常内容
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(ColumnDescription = "异常内容")]
|
||||||
|
public string Exception { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 属性
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(ColumnDescription = "属性")]
|
||||||
|
public string Properties { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 时间
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(ColumnDescription = "时间")]
|
||||||
|
public DateTime _ts { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
24
Src/Dlhis.Entity/Basic/Enums/ApiLogEnumType.cs
Normal file
24
Src/Dlhis.Entity/Basic/Enums/ApiLogEnumType.cs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Dlhis.Entity.Basic.Enums
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// api日志状态
|
||||||
|
/// </summary>
|
||||||
|
[Description("api日志状态")]
|
||||||
|
public enum ApiLogEnumType
|
||||||
|
{
|
||||||
|
Information = 1,
|
||||||
|
|
||||||
|
Warning = 2,
|
||||||
|
|
||||||
|
Error = 3,
|
||||||
|
|
||||||
|
Fatal = 4,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using Dlhis.ScheduledTask.DeviceUploadLog.Request;
|
using Dlhis.Entity.Basic.Entity;
|
||||||
|
using Dlhis.ScheduledTask.DeviceUploadLog.Request;
|
||||||
using Dlhis.ScheduledTask.DeviceUploadLog.Response;
|
using Dlhis.ScheduledTask.DeviceUploadLog.Response;
|
||||||
using Dlhis.ScheduledTask.DeviceUploadLog.Services;
|
using Dlhis.ScheduledTask.DeviceUploadLog.Services;
|
||||||
using Kurisu.Core.DataAccess.Dto;
|
using Kurisu.Core.DataAccess.Dto;
|
||||||
@@ -54,4 +55,5 @@ public class DeviceUploadLogsController : ControllerBase
|
|||||||
{
|
{
|
||||||
await _deviceUploadLogService.UploadLogsAsync(requests);
|
await _deviceUploadLogService.UploadLogsAsync(requests);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Dlhis.ScheduledTask.DeviceUploadLog.Request;
|
using Dlhis.Entity.Basic.Entity;
|
||||||
|
using Dlhis.ScheduledTask.DeviceUploadLog.Request;
|
||||||
using Dlhis.ScheduledTask.DeviceUploadLog.Response;
|
using Dlhis.ScheduledTask.DeviceUploadLog.Response;
|
||||||
using Kurisu.Core.DataAccess.Dto;
|
using Kurisu.Core.DataAccess.Dto;
|
||||||
|
|
||||||
@@ -11,4 +12,5 @@ public interface IDeviceUploadLogService : IScopeDependency
|
|||||||
Task UploadLogAsync(DeviceUploadLogUploadRequest request);
|
Task UploadLogAsync(DeviceUploadLogUploadRequest request);
|
||||||
|
|
||||||
Task UploadLogsAsync(List<DeviceUploadLogUploadRequest> requests);
|
Task UploadLogsAsync(List<DeviceUploadLogUploadRequest> requests);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,18 @@
|
|||||||
using System.Linq.Expressions;
|
using System.Configuration;
|
||||||
|
using System.Linq.Expressions;
|
||||||
using Dlhis.Entity.Basic.Entity;
|
using Dlhis.Entity.Basic.Entity;
|
||||||
using Dlhis.Entity.Device.Entities;
|
using Dlhis.Entity.Device.Entities;
|
||||||
using Dlhis.ScheduledTask.DeviceUploadLog.Request;
|
using Dlhis.ScheduledTask.DeviceUploadLog.Request;
|
||||||
using Dlhis.ScheduledTask.DeviceUploadLog.Response;
|
using Dlhis.ScheduledTask.DeviceUploadLog.Response;
|
||||||
|
using Kurisu.AspNetCore.Scope;
|
||||||
using Kurisu.AspNetCore.Utils.Extensions;
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
using Kurisu.Core.DataAccess.Dto;
|
using Kurisu.Core.DataAccess.Dto;
|
||||||
using Kurisu.SqlSugar.Attributes;
|
using Kurisu.SqlSugar.Attributes;
|
||||||
using Kurisu.SqlSugar.Extensions;
|
using Kurisu.SqlSugar.Extensions;
|
||||||
using Kurisu.SqlSugar.Services;
|
using Kurisu.SqlSugar.Services;
|
||||||
|
using Microsoft.AspNetCore.DataProtection;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using NetTaste;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
|
|
||||||
namespace Dlhis.ScheduledTask.DeviceUploadLog.Services.Implements;
|
namespace Dlhis.ScheduledTask.DeviceUploadLog.Services.Implements;
|
||||||
@@ -101,4 +106,5 @@ public class DeviceUploadLogService : IDeviceUploadLogService
|
|||||||
|
|
||||||
await _dbContext.InsertAsync(records);
|
await _dbContext.InsertAsync(records);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user