S8DetectionLogQueryService.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using Admin.NET.Plugin.AiDOP.Dto.S8;
  2. using Admin.NET.Plugin.AiDOP.Entity.S8;
  3. using Admin.NET.Plugin.AiDOP.Infrastructure;
  4. namespace Admin.NET.Plugin.AiDOP.Service.S8;
  5. public class S8DetectionLogQueryService : ITransient
  6. {
  7. private readonly SqlSugarRepository<AdoS8DetectionLog> _rep;
  8. public S8DetectionLogQueryService(SqlSugarRepository<AdoS8DetectionLog> rep)
  9. {
  10. _rep = rep;
  11. }
  12. public async Task<(int total, List<AdoS8DetectionLogListItemDto> list)> GetPagedAsync(AdoS8DetectionLogQueryDto q)
  13. {
  14. (q.Page, q.PageSize) = PagingGuard.Normalize(q.Page, q.PageSize);
  15. var query = _rep.AsQueryable()
  16. .Where(x => x.TenantId == q.TenantId && x.FactoryId == q.FactoryId && !x.IsDeleted)
  17. .WhereIF(!string.IsNullOrWhiteSpace(q.RuleCode), x => x.RuleCode == q.RuleCode)
  18. .WhereIF(!string.IsNullOrWhiteSpace(q.RuleType), x => x.RuleType == q.RuleType)
  19. .WhereIF(!string.IsNullOrWhiteSpace(q.DetectResult), x => x.DetectResult == q.DetectResult)
  20. .WhereIF(q.ExceptionId.HasValue, x => x.ExceptionId == q.ExceptionId!.Value)
  21. .WhereIF(!string.IsNullOrWhiteSpace(q.DedupKey), x => x.DedupKey == q.DedupKey)
  22. .WhereIF(!string.IsNullOrWhiteSpace(q.SourceObjectType), x => x.SourceObjectType == q.SourceObjectType)
  23. .WhereIF(!string.IsNullOrWhiteSpace(q.SourceObjectId), x => x.SourceObjectId == q.SourceObjectId)
  24. .WhereIF(!string.IsNullOrWhiteSpace(q.TriggerSource), x => x.TriggerSource == q.TriggerSource)
  25. .WhereIF(q.BeginTime.HasValue, x => x.DetectedAt >= q.BeginTime!.Value)
  26. .WhereIF(q.EndTime.HasValue, x => x.DetectedAt <= q.EndTime!.Value);
  27. var total = await query.CountAsync();
  28. var list = await query
  29. .OrderBy(x => x.DetectedAt, OrderByType.Desc)
  30. .OrderBy(x => x.Id, OrderByType.Desc)
  31. .Select(x => new AdoS8DetectionLogListItemDto
  32. {
  33. Id = x.Id,
  34. TenantId = x.TenantId,
  35. FactoryId = x.FactoryId,
  36. RunId = x.RunId,
  37. RuleId = x.RuleId,
  38. RuleCode = x.RuleCode,
  39. RuleType = x.RuleType,
  40. SceneCode = x.SceneCode,
  41. DetectResult = x.DetectResult,
  42. ExceptionId = x.ExceptionId,
  43. DedupKey = x.DedupKey,
  44. SourceObjectType = x.SourceObjectType,
  45. SourceObjectId = x.SourceObjectId,
  46. RelatedObjectCode = x.RelatedObjectCode,
  47. TriggerSource = x.TriggerSource,
  48. DetectedAt = x.DetectedAt,
  49. CreatedAt = x.CreatedAt,
  50. PayloadSnapshot = x.PayloadSnapshot,
  51. FailureReason = x.FailureReason,
  52. FailureMessage = x.FailureMessage,
  53. Remark = x.Remark
  54. })
  55. .ToPageListAsync(q.Page, q.PageSize);
  56. return (total, list);
  57. }
  58. }