Browse Source
- 新增GET /api/casestepconfigs/form-type-step-type-mapping端点 - 实现表单类型到步骤类型映射查询功能 - 遵循现有控制器模式,使用MediatR和CQRS架构 - 添加完整的日志记录和错误处理 - 返回OperationResult<GetFormTypeStepTypeResponse>统一格式 - 支持前端获取表单类型和步骤类型的映射关系 Closes: 表单类型映射查询功能需求release/web-ui-v1.0.0
23 changed files with 2641 additions and 4 deletions
@ -0,0 +1,11 @@ |
|||||
|
using MediatR; |
||||
|
using X1.Domain.Common; |
||||
|
|
||||
|
namespace X1.Application.Features.CaseStepConfigs.Queries.GetFormTypeStepTypeMapping; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 获取表单类型到步骤类型映射查询
|
||||
|
/// </summary>
|
||||
|
public class GetFormTypeStepTypeQuery : IRequest<OperationResult<GetFormTypeStepTypeResponse>> |
||||
|
{ |
||||
|
} |
||||
@ -0,0 +1,48 @@ |
|||||
|
using MediatR; |
||||
|
using X1.Domain.Common; |
||||
|
|
||||
|
namespace X1.Application.Features.CaseStepConfigs.Queries.GetFormTypeStepTypeMapping; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 获取表单类型到步骤类型映射查询处理器
|
||||
|
/// </summary>
|
||||
|
public class GetFormTypeStepTypeQueryHandler : IRequestHandler<GetFormTypeStepTypeQuery, OperationResult<GetFormTypeStepTypeResponse>> |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 处理查询
|
||||
|
/// </summary>
|
||||
|
/// <param name="request">查询请求</param>
|
||||
|
/// <param name="cancellationToken">取消令牌</param>
|
||||
|
/// <returns>操作结果</returns>
|
||||
|
public async Task<OperationResult<GetFormTypeStepTypeResponse>> Handle(GetFormTypeStepTypeQuery request, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
try |
||||
|
{ |
||||
|
// 构建响应对象
|
||||
|
var response = new GetFormTypeStepTypeResponse(); |
||||
|
|
||||
|
// 获取表单类型列表
|
||||
|
response.FormTypes = FormTypeStepTypeConverter.GetFormTypes().Select(ft => new FormTypeDto |
||||
|
{ |
||||
|
Value = ft.Value, |
||||
|
Name = ft.Name, |
||||
|
Description = ft.Description |
||||
|
}).ToList(); |
||||
|
|
||||
|
// 获取步骤类型列表
|
||||
|
response.StepTypes = FormTypeStepTypeConverter.GetStepTypes().Select(st => new StepTypeDto |
||||
|
{ |
||||
|
Value = st.Value, |
||||
|
Name = st.Name, |
||||
|
Description = st.Description |
||||
|
}).ToList(); |
||||
|
|
||||
|
|
||||
|
return await Task.FromResult(OperationResult<GetFormTypeStepTypeResponse>.CreateSuccess(response)); |
||||
|
} |
||||
|
catch (Exception ex) |
||||
|
{ |
||||
|
return await Task.FromResult(OperationResult<GetFormTypeStepTypeResponse>.CreateFailure($"获取映射信息失败: {ex.Message}")); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,100 @@ |
|||||
|
namespace X1.Application.Features.CaseStepConfigs.Queries.GetFormTypeStepTypeMapping; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 获取表单类型到步骤类型映射响应
|
||||
|
/// </summary>
|
||||
|
public class GetFormTypeStepTypeResponse |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 表单类型列表
|
||||
|
/// </summary>
|
||||
|
public List<FormTypeDto> FormTypes { get; set; } = new(); |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 步骤类型列表
|
||||
|
/// </summary>
|
||||
|
public List<StepTypeDto> StepTypes { get; set; } = new(); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 表单类型DTO
|
||||
|
/// </summary>
|
||||
|
public class FormTypeDto |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 表单类型值
|
||||
|
/// </summary>
|
||||
|
public int Value { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 表单类型名称
|
||||
|
/// </summary>
|
||||
|
public string Name { get; set; } = null!; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 表单类型描述
|
||||
|
/// </summary>
|
||||
|
public string Description { get; set; } = null!; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 步骤类型DTO
|
||||
|
/// </summary>
|
||||
|
public class StepTypeDto |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 步骤类型值
|
||||
|
/// </summary>
|
||||
|
public int Value { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 步骤类型名称
|
||||
|
/// </summary>
|
||||
|
public string Name { get; set; } = null!; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 步骤类型描述
|
||||
|
/// </summary>
|
||||
|
public string Description { get; set; } = null!; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 映射关系DTO
|
||||
|
/// </summary>
|
||||
|
public class MappingDto |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 表单类型
|
||||
|
/// </summary>
|
||||
|
public int FormType { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 表单类型名称
|
||||
|
/// </summary>
|
||||
|
public string FormTypeName { get; set; } = null!; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 表单类型描述
|
||||
|
/// </summary>
|
||||
|
public string FormTypeDescription { get; set; } = null!; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 推荐步骤类型
|
||||
|
/// </summary>
|
||||
|
public int RecommendedStepType { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 推荐步骤类型名称
|
||||
|
/// </summary>
|
||||
|
public string RecommendedStepTypeName { get; set; } = null!; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 推荐步骤类型描述
|
||||
|
/// </summary>
|
||||
|
public string RecommendedStepTypeDescription { get; set; } = null!; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 支持的步骤类型列表
|
||||
|
/// </summary>
|
||||
|
public List<StepTypeDto> SupportedStepTypes { get; set; } = new(); |
||||
|
} |
||||
@ -0,0 +1,22 @@ |
|||||
|
namespace X1.Domain.Common; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 枚举项值对象
|
||||
|
/// </summary>
|
||||
|
public class EnumValueObject |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 枚举值
|
||||
|
/// </summary>
|
||||
|
public int Value { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 枚举名称
|
||||
|
/// </summary>
|
||||
|
public string Name { get; set; } = string.Empty; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 枚举描述
|
||||
|
/// </summary>
|
||||
|
public string Description { get; set; } = string.Empty; |
||||
|
} |
||||
@ -0,0 +1,140 @@ |
|||||
|
using X1.Domain.Entities.TestCase; |
||||
|
|
||||
|
namespace X1.Domain.Common; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 表单类型到步骤类型转换器
|
||||
|
/// </summary>
|
||||
|
public static class FormTypeStepTypeConverter |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 根据表单类型获取推荐的步骤类型
|
||||
|
/// </summary>
|
||||
|
/// <param name="formType">表单类型</param>
|
||||
|
/// <returns>推荐的步骤类型</returns>
|
||||
|
public static CaseStepType GetRecommendedStepType(FormType formType) |
||||
|
{ |
||||
|
return formType switch |
||||
|
{ |
||||
|
FormType.None => CaseStepType.Process, |
||||
|
FormType.Registration => CaseStepType.Process, |
||||
|
FormType.Ping => CaseStepType.Process, |
||||
|
FormType.Iperf => CaseStepType.Process, |
||||
|
FormType.Call => CaseStepType.Process, |
||||
|
_ => CaseStepType.Process |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 获取表单类型与步骤类型的映射关系
|
||||
|
/// </summary>
|
||||
|
/// <returns>表单类型到步骤类型的映射字典</returns>
|
||||
|
public static Dictionary<FormType, CaseStepType> GetFormTypeToStepTypeMapping() |
||||
|
{ |
||||
|
return new Dictionary<FormType, CaseStepType> |
||||
|
{ |
||||
|
{ FormType.None, CaseStepType.Process }, |
||||
|
{ FormType.Registration, CaseStepType.Process }, |
||||
|
{ FormType.Ping, CaseStepType.Process }, |
||||
|
{ FormType.Iperf, CaseStepType.Process }, |
||||
|
{ FormType.Call, CaseStepType.Process } |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 获取步骤类型支持的表单类型列表
|
||||
|
/// </summary>
|
||||
|
/// <param name="stepType">步骤类型</param>
|
||||
|
/// <returns>支持的表单类型列表</returns>
|
||||
|
public static List<FormType> GetSupportedFormTypes(CaseStepType stepType) |
||||
|
{ |
||||
|
return stepType switch |
||||
|
{ |
||||
|
CaseStepType.Start => new List<FormType> { FormType.None }, |
||||
|
CaseStepType.End => new List<FormType> { FormType.None }, |
||||
|
CaseStepType.Process => new List<FormType> |
||||
|
{ |
||||
|
FormType.None, |
||||
|
FormType.Registration, |
||||
|
FormType.Ping, |
||||
|
FormType.Iperf, |
||||
|
FormType.Call |
||||
|
}, |
||||
|
CaseStepType.Decision => new List<FormType> { FormType.None }, |
||||
|
_ => new List<FormType> { FormType.None } |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 检查表单类型是否与步骤类型兼容
|
||||
|
/// </summary>
|
||||
|
/// <param name="formType">表单类型</param>
|
||||
|
/// <param name="stepType">步骤类型</param>
|
||||
|
/// <returns>是否兼容</returns>
|
||||
|
public static bool IsCompatible(FormType formType, CaseStepType stepType) |
||||
|
{ |
||||
|
var supportedFormTypes = GetSupportedFormTypes(stepType); |
||||
|
return supportedFormTypes.Contains(formType); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 获取所有表单类型及其描述
|
||||
|
/// </summary>
|
||||
|
/// <returns>表单类型描述字典</returns>
|
||||
|
public static Dictionary<FormType, string> GetFormTypeDescriptions() |
||||
|
{ |
||||
|
return new Dictionary<FormType, string> |
||||
|
{ |
||||
|
{ FormType.None, "无表单" }, |
||||
|
{ FormType.Registration, "注册表单" }, |
||||
|
{ FormType.Ping, "Ping表单" }, |
||||
|
{ FormType.Iperf, "iperf表单" }, |
||||
|
{ FormType.Call, "打电话表单" } |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 获取所有步骤类型及其描述
|
||||
|
/// </summary>
|
||||
|
/// <returns>步骤类型描述字典</returns>
|
||||
|
public static Dictionary<CaseStepType, string> GetStepTypeDescriptions() |
||||
|
{ |
||||
|
return new Dictionary<CaseStepType, string> |
||||
|
{ |
||||
|
{ CaseStepType.Start, "开始步骤" }, |
||||
|
{ CaseStepType.End, "结束步骤" }, |
||||
|
{ CaseStepType.Process, "处理步骤" }, |
||||
|
{ CaseStepType.Decision, "判断步骤" } |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 获取所有表单类型列表
|
||||
|
/// </summary>
|
||||
|
/// <returns>表单类型列表</returns>
|
||||
|
public static List<EnumValueObject> GetFormTypes() |
||||
|
{ |
||||
|
var formTypeDescriptions = GetFormTypeDescriptions(); |
||||
|
return formTypeDescriptions.Select(kvp => new EnumValueObject |
||||
|
{ |
||||
|
Value = (int)kvp.Key, |
||||
|
Name = kvp.Key.ToString(), |
||||
|
Description = kvp.Value |
||||
|
}).ToList(); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 获取所有步骤类型列表
|
||||
|
/// </summary>
|
||||
|
/// <returns>步骤类型列表</returns>
|
||||
|
public static List<EnumValueObject> GetStepTypes() |
||||
|
{ |
||||
|
var stepTypeDescriptions = GetStepTypeDescriptions(); |
||||
|
return stepTypeDescriptions.Select(kvp => new EnumValueObject |
||||
|
{ |
||||
|
Value = (int)kvp.Key, |
||||
|
Name = kvp.Key.ToString(), |
||||
|
Description = kvp.Value |
||||
|
}).ToList(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,32 @@ |
|||||
|
namespace X1.Domain.Entities.TestCase; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 表单类型枚举
|
||||
|
/// </summary>
|
||||
|
public enum FormType |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 无表单
|
||||
|
/// </summary>
|
||||
|
None = 0, |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 注册表单
|
||||
|
/// </summary>
|
||||
|
Registration = 1, |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Ping表单
|
||||
|
/// </summary>
|
||||
|
Ping = 2, |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// iperf表单
|
||||
|
/// </summary>
|
||||
|
Iperf = 3, |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 打电话表单
|
||||
|
/// </summary>
|
||||
|
Call = 4 |
||||
|
} |
||||
File diff suppressed because it is too large
@ -0,0 +1,29 @@ |
|||||
|
using Microsoft.EntityFrameworkCore.Migrations; |
||||
|
|
||||
|
#nullable disable |
||||
|
|
||||
|
namespace X1.Infrastructure.Migrations |
||||
|
{ |
||||
|
/// <inheritdoc />
|
||||
|
public partial class AddFormTypeToCaseStepConfig : Migration |
||||
|
{ |
||||
|
/// <inheritdoc />
|
||||
|
protected override void Up(MigrationBuilder migrationBuilder) |
||||
|
{ |
||||
|
migrationBuilder.AddColumn<int>( |
||||
|
name: "formtype", |
||||
|
table: "tb_casestepconfig", |
||||
|
type: "integer", |
||||
|
nullable: false, |
||||
|
defaultValue: 0); |
||||
|
} |
||||
|
|
||||
|
/// <inheritdoc />
|
||||
|
protected override void Down(MigrationBuilder migrationBuilder) |
||||
|
{ |
||||
|
migrationBuilder.DropColumn( |
||||
|
name: "formtype", |
||||
|
table: "tb_casestepconfig"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue