refactor(功能用例): 列表返回值新增自定义字段name

This commit is contained in:
WangXu10 2023-12-19 18:50:21 +08:00 committed by f2c-ci-robot[bot]
parent 786c6b2077
commit 39a1d0d910
7 changed files with 75 additions and 6 deletions

View File

@ -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;
}

View File

@ -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<FunctionalCaseCustomField> customFields;
private List<FunctionalCaseCustomFieldDTO> customFields;
}

View File

@ -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<FunctionalCaseCustomField> getCustomFieldByCaseIds(@Param("ids") List<String> ids);
void batchUpdate(@Param("functionalCaseCustomField") FunctionalCaseCustomField functionalCaseCustomField, @Param("ids") List<String> ids);
List<FunctionalCaseCustomFieldDTO> getCustomFieldsByCaseIds(@Param("ids") List<String> ids);
}

View File

@ -19,4 +19,20 @@
</foreach>
</update>
<select id="getCustomFieldsByCaseIds" resultType="io.metersphere.functional.dto.FunctionalCaseCustomFieldDTO">
SELECT
fccf.case_id caseId,
fccf.field_id fieldId,
fccf.`value` value,
cf.NAME name,
cf.internal internal
FROM
functional_case_custom_field fccf
LEFT JOIN custom_field cf ON fccf.field_id = cf.id
where case_id in
<foreach collection="ids" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</select>
</mapper>

View File

@ -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<FunctionalCaseCustomFieldDTO> getCustomFieldsByCaseIds(List<String> ids) {
return extFunctionalCaseCustomFieldMapper.getCustomFieldsByCaseIds(ids);
}
}

View File

@ -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<FunctionalCasePageDTO> handleCustomFieldsAnd(List<FunctionalCasePageDTO> functionalCaseLists) {
private List<FunctionalCasePageDTO> handleCustomFields(List<FunctionalCasePageDTO> functionalCaseLists) {
List<String> ids = functionalCaseLists.stream().map(FunctionalCasePageDTO::getId).collect(Collectors.toList());
List<FunctionalCaseCustomField> customFields = functionalCaseCustomFieldService.getCustomFieldByCaseIds(ids);
Map<String, List<FunctionalCaseCustomField>> collect = customFields.stream().collect(Collectors.groupingBy(FunctionalCaseCustomField::getCaseId));
List<FunctionalCaseCustomFieldDTO> customFields = functionalCaseCustomFieldService.getCustomFieldsByCaseIds(ids);
customFields.forEach(customField -> {
if (customField.getInternal()) {
customField.setName(baseCustomFieldService.translateInternalField(customField.getName()));
}
});
Map<String, List<FunctionalCaseCustomFieldDTO>> collect = customFields.stream().collect(Collectors.groupingBy(FunctionalCaseCustomFieldDTO::getCaseId));
functionalCaseLists.forEach(functionalCasePageDTO -> {
functionalCasePageDTO.setCustomFields(collect.get(functionalCasePageDTO.getId()));
});

View File

@ -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)