From 39a1d0d9106318fb1183e67c90fabe5cdd295220 Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Tue, 19 Dec 2023 18:50:21 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E5=8A=9F=E8=83=BD=E7=94=A8=E4=BE=8B):?= =?UTF-8?q?=20=E5=88=97=E8=A1=A8=E8=BF=94=E5=9B=9E=E5=80=BC=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E8=87=AA=E5=AE=9A=E4=B9=89=E5=AD=97=E6=AE=B5name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/FunctionalCaseCustomFieldDTO.java | 33 +++++++++++++++++++ .../functional/dto/FunctionalCasePageDTO.java | 3 +- .../ExtFunctionalCaseCustomFieldMapper.java | 3 ++ .../ExtFunctionalCaseCustomFieldMapper.xml | 16 +++++++++ .../FunctionalCaseCustomFieldService.java | 5 +++ .../service/FunctionalCaseService.java | 17 +++++++--- .../resources/dml/init_file_metadata_test.sql | 4 +++ 7 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 backend/services/case-management/src/main/java/io/metersphere/functional/dto/FunctionalCaseCustomFieldDTO.java diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/dto/FunctionalCaseCustomFieldDTO.java b/backend/services/case-management/src/main/java/io/metersphere/functional/dto/FunctionalCaseCustomFieldDTO.java new file mode 100644 index 0000000000..8bb3351540 --- /dev/null +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/dto/FunctionalCaseCustomFieldDTO.java @@ -0,0 +1,33 @@ +package io.metersphere.functional.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; + +/** + * @author wx + */ +@Data +public class FunctionalCaseCustomFieldDTO implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + @Schema(description = "用例ID") + private String caseId; + + @Schema(description = "字段ID") + private String fieldId; + + @Schema(description = "字段值") + private String value; + + @Schema(description = "字段名称") + private String name; + + @Schema(description = "是否内置字段") + private Boolean internal; + +} diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/dto/FunctionalCasePageDTO.java b/backend/services/case-management/src/main/java/io/metersphere/functional/dto/FunctionalCasePageDTO.java index 532228c99b..f1ea10bc47 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/dto/FunctionalCasePageDTO.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/dto/FunctionalCasePageDTO.java @@ -1,7 +1,6 @@ package io.metersphere.functional.dto; import io.metersphere.functional.domain.FunctionalCase; -import io.metersphere.functional.domain.FunctionalCaseCustomField; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -15,5 +14,5 @@ public class FunctionalCasePageDTO extends FunctionalCase { @Schema(description = "自定义字段集合") - private List customFields; + private List customFields; } diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseCustomFieldMapper.java b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseCustomFieldMapper.java index 158ee52397..f81413d003 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseCustomFieldMapper.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseCustomFieldMapper.java @@ -1,6 +1,7 @@ package io.metersphere.functional.mapper; import io.metersphere.functional.domain.FunctionalCaseCustomField; +import io.metersphere.functional.dto.FunctionalCaseCustomFieldDTO; import org.apache.ibatis.annotations.Param; import java.util.List; @@ -14,4 +15,6 @@ public interface ExtFunctionalCaseCustomFieldMapper { List getCustomFieldByCaseIds(@Param("ids") List ids); void batchUpdate(@Param("functionalCaseCustomField") FunctionalCaseCustomField functionalCaseCustomField, @Param("ids") List ids); + + List getCustomFieldsByCaseIds(@Param("ids") List ids); } diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseCustomFieldMapper.xml b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseCustomFieldMapper.xml index 5138c550e0..72d91c7c5b 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseCustomFieldMapper.xml +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtFunctionalCaseCustomFieldMapper.xml @@ -19,4 +19,20 @@ + + \ No newline at end of file diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseCustomFieldService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseCustomFieldService.java index 655ec8e7ea..9ecc142020 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseCustomFieldService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseCustomFieldService.java @@ -4,6 +4,7 @@ package io.metersphere.functional.service; import io.metersphere.functional.domain.FunctionalCaseCustomField; import io.metersphere.functional.domain.FunctionalCaseCustomFieldExample; import io.metersphere.functional.dto.CaseCustomFieldDTO; +import io.metersphere.functional.dto.FunctionalCaseCustomFieldDTO; import io.metersphere.functional.mapper.ExtFunctionalCaseCustomFieldMapper; import io.metersphere.functional.mapper.FunctionalCaseCustomFieldMapper; import jakarta.annotation.Resource; @@ -134,4 +135,8 @@ public class FunctionalCaseCustomFieldService { functionalCaseCustomField.setValue(customField.getValue()); extFunctionalCaseCustomFieldMapper.batchUpdate(functionalCaseCustomField, ids); } + + public List getCustomFieldsByCaseIds(List ids) { + return extFunctionalCaseCustomFieldMapper.getCustomFieldsByCaseIds(ids); + } } \ No newline at end of file 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 d2773a8d43..cea03018cd 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 @@ -24,6 +24,7 @@ import io.metersphere.sdk.util.JSON; import io.metersphere.system.dto.sdk.TemplateCustomFieldDTO; import io.metersphere.system.dto.sdk.TemplateDTO; import io.metersphere.system.dto.sdk.request.PosRequest; +import io.metersphere.system.service.BaseCustomFieldService; import io.metersphere.system.uid.IDGenerator; import io.metersphere.system.uid.NumGenerator; import io.metersphere.system.utils.ServiceUtils; @@ -88,6 +89,9 @@ public class FunctionalCaseService { @Resource private CaseReviewFunctionalCaseService caseReviewFunctionalCaseService; + @Resource + private BaseCustomFieldService baseCustomFieldService; + private static final String CASE_MODULE_COUNT_ALL = "all"; private static final String ADD_FUNCTIONAL_CASE_FILE_LOG_URL = "/functional/case/add"; @@ -440,13 +444,18 @@ public class FunctionalCaseService { return new ArrayList<>(); } //处理自定义字段值 - return handleCustomFieldsAnd(functionalCaseLists); + return handleCustomFields(functionalCaseLists); } - private List handleCustomFieldsAnd(List functionalCaseLists) { + private List handleCustomFields(List functionalCaseLists) { List ids = functionalCaseLists.stream().map(FunctionalCasePageDTO::getId).collect(Collectors.toList()); - List customFields = functionalCaseCustomFieldService.getCustomFieldByCaseIds(ids); - Map> collect = customFields.stream().collect(Collectors.groupingBy(FunctionalCaseCustomField::getCaseId)); + List customFields = functionalCaseCustomFieldService.getCustomFieldsByCaseIds(ids); + customFields.forEach(customField -> { + if (customField.getInternal()) { + customField.setName(baseCustomFieldService.translateInternalField(customField.getName())); + } + }); + Map> collect = customFields.stream().collect(Collectors.groupingBy(FunctionalCaseCustomFieldDTO::getCaseId)); functionalCaseLists.forEach(functionalCasePageDTO -> { functionalCasePageDTO.setCustomFields(collect.get(functionalCasePageDTO.getId())); }); diff --git a/backend/services/case-management/src/test/resources/dml/init_file_metadata_test.sql b/backend/services/case-management/src/test/resources/dml/init_file_metadata_test.sql index 238f5e7bd4..49a3b6209f 100644 --- a/backend/services/case-management/src/test/resources/dml/init_file_metadata_test.sql +++ b/backend/services/case-management/src/test/resources/dml/init_file_metadata_test.sql @@ -50,6 +50,10 @@ INSERT INTO functional_case_attachment(id, case_id, file_id, file_name, size, lo INSERT INTO functional_case_module(id, project_id, name, parent_id, pos, create_time, update_time, create_user, update_user) VALUES ('TEST_MODULE_ID', '100001100001', '测试所属模块', 'NONE', 0, 1669174143999, 1669174143999, 'admin', 'admin'); INSERT INTO custom_field(id, name, scene, type, remark, internal, scope_type, create_time, update_time, create_user, ref_id, enable_option_key, scope_id) VALUES ('custom_field_id_1', 'functional_priority', 'FUNCTIONAL', 'SELECT', '', b'1', 'ORGANIZATION', 1698983187000, 1698983187000, 'admin', NULL, b'0', '100001'); +INSERT INTO custom_field(id, name, scene, type, remark, internal, scope_type, create_time, update_time, create_user, ref_id, enable_option_key, scope_id) VALUES ('custom_field_id_2', '测试1', 'FUNCTIONAL', 'SELECT', '', b'0', 'ORGANIZATION', 1698983187000, 1698983187000, 'admin', NULL, b'0', '100001'); +INSERT INTO custom_field(id, name, scene, type, remark, internal, scope_type, create_time, update_time, create_user, ref_id, enable_option_key, scope_id) VALUES ('100548878725546079', '测试2', 'FUNCTIONAL', 'SELECT', '', b'0', 'ORGANIZATION', 1698983187000, 1698983187000, 'admin', NULL, b'0', '100001'); +INSERT INTO custom_field(id, name, scene, type, remark, internal, scope_type, create_time, update_time, create_user, ref_id, enable_option_key, scope_id) VALUES ('TEST_FIELD_ID', '测试3', 'FUNCTIONAL', 'SELECT', '', b'0', 'ORGANIZATION', 1698983187000, 1698983187000, 'admin', NULL, b'0', '100001'); +INSERT INTO custom_field(id, name, scene, type, remark, internal, scope_type, create_time, update_time, create_user, ref_id, enable_option_key, scope_id) VALUES ('TEST_FIELD_ID_1', '测试4', 'FUNCTIONAL', 'SELECT', '', b'0', 'ORGANIZATION', 1698983187000, 1698983187000, 'admin', NULL, b'0', '100001'); INSERT INTO functional_case(id, num, module_id, project_id, template_id, name, review_status, tags, case_edit_type, pos, version_id, ref_id, last_execute_result, deleted, public_case, latest, create_user, update_user, delete_user, create_time, update_time, delete_time)