You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
3.7 KiB
88 lines
3.7 KiB
using X1.Domain.Common;
|
|
using X1.Domain.Repositories.TestCase;
|
|
using Microsoft.Extensions.Logging;
|
|
using MediatR;
|
|
|
|
namespace X1.Application.Features.TestCaseFlow.Queries.GetTestCaseFlows;
|
|
|
|
/// <summary>
|
|
/// 获取测试用例流程列表查询处理器
|
|
/// </summary>
|
|
public class GetTestCaseFlowsQueryHandler : IRequestHandler<GetTestCaseFlowsQuery, OperationResult<GetTestCaseFlowsResponse>>
|
|
{
|
|
private readonly ITestCaseFlowRepository _testCaseFlowRepository;
|
|
private readonly ILogger<GetTestCaseFlowsQueryHandler> _logger;
|
|
|
|
/// <summary>
|
|
/// 初始化查询处理器
|
|
/// </summary>
|
|
public GetTestCaseFlowsQueryHandler(
|
|
ITestCaseFlowRepository testCaseFlowRepository,
|
|
ILogger<GetTestCaseFlowsQueryHandler> logger)
|
|
{
|
|
_testCaseFlowRepository = testCaseFlowRepository;
|
|
_logger = logger;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 处理获取测试用例流程列表查询
|
|
/// </summary>
|
|
public async Task<OperationResult<GetTestCaseFlowsResponse>> Handle(GetTestCaseFlowsQuery request, CancellationToken cancellationToken)
|
|
{
|
|
try
|
|
{
|
|
_logger.LogInformation("开始获取测试用例流程列表,搜索条件: {SearchTerm}, 类型: {Type}, 启用状态: {IsEnabled}, 页码: {PageNumber}, 每页大小: {PageSize}",
|
|
request.SearchTerm, request.Type, request.IsEnabled, request.PageNumber, request.PageSize);
|
|
|
|
// 解析流程类型
|
|
X1.Domain.Entities.TestCase.TestFlowType? flowType = null;
|
|
if (!string.IsNullOrEmpty(request.Type) && Enum.TryParse<X1.Domain.Entities.TestCase.TestFlowType>(request.Type, out var parsedType))
|
|
{
|
|
flowType = parsedType;
|
|
}
|
|
|
|
// 获取分页数据
|
|
var pagedResult = await _testCaseFlowRepository.GetPagedFlowsAsync(
|
|
name: request.SearchTerm,
|
|
type: flowType,
|
|
isEnabled: request.IsEnabled,
|
|
pageNumber: request.PageNumber,
|
|
pageSize: request.PageSize,
|
|
cancellationToken);
|
|
|
|
// 构建响应
|
|
var response = new GetTestCaseFlowsResponse
|
|
{
|
|
TestCaseFlows = pagedResult.Items.Select(flow => new TestCaseFlowDto
|
|
{
|
|
Id = flow.Id,
|
|
Name = flow.Name,
|
|
Description = flow.Description,
|
|
Type = flow.Type.ToString(),
|
|
IsEnabled = flow.IsEnabled,
|
|
ViewportX = flow.ViewportX,
|
|
ViewportY = flow.ViewportY,
|
|
ViewportZoom = flow.ViewportZoom,
|
|
CreatedAt = flow.CreatedAt,
|
|
CreatedBy = flow.CreatedBy,
|
|
UpdatedAt = flow.UpdatedAt,
|
|
UpdatedBy = flow.UpdatedBy
|
|
}).ToList(),
|
|
TotalCount = pagedResult.TotalCount,
|
|
PageNumber = request.PageNumber,
|
|
PageSize = request.PageSize,
|
|
TotalPages = (int)Math.Ceiling((double)pagedResult.TotalCount / request.PageSize)
|
|
};
|
|
|
|
_logger.LogInformation("成功获取测试用例流程列表,总数: {TotalCount}, 当前页: {PageNumber}, 每页大小: {PageSize}",
|
|
response.TotalCount, response.PageNumber, response.PageSize);
|
|
|
|
return OperationResult<GetTestCaseFlowsResponse>.CreateSuccess(response);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "获取测试用例流程列表时发生错误");
|
|
return OperationResult<GetTestCaseFlowsResponse>.CreateFailure("获取测试用例流程列表失败,请稍后重试");
|
|
}
|
|
}
|
|
}
|
|
|