fix(测试跟踪): 脑图模块移动报错

--bug=1010184 --user=陈建星 【测试跟踪】github#10391脑图模块移动报错 https://www.tapd.cn/55049933/s/11101722
This commit is contained in:
chenjianxing 2022-02-25 12:09:53 +08:00 committed by jianxing
parent ab20bf0b12
commit 01f186ae1b
7 changed files with 66 additions and 19 deletions

View File

@ -8,7 +8,6 @@ import io.metersphere.track.dto.TestCaseDTO;
import io.metersphere.track.request.testcase.QueryTestCaseRequest;
import io.metersphere.track.request.testcase.TestCaseBatchRequest;
import io.metersphere.track.response.TrackCountResult;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -146,4 +145,6 @@ public interface ExtTestCaseMapper {
int addLatestVersion(@Param("refId") String refId);
List<TestCase> getMaintainerMap(@Param("request") QueryTestCaseRequest request);
List<TestCaseDTO> getForNodeEdit(@Param("ids") List<String> ids);
}

View File

@ -991,6 +991,13 @@
and T2.case_id is null
order by test_case.`order` desc, test_case.sort desc
</select>
<select id="getForNodeEdit" resultType="io.metersphere.track.dto.TestCaseDTO">
select test_case.id, test_case.node_id, test_case.node_path
from test_case where node_id in
<foreach collection="ids" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</select>
<update id="addLatestVersion">
UPDATE test_case

View File

@ -16,4 +16,6 @@ public interface ExtTestCaseNodeMapper {
void updatePos(String id, Double pos);
List<String> getNodes(@Param("parentId") String parentId);
List<TestCaseNodeDTO> getNodeTreeByIds(@Param("nodeIds") List<String> nodeIds);
}

View File

@ -29,9 +29,18 @@
from test_case_node
where parent_id = #{parentId}
</select>
<select id="getNodeTreeByIds" resultType="io.metersphere.track.dto.TestCaseNodeDTO">
select
<include refid="io.metersphere.base.mapper.TestCaseNodeMapper.Base_Column_List"/>
from test_case_node
where test_case_node.id in
<foreach collection="nodeIds" open="(" close=")" separator="," item="id">
#{id}
</foreach>
</select>
<update id="updatePos">
update test_case_node
set pos = #{pos}
where id = #{id}
</update>
</mapper>
</mapper>

View File

@ -1,6 +1,4 @@
package io.metersphere.track.dto;
import io.metersphere.api.dto.definition.ApiModuleDTO;
import lombok.Data;
import java.util.List;

View File

@ -211,7 +211,7 @@ public class TestCaseNodeService extends NodeTreeService<TestCaseNodeDTO> {
request.setUpdateTime(System.currentTimeMillis());
checkTestCaseNodeExist(request);
if (!CollectionUtils.isEmpty(request.getNodeIds())) {
List<TestCaseDTO> testCases = QueryTestCaseByNodeIds(request.getNodeIds());
List<TestCaseDTO> testCases = extTestCaseMapper.getForNodeEdit(request.getNodeIds());
testCases.forEach(testCase -> {
StringBuilder path = new StringBuilder(testCase.getNodePath());
List<String> pathLists = Arrays.asList(path.toString().split("/"));
@ -224,12 +224,23 @@ public class TestCaseNodeService extends NodeTreeService<TestCaseNodeDTO> {
});
batchUpdateTestCase(testCases);
}
if (StringUtils.isBlank(request.getParentId())) {
request.setParentId(null);
}
return testCaseNodeMapper.updateByPrimaryKeySelective(request);
}
/**
* 修改用例的 nodePath
* @param editNodeIds
* @param projectId
*/
public void editCasePathForMinder(List<String> editNodeIds, String projectId) {
if (!CollectionUtils.isEmpty(editNodeIds)) {
List<TestCaseNodeDTO> nodeTrees = getNodeTrees(extTestCaseNodeMapper.getNodeTreeByProjectId(projectId));
List<TestCaseDTO> testCases = extTestCaseMapper.getForNodeEdit(editNodeIds);
nodeTrees.forEach(nodeTree -> buildUpdateTestCase(nodeTree, testCases, null, "/", "0", 1));
batchUpdateTestCase(testCases);
}
}
public int deleteNode(List<String> nodeIds) {
if (CollectionUtils.isEmpty(nodeIds)) {
return 1;
@ -520,11 +531,13 @@ public class TestCaseNodeService extends NodeTreeService<TestCaseNodeDTO> {
MSException.throwException(Translator.get("node_deep_limit"));
}
TestCaseNode testCaseNode = new TestCaseNode();
testCaseNode.setId(rootNode.getId());
testCaseNode.setLevel(level);
testCaseNode.setParentId(pId);
updateNodes.add(testCaseNode);
if (updateNodes != null) {
TestCaseNode testCaseNode = new TestCaseNode();
testCaseNode.setId(rootNode.getId());
testCaseNode.setLevel(level);
testCaseNode.setParentId(pId);
updateNodes.add(testCaseNode);
}
for (TestCaseDTO item : testCases) {
if (StringUtils.equals(item.getNodeId(), rootNode.getId())) {
@ -697,17 +710,21 @@ public class TestCaseNodeService extends NodeTreeService<TestCaseNodeDTO> {
deleteNode(request.getIds());
List<TestCaseMinderEditRequest.TestCaseNodeMinderEditItem> testCaseNodes = request.getTestCaseNodes();
List<String> editNodeIds = new ArrayList<>();
if (org.apache.commons.collections.CollectionUtils.isNotEmpty(testCaseNodes)) {
for (TestCaseMinderEditRequest.TestCaseNodeMinderEditItem item: testCaseNodes) {
if (StringUtils.isBlank(item.getParentId()) || item.getParentId().equals("root")) {
item.setParentId("");
item.setParentId(null);
}
item.setProjectId(request.getProjectId());
if (item.getIsEdit()) {
DragNodeRequest editNode = new DragNodeRequest();
BeanUtils.copyBean(editNode, item);
editNode(editNode);
checkTestCaseNodeExist(editNode);
editNodeIds.add(editNode.getId());
testCaseNodeMapper.updateByPrimaryKeySelective(editNode);
} else {
TestCaseNode testCaseNode = new TestCaseNode();
BeanUtils.copyBean(testCaseNode, item);
@ -715,6 +732,8 @@ public class TestCaseNodeService extends NodeTreeService<TestCaseNodeDTO> {
addNode(testCaseNode);
}
}
editCasePathForMinder(editNodeIds, request.getProjectId());
}
}

View File

@ -23,12 +23,23 @@
:show-operator="showOperator"
:condition="condition"
:commands="operators"/>
<module-trash-button :condition="condition" :total="total" :exe="enableTrash"/>
<module-public-button :condition="condition" :public-total="publicTotal" :exe="enablePublic"/>
<module-trash-button
:condition="condition"
:total="total"
:exe="enableTrash"/>
<module-public-button
:condition="condition"
:public-total="publicTotal"
:exe="enablePublic"/>
</template>
</ms-node-tree>
<test-case-import @refreshAll="refreshAll" ref="testCaseImport"/>
<test-case-export @refreshAll="refreshAll" @exportTestCase="exportTestCase" ref="testCaseExport"/>
<test-case-import
@refreshAll="refreshAll"
ref="testCaseImport"/>
<test-case-export
@refreshAll="refreshAll"
@exportTestCase="exportTestCase"
ref="testCaseExport"/>
<test-case-create
:tree-nodes="treeNodes"
@saveAsEdit="saveAsEdit"