feat(用例管理): 成员属性下拉options

This commit is contained in:
WangXu10 2024-03-15 19:23:10 +08:00 committed by Craftsman
parent bda0fd6e43
commit bca7225a92
3 changed files with 44 additions and 23 deletions

View File

@ -19,6 +19,7 @@ import io.metersphere.project.dto.ModuleCountDTO;
import io.metersphere.project.mapper.ExtBaseProjectVersionMapper;
import io.metersphere.project.mapper.FileAssociationMapper;
import io.metersphere.project.mapper.ProjectApplicationMapper;
import io.metersphere.project.service.ProjectService;
import io.metersphere.project.service.ProjectTemplateService;
import io.metersphere.provider.BaseCaseProvider;
import io.metersphere.sdk.constants.*;
@ -37,6 +38,7 @@ import io.metersphere.system.dto.OperationHistoryDTO;
import io.metersphere.system.dto.request.OperationHistoryRequest;
import io.metersphere.system.dto.sdk.*;
import io.metersphere.system.dto.sdk.request.PosRequest;
import io.metersphere.system.dto.user.UserExtendDTO;
import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.log.dto.LogDTO;
@ -168,6 +170,8 @@ public class FunctionalCaseService {
private CaseReviewHistoryMapper caseReviewHistoryMapper;
@Resource
private FunctionalCaseCommentMapper functionalCaseCommentMapper;
@Resource
private ProjectService projectService;
public FunctionalCase addFunctionalCase(FunctionalCaseAddRequest request, List<MultipartFile> files, String userId, String organizationId) {
String caseId = IDGenerator.nextStr();
@ -454,16 +458,28 @@ public class FunctionalCaseService {
TemplateDTO templateDTO = projectTemplateService.getTemplateDTOById(functionalCase.getTemplateId(), functionalCase.getProjectId(), TemplateScene.FUNCTIONAL.name());
if (CollectionUtils.isNotEmpty(templateDTO.getCustomFields())) {
List<TemplateCustomFieldDTO> customFields = templateDTO.getCustomFields();
List<UserExtendDTO> memberOption = projectService.getMemberOption(functionalCase.getProjectId(), 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();
customFields.forEach(item -> {
FunctionalCaseCustomField caseCustomField = functionalCaseCustomFieldService.getCustomField(item.getFieldId(), functionalCase.getId());
Optional.ofNullable(caseCustomField).ifPresentOrElse(customField -> {
item.setDefaultValue(customField.getValue());
if (Translator.get("custom_field.functional_priority").equals(item.getFieldName())) {
functionalCaseDetailDTO.setFunctionalPriority(customField.getValue());
}
}, () -> {
});
if (StringUtils.equalsAnyIgnoreCase(item.getType(), CustomFieldType.MEMBER.name(), CustomFieldType.MULTIPLE_MEMBER.name())) {
item.setOptions(memberCustomOption);
} else {
FunctionalCaseCustomField caseCustomField = functionalCaseCustomFieldService.getCustomField(item.getFieldId(), functionalCase.getId());
Optional.ofNullable(caseCustomField).ifPresentOrElse(customField -> {
item.setDefaultValue(customField.getValue());
if (Translator.get("custom_field.functional_priority").equals(item.getFieldName())) {
functionalCaseDetailDTO.setFunctionalPriority(customField.getValue());
}
}, () -> {
});
}
});
functionalCaseDetailDTO.setCustomFields(customFields);
}

View File

@ -6,10 +6,7 @@ import io.metersphere.project.domain.ProjectApplication;
import io.metersphere.project.dto.CustomFieldOptions;
import io.metersphere.project.dto.ProjectTemplateDTO;
import io.metersphere.project.dto.ProjectTemplateOptionDTO;
import io.metersphere.sdk.constants.InternalUser;
import io.metersphere.sdk.constants.ProjectApplicationType;
import io.metersphere.sdk.constants.TemplateScene;
import io.metersphere.sdk.constants.TemplateScopeType;
import io.metersphere.sdk.constants.*;
import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.BeanUtils;
import io.metersphere.sdk.util.Translator;
@ -17,6 +14,7 @@ import io.metersphere.system.domain.*;
import io.metersphere.system.dto.ProjectDTO;
import io.metersphere.system.dto.sdk.TemplateDTO;
import io.metersphere.system.dto.sdk.request.TemplateUpdateRequest;
import io.metersphere.system.dto.user.UserExtendDTO;
import io.metersphere.system.mapper.CustomFieldOptionMapper;
import io.metersphere.system.service.BaseTemplateService;
import io.metersphere.system.service.PlatformPluginService;
@ -163,7 +161,22 @@ public class ProjectTemplateService extends BaseTemplateService {
template = getInternalTemplate(projectId, scene);
}
}
return getTemplateDTO(template);
TemplateDTO templateDTO = getTemplateDTO(template);
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();
templateDTO.getCustomFields().forEach(item -> {
if (StringUtils.equalsAnyIgnoreCase(item.getType(), CustomFieldType.MEMBER.name(), CustomFieldType.MULTIPLE_MEMBER.name())) {
item.setOptions(memberCustomOption);
}
});
return templateDTO;
}

View File

@ -388,16 +388,8 @@
const result = customFields.map((item: any) => {
const memberType = ['MEMBER', 'MULTIPLE_MEMBER'];
let initValue = item.defaultValue;
let optionsValue: OptionsFieldId[] = item.options;
const optionsValue: OptionsFieldId[] = item.options;
if (memberType.includes(item.type)) {
optionsValue = [
{
fieldId: item.fieldId,
internal: item.internal,
text: userStore.name || '',
value: userStore.id || '',
},
];
if (item.defaultValue === 'CREATE_USER' || item.defaultValue.includes('CREATE_USER')) {
initValue = item.type === 'MEMBER' ? userStore.id : [userStore.id];
}