mirror of
https://gitee.com/fit2cloud-feizhiyun/MeterSphere.git
synced 2024-12-02 12:09:13 +08:00
Merge branch 'v1.6' of https://github.com/metersphere/metersphere into v1.6
This commit is contained in:
commit
0d037a9165
@ -24,6 +24,7 @@ import org.apache.ibatis.session.SqlSession;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
@ -69,10 +70,32 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
||||
return addNodeWithoutValidate(node);
|
||||
}
|
||||
|
||||
private double getNextLevelPos(String projectId, int level, String parentId) {
|
||||
List<ApiModule> list = getPos(projectId, level, parentId, "pos desc");
|
||||
if (!CollectionUtils.isEmpty(list) && list.get(0) != null && list.get(0).getPos() != null) {
|
||||
return list.get(0).getPos() + DEFAULT_POS;
|
||||
} else {
|
||||
return DEFAULT_POS;
|
||||
}
|
||||
}
|
||||
|
||||
private List<ApiModule> getPos(String projectId, int level, String parentId, String order) {
|
||||
ApiModuleExample example = new ApiModuleExample();
|
||||
ApiModuleExample.Criteria criteria = example.createCriteria();
|
||||
criteria.andProjectIdEqualTo(projectId).andLevelEqualTo(level);
|
||||
if (level != 1 && StringUtils.isNotBlank(parentId)) {
|
||||
criteria.andParentIdEqualTo(parentId);
|
||||
}
|
||||
example.setOrderByClause(order);
|
||||
return apiModuleMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
public String addNodeWithoutValidate(ApiModule node) {
|
||||
node.setCreateTime(System.currentTimeMillis());
|
||||
node.setUpdateTime(System.currentTimeMillis());
|
||||
node.setId(UUID.randomUUID().toString());
|
||||
double pos = getNextLevelPos(node.getProjectId(), node.getLevel(), node.getParentId());
|
||||
node.setPos(pos);
|
||||
apiModuleMapper.insertSelective(node);
|
||||
return node.getId();
|
||||
}
|
||||
@ -253,7 +276,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
||||
if (nodeTree == null) {
|
||||
return;
|
||||
}
|
||||
buildUpdateDefinition(nodeTree, apiModule, updateNodes, "/", "0", nodeTree.getLevel());
|
||||
buildUpdateDefinition(nodeTree, apiModule, updateNodes, "/", "0", 1);
|
||||
|
||||
updateNodes = updateNodes.stream()
|
||||
.filter(item -> nodeIds.contains(item.getId()))
|
||||
|
@ -6,7 +6,6 @@ import io.metersphere.api.dto.automation.ApiScenarioDTO;
|
||||
import io.metersphere.api.dto.automation.ApiScenarioModuleDTO;
|
||||
import io.metersphere.api.dto.automation.ApiScenarioRequest;
|
||||
import io.metersphere.api.dto.automation.DragApiScenarioModuleRequest;
|
||||
import io.metersphere.api.dto.definition.ApiModuleDTO;
|
||||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.base.mapper.ApiScenarioMapper;
|
||||
import io.metersphere.base.mapper.ApiScenarioModuleMapper;
|
||||
@ -24,6 +23,7 @@ import org.apache.ibatis.session.SqlSession;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
@ -61,11 +61,33 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
||||
return getNodeTrees(nodes);
|
||||
}
|
||||
|
||||
private double getNextLevelPos(String projectId, int level, String parentId) {
|
||||
List<ApiScenarioModule> list = getPos(projectId, level, parentId, "pos desc");
|
||||
if (!CollectionUtils.isEmpty(list) && list.get(0) != null && list.get(0).getPos() != null) {
|
||||
return list.get(0).getPos() + DEFAULT_POS;
|
||||
} else {
|
||||
return DEFAULT_POS;
|
||||
}
|
||||
}
|
||||
|
||||
private List<ApiScenarioModule> getPos(String projectId, int level, String parentId, String order) {
|
||||
ApiScenarioModuleExample example = new ApiScenarioModuleExample();
|
||||
ApiScenarioModuleExample.Criteria criteria = example.createCriteria();
|
||||
criteria.andProjectIdEqualTo(projectId).andLevelEqualTo(level);
|
||||
if (level != 1 && StringUtils.isNotBlank(parentId)) {
|
||||
criteria.andParentIdEqualTo(parentId);
|
||||
}
|
||||
example.setOrderByClause(order);
|
||||
return apiScenarioModuleMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
public String addNode(ApiScenarioModule node) {
|
||||
validateNode(node);
|
||||
node.setId(UUID.randomUUID().toString());
|
||||
node.setCreateTime(System.currentTimeMillis());
|
||||
node.setUpdateTime(System.currentTimeMillis());
|
||||
node.setId(UUID.randomUUID().toString());
|
||||
double pos = getNextLevelPos(node.getProjectId(), node.getLevel(), node.getParentId());
|
||||
node.setPos(pos);
|
||||
apiScenarioModuleMapper.insertSelective(node);
|
||||
return node.getId();
|
||||
}
|
||||
@ -212,7 +234,7 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
||||
if (nodeTree == null) {
|
||||
return;
|
||||
}
|
||||
buildUpdateDefinition(nodeTree, apiScenarios, updateNodes, "/", "0", nodeTree.getLevel());
|
||||
buildUpdateDefinition(nodeTree, apiScenarios, updateNodes, "/", "0", 1);
|
||||
|
||||
updateNodes = updateNodes.stream()
|
||||
.filter(item -> nodeIds.contains(item.getId()))
|
||||
|
Loading…
Reference in New Issue
Block a user