add 操作日志
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
using Dlhis.Basic.Common.ApiLog.Request;
|
||||
using Dlhis.Basic.Common.ApiLog.Response;
|
||||
using Dlhis.Basic.Common.ApiLog.Services.Implements;
|
||||
using Dlhis.Entity.Common;
|
||||
using Dlhis.Entity.Common.Entities;
|
||||
using Kurisu.AspNetCore.CustomClass;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using SqlSugar;
|
||||
|
||||
9
Src/Dlhis.Basic/Common/ApiLog/Services/IOperateLog.cs
Normal file
9
Src/Dlhis.Basic/Common/ApiLog/Services/IOperateLog.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using Dlhis.Entity.Common.Enums;
|
||||
|
||||
namespace Dlhis.Basic.Common.ApiLog.Services;
|
||||
|
||||
public interface IOperateLog : IScopeDependency
|
||||
{
|
||||
Task LogAsync(OperateLogType type, string content);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
using Dlhis.Entity.Common.Entities;
|
||||
using Dlhis.Entity.Common.Enums;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
|
||||
namespace Dlhis.Basic.Common.ApiLog.Services.Implements;
|
||||
|
||||
public class OperateLogService : IOperateLog
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
|
||||
public OperateLogService(IDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext.ChangeDb("log");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task LogAsync(OperateLogType type, string content)
|
||||
{
|
||||
await _dbContext.InsertAsync(new OperateLogEntity
|
||||
{
|
||||
Type = type,
|
||||
Content = content
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using Dlhis.Basic.Common.FileOperation.Request;
|
||||
using Dlhis.Basic.Common.FileOperation.Response;
|
||||
using Dlhis.Entity.Common;
|
||||
using Dlhis.Entity.Common.Entities;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using Dlhis.Basic.Common.ApiLog.Services;
|
||||
using Dlhis.Basic.WorkGrids.Request;
|
||||
using Dlhis.Basic.WorkGrids.Response;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Basic.Enums;
|
||||
using Dlhis.Entity.Common.Enums;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Jip.Api;
|
||||
using Dlhis.Jip.Api.Requests;
|
||||
@@ -17,15 +19,20 @@ public class WorkGridScheduleService : IWorkGridScheduleService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly IJinkoJipApi _jinkoJipApi;
|
||||
private readonly IOperateLog _operateLog;
|
||||
|
||||
public WorkGridScheduleService(IDbContext dbContext, IJinkoJipApi jinkoJipApi)
|
||||
public WorkGridScheduleService(IDbContext dbContext, IJinkoJipApi jinkoJipApi, IOperateLog operateLog)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_jinkoJipApi = jinkoJipApi;
|
||||
_operateLog = operateLog;
|
||||
}
|
||||
|
||||
public async Task SaveAsync(WorkGridScheduleSaveRequest request)
|
||||
{
|
||||
var workGrid = await _dbContext.Queryable<WorkGridEntity>().SingleAsync(x => x.Code == request.WorkGridCode);
|
||||
workGrid.ThrowIfNull("工作网格不存在");
|
||||
|
||||
var exists = await _dbContext.Queryable<WorkGridScheduleEntity>()
|
||||
.Where(x => x.WorkGridCode == request.WorkGridCode
|
||||
&& x.PeriodType == request.PeriodType
|
||||
@@ -45,11 +52,16 @@ public class WorkGridScheduleService : IWorkGridScheduleService
|
||||
}).ToList();
|
||||
|
||||
await _dbContext.InsertAsync(toInserts);
|
||||
|
||||
await _operateLog.LogAsync(OperateLogType.WorkGrid, $"新增网格({workGrid.Name}){request.Date.ToString("yyyy-M-d")}的{request.PeriodType.GetDescription()}人员:{request.UserCodes.Join(",")}");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task RemoveAsync(WorkGridScheduleSaveRequest request)
|
||||
{
|
||||
var workGrid = await _dbContext.Queryable<WorkGridEntity>().SingleAsync(x => x.Code == request.WorkGridCode);
|
||||
workGrid.ThrowIfNull("工作网格不存在");
|
||||
|
||||
var data = await _dbContext.Queryable<WorkGridScheduleEntity>()
|
||||
.Where(x => x.WorkGridCode == request.WorkGridCode)
|
||||
.Where(x => x.Date == request.Date)
|
||||
@@ -58,6 +70,7 @@ public class WorkGridScheduleService : IWorkGridScheduleService
|
||||
.ToListAsync();
|
||||
|
||||
await _dbContext.DeleteReallyAsync(data);
|
||||
await _operateLog.LogAsync(OperateLogType.WorkGrid, $"移除网格({workGrid.Name}){request.Date.ToString("yyyy-M-d")}的{request.PeriodType.GetDescription()}人员:{request.UserCodes.Join(",")}");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using Dlhis.Basic.Common.ApiLog.Services;
|
||||
using Dlhis.Basic.WorkGrids.Request;
|
||||
using Dlhis.Basic.WorkGrids.Response;
|
||||
using Dlhis.Constants;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Common.Enums;
|
||||
using Kurisu.AspNetCore.Authentication.Abstractions;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
|
||||
@@ -16,16 +18,21 @@ public class WorkGridService : IWorkGridService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly ICurrentUser _currentUser;
|
||||
private readonly IOperateLog _operateLog;
|
||||
|
||||
public WorkGridService(IDbContext dbContext, ICurrentUser currentUser)
|
||||
public WorkGridService(IDbContext dbContext, ICurrentUser currentUser, IOperateLog operateLog)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_currentUser = currentUser;
|
||||
_operateLog = operateLog;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task SaveAsync(List<WorkGridSaveRequest> requests)
|
||||
{
|
||||
var insertGrids = new List<string>();
|
||||
var updateGrids = new List<string>();
|
||||
|
||||
foreach (var request in requests)
|
||||
{
|
||||
var exists = await _dbContext.Queryable<WorkGridEntity>()
|
||||
@@ -53,15 +60,22 @@ public class WorkGridService : IWorkGridService
|
||||
entity.Code = Guid.NewGuid();
|
||||
|
||||
await _dbContext.InsertAsync(entity);
|
||||
insertGrids.Add($"{entity.Name}({entity.LeaderUserCode})");
|
||||
}
|
||||
else
|
||||
{
|
||||
var entity = await _dbContext.Queryable<WorkGridEntity>().Where(x => x.Id == request.Id).SingleAsync();
|
||||
entity.ThrowIfNull("网格不存在");
|
||||
|
||||
updateGrids.Add($"{entity.Name}->{request.Name}");
|
||||
request.Adapt(entity);
|
||||
|
||||
await _dbContext.UpdateAsync(entity);
|
||||
}
|
||||
}
|
||||
|
||||
await _operateLog.LogAsync(OperateLogType.WorkGrid, "创建网格:" + insertGrids.Join("\r\n"));
|
||||
await _operateLog.LogAsync(OperateLogType.WorkGrid, "修改网格:" + updateGrids.Join("\r\n"));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -99,6 +113,8 @@ public class WorkGridService : IWorkGridService
|
||||
|
||||
workGrid.LeaderUserCode = to;
|
||||
await _dbContext.UpdateAsync(workGrid);
|
||||
|
||||
await _operateLog.LogAsync(OperateLogType.WorkGrid, $"网格({workGrid.Name})修改负责人{from}->{to}");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -158,6 +174,7 @@ public class WorkGridService : IWorkGridService
|
||||
}).ToList();
|
||||
|
||||
await _dbContext.InsertAsync(dataToInserts);
|
||||
await _operateLog.LogAsync(OperateLogType.WorkGrid, $"分配人员到网格({myWorkGrid.Name}),人员:{dataToInserts.Select(x => x.UserCode).Join(",")}");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -177,5 +194,7 @@ public class WorkGridService : IWorkGridService
|
||||
|
||||
await _dbContext.DeleteReallyAsync(workGridUsers);
|
||||
await _dbContext.DeleteReallyAsync(workGridSchedules);
|
||||
|
||||
await _operateLog.LogAsync(OperateLogType.WorkGrid, $"从网格({myWorkGrid.Name})移除人员:{request.UserCodes.Join(",")}");
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
using Dlhis.Basic.Common.ApiLog.Services;
|
||||
using Dlhis.Basic.WorkGrids.Request;
|
||||
using Dlhis.Basic.WorkGrids.Response;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Basic.Enums;
|
||||
using Kurisu.AspNetCore.CustomClass;
|
||||
using Dlhis.Entity.Common.Enums;
|
||||
using Kurisu.AspNetCore.DataAccess.Dto;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
@@ -14,10 +15,12 @@ namespace Dlhis.Basic.WorkGrids.Services.Implements;
|
||||
public class WorkGridTimePeriodService : IWorkGridTimePeriodService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly IOperateLog _operateLog;
|
||||
|
||||
public WorkGridTimePeriodService(IDbContext dbContext)
|
||||
public WorkGridTimePeriodService(IDbContext dbContext, IOperateLog operateLog)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_operateLog = operateLog;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -37,13 +40,16 @@ public class WorkGridTimePeriodService : IWorkGridTimePeriodService
|
||||
var data = request.Adapt<WorkGridTimePeriodEntity>();
|
||||
data.Type = request.Type;
|
||||
await _dbContext.InsertAsync(data);
|
||||
|
||||
await _operateLog.LogAsync(OperateLogType.WorkGrid, $"创建网格时间配置:{request.ToJson()}");
|
||||
}
|
||||
else
|
||||
{
|
||||
var entity = await _dbContext.Queryable<WorkGridTimePeriodEntity>().Where(x => x.Id == request.Id).SingleAsync();
|
||||
var log = $"修改网格时间配置:{entity.ToJson()}->{request.ToJson()}";
|
||||
request.Adapt(entity);
|
||||
|
||||
await _dbContext.UpdateAsync(entity);
|
||||
await _operateLog.LogAsync(OperateLogType.WorkGrid, log);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ public class WorkGridEntity : SugarBaseEntity
|
||||
/// <summary>
|
||||
/// 负责人工号
|
||||
/// </summary>
|
||||
[AdaptIgnore(MemberSide.Destination)]
|
||||
[SugarColumn(IsNullable = false, ColumnDescription = "负责人工号", UniqueGroupNameList = new[] { "idx_WorkGrid_LeaderUserCode" })]
|
||||
public string LeaderUserCode { get; set; }
|
||||
|
||||
|
||||
@@ -41,8 +41,6 @@ public class WorkGridTimePeriodEntity : SugarBaseEntity, ITenantId
|
||||
/// </summary>
|
||||
[SugarColumn(IsNullable = false, ColumnDataType = "date")]
|
||||
public TimeOnly End { get; set; }
|
||||
|
||||
|
||||
[SugarColumn(UniqueGroupNameList = new[] { "idx_workGridTimePeriod_type_tenantId" })]
|
||||
|
||||
public string TenantId { get; set; }
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SqlSugar;
|
||||
using SqlSugar.DbConvert;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Dlhis.Entity.Common;
|
||||
namespace Dlhis.Entity.Common.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// api日志表
|
||||
@@ -1,7 +1,7 @@
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Dlhis.Entity.Common;
|
||||
namespace Dlhis.Entity.Common.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// 文件版本信息
|
||||
21
Src/Dlhis.Entity/Common/Entities/OperateLogEntity.cs
Normal file
21
Src/Dlhis.Entity/Common/Entities/OperateLogEntity.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using Dlhis.Entity.Common.Enums;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar;
|
||||
using SqlSugar;
|
||||
using SqlSugar.DbConvert;
|
||||
|
||||
namespace Dlhis.Entity.Common.Entities;
|
||||
|
||||
[SugarTable(TableName = "OperateLogs")]
|
||||
public class OperateLogEntity : SugarBaseEntity
|
||||
{
|
||||
[SugarColumn(IsNullable = false, SqlParameterDbType = typeof(EnumToStringConvert))]
|
||||
public OperateLogType Type { get; set; }
|
||||
|
||||
|
||||
[SugarColumn(IsNullable = true, ColumnDataType = "text")]
|
||||
public string Request { get; set; }
|
||||
|
||||
|
||||
[SugarColumn(IsNullable = false)]
|
||||
public string Content { get; set; }
|
||||
}
|
||||
10
Src/Dlhis.Entity/Common/Enums/OperateLogType.cs
Normal file
10
Src/Dlhis.Entity/Common/Enums/OperateLogType.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Dlhis.Entity.Common.Enums;
|
||||
|
||||
[Description("操作日志类型")]
|
||||
public enum OperateLogType
|
||||
{
|
||||
[Description("工作网格")]
|
||||
WorkGrid
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using Dlhis.Entity.Common;
|
||||
using Dlhis.Entity.Common.Entities;
|
||||
using Dlhis.ScheduledTask.Attributes;
|
||||
|
||||
namespace Dlhis.ScheduledTask.Jobs;
|
||||
|
||||
Reference in New Issue
Block a user