refactor(功能用例): 脑图查询排序优化

This commit is contained in:
guoyuqi 2024-06-15 22:18:33 +08:00 committed by Craftsman
parent cdc255507b
commit 49aaa42d07
3 changed files with 63 additions and 16 deletions

View File

@ -87,7 +87,7 @@ public interface ExtFunctionalCaseMapper {
*/ */
List<FunctionalCaseMindDTO> getMinderCaseList(@Param("request") FunctionalCaseMindRequest request, @Param("deleted") boolean deleted); List<FunctionalCaseMindDTO> getMinderCaseList(@Param("request") FunctionalCaseMindRequest request, @Param("deleted") boolean deleted);
List<FunctionalCaseCustomField> getCaseCustomFieldList(@Param("request") FunctionalCaseMindRequest request, @Param("deleted") boolean deleted); List<FunctionalCaseCustomField> getCaseCustomFieldList(@Param("request") FunctionalCaseMindRequest request, @Param("deleted") boolean deleted, @Param("fieldIds") List<String>fieldIds);
/** /**

View File

@ -823,6 +823,12 @@
cf.name = 'functional_priority' cf.name = 'functional_priority'
AND cf.scene = 'FUNCTIONAL' AND cf.scene = 'FUNCTIONAL'
AND cf.internal= true AND cf.internal= true
<if test="fieldIds != null and fieldIds.size() > 0">
and fccf.field_id in
<foreach collection="fieldIds" item="fieldId" open="(" separator="," close=")">
#{fieldId}
</foreach>
</if>
order by fc.pos order by fc.pos
</select> </select>

View File

@ -39,6 +39,7 @@ import io.metersphere.system.service.CommonNoticeSendService;
import io.metersphere.system.uid.IDGenerator; import io.metersphere.system.uid.IDGenerator;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSession;
@ -143,7 +144,10 @@ public class FunctionalCaseMinderService {
return new ArrayList<>(); return new ArrayList<>();
} }
List<FunctionalCaseMindDTO> functionalCaseMindDTOList = extFunctionalCaseMapper.getMinderCaseList(request, deleted); List<FunctionalCaseMindDTO> functionalCaseMindDTOList = extFunctionalCaseMapper.getMinderCaseList(request, deleted);
List<FunctionalCaseCustomField> caseCustomFieldList = extFunctionalCaseMapper.getCaseCustomFieldList(request, deleted); List<String> fieldIds = getFieldIds(request);
List<FunctionalCaseCustomField> caseCustomFieldList = extFunctionalCaseMapper.getCaseCustomFieldList(request, deleted, fieldIds);
Map<String, String> priorityMap = caseCustomFieldList.stream().collect(Collectors.toMap(FunctionalCaseCustomField::getCaseId, FunctionalCaseCustomField::getValue)); Map<String, String> priorityMap = caseCustomFieldList.stream().collect(Collectors.toMap(FunctionalCaseCustomField::getCaseId, FunctionalCaseCustomField::getValue));
List<FunctionalMinderTreeDTO> functionalMinderTreeDTOS = buildAdditionalData(request.getModuleId()); List<FunctionalMinderTreeDTO> functionalMinderTreeDTOS = buildAdditionalData(request.getModuleId());
@ -155,6 +159,14 @@ public class FunctionalCaseMinderService {
return list; return list;
} }
@NotNull
private List<String> getFieldIds(FunctionalCaseMindRequest request) {
TemplateDTO defaultTemplateDTO = projectTemplateService.getDefaultTemplateDTO(request.getProjectId(), TemplateScene.FUNCTIONAL.toString());
List<TemplateCustomFieldDTO> customFields = defaultTemplateDTO.getCustomFields();
List<String> fieldIds = customFields.stream().map(TemplateCustomFieldDTO::getFieldId).toList();
return fieldIds;
}
private List<FunctionalMinderTreeDTO> buildAdditionalData(String moduleId) { private List<FunctionalMinderTreeDTO> buildAdditionalData(String moduleId) {
List<FunctionalMinderTreeDTO> list = new ArrayList<>(); List<FunctionalMinderTreeDTO> list = new ArrayList<>();
MindAdditionalNodeExample mindAdditionalNodeExample = new MindAdditionalNodeExample(); MindAdditionalNodeExample mindAdditionalNodeExample = new MindAdditionalNodeExample();
@ -524,16 +536,34 @@ public class FunctionalCaseMinderService {
sources.remove(nodeIndex); sources.remove(nodeIndex);
List<T> beforeNode; List<T> beforeNode;
List<T> afterNode; List<T> afterNode;
//证明相邻点不是同种类型放到1位
if (targetIndex == 0 && !findTarget) {
beforeNode = new ArrayList<>();
afterNode = sources;
} else {
if (StringUtils.equals(moveMode, MoveTypeEnum.AFTER.name())) { if (StringUtils.equals(moveMode, MoveTypeEnum.AFTER.name())) {
if (targetIndex+1>sources.size()) {
beforeNode = sources;
afterNode = new ArrayList<>();
} else {
beforeNode = sources.subList(0, targetIndex+1); beforeNode = sources.subList(0, targetIndex+1);
afterNode = sources.subList(targetIndex+1, sources.size()); afterNode = sources.subList(targetIndex+1, sources.size());
}
} else { } else {
beforeNode = sources.subList(0, targetIndex); beforeNode = sources.subList(0, targetIndex);
afterNode = sources.subList(targetIndex, sources.size()); afterNode = sources.subList(targetIndex, sources.size());
} }
List<T> finallyNode = new ArrayList<>(beforeNode); }
List<T> finallyNode = new ArrayList<>();
if (CollectionUtils.isNotEmpty(beforeNode)) {
finallyNode.addAll(beforeNode);
}
if (currentNode!=null) {
finallyNode.add(currentNode); finallyNode.add(currentNode);
}
if (CollectionUtils.isNotEmpty(afterNode)) {
finallyNode.addAll(afterNode); finallyNode.addAll(afterNode);
}
return finallyNode; return finallyNode;
} }
@ -544,7 +574,7 @@ public class FunctionalCaseMinderService {
String textParentId = targetTextMap.get(targetId); String textParentId = targetTextMap.get(targetId);
if (StringUtils.isNotBlank(parentId)) { if (StringUtils.isNotBlank(parentId)) {
moduleMapKey = parentId; moduleMapKey = parentId;
} else if (StringUtils.isNotBlank(parentId)) { } else if (StringUtils.isNotBlank(caseModuleId)) {
moduleMapKey = caseModuleId; moduleMapKey = caseModuleId;
} else { } else {
moduleMapKey = textParentId; moduleMapKey = textParentId;
@ -641,7 +671,7 @@ public class FunctionalCaseMinderService {
} }
} }
} }
functionalMinderUpdateDTO.setSourceIdAndTargetIdsMap(sourceIdAndTargetIdsMap); setDTOTargetMap(functionalMinderUpdateDTO, sourceIdAndTargetIdsMap);
return sourceIdAndInsertCaseIdMap; return sourceIdAndInsertCaseIdMap;
} }
@ -721,10 +751,19 @@ public class FunctionalCaseMinderService {
} }
} }
} }
functionalMinderUpdateDTO.setSourceIdAndTargetIdsMap(sourceIdAndTargetIdsMap); setDTOTargetMap(functionalMinderUpdateDTO, sourceIdAndTargetIdsMap);
return sourceIdAndInsertTextIdMap; return sourceIdAndInsertTextIdMap;
} }
private static void setDTOTargetMap(FunctionalMinderUpdateDTO functionalMinderUpdateDTO, Map<String, String> sourceIdAndTargetIdsMap) {
Map<String, String> existMap = functionalMinderUpdateDTO.getSourceIdAndTargetIdsMap();
if (MapUtils.isEmpty(existMap)) {
existMap = new HashMap<>();
}
existMap.putAll(sourceIdAndTargetIdsMap);
functionalMinderUpdateDTO.setSourceIdAndTargetIdsMap(existMap);
}
private MindAdditionalNode updateNode(String userId, MindAdditionalNodeRequest mindAdditionalNodeRequest, MindAdditionalNodeMapper mindAdditionalNodeMapper) { private MindAdditionalNode updateNode(String userId, MindAdditionalNodeRequest mindAdditionalNodeRequest, MindAdditionalNodeMapper mindAdditionalNodeMapper) {
MindAdditionalNode mindAdditionalNode = new MindAdditionalNode(); MindAdditionalNode mindAdditionalNode = new MindAdditionalNode();
mindAdditionalNode.setId(mindAdditionalNodeRequest.getId()); mindAdditionalNode.setId(mindAdditionalNodeRequest.getId());
@ -796,7 +835,7 @@ public class FunctionalCaseMinderService {
} }
} }
} }
functionalMinderUpdateDTO.setSourceIdAndTargetIdsMap(sourceIdAndTargetIdsMap); setDTOTargetMap(functionalMinderUpdateDTO, sourceIdAndTargetIdsMap);
return sourceIdAndInsertIdMap; return sourceIdAndInsertIdMap;
} }
@ -1113,7 +1152,8 @@ public class FunctionalCaseMinderService {
List<FunctionalMinderTreeDTO> list = new ArrayList<>(); List<FunctionalMinderTreeDTO> list = new ArrayList<>();
//查出当前模块下的所有用例 //查出当前模块下的所有用例
List<FunctionalCaseMindDTO> functionalCaseMindDTOList = extFunctionalCaseMapper.getMinderCaseReviewList(request, deleted, userId, viewStatusUserId); List<FunctionalCaseMindDTO> functionalCaseMindDTOList = extFunctionalCaseMapper.getMinderCaseReviewList(request, deleted, userId, viewStatusUserId);
List<FunctionalCaseCustomField> caseCustomFieldList = extFunctionalCaseMapper.getCaseCustomFieldList(request, deleted); List<String> fieldIds = getFieldIds(request);
List<FunctionalCaseCustomField> caseCustomFieldList = extFunctionalCaseMapper.getCaseCustomFieldList(request, deleted, fieldIds);
Map<String, String> priorityMap = caseCustomFieldList.stream().collect(Collectors.toMap(FunctionalCaseCustomField::getCaseId, FunctionalCaseCustomField::getValue)); Map<String, String> priorityMap = caseCustomFieldList.stream().collect(Collectors.toMap(FunctionalCaseCustomField::getCaseId, FunctionalCaseCustomField::getValue));
//构造父子级数据 //构造父子级数据
buildList(functionalCaseMindDTOList, list, priorityMap); buildList(functionalCaseMindDTOList, list, priorityMap);
@ -1124,7 +1164,8 @@ public class FunctionalCaseMinderService {
List<FunctionalMinderTreeDTO> list = new ArrayList<>(); List<FunctionalMinderTreeDTO> list = new ArrayList<>();
//查出当前模块下的所有用例 //查出当前模块下的所有用例
List<FunctionalCaseMindDTO> functionalCaseMindDTOList = extFunctionalCaseMapper.getMinderTestPlanList(request, deleted); List<FunctionalCaseMindDTO> functionalCaseMindDTOList = extFunctionalCaseMapper.getMinderTestPlanList(request, deleted);
List<FunctionalCaseCustomField> caseCustomFieldList = extFunctionalCaseMapper.getCaseCustomFieldList(request, deleted); List<String> fieldIds = getFieldIds(request);
List<FunctionalCaseCustomField> caseCustomFieldList = extFunctionalCaseMapper.getCaseCustomFieldList(request, deleted, fieldIds);
Map<String, String> priorityMap = caseCustomFieldList.stream().collect(Collectors.toMap(FunctionalCaseCustomField::getCaseId, FunctionalCaseCustomField::getValue)); Map<String, String> priorityMap = caseCustomFieldList.stream().collect(Collectors.toMap(FunctionalCaseCustomField::getCaseId, FunctionalCaseCustomField::getValue));
//构造父子级数据 //构造父子级数据
buildList(functionalCaseMindDTOList, list, priorityMap); buildList(functionalCaseMindDTOList, list, priorityMap);