feat (接口自动化): 场景生成依赖关系

This commit is contained in:
fit2-zhao 2021-10-18 16:45:57 +08:00 committed by fit2-zhao
parent 50cbaa3d7c
commit 6c90ff32c6
6 changed files with 68 additions and 12 deletions

View File

@ -0,0 +1,8 @@
package io.metersphere.api.service;
import io.metersphere.base.domain.ApiScenarioWithBLOBs;
public interface ApiAutomationRelationshipEdgeService {
// 初始化引用关系
public void initRelationshipEdge(ApiScenarioWithBLOBs before, ApiScenarioWithBLOBs now);
}

View File

@ -256,7 +256,11 @@ public class ApiAutomationService {
apiScenarioMapper.insert(scenario);
apiScenarioReferenceIdService.saveByApiScenario(scenario);
// 存储依赖关系
ApiAutomationRelationshipEdgeService relationshipEdgeService = CommonBeanFactory.getBean(ApiAutomationRelationshipEdgeService.class);
if (relationshipEdgeService != null) {
relationshipEdgeService.initRelationshipEdge(null, scenario);
}
uploadFiles(request, bodyFiles, scenarioFiles);
return scenario;
@ -340,7 +344,8 @@ public class ApiAutomationService {
final ApiScenarioWithBLOBs scenario = buildSaveScenario(request);
Integer version = apiScenarioMapper.selectByPrimaryKey(request.getId()).getVersion();
ApiScenarioWithBLOBs beforeScenario = apiScenarioMapper.selectByPrimaryKey(request.getId());
Integer version = beforeScenario.getVersion();
if (version == null) {
scenario.setVersion(0);
} else {
@ -354,6 +359,12 @@ public class ApiAutomationService {
apiScenarioReferenceIdService.saveByApiScenario(scenario);
extScheduleMapper.updateNameByResourceID(request.getId(), request.getName());// 修改场景name同步到修改首页定时任务
uploadFiles(request, bodyFiles, scenarioFiles);
// 存储依赖关系
ApiAutomationRelationshipEdgeService relationshipEdgeService = CommonBeanFactory.getBean(ApiAutomationRelationshipEdgeService.class);
if (relationshipEdgeService != null) {
relationshipEdgeService.initRelationshipEdge(beforeScenario, scenario);
}
return scenario;
}
@ -1888,6 +1899,12 @@ public class ApiAutomationService {
scenarioWithBLOBs.setOrder(getImportNextOrder(request.getProjectId()));
scenarioWithBLOBs.setId(UUID.randomUUID().toString());
batchMapper.insert(scenarioWithBLOBs);
// 存储依赖关系
ApiAutomationRelationshipEdgeService relationshipEdgeService = CommonBeanFactory.getBean(ApiAutomationRelationshipEdgeService.class);
if (relationshipEdgeService != null) {
relationshipEdgeService.initRelationshipEdge(null, scenarioWithBLOBs);
}
apiScenarioReferenceIdService.saveByApiScenario(scenarioWithBLOBs);
}

View File

@ -4,13 +4,14 @@ import io.metersphere.api.dto.automation.ApiScenarioDTO;
import io.metersphere.api.dto.automation.ApiScenarioRequest;
import io.metersphere.api.dto.datacount.ApiDataCountResult;
import io.metersphere.base.domain.ApiScenario;
import io.metersphere.base.domain.ApiScenarioExample;
import io.metersphere.base.domain.ApiScenarioExampleWithOperation;
import io.metersphere.base.domain.ApiScenarioWithBLOBs;
import io.metersphere.dto.RelationshipGraphData;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
import java.util.Set;
public interface ExtApiScenarioMapper {
List<ApiScenarioDTO> list(@Param("request") ApiScenarioRequest request);
@ -67,7 +68,7 @@ public interface ExtApiScenarioMapper {
List<ApiScenarioWithBLOBs> selectByNoReferenceId();
void checkOriginalStatusByIds(@Param("ids")List<String> ids);
void checkOriginalStatusByIds(@Param("ids") List<String> ids);
List<String> selectIdsByExecuteTimeIsNull();
@ -77,7 +78,9 @@ public interface ExtApiScenarioMapper {
List<String> getIdsOrderByUpdateTime(@Param("projectId") String projectId);
Long getPreOrder(@Param("projectId")String projectId, @Param("baseOrder") Long baseOrder);
Long getPreOrder(@Param("projectId") String projectId, @Param("baseOrder") Long baseOrder);
Long getLastOrder(@Param("projectId")String projectId, @Param("baseOrder") Long baseOrder);
Long getLastOrder(@Param("projectId") String projectId, @Param("baseOrder") Long baseOrder);
List<RelationshipGraphData.Node> getTestCaseForGraph(@Param("ids") Set<String> ids);
}

View File

@ -582,5 +582,13 @@
</if>
</where>
</sql>
<select id="getTestCaseForGraph" resultType="io.metersphere.dto.RelationshipGraphData$Node">
select id,num,custom_num,`name`
from api_scenario
where id in
<foreach collection="ids" item="id" separator="," open="(" close=")">
#{id}
</foreach>
and api_scenario.status != 'Trash';
</select>
</mapper>

@ -1 +1 @@
Subproject commit 98bc55c1045fb8abc2ca0131bedaf9be69be4919
Subproject commit 77d0367751b0a996a32f1c4b6b18bee9becfc4e3

View File

@ -238,15 +238,17 @@
<ms-run :debug="true" :environment="projectEnvMap" @runRefresh="runRefresh" :reportId="reportId" :saved="true"
:run-data="debugData" ref="runTest"/>
<ms-task-center ref="taskCenter"/>
<relationship-graph-drawer :graph-data="graphData" ref="relationshipGraph"/>
</div>
</template>
<script>
import {downloadFile, getCurrentProjectID, getUUID, strMapToObj} from "@/common/js/utils";
import {downloadFile, getCurrentProjectID, getUUID, setDefaultTheme, strMapToObj} from "@/common/js/utils";
import {API_SCENARIO_CONFIGS} from "@/business/components/common/components/search/search-components";
import {API_SCENARIO_LIST} from "../../../../../common/js/constants";
import {API_SCENARIO_LIST, ORIGIN_COLOR} from "../../../../../common/js/constants";
import {getCustomTableHeader, getCustomTableWidth, getLastTableSortField} from "@/common/js/tableUtils";
import {buildBatchParam, getCustomTableHeader, getCustomTableWidth, getLastTableSortField} from "@/common/js/tableUtils";
import {API_SCENARIO_FILTERS} from "@/common/js/table-constants";
import {scenario} from "@/business/components/track/plan/event-bus";
import MsTable from "@/business/components/common/components/table/MsTable";
@ -255,7 +257,9 @@ import HeaderLabelOperate from "@/business/components/common/head/HeaderLabelOpe
import {editApiScenarioCaseOrder} from "@/business/components/api/automation/api-automation";
import {TYPE_TO_C} from "@/business/components/api/automation/scenario/Setting";
import axios from "axios";
import {error} from "@/common/js/message";
import RelationshipGraphDrawer from "@/business/components/xpack/graph/RelationshipGraphDrawer";
import {getGraphByCondition} from "@/network/graph";
import {hasLicense} from "@/common/js/utils";
export default {
name: "MsApiScenarioList",
@ -263,6 +267,7 @@ export default {
MsTable,
MsTableColumn,
HeaderLabelOperate,
RelationshipGraphDrawer,
HeaderCustom: () => import("@/business/components/common/head/HeaderCustom"),
BatchMove: () => import("../../../track/case/components/BatchMove"),
EnvironmentSelect: () => import("../../definition/components/environment/EnvironmentSelect"),
@ -438,6 +443,11 @@ export default {
handleClick: this.handleDeleteBatch,
permissions: ['PROJECT_API_SCENARIO:READ+DELETE']
},
{
name: "生成依赖关系",
handleClick: this.generateGraph,
permissions: ['PROJECT_API_SCENARIO:READ+MOVE_BATCH']
},
{
name: this.$t('api_test.automation.batch_add_plan'),
handleClick: this.handleBatchAddCase,
@ -478,9 +488,13 @@ export default {
projectEnv: [],
projectId: ''
},
graphData: {}
};
},
created() {
if (!hasLicense()) {
this.unTrashButtons.splice(5,1);
}
scenario.$on('hide', id => {
this.hideStopBtn(id);
});
@ -559,6 +573,12 @@ export default {
}
},
methods: {
generateGraph() {
getGraphByCondition('API_SCENARIO', buildBatchParam(this, this.$refs.scenarioTable.selectIds),(data) => {
this.graphData = data;
this.$refs.relationshipGraph.open();
});
},
getProjectName() {
this.$get('project/get/' + this.projectId, response => {
let project = response.data;