曲线回读+测试报告导出前期工作
This commit is contained in:
69
Service/Implement/TestReportService.cs
Normal file
69
Service/Implement/TestReportService.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using Model;
|
||||
using Model.Entity;
|
||||
using Model.Models;
|
||||
using ORM;
|
||||
using Service.Interface;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Formats.Asn1.AsnWriter;
|
||||
|
||||
namespace Service.Implement
|
||||
{
|
||||
public class TestReportService : BaseService<TestReportEntity>, ITestReportService
|
||||
{
|
||||
public TestReportService(SqlSugarRepository<TestReportEntity> repository) : base(repository)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据 TestRoundId 获取符合条件的测试步骤
|
||||
/// </summary>
|
||||
public async Task<Result<List<TestReportEntity>>> GetByTestRoundIdAsync(Guid testRoundId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = await _repository.Entities
|
||||
.Where(x => x.TestRoundId == testRoundId)
|
||||
.ToListAsync();
|
||||
|
||||
return Result<List<TestReportEntity>>.Success(list);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Result<List<TestReportEntity>>.Error("根据 TestRoundId 查询数据失败", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据 TestRoundId 分组,获取唯一记录并按分组统计最大与最小时间
|
||||
/// </summary>
|
||||
public async Task<Result<IList<TestReportModel>>> GetFilterList()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 使用 SqlSugar 的 GroupBy 查询,聚合最大/最小时间
|
||||
// 推荐采用这种按组投影的方式,将分组计算交由数据库处理,性能最佳
|
||||
var list = await _repository.Context.Queryable<TestReportEntity>()
|
||||
.GroupBy(x => x.TestRoundId)
|
||||
.Select(x => new TestReportModel
|
||||
{
|
||||
TestRoundId = x.TestRoundId,
|
||||
StartTime = SqlFunc.AggregateMin(x.CreateTime),
|
||||
EndTime = SqlFunc.AggregateMax(x.CreateTime),
|
||||
Scope=x.Scope,
|
||||
FileName = x.FileName,
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
return Result<IList<TestReportModel>>.Success(list);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Result<IList<TestReportModel>>.Error("获取分组过滤列表失败", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
26
Service/Interface/ITestReportService.cs
Normal file
26
Service/Interface/ITestReportService.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Model;
|
||||
using Model.Entity;
|
||||
using Model.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Service.Interface
|
||||
{
|
||||
public interface ITestReportService:IBaseService<TestReportEntity>
|
||||
{
|
||||
/// <summary>
|
||||
/// 根据TestRoundId获符合的测试步骤
|
||||
/// </summary>
|
||||
/// <param name="TestRoundId">TestRoundId</param>
|
||||
/// <returns>返回符合的TestReportEntity列表</returns>
|
||||
Task<Result<List<TestReportEntity>>> GetByTestRoundIdAsync(Guid TestRoundId);
|
||||
|
||||
/// <summary>
|
||||
/// 根据 TestRoundId 分组,获取唯一记录并按分组统计最大与最小时间
|
||||
/// </summary>
|
||||
Task<Result<IList<TestReportModel>>> GetFilterList();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user