refactor(消息管理): 获取模版列表接口内容国际化

This commit is contained in:
guoyuqi 2023-10-23 14:29:11 +08:00 committed by 刘瑞斌
parent 889ac1d1f9
commit a0165f2dd6
1 changed files with 17 additions and 11 deletions

View File

@ -44,52 +44,52 @@ public class NoticeTemplateService {
switch (taskType) {
case NoticeConstants.TaskType.API_DEFINITION_TASK -> {
Field[] allFields = FieldUtils.getAllFields(ApiDefinitionCaseDTO.class);
addOptionDto(messageTemplateFieldDTOList, allFields);
addOptionDto(messageTemplateFieldDTOList, allFields, null);
addCustomFiled(messageTemplateFieldDTOList, projectId, TemplateScene.API.toString());
//TODO获取报告
}
case NoticeConstants.TaskType.API_SCENARIO_TASK -> {
Field[] allFields = FieldUtils.getAllFields(ApiScenario.class);
addOptionDto(messageTemplateFieldDTOList, allFields);
addOptionDto(messageTemplateFieldDTOList, allFields, "api_scenario_");
//TODO获取报告
}
case NoticeConstants.TaskType.TEST_PLAN_TASK -> {
Field[] allFields = FieldUtils.getAllFields(TestPlan.class);
addOptionDto(messageTemplateFieldDTOList, allFields);
addOptionDto(messageTemplateFieldDTOList, allFields, "test_plan_");
addCustomFiled(messageTemplateFieldDTOList, projectId, TemplateScene.TEST_PLAN.toString());
//TODO获取报告
}
case NoticeConstants.TaskType.CASE_REVIEW_TASK -> {
Field[] allFields = FieldUtils.getAllFields(CaseReview.class);
addOptionDto(messageTemplateFieldDTOList, allFields);
addOptionDto(messageTemplateFieldDTOList, allFields, "case_review_");
//TODO获取报告
}
case NoticeConstants.TaskType.FUNCTIONAL_CASE_TASK -> {
Field[] allFields = FieldUtils.getAllFields(FunctionalCaseMessageDTO.class);
addOptionDto(messageTemplateFieldDTOList, allFields);
addOptionDto(messageTemplateFieldDTOList, allFields, null);
addCustomFiled(messageTemplateFieldDTOList, projectId, TemplateScene.FUNCTIONAL.toString());
//TODO获取报告
}
case NoticeConstants.TaskType.BUG_TASK -> {
Field[] allFields = FieldUtils.getAllFields(Bug.class);
addOptionDto(messageTemplateFieldDTOList, allFields);
addOptionDto(messageTemplateFieldDTOList, allFields, "bug_");
addCustomFiled(messageTemplateFieldDTOList, projectId, TemplateScene.BUG.toString());
//TODO获取报告
}
case NoticeConstants.TaskType.UI_SCENARIO_TASK -> {
Field[] allFields = FieldUtils.getAllFields(UiScenario.class);
addOptionDto(messageTemplateFieldDTOList, allFields);
addOptionDto(messageTemplateFieldDTOList, allFields, "ui_");
addCustomFiled(messageTemplateFieldDTOList, projectId, TemplateScene.UI.toString());
//TODO获取报告
}
case NoticeConstants.TaskType.LOAD_TEST_TASK -> {
Field[] allFields = FieldUtils.getAllFields(LoadTest.class);
addOptionDto(messageTemplateFieldDTOList, allFields);
addOptionDto(messageTemplateFieldDTOList, allFields, "load_");
//TODO获取报告
}
case NoticeConstants.TaskType.SCHEDULE_TASK -> {
Field[] allFields = FieldUtils.getAllFields(Schedule.class);
addOptionDto(messageTemplateFieldDTOList, allFields);
addOptionDto(messageTemplateFieldDTOList, allFields, "schedule_");
//TODO获取报告
}
case NoticeConstants.TaskType.JENKINS_TASK -> {
@ -132,7 +132,7 @@ public class NoticeTemplateService {
* @param messageTemplateFieldDTOS messageTemplateFieldDTOS
* @param allFields allFields
*/
private static void addOptionDto(List<MessageTemplateFieldDTO> messageTemplateFieldDTOS, Field[] allFields) {
private static void addOptionDto(List<MessageTemplateFieldDTO> messageTemplateFieldDTOS, Field[] allFields, String tableName) {
Field[] sensitiveFields = FieldUtils.getAllFields(NoticeConstants.SensitiveField.class);
ArrayList<Field> sensitiveFieldList = new ArrayList<>(sensitiveFields.length);
Collections.addAll(sensitiveFieldList, sensitiveFields);
@ -146,7 +146,12 @@ public class NoticeTemplateService {
Schema annotation = allField.getAnnotation(Schema.class);
if (annotation != null) {
messageTemplateFieldDTO.setId(allField.getName());
String description = annotation.description();
String description;
if (StringUtils.isBlank(tableName)) {
description = Translator.get(annotation.description());
} else {
description = Translator.get("message.domain." + tableName + allField.getName());
}
messageTemplateFieldDTO.setName(description);
messageTemplateFieldDTO.setFieldSource(NoticeConstants.FieldSource.CASE_FIELD);
messageTemplateFieldDTOS.add(messageTemplateFieldDTO);
@ -184,4 +189,5 @@ public class NoticeTemplateService {
messageTemplateResultDTO.setFieldSourceList(optionDTOList);
return messageTemplateResultDTO;
}
}