refactor(用例管理): 用例列表返回成员options

This commit is contained in:
WangXu10 2024-04-03 15:13:57 +08:00 committed by Craftsman
parent e067d7db1e
commit c5452f2cbb
3 changed files with 25 additions and 16 deletions

View File

@ -33,7 +33,7 @@ public class AssociateCaseProvider implements BaseAssociateCaseProvider {
return new ArrayList<>(); return new ArrayList<>();
} }
List<String> ids = functionalCases.stream().map(TestCaseProviderDTO::getId).toList(); List<String> ids = functionalCases.stream().map(TestCaseProviderDTO::getId).toList();
Map<String, List<FunctionalCaseCustomFieldDTO>> caseCustomFiledMap = functionalCaseService.getCaseCustomFiledMap(ids); Map<String, List<FunctionalCaseCustomFieldDTO>> caseCustomFiledMap = functionalCaseService.getCaseCustomFiledMap(ids,testCasePageProviderRequest.getProjectId());
functionalCases.forEach(functionalCase -> { functionalCases.forEach(functionalCase -> {
List<FunctionalCaseCustomFieldDTO> customFields = caseCustomFiledMap.get(functionalCase.getId()); List<FunctionalCaseCustomFieldDTO> customFields = caseCustomFiledMap.get(functionalCase.getId());
Optional<FunctionalCaseCustomFieldDTO> priorityField = customFields.stream().filter(field -> StringUtils.equals(Translator.get("custom_field.functional_priority"), field.getFieldName())).findFirst(); Optional<FunctionalCaseCustomFieldDTO> priorityField = customFields.stream().filter(field -> StringUtils.equals(Translator.get("custom_field.functional_priority"), field.getFieldName())).findFirst();

View File

@ -166,7 +166,7 @@ public class FunctionalCaseMinderService {
baseTreeNodes.remove(0); baseTreeNodes.remove(0);
} }
//自定义字段 //自定义字段
Map<String, List<FunctionalCaseCustomFieldDTO>> caseCustomFiledMap = functionalCaseService.getCaseCustomFiledMap(caseIds); Map<String, List<FunctionalCaseCustomFieldDTO>> caseCustomFiledMap = functionalCaseService.getCaseCustomFiledMap(caseIds,request.getProjectId());
//构建返回数据主层级应与模块树层级相同 //构建返回数据主层级应与模块树层级相同
MinderSearchDTO minderSearchDTO = new MinderSearchDTO(); MinderSearchDTO minderSearchDTO = new MinderSearchDTO();
minderSearchDTO.setBaseTreeNodes(baseTreeNodes); minderSearchDTO.setBaseTreeNodes(baseTreeNodes);

View File

@ -460,20 +460,11 @@ public class FunctionalCaseService {
TemplateDTO templateDTO = projectTemplateService.getTemplateDTOById(functionalCase.getTemplateId(), functionalCase.getProjectId(), TemplateScene.FUNCTIONAL.name()); TemplateDTO templateDTO = projectTemplateService.getTemplateDTOById(functionalCase.getTemplateId(), functionalCase.getProjectId(), TemplateScene.FUNCTIONAL.name());
if (CollectionUtils.isNotEmpty(templateDTO.getCustomFields())) { if (CollectionUtils.isNotEmpty(templateDTO.getCustomFields())) {
List<TemplateCustomFieldDTO> customFields = templateDTO.getCustomFields(); List<TemplateCustomFieldDTO> customFields = templateDTO.getCustomFields();
List<UserExtendDTO> memberOption = projectService.getMemberOption(functionalCase.getProjectId(), null); List<CustomFieldOption> memberCustomOption = getMemberOptions(functionalCase.getProjectId());
List<CustomFieldOption> memberCustomOption = memberOption.stream().map(option -> {
CustomFieldOption customFieldOption = new CustomFieldOption();
customFieldOption.setFieldId(option.getId());
customFieldOption.setValue(option.getId());
customFieldOption.setInternal(false);
customFieldOption.setText(option.getName());
return customFieldOption;
}).toList();
customFields.forEach(item -> { customFields.forEach(item -> {
if (StringUtils.equalsAnyIgnoreCase(item.getType(), CustomFieldType.MEMBER.name(), CustomFieldType.MULTIPLE_MEMBER.name())) { if (StringUtils.equalsAnyIgnoreCase(item.getType(), CustomFieldType.MEMBER.name(), CustomFieldType.MULTIPLE_MEMBER.name())) {
item.setOptions(memberCustomOption); item.setOptions(memberCustomOption);
} }
;
FunctionalCaseCustomField caseCustomField = functionalCaseCustomFieldService.getCustomField(item.getFieldId(), functionalCase.getId()); FunctionalCaseCustomField caseCustomField = functionalCaseCustomFieldService.getCustomField(item.getFieldId(), functionalCase.getId());
Optional.ofNullable(caseCustomField).ifPresentOrElse(customField -> { Optional.ofNullable(caseCustomField).ifPresentOrElse(customField -> {
item.setDefaultValue(customField.getValue()); item.setDefaultValue(customField.getValue());
@ -483,10 +474,24 @@ public class FunctionalCaseService {
}, () -> { }, () -> {
}); });
}); });
functionalCaseDetailDTO.setCustomFields(customFields); functionalCaseDetailDTO.setCustomFields(customFields);
} }
} }
private List<CustomFieldOption> getMemberOptions(String projectId) {
List<UserExtendDTO> memberOption = projectService.getMemberOption(projectId, null);
List<CustomFieldOption> memberCustomOption = memberOption.stream().map(option -> {
CustomFieldOption customFieldOption = new CustomFieldOption();
customFieldOption.setFieldId(option.getId());
customFieldOption.setValue(option.getId());
customFieldOption.setInternal(false);
customFieldOption.setText(option.getName());
return customFieldOption;
}).toList();
return memberCustomOption;
}
/** /**
* 更新用例 基本信息 * 更新用例 基本信息
@ -669,12 +674,12 @@ public class FunctionalCaseService {
return new ArrayList<>(); return new ArrayList<>();
} }
//处理自定义字段值 //处理自定义字段值
return handleCustomFields(functionalCaseLists); return handleCustomFields(functionalCaseLists, request.getProjectId());
} }
private List<FunctionalCasePageDTO> handleCustomFields(List<FunctionalCasePageDTO> functionalCaseLists) { private List<FunctionalCasePageDTO> handleCustomFields(List<FunctionalCasePageDTO> functionalCaseLists,String projectId) {
List<String> ids = functionalCaseLists.stream().map(FunctionalCasePageDTO::getId).collect(Collectors.toList()); List<String> ids = functionalCaseLists.stream().map(FunctionalCasePageDTO::getId).collect(Collectors.toList());
Map<String, List<FunctionalCaseCustomFieldDTO>> collect = getCaseCustomFiledMap(ids); Map<String, List<FunctionalCaseCustomFieldDTO>> collect = getCaseCustomFiledMap(ids,projectId);
Set<String> userIds = extractUserIds(functionalCaseLists); Set<String> userIds = extractUserIds(functionalCaseLists);
Map<String, String> userMap = userLoginService.getUserNameMap(new ArrayList<>(userIds)); Map<String, String> userMap = userLoginService.getUserNameMap(new ArrayList<>(userIds));
functionalCaseLists.forEach(functionalCasePageDTO -> { functionalCaseLists.forEach(functionalCasePageDTO -> {
@ -693,9 +698,13 @@ public class FunctionalCaseService {
.collect(Collectors.toSet()); .collect(Collectors.toSet());
} }
public Map<String, List<FunctionalCaseCustomFieldDTO>> getCaseCustomFiledMap(List<String> ids) { public Map<String, List<FunctionalCaseCustomFieldDTO>> getCaseCustomFiledMap(List<String> ids,String projectId) {
List<CustomFieldOption> memberCustomOption = getMemberOptions(projectId);
List<FunctionalCaseCustomFieldDTO> customFields = functionalCaseCustomFieldService.getCustomFieldsByCaseIds(ids); List<FunctionalCaseCustomFieldDTO> customFields = functionalCaseCustomFieldService.getCustomFieldsByCaseIds(ids);
customFields.forEach(customField -> { customFields.forEach(customField -> {
if (StringUtils.equalsAnyIgnoreCase(customField.getType(), CustomFieldType.MEMBER.name(), CustomFieldType.MULTIPLE_MEMBER.name())) {
customField.setOptions(memberCustomOption);
}
if (customField.getInternal()) { if (customField.getInternal()) {
customField.setFieldName(baseCustomFieldService.translateInternalField(customField.getFieldName())); customField.setFieldName(baseCustomFieldService.translateInternalField(customField.getFieldName()));
} }