feat(测试计划): 测试计划复制
This commit is contained in:
parent
8b95866135
commit
cd575d83d6
|
@ -41,7 +41,7 @@ public class TestPlanController {
|
|||
CheckPermissionService checkPermissionService;
|
||||
|
||||
@PostMapping("/autoCheck/{testPlanId}")
|
||||
public void autoCheck(@PathVariable String testPlanId){
|
||||
public void autoCheck(@PathVariable String testPlanId) {
|
||||
testPlanService.checkStatus(testPlanId);
|
||||
}
|
||||
|
||||
|
@ -162,4 +162,8 @@ public class TestPlanController {
|
|||
return testPlanService.run(testplanRunRequest.getTestPlanId(), testplanRunRequest.getProjectId(), testplanRunRequest.getUserId(), testplanRunRequest.getTriggerMode(), apiRunConfig);
|
||||
}
|
||||
|
||||
@PostMapping("/copy/{id}")
|
||||
public TestPlan copy(@PathVariable String id) {
|
||||
return testPlanService.copy(id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -342,4 +342,13 @@ public class TestPlanLoadCaseService {
|
|||
.andStatusEqualTo("error");
|
||||
return testPlanLoadCaseMapper.countByExample(example) > 0 ? true : false;
|
||||
}
|
||||
|
||||
public void deleteByPlanId(String planId) {
|
||||
if (StringUtils.isBlank(planId)) {
|
||||
return;
|
||||
}
|
||||
TestPlanLoadCaseExample example = new TestPlanLoadCaseExample();
|
||||
example.createCriteria().andTestPlanIdEqualTo(planId);
|
||||
testPlanLoadCaseMapper.deleteByExample(example);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -309,6 +309,9 @@ public class TestPlanScenarioCaseService {
|
|||
}
|
||||
Project project = projectService.getProjectById(projectId);
|
||||
ApiTestEnvironmentWithBLOBs environment = apiTestEnvironmentMapper.selectByPrimaryKey(envId);
|
||||
if (project == null || environment == null) {
|
||||
continue;
|
||||
}
|
||||
String projectName = project.getName();
|
||||
String envName = environment.getName();
|
||||
if (StringUtils.isBlank(projectName) || StringUtils.isBlank(envName)) {
|
||||
|
|
|
@ -52,6 +52,7 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
@ -299,6 +300,7 @@ public class TestPlanService {
|
|||
deleteTestCaseByPlanId(planId);
|
||||
testPlanApiCaseService.deleteByPlanId(planId);
|
||||
testPlanScenarioCaseService.deleteByPlanId(planId);
|
||||
testPlanLoadCaseService.deleteByPlanId(planId);
|
||||
|
||||
//删除定时任务
|
||||
scheduleService.deleteByResourceId(planId, ScheduleGroup.TEST_PLAN_TEST.name());
|
||||
|
@ -1148,4 +1150,108 @@ public class TestPlanService {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public TestPlan copy(String planId) {
|
||||
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(planId);
|
||||
if (testPlan == null) {
|
||||
return null;
|
||||
}
|
||||
String sourcePlanId = testPlan.getId();
|
||||
String targetPlanId = UUID.randomUUID().toString();
|
||||
|
||||
TestPlan targetPlan = new TestPlan();
|
||||
targetPlan.setId(targetPlanId);
|
||||
targetPlan.setName(testPlan.getName() + "_COPY");
|
||||
targetPlan.setWorkspaceId(testPlan.getWorkspaceId());
|
||||
targetPlan.setDescription(testPlan.getDescription());
|
||||
targetPlan.setStage(testPlan.getStage());
|
||||
targetPlan.setPrincipal(testPlan.getPrincipal());
|
||||
targetPlan.setTags(testPlan.getTags());
|
||||
targetPlan.setProjectId(testPlan.getProjectId());
|
||||
testPlan.setAutomaticStatusUpdate(testPlan.getAutomaticStatusUpdate());
|
||||
targetPlan.setStatus(TestPlanStatus.Prepare.name());
|
||||
targetPlan.setCreator(SessionUtils.getUserId());
|
||||
targetPlan.setCreateTime(System.currentTimeMillis());
|
||||
targetPlan.setUpdateTime(System.currentTimeMillis());
|
||||
testPlanMapper.insert(targetPlan);
|
||||
|
||||
copyPlanCase(sourcePlanId, targetPlanId);
|
||||
|
||||
return targetPlan;
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void copyPlanCase(String sourcePlanId, String targetPlanId) {
|
||||
TestPlanTestCaseExample testPlanTestCaseExample = new TestPlanTestCaseExample();
|
||||
testPlanTestCaseExample.createCriteria().andPlanIdEqualTo(sourcePlanId);
|
||||
List<TestPlanTestCase> testPlanTestCases = testPlanTestCaseMapper.selectByExample(testPlanTestCaseExample);
|
||||
try(SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH)){
|
||||
TestPlanTestCaseMapper testCaseMapper = sqlSession.getMapper(TestPlanTestCaseMapper.class);
|
||||
testPlanTestCases.forEach(testCase -> {
|
||||
TestPlanTestCaseWithBLOBs testPlanTestCase = new TestPlanTestCaseWithBLOBs();
|
||||
testPlanTestCase.setId(UUID.randomUUID().toString());
|
||||
testPlanTestCase.setPlanId(targetPlanId);
|
||||
testPlanTestCase.setCaseId(testCase.getCaseId());
|
||||
testPlanTestCase.setStatus("Prepare");
|
||||
testPlanTestCase.setExecutor(testCase.getExecutor());
|
||||
testPlanTestCase.setCreateTime(System.currentTimeMillis());
|
||||
testPlanTestCase.setUpdateTime(System.currentTimeMillis());
|
||||
testPlanTestCase.setCreateUser(SessionUtils.getUserId());
|
||||
testPlanTestCase.setRemark(testCase.getRemark());
|
||||
testCaseMapper.insert(testPlanTestCase);
|
||||
});
|
||||
sqlSession.flushStatements();
|
||||
|
||||
TestPlanApiCaseExample testPlanApiCaseExample = new TestPlanApiCaseExample();
|
||||
testPlanApiCaseExample.createCriteria().andTestPlanIdEqualTo(sourcePlanId);
|
||||
List<TestPlanApiCase> testPlanApiCases = testPlanApiCaseMapper.selectByExample(testPlanApiCaseExample);
|
||||
TestPlanApiCaseMapper apiCaseMapper = sqlSession.getMapper(TestPlanApiCaseMapper.class);
|
||||
testPlanApiCases.forEach(apiCase -> {
|
||||
TestPlanApiCase api = new TestPlanApiCase();
|
||||
api.setId(UUID.randomUUID().toString());
|
||||
api.setTestPlanId(targetPlanId);
|
||||
api.setApiCaseId(apiCase.getApiCaseId());
|
||||
api.setEnvironmentId(apiCase.getEnvironmentId());
|
||||
api.setCreateTime(System.currentTimeMillis());
|
||||
api.setUpdateTime(System.currentTimeMillis());
|
||||
api.setCreateUser(SessionUtils.getUserId());
|
||||
apiCaseMapper.insert(api);
|
||||
});
|
||||
sqlSession.flushStatements();
|
||||
|
||||
TestPlanApiScenarioExample testPlanApiScenarioExample = new TestPlanApiScenarioExample();
|
||||
testPlanApiScenarioExample.createCriteria().andTestPlanIdEqualTo(sourcePlanId);
|
||||
List<TestPlanApiScenario> apiScenarios = testPlanApiScenarioMapper.selectByExampleWithBLOBs(testPlanApiScenarioExample);
|
||||
TestPlanApiScenarioMapper apiScenarioMapper = sqlSession.getMapper(TestPlanApiScenarioMapper.class);
|
||||
apiScenarios.forEach(apiScenario -> {
|
||||
TestPlanApiScenario planScenario = new TestPlanApiScenario();
|
||||
planScenario.setId(UUID.randomUUID().toString());
|
||||
planScenario.setTestPlanId(targetPlanId);
|
||||
planScenario.setApiScenarioId(apiScenario.getApiScenarioId());
|
||||
planScenario.setEnvironment(apiScenario.getEnvironment());
|
||||
planScenario.setCreateTime(System.currentTimeMillis());
|
||||
planScenario.setUpdateTime(System.currentTimeMillis());
|
||||
planScenario.setCreateUser(SessionUtils.getUserId());
|
||||
apiScenarioMapper.insert(planScenario);
|
||||
});
|
||||
sqlSession.flushStatements();
|
||||
|
||||
TestPlanLoadCaseExample example = new TestPlanLoadCaseExample();
|
||||
example.createCriteria().andTestPlanIdEqualTo(sourcePlanId);
|
||||
List<TestPlanLoadCase> loadCases = testPlanLoadCaseMapper.selectByExample(example);
|
||||
TestPlanLoadCaseMapper mapper = sqlSession.getMapper(TestPlanLoadCaseMapper.class);
|
||||
loadCases.forEach(loadCase -> {
|
||||
TestPlanLoadCase load = new TestPlanLoadCase();
|
||||
load.setId(UUID.randomUUID().toString());
|
||||
load.setTestPlanId(targetPlanId);
|
||||
load.setLoadCaseId(loadCase.getLoadCaseId());
|
||||
load.setCreateTime(System.currentTimeMillis());
|
||||
load.setUpdateTime(System.currentTimeMillis());
|
||||
load.setCreateUser(SessionUtils.getUserId());
|
||||
mapper.insert(load);
|
||||
});
|
||||
sqlSession.flushStatements();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,13 +37,6 @@ export default {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
isTesterPermission() {
|
||||
return function (btn) {
|
||||
return btn.isTesterPermission !== false;
|
||||
};
|
||||
},
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
|
|
@ -185,10 +185,11 @@
|
|||
<template v-slot:default="scope">
|
||||
<div>
|
||||
<ms-table-operator :edit-permission="['PROJECT_TRACK_PLAN:READ+EDIT']"
|
||||
:delete-permission="['PROJECT_TRACK_PLAN:READ+DELETE']"
|
||||
@editClick="handleEdit(scope.row)"
|
||||
@deleteClick="handleDelete(scope.row)">
|
||||
:show-delete="false"
|
||||
@editClick="handleEdit(scope.row)">
|
||||
<template v-slot:middle>
|
||||
<ms-table-operator-button :tip="$t('commons.copy')" icon="el-icon-copy-document"
|
||||
@exec="handleCopy(scope.row)"/>
|
||||
<ms-table-operator-button v-permission="['PROJECT_TRACK_PLAN:READ+EDIT']"
|
||||
v-if="!scope.row.reportId"
|
||||
:tip="$t('test_track.plan_view.create_report')" icon="el-icon-s-data"
|
||||
|
@ -199,17 +200,19 @@
|
|||
@exec="openReport(scope.row.id, scope.row.reportId)"/>
|
||||
</template>
|
||||
</ms-table-operator>
|
||||
<ms-table-operator-button class="schedule-btn"
|
||||
v-permission="['PROJECT_TRACK_PLAN:READ+SCHEDULE']"
|
||||
v-if="!scope.row.scheduleOpen" type="text"
|
||||
:tip="$t('commons.trigger_mode.schedule')" icon="el-icon-time"
|
||||
@exec="scheduleTask(scope.row)"/>
|
||||
<ms-table-operator-button
|
||||
class="schedule-btn"
|
||||
v-permission="['PROJECT_TRACK_PLAN:READ+SCHEDULE']"
|
||||
v-if="scope.row.scheduleOpen" type="text"
|
||||
:tip="$t('commons.trigger_mode.schedule')" icon="el-icon-time"
|
||||
@exec="scheduleTask(scope.row)"/>
|
||||
<el-dropdown @command="handleCommand($event, scope.row)" class="scenario-ext-btn">
|
||||
<el-link type="primary" :underline="false">
|
||||
<el-icon class="el-icon-more"></el-icon>
|
||||
</el-link>
|
||||
<el-dropdown-menu slot="dropdown">
|
||||
<el-dropdown-item command="delete" v-permission="['PROJECT_TRACK_PLAN:READ+DELETE']">
|
||||
{{ $t('commons.delete') }}
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item command="schedule_task" v-permission="['PROJECT_TRACK_PLAN:READ+SCHEDULE']">
|
||||
{{ $t('commons.trigger_mode.schedule') }}
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</el-dropdown>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
@ -462,6 +465,22 @@ export default {
|
|||
}
|
||||
}
|
||||
return returnObj;
|
||||
},
|
||||
handleCommand(cmd, row) {
|
||||
switch (cmd) {
|
||||
case "delete":
|
||||
this.handleDelete(row);
|
||||
break;
|
||||
case "schedule_task":
|
||||
this.scheduleTask(row);
|
||||
break;
|
||||
}
|
||||
},
|
||||
handleCopy(row) {
|
||||
this.cardResult.loading = true;
|
||||
this.$post('test/plan/copy/' + row.id, {},() => {
|
||||
this.initTableData();
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -485,4 +504,8 @@ export default {
|
|||
border-color: #85888E;
|
||||
border-width: thin;
|
||||
}
|
||||
|
||||
.scenario-ext-btn {
|
||||
margin-left: 10px;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -323,9 +323,11 @@ export default {
|
|||
this.tableData.forEach(item => {
|
||||
try {
|
||||
const envs = JSON.parse(item.environment);
|
||||
this.$post("/test/plan/scenario/case/env", envs, res => {
|
||||
this.$set(item, 'envs', res.data);
|
||||
})
|
||||
if (envs) {
|
||||
this.$post("/test/plan/scenario/case/env", envs, res => {
|
||||
this.$set(item, 'envs', res.data);
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
this.$set(item, 'envs', {});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue