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 { /// /// 通用业务操作日志 /// public class BusinessOperationLogService : IBusinessOperationLogService, ITransient { private readonly ISqlSugarClient _db; private readonly IUserManager _userManager; public BusinessOperationLogService(ISqlSugarClient db, IUserManager userManager) { _db = db; _userManager = userManager; } /// 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(); } } }