BusinessOperationLogService.cs
2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Threading.Tasks;
using NCC.Common.Core.Manager;
using NCC.Dependency;
using NCC.Extend.Entitys.lq_business_operation_log;
using NCC.Extend.Interfaces.BusinessOperationLog;
using SqlSugar;
using Yitter.IdGenerator;
namespace NCC.Extend
{
/// <summary>
/// 通用业务操作日志
/// </summary>
public class BusinessOperationLogService : IBusinessOperationLogService, ITransient
{
private readonly ISqlSugarClient _db;
private readonly IUserManager _userManager;
public BusinessOperationLogService(ISqlSugarClient db, IUserManager userManager)
{
_db = db;
_userManager = userManager;
}
/// <inheritdoc />
public async Task WriteAsync(
string moduleCode,
string actionCode,
string bizType,
string bizId,
string summary,
string detailJson = null)
{
if (string.IsNullOrWhiteSpace(moduleCode) || string.IsNullOrWhiteSpace(actionCode))
{
return;
}
var uid = _userManager?.UserId?.Trim();
var userInfo = await _userManager.GetUserInfo();
var userName = userInfo?.userName?.Trim();
if (string.IsNullOrWhiteSpace(userName))
{
userName = "系统";
}
var entity = new LqBusinessOperationLogEntity
{
Id = YitIdHelper.NextId().ToString(),
ModuleCode = moduleCode.Trim(),
ActionCode = actionCode.Trim(),
BizType = string.IsNullOrWhiteSpace(bizType) ? null : bizType.Trim(),
BizId = string.IsNullOrWhiteSpace(bizId) ? null : bizId.Trim(),
Summary = string.IsNullOrWhiteSpace(summary) ? null : summary.Trim(),
DetailJson = detailJson,
OperatorUserId = string.IsNullOrWhiteSpace(uid) ? null : uid,
OperatorUserName = userName,
OperateTime = DateTime.Now
};
await _db.Insertable(entity).ExecuteCommandAsync();
}
}
}