refactor: 关系图优化

This commit is contained in:
chenjianxing 2021-10-18 10:32:19 +08:00 committed by jianxing
parent 9e773d20be
commit 50cbaa3d7c
12 changed files with 92 additions and 13 deletions

View File

@ -566,6 +566,7 @@
<foreach collection="ids" item="id" separator="," open="(" close=")"> <foreach collection="ids" item="id" separator="," open="(" close=")">
#{id} #{id}
</foreach> </foreach>
and test_case.status != 'Trash';
</select> </select>
<update id="deleteToGc"> <update id="deleteToGc">

View File

@ -1,8 +1,11 @@
package io.metersphere.dto; package io.metersphere.dto;
import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@Getter @Getter
@ -12,12 +15,18 @@ public class RelationshipGraphData {
private List<Node> data; private List<Node> data;
private List<Edge> links; private List<Edge> links;
public RelationshipGraphData() {
this.data = new ArrayList<>();
this.links = new ArrayList<>();
}
@Getter @Getter
@Setter @Setter
public static class Node { public static class Node {
private String id; private String id;
private Integer index; private Integer index;
private String name; private String name;
private Boolean highlight;
private Integer x; private Integer x;
private Integer y; private Integer y;
} }
@ -28,4 +37,16 @@ public class RelationshipGraphData {
private Integer source; private Integer source;
private Integer target; private Integer target;
} }
/**
* 记录当前遍历时已经占用的 x 坐标的最大最小值
*/
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public static class XAxisMark {
private Integer min;
private Integer max;
}
} }

View File

@ -39,6 +39,24 @@ public class RelationshipEdgeService {
relationshipEdgeMapper.deleteByExample(example); relationshipEdgeMapper.deleteByExample(example);
} }
public void delete(String sourceIdOrTargetId) {
RelationshipEdgeExample example = new RelationshipEdgeExample();
example.createCriteria()
.andSourceIdEqualTo(sourceIdOrTargetId);
example.or(example.createCriteria()
.andTargetIdEqualTo(sourceIdOrTargetId));
relationshipEdgeMapper.deleteByExample(example);
}
public void delete(List<String> sourceIdOrTargetIds) {
RelationshipEdgeExample example = new RelationshipEdgeExample();
example.createCriteria()
.andSourceIdIn(sourceIdOrTargetIds);
example.or(example.createCriteria()
.andTargetIdIn(sourceIdOrTargetIds));
relationshipEdgeMapper.deleteByExample(example);
}
public List<RelationshipEdge> getBySourceId(String sourceId) { public List<RelationshipEdge> getBySourceId(String sourceId) {
RelationshipEdgeExample example = new RelationshipEdgeExample(); RelationshipEdgeExample example = new RelationshipEdgeExample();
example.createCriteria() example.createCriteria()

View File

@ -325,6 +325,7 @@ public class TestCaseService {
examples.createCriteria().andTestCaseIdEqualTo(testCaseId); examples.createCriteria().andTestCaseIdEqualTo(testCaseId);
testCaseTestMapper.deleteByExample(examples); testCaseTestMapper.deleteByExample(examples);
relateDelete(testCaseId); relateDelete(testCaseId);
relationshipEdgeService.delete(testCaseId); // 删除关系图
return testCaseMapper.deleteByPrimaryKey(testCaseId); return testCaseMapper.deleteByPrimaryKey(testCaseId);
} }
@ -1237,6 +1238,17 @@ public class TestCaseService {
public void deleteTestCaseBath(TestCaseBatchRequest request) { public void deleteTestCaseBath(TestCaseBatchRequest request) {
TestCaseExample example = this.getBatchExample(request); TestCaseExample example = this.getBatchExample(request);
deleteTestPlanTestCaseBath(request.getIds()); deleteTestPlanTestCaseBath(request.getIds());
relationshipEdgeService.delete(request.getIds()); // 删除关系图
request.getIds().forEach(testCaseId -> { // todo 优化下效率
testCaseIssueService.delTestCaseIssues(testCaseId);
testCaseCommentService.deleteCaseComment(testCaseId);
TestCaseTestExample examples = new TestCaseTestExample();
examples.createCriteria().andTestCaseIdEqualTo(testCaseId);
testCaseTestMapper.deleteByExample(examples);
relateDelete(testCaseId);
});
testCaseMapper.deleteByExample(example); testCaseMapper.deleteByExample(example);
} }
@ -1810,7 +1822,6 @@ public class TestCaseService {
} }
public void deleteToGcBatch(TestCaseBatchRequest request) { public void deleteToGcBatch(TestCaseBatchRequest request) {
TestCaseExample example = this.getBatchExample(request);
if (CollectionUtils.isNotEmpty(request.getIds())) { if (CollectionUtils.isNotEmpty(request.getIds())) {
for (String id : request.getIds()) { for (String id : request.getIds()) {
this.deleteTestCaseToGc(id); this.deleteTestCaseToGc(id);

@ -1 +1 @@
Subproject commit 8eb2b79893a70986d06f47ffeac9c6ae12e6fff7 Subproject commit 98bc55c1045fb8abc2ca0131bedaf9be69be4919

View File

@ -8,6 +8,7 @@
@setTreeNodes="setTreeNodes" @setTreeNodes="setTreeNodes"
@exportTestCase="exportTestCase" @exportTestCase="exportTestCase"
@saveAsEdit="editTestCase" @saveAsEdit="editTestCase"
@openGraph="openGraph"
:show-operator="true" :show-operator="true"
@createCase="handleCaseSimpleCreate($event, 'add')" @createCase="handleCaseSimpleCreate($event, 'add')"
@refreshAll="refreshAll" @refreshAll="refreshAll"
@ -323,6 +324,9 @@ export default {
} }
this.$refs.testCaseList.exportTestCase(type); this.$refs.testCaseList.exportTestCase(type);
}, },
openGraph() {
this.$refs.testCaseList.generateGraph();
},
addListener() { addListener() {
let index = this.tabs.findIndex(item => item.name === this.activeName); // tabindex let index = this.tabs.findIndex(item => item.name === this.activeName); // tabindex
if (index != -1) { // tab if (index != -1) { // tab

View File

@ -15,7 +15,7 @@
<script> <script>
import TestCaseRelationshipList from "@/business/components/track/case/components/TestCaseRelationshipList"; import TestCaseRelationshipList from "@/business/components/track/case/components/TestCaseRelationshipList";
import RelationshipGraphDrawer from "@/business/components/xpack/graph/RelationshipGraphDrawer"; import RelationshipGraphDrawer from "@/business/components/xpack/graph/RelationshipGraphDrawer";
import {getRelationshipGraph} from "@/network/testCase"; import {getRelationshipGraph} from "@/network/graph";
export default { export default {
name: "TestCaseDependencies", name: "TestCaseDependencies",
components: {RelationshipGraphDrawer, TestCaseRelationshipList}, components: {RelationshipGraphDrawer, TestCaseRelationshipList},

View File

@ -176,6 +176,8 @@
<batch-move @refresh="refresh" @moveSave="moveSave" ref="testBatchMove"/> <batch-move @refresh="refresh" @moveSave="moveSave" ref="testBatchMove"/>
<test-case-preview ref="testCasePreview" :loading="rowCaseResult.loading"/> <test-case-preview ref="testCasePreview" :loading="rowCaseResult.loading"/>
<relationship-graph-drawer :graph-data="graphData" ref="relationshipGraph"/>
</div> </div>
</template> </template>
@ -223,10 +225,13 @@ import BatchMove from "@/business/components/track/case/components/BatchMove";
import {SYSTEM_FIELD_NAME_MAP} from "@/common/js/table-constants"; import {SYSTEM_FIELD_NAME_MAP} from "@/common/js/table-constants";
import TestCasePreview from "@/business/components/track/case/components/TestCasePreview"; import TestCasePreview from "@/business/components/track/case/components/TestCasePreview";
import {editTestCaseOrder} from "@/network/testCase"; import {editTestCaseOrder} from "@/network/testCase";
import {getGraphByCondition} from "@/network/graph";
import RelationshipGraphDrawer from "@/business/components/xpack/graph/RelationshipGraphDrawer";
export default { export default {
name: "TestCaseList", name: "TestCaseList",
components: { components: {
RelationshipGraphDrawer,
TestCasePreview, TestCasePreview,
BatchMove, BatchMove,
MsTableColumn, MsTableColumn,
@ -264,6 +269,7 @@ export default {
condition: { condition: {
components: TEST_CASE_CONFIGS components: TEST_CASE_CONFIGS
}, },
graphData: {},
priorityFilters: [ priorityFilters: [
{text: 'P0', value: 'P0'}, {text: 'P0', value: 'P0'},
{text: 'P1', value: 'P1'}, {text: 'P1', value: 'P1'},
@ -704,6 +710,12 @@ export default {
} }
}); });
}, },
generateGraph() {
getGraphByCondition('TEST_CASE', buildBatchParam(this, this.$refs.table.selectIds),(data) => {
this.graphData = data;
this.$refs.relationshipGraph.open();
});
},
handleDeleteBatchToGc() { handleDeleteBatchToGc() {
this.$alert(this.$t('test_track.case.delete_confirm') + "", '', { this.$alert(this.$t('test_track.case.delete_confirm') + "", '', {
confirmButtonText: this.$t('commons.confirm'), confirmButtonText: this.$t('commons.confirm'),

View File

@ -26,15 +26,14 @@
<module-trash-button :condition="condition" :exe="enableTrash"/> <module-trash-button :condition="condition" :exe="enableTrash"/>
</template> </template>
</ms-node-tree> </ms-node-tree>
<test-case-import @refreshAll="refreshAll" ref="testCaseImport"></test-case-import> <test-case-import @refreshAll="refreshAll" ref="testCaseImport"/>
<test-case-export @refreshAll="refreshAll" @exportTestCase="exportTestCase" ref="testCaseExport"></test-case-export> <test-case-export @refreshAll="refreshAll" @exportTestCase="exportTestCase" ref="testCaseExport"/>
<test-case-create <test-case-create
:tree-nodes="treeNodes" :tree-nodes="treeNodes"
@saveAsEdit="saveAsEdit" @saveAsEdit="saveAsEdit"
@createCase="createCase" @createCase="createCase"
@refresh="refresh" @refresh="refresh"
ref="testCaseCreate" ref="testCaseCreate"/>
></test-case-create>
</div> </div>
</template> </template>
@ -82,6 +81,11 @@ export default {
label: this.$t('api_test.export_config'), label: this.$t('api_test.export_config'),
callback: this.handleExport, callback: this.handleExport,
permissions: ['PROJECT_TRACK_CASE:READ+EXPORT'] permissions: ['PROJECT_TRACK_CASE:READ+EXPORT']
},
{
label: this.$t('查看依赖'),
callback: this.openGraph,
// permissions: ['PROJECT_TRACK_CASE:READ+EXPORT']
} }
] ]
}; };
@ -110,6 +114,9 @@ export default {
}, },
}, },
methods: { methods: {
openGraph() {
this.$emit('openGraph');
},
addTestCase(){ addTestCase(){
if (!this.projectId) { if (!this.projectId) {
this.$warning(this.$t('commons.check_project_tip')); this.$warning(this.$t('commons.check_project_tip'));

@ -1 +1 @@
Subproject commit 3c2c5a4b0e81b4235e75a1f8f36d2a0187f31443 Subproject commit b52d1dece80ce636bca17121ce491bbad433213d

View File

@ -0,0 +1,10 @@
import {baseGet, basePost} from "@/network/base-network";
export function getRelationshipGraph(id, type, callback) {
return baseGet('/graph/relationship/graph/' + id + '/' + type, callback);
}
export function getGraphByCondition(relationshipType, param, callback) {
return basePost('/graph/relationship/graph/condition/' + relationshipType, param, callback);
}

View File

@ -70,8 +70,3 @@ export function getTestCaseNodes(projectId, callback) {
export function getRelationshipCase(id, relationshipType, callback) { export function getRelationshipCase(id, relationshipType, callback) {
return baseGet('/test/case/relationship/case/' + id + '/' + relationshipType, callback); return baseGet('/test/case/relationship/case/' + id + '/' + relationshipType, callback);
} }
export function getRelationshipGraph(id, type, callback) {
return baseGet('/graph/relationship/graph/' + id + '/' + type, callback);
}