SeOrderOperationLogService.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using Yitter.IdGenerator;
  2. namespace Admin.NET.Plugin.AiDOP.Order;
  3. /// <summary>
  4. /// 销售订单评审业务操作日志写入(sys_log_op)
  5. /// </summary>
  6. public class SeOrderOperationLogService : ITransient
  7. {
  8. private readonly SqlSugarRepository<SysLogOp> _logOpRep;
  9. private readonly UserManager _userManager;
  10. public SeOrderOperationLogService(SqlSugarRepository<SysLogOp> logOpRep, UserManager userManager)
  11. {
  12. _logOpRep = logOpRep;
  13. _userManager = userManager;
  14. }
  15. /// <summary>
  16. /// 写入操作日志;失败不影响主流程
  17. /// </summary>
  18. public async Task WriteAsync(SeOrderOperationLogDto dto)
  19. {
  20. try
  21. {
  22. var uid = dto.UserId > 0 ? dto.UserId : _userManager.UserId;
  23. var requestParam = string.IsNullOrEmpty(dto.BeforeJson) && string.IsNullOrEmpty(dto.AfterJson)
  24. ? null
  25. : System.Text.Json.JsonSerializer.Serialize(new
  26. {
  27. tableName = dto.TableName,
  28. keyValue = dto.KeyValue,
  29. before = dto.BeforeJson,
  30. after = dto.AfterJson
  31. });
  32. await _logOpRep.InsertAsync(new SysLogOp
  33. {
  34. Id = YitIdHelper.NextId(),
  35. DisplayTitle = dto.Action,
  36. ControllerName = dto.TableName,
  37. ActionName = dto.Action,
  38. Message = dto.Content,
  39. RequestParam = requestParam,
  40. LogDateTime = DateTime.Now,
  41. Account = _userManager.Account,
  42. RealName = _userManager.RealName,
  43. CreateUserId = uid,
  44. TenantId = _userManager.TenantId,
  45. Status = "200",
  46. LogLevel = Microsoft.Extensions.Logging.LogLevel.Information,
  47. });
  48. }
  49. catch
  50. {
  51. // 日志失败不抛出
  52. }
  53. }
  54. }