diff --git a/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs b/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs
index 74e3ca8b..accdbbb3 100644
--- a/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs
+++ b/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs
@@ -1,6 +1,7 @@
using Dlhis.Basic.Device.Request;
using Dlhis.Basic.Device.Response;
using Dlhis.Basic.Device.Services;
+using Dlhis.Entity.Basic.Entity;
using Kurisu.Core.DataAccess.Dto;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
@@ -198,8 +199,18 @@ public class DevicesController : ControllerBase
///
///
[HttpGet("recentnumbers")]
- public async Task> GetRecentNumbersAsync()
+ public async Task> GetRecentNumbersAsync()
{
return await _deviceService.GetRecentNumbersAsync();
}
+
+ ///
+ /// 获取api日志
+ ///
+ ///
+ [HttpGet("logs")]
+ public async Task> GetLogsAsync([FromQuery]ApiLogRequest request)
+ {
+ return await _deviceService.GetLogsAsync(request);
+ }
}
diff --git a/Src/Dlhis.Basic/Device/Request/ApiLogRequest.cs b/Src/Dlhis.Basic/Device/Request/ApiLogRequest.cs
new file mode 100644
index 00000000..484b5983
--- /dev/null
+++ b/Src/Dlhis.Basic/Device/Request/ApiLogRequest.cs
@@ -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; }
+ }
+}
diff --git a/Src/Dlhis.Basic/Device/Response/ApiLogResponse.cs b/Src/Dlhis.Basic/Device/Response/ApiLogResponse.cs
new file mode 100644
index 00000000..f2a3f501
--- /dev/null
+++ b/Src/Dlhis.Basic/Device/Response/ApiLogResponse.cs
@@ -0,0 +1,49 @@
+using SqlSugar;
+
+namespace Dlhis.Basic.Device.Response
+{
+ public class ApiLogResponse
+ {
+ ///
+ /// 时间
+ ///
+ [SugarColumn(ColumnDescription = "时间")]
+ public string Timestamp { get; set; }
+
+ ///
+ /// 级别
+ ///
+ [SugarColumn(ColumnDescription = "级别")]
+ public string Level { get; set; }
+
+ ///
+ /// 模板
+ ///
+ [SugarColumn(ColumnDescription = "模板")]
+ public string Template { get; set; }
+
+ ///
+ /// 消息内容
+ ///
+ [SugarColumn(ColumnDescription = "消息内容")]
+ public string Message { get; set; }
+
+ ///
+ /// 异常内容
+ ///
+ [SugarColumn(ColumnDescription = "异常内容")]
+ public string Exception { get; set; }
+
+ ///
+ /// 属性
+ ///
+ [SugarColumn(ColumnDescription = "属性")]
+ public string Properties { get; set; }
+
+ ///
+ /// 时间
+ ///
+ [SugarColumn(ColumnDescription = "时间")]
+ public DateTime _ts { get; set; }
+ }
+}
diff --git a/Src/Dlhis.Basic/Device/Response/RecentNumberResponse.cs b/Src/Dlhis.Basic/Device/Response/RecentNumberResponse.cs
new file mode 100644
index 00000000..ce0de9ea
--- /dev/null
+++ b/Src/Dlhis.Basic/Device/Response/RecentNumberResponse.cs
@@ -0,0 +1,9 @@
+namespace Dlhis.Basic.Device.Response
+{
+ public class RecentNumberResponse
+ {
+ public string Date { get; set; }
+
+ public int Num { get; set; }
+ }
+}
diff --git a/Src/Dlhis.Basic/Device/Services/IDeviceService.cs b/Src/Dlhis.Basic/Device/Services/IDeviceService.cs
index 745702d4..889fb755 100644
--- a/Src/Dlhis.Basic/Device/Services/IDeviceService.cs
+++ b/Src/Dlhis.Basic/Device/Services/IDeviceService.cs
@@ -1,5 +1,6 @@
using Dlhis.Basic.Device.Request;
using Dlhis.Basic.Device.Response;
+using Dlhis.Entity.Basic.Entity;
using Kurisu.Core.DataAccess.Dto;
using Microsoft.AspNetCore.Mvc;
@@ -23,5 +24,7 @@ public interface IDeviceService : IScopeDependency
Task> GetAttendanceOfflineAsync(DeviceOnlineAndofflineRequest request);
- Task> GetRecentNumbersAsync();
+ Task> GetRecentNumbersAsync();
+
+ Task> GetLogsAsync(ApiLogRequest request);
}
diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs
index 28b2f66c..fe0257a7 100644
--- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs
+++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceService.cs
@@ -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> GetRecentNumbersAsync()
+ public async Task> GetRecentNumbersAsync()
{
//获取近30天并转化为"yyyy-MM-dd"集合
DateTime currentDate = DateTime.Now;
@@ -260,13 +261,39 @@ public class DeviceService : IDeviceService
var devices = await _dbContext.Queryable().ToListAsync();
- var dic = new Dictionary();
+ var list = new List();
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> GetLogsAsync(ApiLogRequest request)
+ {
+ var level = request.Type.ToString();
+ return await Scoped.Request.Value.CreateAsync(async (sp) =>
+ {
+ var configuration = sp.GetService();
+ var logConnectionString = configuration.GetSection("SqlSugarOptions:LogConnectionString").Value;
+
+ //todo 切换连接字符串
+ var dbContext = sp.GetService();
+ dbContext.Client.CurrentConnectionConfig.ConnectionString = logConnectionString;
+ var logs = await dbContext.Queryable()
+ .WhereIF(!request.message.IsEmpty(), x => x.Message.Contains(request.message))
+ .WhereIF(!level.IsEmpty(),x => x.Level == level)
+ .Select()
+ .ToPageListAsync(request);
+ return logs;
+
});
- return dic;
}
}
diff --git a/Src/Dlhis.Basic/Program.cs b/Src/Dlhis.Basic/Program.cs
index 48192332..0ebc0761 100644
--- a/Src/Dlhis.Basic/Program.cs
+++ b/Src/Dlhis.Basic/Program.cs
@@ -24,9 +24,9 @@ public class Startup : DefaultStartup
base.ConfigureServices(services);
//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()
.SetApplicationName("basic")
- .PersistKeysToStackExchangeRedis(redis, "DataProtection-Keys");
+ .PersistKeysToStackExchangeRedis(redis, "DataProtection-Keys");*/
}
}
\ No newline at end of file
diff --git a/Src/Dlhis.Basic/appsettings.json b/Src/Dlhis.Basic/appsettings.json
index 6c35cbca..f40f7fef 100644
--- a/Src/Dlhis.Basic/appsettings.json
+++ b/Src/Dlhis.Basic/appsettings.json
@@ -18,6 +18,7 @@
"DefaultConnectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=yikatong;charset=utf8mb4;",
"SlaveConnectionString": [],
"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,
"SlowSqlTime": 1,
"EnableSqlLog": false
diff --git a/Src/Dlhis.Entity/Basic/Entity/ApiLogEntity.cs b/Src/Dlhis.Entity/Basic/Entity/ApiLogEntity.cs
new file mode 100644
index 00000000..889cbd8c
--- /dev/null
+++ b/Src/Dlhis.Entity/Basic/Entity/ApiLogEntity.cs
@@ -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
+{
+ ///
+ /// api日志表
+ ///
+ [SugarTable(TableName = "Logs", TableDescription = "api日志表")]
+ public class ApiLogEntity
+ {
+ ///
+ /// 时间
+ ///
+ [SugarColumn(ColumnDescription = "时间")]
+ public string Timestamp { get; set; }
+
+ ///
+ /// 级别
+ ///
+ [SugarColumn(ColumnDescription = "级别")]
+ public string Level { get; set; }
+
+ ///
+ /// 模板
+ ///
+ [SugarColumn(ColumnDescription = "模板")]
+ public string Template { get; set; }
+
+ ///
+ /// 消息内容
+ ///
+ [SugarColumn(ColumnDescription = "消息内容")]
+ public string Message { get; set; }
+
+ ///
+ /// 异常内容
+ ///
+ [SugarColumn(ColumnDescription = "异常内容")]
+ public string Exception { get; set; }
+
+ ///
+ /// 属性
+ ///
+ [SugarColumn(ColumnDescription = "属性")]
+ public string Properties { get; set; }
+
+ ///
+ /// 时间
+ ///
+ [SugarColumn(ColumnDescription = "时间")]
+ public DateTime _ts { get; set; }
+
+ }
+}
diff --git a/Src/Dlhis.Entity/Basic/Enums/ApiLogEnumType.cs b/Src/Dlhis.Entity/Basic/Enums/ApiLogEnumType.cs
new file mode 100644
index 00000000..a65befdd
--- /dev/null
+++ b/Src/Dlhis.Entity/Basic/Enums/ApiLogEnumType.cs
@@ -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
+{
+ ///
+ /// api日志状态
+ ///
+ [Description("api日志状态")]
+ public enum ApiLogEnumType
+ {
+ Information = 1,
+
+ Warning = 2,
+
+ Error = 3,
+
+ Fatal = 4,
+ }
+}
diff --git a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Controllers/DeviceUploadLogsController.cs b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Controllers/DeviceUploadLogsController.cs
index b9e57664..7a487c2d 100644
--- a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Controllers/DeviceUploadLogsController.cs
+++ b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Controllers/DeviceUploadLogsController.cs
@@ -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.Services;
using Kurisu.Core.DataAccess.Dto;
@@ -54,4 +55,5 @@ public class DeviceUploadLogsController : ControllerBase
{
await _deviceUploadLogService.UploadLogsAsync(requests);
}
+
}
diff --git a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/IDeviceUploadLogService.cs b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/IDeviceUploadLogService.cs
index 8a6285e2..fa2fed08 100644
--- a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/IDeviceUploadLogService.cs
+++ b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/IDeviceUploadLogService.cs
@@ -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 Kurisu.Core.DataAccess.Dto;
@@ -11,4 +12,5 @@ public interface IDeviceUploadLogService : IScopeDependency
Task UploadLogAsync(DeviceUploadLogUploadRequest request);
Task UploadLogsAsync(List requests);
+
}
diff --git a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs
index e479e4df..0577b046 100644
--- a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs
+++ b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs
@@ -1,13 +1,18 @@
-using System.Linq.Expressions;
+using System.Configuration;
+using System.Linq.Expressions;
using Dlhis.Entity.Basic.Entity;
using Dlhis.Entity.Device.Entities;
using Dlhis.ScheduledTask.DeviceUploadLog.Request;
using Dlhis.ScheduledTask.DeviceUploadLog.Response;
+using Kurisu.AspNetCore.Scope;
using Kurisu.AspNetCore.Utils.Extensions;
using Kurisu.Core.DataAccess.Dto;
using Kurisu.SqlSugar.Attributes;
using Kurisu.SqlSugar.Extensions;
using Kurisu.SqlSugar.Services;
+using Microsoft.AspNetCore.DataProtection;
+using Microsoft.AspNetCore.Mvc;
+using NetTaste;
using SqlSugar;
namespace Dlhis.ScheduledTask.DeviceUploadLog.Services.Implements;
@@ -101,4 +106,5 @@ public class DeviceUploadLogService : IDeviceUploadLogService
await _dbContext.InsertAsync(records);
}
+
}