完善数据报表模块
This commit is contained in:
@@ -38,22 +38,35 @@ namespace Service.Implement
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据 TestRoundId 分组,获取唯一记录并按分组统计最大与最小时间
|
||||
/// 根据 TestRoundId 分组,获取唯一记录并按分组统计最大与最小时间,
|
||||
/// 支持按日期范围与台架名称筛选。
|
||||
/// </summary>
|
||||
public async Task<Result<IList<TestReportModel>>> GetFilterList()
|
||||
public async Task<Result<IList<TestReportModel>>> GetFilterList(DateTime? startTime = null, DateTime? endTime = null, string? scope = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 使用 SqlSugar 的 GroupBy 查询,聚合最大/最小时间
|
||||
// 推荐采用这种按组投影的方式,将分组计算交由数据库处理,性能最佳
|
||||
var list = await _repository.Context.Queryable<TestReportEntity>()
|
||||
var query = _repository.Context.Queryable<TestReportEntity>();
|
||||
|
||||
// 日期范围筛选
|
||||
if (startTime.HasValue)
|
||||
query = query.Where(x => x.CreateTime >= startTime.Value);
|
||||
if (endTime.HasValue)
|
||||
query = query.Where(x => x.CreateTime <= endTime.Value);
|
||||
|
||||
// 台架名称筛选
|
||||
if (!string.IsNullOrEmpty(scope))
|
||||
query = query.Where(x => x.Scope == scope);
|
||||
|
||||
var list = await query
|
||||
.GroupBy(x => x.TestRoundId)
|
||||
.Select(x => new TestReportModel
|
||||
{
|
||||
TestRoundId = x.TestRoundId,
|
||||
StartTime = SqlFunc.AggregateMin(x.CreateTime),
|
||||
EndTime = SqlFunc.AggregateMax(x.CreateTime),
|
||||
Scope=x.Scope,
|
||||
Scope = x.Scope,
|
||||
FileName = x.FileName,
|
||||
})
|
||||
.ToListAsync();
|
||||
@@ -65,5 +78,32 @@ namespace Service.Implement
|
||||
return Result<IList<TestReportModel>>.Error("获取分组过滤列表失败", ex);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据日期和台架名称筛选获取完整的测试步骤实体列表(无分组,用于导出)
|
||||
/// </summary>
|
||||
public async Task<Result<List<TestReportEntity>>> GetEntitiesByFilter(DateTime? startTime = null, DateTime? endTime = null, string? scope = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var query = _repository.Context.Queryable<TestReportEntity>();
|
||||
|
||||
if (startTime.HasValue)
|
||||
query = query.Where(x => x.CreateTime >= startTime.Value);
|
||||
if (endTime.HasValue)
|
||||
query = query.Where(x => x.CreateTime <= endTime.Value);
|
||||
if (!string.IsNullOrEmpty(scope))
|
||||
query = query.Where(x => x.Scope == scope);
|
||||
|
||||
var list = await query
|
||||
.OrderBy(x => x.CreateTime)
|
||||
.ToListAsync();
|
||||
|
||||
return Result<List<TestReportEntity>>.Success(list);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Result<List<TestReportEntity>>.Error("获取导出数据失败", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user