refactor(功能用例): 功能用例自定义字段存储格式问题
This commit is contained in:
parent
fa4eb4d326
commit
e6c918a8b6
|
@ -1,5 +1,6 @@
|
|||
package io.metersphere.functional.request;
|
||||
|
||||
import io.metersphere.functional.dto.CaseCustomFieldDTO;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
@ -7,7 +8,6 @@ import lombok.Data;
|
|||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author wx
|
||||
|
@ -63,7 +63,7 @@ public class FunctionalCaseAddRequest implements Serializable {
|
|||
private List<String> tags;
|
||||
|
||||
@Schema(description = "自定义字段集合")
|
||||
private Map<String, Object> customFields;
|
||||
private List<CaseCustomFieldDTO> customFields;
|
||||
|
||||
@Schema(description = "附件关联文件ID集合")
|
||||
private List<String> relateFileMetaIds;
|
||||
|
|
|
@ -3,6 +3,7 @@ package io.metersphere.functional.service;
|
|||
import io.metersphere.functional.domain.FunctionalCase;
|
||||
import io.metersphere.functional.domain.FunctionalCaseCustomField;
|
||||
import io.metersphere.functional.domain.FunctionalCaseCustomFieldExample;
|
||||
import io.metersphere.functional.dto.CaseCustomFieldDTO;
|
||||
import io.metersphere.functional.dto.FunctionalCaseDTO;
|
||||
import io.metersphere.functional.mapper.FunctionalCaseCustomFieldMapper;
|
||||
import io.metersphere.functional.mapper.FunctionalCaseMapper;
|
||||
|
@ -18,7 +19,6 @@ import io.metersphere.system.mapper.ExtOrganizationCustomFieldMapper;
|
|||
import io.metersphere.system.notice.constants.NoticeConstants;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -127,23 +127,24 @@ public class FunctionalCaseNoticeService {
|
|||
return optionDTOList;
|
||||
}
|
||||
|
||||
public FunctionalCaseDTO getMainFunctionalCaseDTO(String name, String caseEditType, String projectId, Map<String, Object> customFields) {
|
||||
public FunctionalCaseDTO getMainFunctionalCaseDTO(String name, String caseEditType, String projectId, List<CaseCustomFieldDTO> customFields) {
|
||||
FunctionalCaseDTO functionalCaseDTO = new FunctionalCaseDTO();
|
||||
functionalCaseDTO.setName(name);
|
||||
functionalCaseDTO.setProjectId(projectId);
|
||||
functionalCaseDTO.setCaseEditType(caseEditType);
|
||||
functionalCaseDTO.setCreateUser(null);
|
||||
List<OptionDTO> fields = new ArrayList<>();
|
||||
if (MapUtils.isNotEmpty(customFields)) {
|
||||
customFields.keySet().forEach(key -> {
|
||||
CustomField customField = customFieldMapper.selectByPrimaryKey(key);
|
||||
Optional.ofNullable(customField).ifPresent(item -> {
|
||||
if (CollectionUtils.isNotEmpty(customFields)) {
|
||||
for (CaseCustomFieldDTO customFieldDTO : customFields) {
|
||||
OptionDTO optionDTO = new OptionDTO();
|
||||
optionDTO.setId(customField.getId());
|
||||
optionDTO.setName(customField.getName());
|
||||
CustomField customField = customFieldMapper.selectByPrimaryKey(customFieldDTO.getFieldId());
|
||||
if (customField == null) {
|
||||
continue;
|
||||
}
|
||||
optionDTO.setId(customField.getName());
|
||||
optionDTO.setName(customFieldDTO.getValue());
|
||||
fields.add(optionDTO);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
functionalCaseDTO.setFields(fields);
|
||||
//TODO:设置测试计划名称
|
||||
|
|
|
@ -21,7 +21,6 @@ import io.metersphere.sdk.constants.FunctionalCaseExecuteResult;
|
|||
import io.metersphere.sdk.constants.TemplateScene;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.dto.sdk.TemplateCustomFieldDTO;
|
||||
import io.metersphere.system.dto.sdk.TemplateDTO;
|
||||
|
@ -32,7 +31,6 @@ import io.metersphere.system.uid.NumGenerator;
|
|||
import io.metersphere.system.utils.ServiceUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.ibatis.session.ExecutorType;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
|
@ -180,10 +178,10 @@ public class FunctionalCaseService {
|
|||
functionalCaseBlob.setDescription(StringUtils.defaultIfBlank(request.getDescription(), StringUtils.EMPTY).getBytes(StandardCharsets.UTF_8));
|
||||
functionalCaseBlobMapper.insertSelective(functionalCaseBlob);
|
||||
//保存自定义字段
|
||||
Map<String, Object> customFields = request.getCustomFields();
|
||||
if (MapUtils.isNotEmpty(customFields)) {
|
||||
List<CaseCustomFieldDTO> list = getCustomFields(customFields);
|
||||
functionalCaseCustomFieldService.saveCustomField(caseId, list);
|
||||
List<CaseCustomFieldDTO> customFields = request.getCustomFields();
|
||||
if (CollectionUtils.isNotEmpty(customFields)) {
|
||||
customFields = customFields.stream().distinct().collect(Collectors.toList());
|
||||
functionalCaseCustomFieldService.saveCustomField(caseId, customFields);
|
||||
}
|
||||
return functionalCase;
|
||||
}
|
||||
|
@ -193,7 +191,7 @@ public class FunctionalCaseService {
|
|||
customFields.keySet().forEach(key -> {
|
||||
CaseCustomFieldDTO caseCustomFieldDTO = new CaseCustomFieldDTO();
|
||||
caseCustomFieldDTO.setFieldId(key);
|
||||
caseCustomFieldDTO.setValue(JSON.toJSONString(customFields.get(key)));
|
||||
caseCustomFieldDTO.setValue(customFields.get(key).toString());
|
||||
list.add(caseCustomFieldDTO);
|
||||
});
|
||||
return list;
|
||||
|
@ -409,10 +407,10 @@ public class FunctionalCaseService {
|
|||
functionalCaseBlobMapper.updateByPrimaryKeyWithBLOBs(functionalCaseBlob);
|
||||
|
||||
//更新自定义字段
|
||||
Map<String, Object> customFields = request.getCustomFields();
|
||||
if (MapUtils.isNotEmpty(customFields)) {
|
||||
List<CaseCustomFieldDTO> list = getCustomFields(customFields);
|
||||
functionalCaseCustomFieldService.updateCustomField(request.getId(), list);
|
||||
List<CaseCustomFieldDTO> customFields = request.getCustomFields();
|
||||
if (CollectionUtils.isNotEmpty(customFields)) {
|
||||
customFields = customFields.stream().distinct().collect(Collectors.toList());
|
||||
functionalCaseCustomFieldService.updateCustomField(request.getId(), customFields);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -94,10 +94,8 @@ public class FunctionalCaseControllerTests extends BaseTest {
|
|||
Assertions.assertNotNull(resultHolder);
|
||||
|
||||
//设置自定义字段
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("custom_field_id_1", "custom_field_value_1");
|
||||
map.put("custom_field_id_2", "custom_field_value_2");
|
||||
request.setCustomFields(map);
|
||||
List<CaseCustomFieldDTO> dtoList = creatCustomFields();
|
||||
request.setCustomFields(dtoList);
|
||||
|
||||
//设置文件
|
||||
String filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/test.JPG")).getPath();
|
||||
|
@ -123,6 +121,19 @@ public class FunctionalCaseControllerTests extends BaseTest {
|
|||
System.out.println(jsonString);
|
||||
}
|
||||
|
||||
private List<CaseCustomFieldDTO> creatCustomFields() {
|
||||
insertCustomField();
|
||||
List<CaseCustomFieldDTO> list = new ArrayList<>();
|
||||
CaseCustomFieldDTO customFieldDTO = new CaseCustomFieldDTO();
|
||||
customFieldDTO.setFieldId("custom_field_id_3");
|
||||
customFieldDTO.setValue("custom_field_value_1");
|
||||
list.add(customFieldDTO);
|
||||
CaseCustomFieldDTO customFieldDTO2 = new CaseCustomFieldDTO();
|
||||
customFieldDTO2.setFieldId("custom_field_id_2");
|
||||
customFieldDTO2.setValue("custom_field_value_2");
|
||||
list.add(customFieldDTO2);
|
||||
return list;
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
|
@ -199,10 +210,8 @@ public class FunctionalCaseControllerTests extends BaseTest {
|
|||
public void testUpdateFunctionalCase() throws Exception {
|
||||
FunctionalCaseEditRequest request = creatEditRequest();
|
||||
//设置自定义字段
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("custom_field_id_1", "测试更新");
|
||||
map.put("custom_field_id_2", "更新时存在新字段");
|
||||
request.setCustomFields(map);
|
||||
List<CaseCustomFieldDTO> list = updateCustomFields(request);
|
||||
request.setCustomFields(list);
|
||||
LinkedMultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
|
||||
List<MockMultipartFile> files = new ArrayList<>();
|
||||
paramMap.add("request", JSON.toJSONString(request));
|
||||
|
@ -250,6 +259,19 @@ public class FunctionalCaseControllerTests extends BaseTest {
|
|||
this.requestMultipart(FUNCTIONAL_CASE_UPDATE_URL, paramMap);
|
||||
}
|
||||
|
||||
private List<CaseCustomFieldDTO> updateCustomFields(FunctionalCaseEditRequest editRequest) {
|
||||
List<CaseCustomFieldDTO> list = new ArrayList<>() {{
|
||||
add(new CaseCustomFieldDTO() {{
|
||||
setFieldId("custom_field_id_1");
|
||||
setValue("测试更新");
|
||||
}});
|
||||
add(new CaseCustomFieldDTO() {{
|
||||
setFieldId("custom_field_id_2");
|
||||
setValue("更新时存在新字段");
|
||||
}});
|
||||
}};
|
||||
return list;
|
||||
}
|
||||
|
||||
private FunctionalCaseEditRequest creatEditRequest() {
|
||||
FunctionalCaseEditRequest editRequest = new FunctionalCaseEditRequest();
|
||||
|
|
|
@ -50,7 +50,7 @@ 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_GYQ', '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_3', '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');
|
||||
|
|
|
@ -598,6 +598,7 @@ public class ProjectApplicationService {
|
|||
|
||||
/**
|
||||
* 过滤掉非Local平台的项目
|
||||
*
|
||||
* @param projectIds 项目ID集合
|
||||
* @return 非Local平台的项目
|
||||
*/
|
||||
|
@ -638,6 +639,7 @@ public class ProjectApplicationService {
|
|||
|
||||
/**
|
||||
* 查询插件具体的服务集成信息(缺陷PLATFORM_KEY, 需求PLATFORM_KEY)
|
||||
*
|
||||
* @param projectId 项目ID
|
||||
* @param isSync 是否缺陷同步配置
|
||||
* @return 插件服务集成信息
|
||||
|
@ -650,7 +652,7 @@ public class ProjectApplicationService {
|
|||
platformEnableConfig = getByType(projectId, ProjectApplicationType.BUG.BUG_SYNC.name() + "_" + ProjectApplicationType.BUG_SYNC_CONFIG.SYNC_ENABLE.name());
|
||||
platformKeyConfig = getByType(projectId, ProjectApplicationType.BUG.BUG_SYNC.name() + "_PLATFORM_KEY");
|
||||
} else {
|
||||
platformEnableConfig = getByType(projectId, ProjectApplicationType.CASE_RELATED_CONFIG.CASE_ENABLE.name());
|
||||
platformEnableConfig = getByType(projectId, ProjectApplicationType.CASE_RELATED_CONFIG.CASE_RELATED.name() + "_" + ProjectApplicationType.CASE_RELATED_CONFIG.CASE_ENABLE.name());
|
||||
platformKeyConfig = getByType(projectId, ProjectApplicationType.CASE_RELATED_CONFIG.CASE_RELATED.name() + "_PLATFORM_KEY");
|
||||
}
|
||||
|
||||
|
@ -678,6 +680,7 @@ public class ProjectApplicationService {
|
|||
|
||||
/**
|
||||
* 获取项目同步配置或需求配置的所属平台
|
||||
*
|
||||
* @param projectId 项目ID
|
||||
* @param isSync 是否同步
|
||||
* @return 平台
|
||||
|
|
Loading…
Reference in New Issue