using Admin.NET.Plugin.AiDOP.Dto.S8; using Admin.NET.Plugin.AiDOP.Entity.S8; using Admin.NET.Plugin.AiDOP.Infrastructure; namespace Admin.NET.Plugin.AiDOP.Service.S8; public class S8DetectionLogQueryService : ITransient { private readonly SqlSugarRepository _rep; public S8DetectionLogQueryService(SqlSugarRepository rep) { _rep = rep; } public async Task<(int total, List list)> GetPagedAsync(AdoS8DetectionLogQueryDto q) { (q.Page, q.PageSize) = PagingGuard.Normalize(q.Page, q.PageSize); var query = _rep.AsQueryable() .Where(x => x.TenantId == q.TenantId && x.FactoryId == q.FactoryId && !x.IsDeleted) .WhereIF(!string.IsNullOrWhiteSpace(q.RuleCode), x => x.RuleCode == q.RuleCode) .WhereIF(!string.IsNullOrWhiteSpace(q.RuleType), x => x.RuleType == q.RuleType) .WhereIF(!string.IsNullOrWhiteSpace(q.DetectResult), x => x.DetectResult == q.DetectResult) .WhereIF(q.ExceptionId.HasValue, x => x.ExceptionId == q.ExceptionId!.Value) .WhereIF(!string.IsNullOrWhiteSpace(q.DedupKey), x => x.DedupKey == q.DedupKey) .WhereIF(!string.IsNullOrWhiteSpace(q.SourceObjectType), x => x.SourceObjectType == q.SourceObjectType) .WhereIF(!string.IsNullOrWhiteSpace(q.SourceObjectId), x => x.SourceObjectId == q.SourceObjectId) .WhereIF(!string.IsNullOrWhiteSpace(q.TriggerSource), x => x.TriggerSource == q.TriggerSource) .WhereIF(q.BeginTime.HasValue, x => x.DetectedAt >= q.BeginTime!.Value) .WhereIF(q.EndTime.HasValue, x => x.DetectedAt <= q.EndTime!.Value); var total = await query.CountAsync(); var list = await query .OrderBy(x => x.DetectedAt, OrderByType.Desc) .OrderBy(x => x.Id, OrderByType.Desc) .Select(x => new AdoS8DetectionLogListItemDto { Id = x.Id, TenantId = x.TenantId, FactoryId = x.FactoryId, RunId = x.RunId, RuleId = x.RuleId, RuleCode = x.RuleCode, RuleType = x.RuleType, SceneCode = x.SceneCode, DetectResult = x.DetectResult, ExceptionId = x.ExceptionId, DedupKey = x.DedupKey, SourceObjectType = x.SourceObjectType, SourceObjectId = x.SourceObjectId, RelatedObjectCode = x.RelatedObjectCode, TriggerSource = x.TriggerSource, DetectedAt = x.DetectedAt, CreatedAt = x.CreatedAt, PayloadSnapshot = x.PayloadSnapshot, FailureReason = x.FailureReason, FailureMessage = x.FailureMessage, Remark = x.Remark }) .ToPageListAsync(q.Page, q.PageSize); return (total, list); } }