diff --git a/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioModuleDTO.java b/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioModuleDTO.java index 40a463b38c..c4e9200298 100644 --- a/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioModuleDTO.java +++ b/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioModuleDTO.java @@ -1,6 +1,7 @@ package io.metersphere.api.dto.automation; import io.metersphere.base.domain.ApiScenarioModule; +import io.metersphere.track.dto.TreeNodeDTO; import lombok.Getter; import lombok.Setter; @@ -8,9 +9,5 @@ import java.util.List; @Getter @Setter -public class ApiScenarioModuleDTO extends ApiScenarioModule { - - private String label; - private List children; - +public class ApiScenarioModuleDTO extends TreeNodeDTO { } diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index 90c436f519..ee13eb7368 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -104,7 +104,7 @@ public class ApiAutomationService { checkNameExist(request); final ApiScenario scenario = new ApiScenario(); - scenario.setId(request.getId()); + scenario.setId(UUID.randomUUID().toString()); scenario.setName(request.getName()); scenario.setProjectId(request.getProjectId()); scenario.setTagId(request.getTagId()); diff --git a/backend/src/main/java/io/metersphere/api/service/ApiScenarioModuleService.java b/backend/src/main/java/io/metersphere/api/service/ApiScenarioModuleService.java index 374f6a8c58..abe169d458 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioModuleService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioModuleService.java @@ -10,10 +10,12 @@ import io.metersphere.base.domain.ApiScenarioModule; import io.metersphere.base.domain.ApiScenarioModuleExample; import io.metersphere.base.mapper.ApiScenarioMapper; import io.metersphere.base.mapper.ApiScenarioModuleMapper; +import io.metersphere.base.mapper.ext.ExtApiScenarioModuleMapper; import io.metersphere.commons.constants.TestCaseConstants; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.BeanUtils; import io.metersphere.i18n.Translator; +import io.metersphere.service.NodeTreeService; import org.apache.commons.lang3.StringUtils; import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.SqlSession; @@ -27,65 +29,22 @@ import java.util.stream.Collectors; @Service @Transactional(rollbackFor = Exception.class) -public class ApiScenarioModuleService { +public class ApiScenarioModuleService extends NodeTreeService { @Resource ApiScenarioModuleMapper apiScenarioModuleMapper; @Resource + ExtApiScenarioModuleMapper extApiScenarioModuleMapper; + @Resource ApiAutomationService apiAutomationService; @Resource SqlSessionFactory sqlSessionFactory; public List getNodeTreeByProjectId(String projectId) { - ApiScenarioModuleExample example = new ApiScenarioModuleExample(); - example.createCriteria().andProjectIdEqualTo(projectId); - example.setOrderByClause("create_time asc"); - List nodes = apiScenarioModuleMapper.selectByExample(example); + List nodes = extApiScenarioModuleMapper.getNodeTreeByProjectId(projectId); return getNodeTrees(nodes); } - public List getNodeTrees(List nodes) { - List nodeTreeList = new ArrayList<>(); - Map> nodeLevelMap = new HashMap<>(); - nodes.forEach(node -> { - Integer level = node.getLevel(); - if (nodeLevelMap.containsKey(level)) { - nodeLevelMap.get(level).add(node); - } else { - List apiScenarioModules = new ArrayList<>(); - apiScenarioModules.add(node); - nodeLevelMap.put(node.getLevel(), apiScenarioModules); - } - }); - List rootNodes = Optional.ofNullable(nodeLevelMap.get(1)).orElse(new ArrayList<>()); - rootNodes.forEach(rootNode -> nodeTreeList.add(buildNodeTree(nodeLevelMap, rootNode))); - return nodeTreeList; - } - - /** - * 递归构建节点树 - */ - private ApiScenarioModuleDTO buildNodeTree(Map> nodeLevelMap, ApiScenarioModule rootNode) { - - ApiScenarioModuleDTO nodeTree = new ApiScenarioModuleDTO(); - BeanUtils.copyBean(nodeTree, rootNode); - nodeTree.setLabel(rootNode.getName()); - - List lowerNodes = nodeLevelMap.get(rootNode.getLevel() + 1); - if (lowerNodes == null) { - return nodeTree; - } - List children = Optional.ofNullable(nodeTree.getChildren()).orElse(new ArrayList<>()); - lowerNodes.forEach(node -> { - if (node.getParentId() != null && node.getParentId().equals(rootNode.getId())) { - children.add(buildNodeTree(nodeLevelMap, node)); - nodeTree.setChildren(children); - } - }); - - return nodeTree; - } - public String addNode(ApiScenarioModule node) { validateNode(node); node.setCreateTime(System.currentTimeMillis()); @@ -227,5 +186,4 @@ public class ApiScenarioModuleService { sqlSession.flushStatements(); } - } diff --git a/backend/src/main/java/io/metersphere/base/domain/ApiScenarioModule.java b/backend/src/main/java/io/metersphere/base/domain/ApiScenarioModule.java index ca48bfb138..82d9cbb204 100644 --- a/backend/src/main/java/io/metersphere/base/domain/ApiScenarioModule.java +++ b/backend/src/main/java/io/metersphere/base/domain/ApiScenarioModule.java @@ -19,5 +19,7 @@ public class ApiScenarioModule implements Serializable { private Long updateTime; + private Double pos; + private static final long serialVersionUID = 1L; } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/domain/ApiScenarioModuleExample.java b/backend/src/main/java/io/metersphere/base/domain/ApiScenarioModuleExample.java index 48d8f981dd..d0eba1f079 100644 --- a/backend/src/main/java/io/metersphere/base/domain/ApiScenarioModuleExample.java +++ b/backend/src/main/java/io/metersphere/base/domain/ApiScenarioModuleExample.java @@ -563,6 +563,66 @@ public class ApiScenarioModuleExample { addCriterion("update_time not between", value1, value2, "updateTime"); return (Criteria) this; } + + public Criteria andPosIsNull() { + addCriterion("pos is null"); + return (Criteria) this; + } + + public Criteria andPosIsNotNull() { + addCriterion("pos is not null"); + return (Criteria) this; + } + + public Criteria andPosEqualTo(Double value) { + addCriterion("pos =", value, "pos"); + return (Criteria) this; + } + + public Criteria andPosNotEqualTo(Double value) { + addCriterion("pos <>", value, "pos"); + return (Criteria) this; + } + + public Criteria andPosGreaterThan(Double value) { + addCriterion("pos >", value, "pos"); + return (Criteria) this; + } + + public Criteria andPosGreaterThanOrEqualTo(Double value) { + addCriterion("pos >=", value, "pos"); + return (Criteria) this; + } + + public Criteria andPosLessThan(Double value) { + addCriterion("pos <", value, "pos"); + return (Criteria) this; + } + + public Criteria andPosLessThanOrEqualTo(Double value) { + addCriterion("pos <=", value, "pos"); + return (Criteria) this; + } + + public Criteria andPosIn(List values) { + addCriterion("pos in", values, "pos"); + return (Criteria) this; + } + + public Criteria andPosNotIn(List values) { + addCriterion("pos not in", values, "pos"); + return (Criteria) this; + } + + public Criteria andPosBetween(Double value1, Double value2) { + addCriterion("pos between", value1, value2, "pos"); + return (Criteria) this; + } + + public Criteria andPosNotBetween(Double value1, Double value2) { + addCriterion("pos not between", value1, value2, "pos"); + return (Criteria) this; + } } public static class Criteria extends GeneratedCriteria { diff --git a/backend/src/main/java/io/metersphere/base/mapper/ApiScenarioModuleMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ApiScenarioModuleMapper.xml index ca711317ba..0bfb36a80b 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ApiScenarioModuleMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ApiScenarioModuleMapper.xml @@ -9,6 +9,7 @@ + @@ -69,7 +70,7 @@ - id, project_id, `name`, parent_id, `level`, create_time, update_time + id, project_id, `name`, parent_id, `level`, create_time, update_time, pos @@ -188,6 +195,9 @@ update_time = #{record.updateTime,jdbcType=BIGINT}, + + pos = #{record.pos,jdbcType=DOUBLE}, + @@ -201,7 +211,8 @@ parent_id = #{record.parentId,jdbcType=VARCHAR}, `level` = #{record.level,jdbcType=INTEGER}, create_time = #{record.createTime,jdbcType=BIGINT}, - update_time = #{record.updateTime,jdbcType=BIGINT} + update_time = #{record.updateTime,jdbcType=BIGINT}, + pos = #{record.pos,jdbcType=DOUBLE} @@ -227,6 +238,9 @@ update_time = #{updateTime,jdbcType=BIGINT}, + + pos = #{pos,jdbcType=DOUBLE}, + where id = #{id,jdbcType=VARCHAR} @@ -237,7 +251,8 @@ parent_id = #{parentId,jdbcType=VARCHAR}, `level` = #{level,jdbcType=INTEGER}, create_time = #{createTime,jdbcType=BIGINT}, - update_time = #{updateTime,jdbcType=BIGINT} + update_time = #{updateTime,jdbcType=BIGINT}, + pos = #{pos,jdbcType=DOUBLE} where id = #{id,jdbcType=VARCHAR} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioModuleMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioModuleMapper.java new file mode 100644 index 0000000000..73304803ea --- /dev/null +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioModuleMapper.java @@ -0,0 +1,10 @@ +package io.metersphere.base.mapper.ext; + +import io.metersphere.api.dto.automation.ApiScenarioModuleDTO; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +public interface ExtApiScenarioModuleMapper { + List getNodeTreeByProjectId(@Param("projectId") String projectId); +} diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioModuleMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioModuleMapper.xml new file mode 100644 index 0000000000..b679667954 --- /dev/null +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioModuleMapper.xml @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/xpack b/backend/src/main/java/io/metersphere/xpack index 1fe20ba15a..bb494fc68a 160000 --- a/backend/src/main/java/io/metersphere/xpack +++ b/backend/src/main/java/io/metersphere/xpack @@ -1 +1 @@ -Subproject commit 1fe20ba15a7ca3fe9f77ddf866021e7c7dfe5969 +Subproject commit bb494fc68a2367359c9048fa7250c7618de4afb6 diff --git a/backend/src/main/resources/db/migration/V50__api_scenario.sql b/backend/src/main/resources/db/migration/V50__api_scenario.sql index a43cca5292..cdee3a499f 100644 --- a/backend/src/main/resources/db/migration/V50__api_scenario.sql +++ b/backend/src/main/resources/db/migration/V50__api_scenario.sql @@ -32,6 +32,7 @@ CREATE TABLE `api_scenario_module` ( `name` varchar(64) NOT NULL COMMENT 'Node name', `parent_id` varchar(50) DEFAULT NULL COMMENT 'Parent node ID', `level` int(10) DEFAULT '1' COMMENT 'Node level', + `pos` double DEFAULT NULL COMMENT 'Node order', `create_time` bigint(13) NOT NULL COMMENT 'Create timestamp', `update_time` bigint(13) NOT NULL COMMENT 'Update timestamp', PRIMARY KEY (`id`) diff --git a/backend/src/main/resources/generatorConfig.xml b/backend/src/main/resources/generatorConfig.xml index b178cd6d05..865eb05994 100644 --- a/backend/src/main/resources/generatorConfig.xml +++ b/backend/src/main/resources/generatorConfig.xml @@ -64,7 +64,7 @@ - +
diff --git a/frontend/src/business/components/api/automation/ApiAutomation.vue b/frontend/src/business/components/api/automation/ApiAutomation.vue index 8b489609e5..70aa7fb86d 100644 --- a/frontend/src/business/components/api/automation/ApiAutomation.vue +++ b/frontend/src/business/components/api/automation/ApiAutomation.vue @@ -1,14 +1,24 @@