using System; using System.Threading.Tasks; using NCC; 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; public BusinessOperationLogService(ISqlSugarClient db) { _db = db; } /// 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; } // 延迟解析,避免 UserManager → UsersService → SysConfigService → 本服务 → UserManager 循环依赖 var userManager = App.GetService(); var uid = userManager?.UserId?.Trim(); var userName = "系统"; if (userManager != null) { var userInfo = await userManager.GetUserInfo(); if (!string.IsNullOrWhiteSpace(userInfo?.userName)) { userName = userInfo.userName.Trim(); } } 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(); } } }