From bca7225a926e55710d0ec7ec50ec639bbc651434 Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Fri, 15 Mar 2024 19:23:10 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E7=94=A8=E4=BE=8B=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E6=88=90=E5=91=98=E5=B1=9E=E6=80=A7=E4=B8=8B=E6=8B=89options?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/FunctionalCaseService.java | 34 ++++++++++++++----- .../service/ProjectTemplateService.java | 23 ++++++++++--- .../components/caseTemplateDetail.vue | 10 +----- 3 files changed, 44 insertions(+), 23 deletions(-) diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java index b37079cb8d..3d3e8f1da0 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java @@ -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 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 customFields = templateDTO.getCustomFields(); + List memberOption = projectService.getMemberOption(functionalCase.getProjectId(), null); + List 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); } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectTemplateService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectTemplateService.java index dcac5e92af..7fc7b4b637 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectTemplateService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectTemplateService.java @@ -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 memberOption = projectService.getMemberOption(projectId, null); + List 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; } diff --git a/frontend/src/views/case-management/caseManagementFeature/components/caseTemplateDetail.vue b/frontend/src/views/case-management/caseManagementFeature/components/caseTemplateDetail.vue index 58260b6bd3..d3b23b0cbe 100644 --- a/frontend/src/views/case-management/caseManagementFeature/components/caseTemplateDetail.vue +++ b/frontend/src/views/case-management/caseManagementFeature/components/caseTemplateDetail.vue @@ -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]; }