From 2f32885663b9fbbf59cfc0c2bdaf46e0032704b8 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Tue, 4 Mar 2025 10:27:20 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BC=98=E5=8C=96=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Implements/OperateLogService.cs | 31 ++++++++++++++++--- .../Services/Implements/WorkGridService.cs | 2 +- .../Common/Entities/OperateLogEntity.cs | 12 +++---- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/Src/Dlhis.Basic/Common/ApiLog/Services/Implements/OperateLogService.cs b/Src/Dlhis.Basic/Common/ApiLog/Services/Implements/OperateLogService.cs index 68b91673..3081ccbf 100644 --- a/Src/Dlhis.Basic/Common/ApiLog/Services/Implements/OperateLogService.cs +++ b/Src/Dlhis.Basic/Common/ApiLog/Services/Implements/OperateLogService.cs @@ -1,25 +1,46 @@ using Dlhis.Entity.Common.Entities; using Dlhis.Entity.Common.Enums; +using Kurisu.AspNetCore.Authentication.Abstractions; using Kurisu.AspNetCore.DataAccess.SqlSugar.Services; namespace Dlhis.Basic.Common.ApiLog.Services.Implements; public class OperateLogService : IOperateLog { + private readonly ICurrentUser _currentUser; + private readonly ILogger _logger; private readonly IDbContext _dbContext; - public OperateLogService(IDbContext dbContext) + public OperateLogService(IDbContext dbContext, ICurrentUser currentUser, ILogger logger) { + _currentUser = currentUser; + _logger = logger; _dbContext = dbContext.ChangeDb("log"); } /// public async Task LogAsync(OperateLogType type, string content) { - await _dbContext.InsertAsync(new OperateLogEntity + var now = DateTime.Now; + var userId = _currentUser.GetIntSubjectId(); + var userName = _currentUser.GetName(); + + try { - Type = type, - Content = content - }); + await _dbContext.InsertAsync(new OperateLogEntity + { + Type = type, + Content = content, + Operator = userName, + CreateTime = now, + ModifiedTime = now, + CreatedBy = userId, + ModifiedBy = userId + }); + } + catch (Exception e) + { + _logger.LogError(e, "记录操作日志失败:{error}", e.Message); + } } } \ No newline at end of file diff --git a/Src/Dlhis.Basic/WorkGrids/Services/Implements/WorkGridService.cs b/Src/Dlhis.Basic/WorkGrids/Services/Implements/WorkGridService.cs index 9a7c27de..9b6c977a 100644 --- a/Src/Dlhis.Basic/WorkGrids/Services/Implements/WorkGridService.cs +++ b/Src/Dlhis.Basic/WorkGrids/Services/Implements/WorkGridService.cs @@ -149,7 +149,7 @@ public class WorkGridService : IWorkGridService public async Task AssignAsync(WorkGridUserAssignRequest request) { var currentFactory = _currentUser.GetStringTenantId(); - var currentUserCode = _currentUser.GetUserClaim("jinko-code"); + var currentUserCode = _currentUser.GetUserClaim(UserClaimConstants.JinkoCode); var myWorkGrid = await _dbContext.Queryable().Where(x => x.LeaderUserCode == currentUserCode).SingleAsync(); myWorkGrid.ThrowIfNull("工作网格尚未配置,请联系管理员"); diff --git a/Src/Dlhis.Entity/Common/Entities/OperateLogEntity.cs b/Src/Dlhis.Entity/Common/Entities/OperateLogEntity.cs index 2f9f724e..b8080855 100644 --- a/Src/Dlhis.Entity/Common/Entities/OperateLogEntity.cs +++ b/Src/Dlhis.Entity/Common/Entities/OperateLogEntity.cs @@ -5,17 +5,17 @@ using SqlSugar.DbConvert; namespace Dlhis.Entity.Common.Entities; -[SugarTable(TableName = "OperateLogs")] +[SugarTable(TableName = "OperateLogs", TableDescription = "操作日志")] public class OperateLogEntity : SugarBaseEntity { - [SugarColumn(IsNullable = false, SqlParameterDbType = typeof(EnumToStringConvert))] + [SugarColumn(IsNullable = false, ColumnDataType = "varchar(50)", SqlParameterDbType = typeof(EnumToStringConvert))] public OperateLogType Type { get; set; } - [SugarColumn(IsNullable = true, ColumnDataType = "text")] - public string Request { get; set; } - + [SugarColumn(IsNullable = false, ColumnDataType = "text")] + public string Content { get; set; } + [SugarColumn(IsNullable = false)] - public string Content { get; set; } + public string Operator { get; set; } } \ No newline at end of file