fix: 批量修改执行环境

This commit is contained in:
shiziyuan9527 2021-03-17 14:05:44 +08:00
parent 51e0461dc3
commit e58dcf4d88
12 changed files with 66 additions and 129 deletions

View File

@ -86,7 +86,7 @@ public class ApiAutomationController {
} }
@GetMapping("/getApiScenario/{id}") @GetMapping("/getApiScenario/{id}")
public ApiScenario getScenarioDefinition(@PathVariable String id) { public ApiScenarioDTO getScenarioDefinition(@PathVariable String id) {
return apiAutomationService.getApiScenario(id); return apiAutomationService.getApiScenario(id);
} }

View File

@ -18,4 +18,6 @@ public class ApiScenarioDTO extends ApiScenarioWithBLOBs {
* 场景跨项目ID * 场景跨项目ID
*/ */
private List<String> projectIds; private List<String> projectIds;
private String caseId;
} }

View File

@ -94,42 +94,38 @@ public class ApiAutomationService {
public List<ApiScenarioDTO> list(ApiScenarioRequest request) { public List<ApiScenarioDTO> list(ApiScenarioRequest request) {
request = this.initRequest(request, true, true); request = this.initRequest(request, true, true);
List<ApiScenarioDTO> list = extApiScenarioMapper.list(request); List<ApiScenarioDTO> list = extApiScenarioMapper.list(request);
setApiScenarioProjectIds(list);
return list; return list;
} }
public List<ApiScenarioDTO> listReview(ApiScenarioRequest request) { public List<ApiScenarioDTO> listReview(ApiScenarioRequest request) {
request = this.initRequest(request, true, true); request = this.initRequest(request, true, true);
List<ApiScenarioDTO> list = extApiScenarioMapper.listReview(request); List<ApiScenarioDTO> list = extApiScenarioMapper.listReview(request);
setApiScenarioProjectIds(list);
return list; return list;
} }
private void setApiScenarioProjectIds(List<ApiScenarioDTO> list) { private void setApiScenarioProjectIds(ApiScenarioDTO data) {
// 如果场景步骤涉及多项目则把涉及到的项目ID保存在projectIds属性 // 如果场景步骤涉及多项目则把涉及到的项目ID保存在projectIds属性
list.forEach(data -> { List<String> idList = new ArrayList<>();
List<String> idList = new ArrayList<>(); String definition = data.getScenarioDefinition();
String definition = data.getScenarioDefinition(); if (StringUtils.isNotBlank(definition)) {
if (StringUtils.isNotBlank(definition)) { RunDefinitionRequest d = JSON.parseObject(definition, RunDefinitionRequest.class);
RunDefinitionRequest d = JSON.parseObject(definition, RunDefinitionRequest.class);
if (d != null) { if (d != null) {
Map<String, String> map = d.getEnvironmentMap(); Map<String, String> map = d.getEnvironmentMap();
if (map != null) { if (map != null) {
if (map.isEmpty()) { if (map.isEmpty()) {
List<String> ids = (List<String>) JSONPath.read(definition, "$..projectId"); List<String> ids = (List<String>) JSONPath.read(definition, "$..projectId");
idList.addAll(new HashSet<>(ids)); idList.addAll(new HashSet<>(ids));
} else {
Set<String> set = d.getEnvironmentMap().keySet();
idList = new ArrayList<>(set);
}
} else { } else {
// 兼容历史数据无EnvironmentMap直接赋值场景所属项目 Set<String> set = d.getEnvironmentMap().keySet();
idList.add(data.getProjectId()); idList = new ArrayList<>(set);
} }
} else {
// 兼容历史数据无EnvironmentMap直接赋值场景所属项目
idList.add(data.getProjectId());
} }
} }
data.setProjectIds(idList);
}); }
data.setProjectIds(idList);
} }
/** /**
@ -333,8 +329,12 @@ public class ApiAutomationService {
} }
} }
public ApiScenarioWithBLOBs getApiScenario(String id) { public ApiScenarioDTO getApiScenario(String id) {
return apiScenarioMapper.selectByPrimaryKey(id); ApiScenarioDTO apiScenarioDTO = new ApiScenarioDTO();
ApiScenarioWithBLOBs scenarioWithBLOBs = apiScenarioMapper.selectByPrimaryKey(id);
BeanUtils.copyBean(apiScenarioDTO, scenarioWithBLOBs);
setApiScenarioProjectIds(apiScenarioDTO);
return apiScenarioDTO;
} }
public List<ApiScenarioWithBLOBs> getApiScenarios(List<String> ids) { public List<ApiScenarioWithBLOBs> getApiScenarios(List<String> ids) {

View File

@ -134,7 +134,6 @@
</sql> </sql>
<select id="list" resultMap="BaseResultMap"> <select id="list" resultMap="BaseResultMap">
select api_scenario.id, api_scenario.project_id, api_scenario.tags, api_scenario.user_id, api_scenario.num, select api_scenario.id, api_scenario.project_id, api_scenario.tags, api_scenario.user_id, api_scenario.num,
api_scenario.scenario_definition,
api_scenario.api_scenario_module_id,api_scenario.module_path, api_scenario.name, api_scenario.level, api_scenario.api_scenario_module_id,api_scenario.module_path, api_scenario.name, api_scenario.level,
api_scenario.status, api_scenario.principal, api_scenario.step_total, api_scenario.follow_people, api_scenario.status, api_scenario.principal, api_scenario.step_total, api_scenario.follow_people,
api_scenario.last_result,api_scenario.pass_rate,api_scenario.report_id, api_scenario.last_result,api_scenario.pass_rate,api_scenario.report_id,
@ -339,7 +338,6 @@
</select> </select>
<select id="listReview" resultMap="BaseResultMap"> <select id="listReview" resultMap="BaseResultMap">
select api_scenario.id, api_scenario.project_id, api_scenario.tags, api_scenario.user_id, api_scenario.num, select api_scenario.id, api_scenario.project_id, api_scenario.tags, api_scenario.user_id, api_scenario.num,
api_scenario.scenario_definition,
api_scenario.api_scenario_module_id,api_scenario.module_path, api_scenario.name, api_scenario.level, api_scenario.api_scenario_module_id,api_scenario.module_path, api_scenario.name, api_scenario.level,
api_scenario.status, api_scenario.principal, api_scenario.step_total, api_scenario.follow_people, api_scenario.status, api_scenario.principal, api_scenario.step_total, api_scenario.follow_people,
api_scenario.last_result,api_scenario.pass_rate,api_scenario.report_id, api_scenario.last_result,api_scenario.pass_rate,api_scenario.report_id,

View File

@ -1,22 +1,16 @@
package io.metersphere.track.service; package io.metersphere.track.service;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONPath;
import io.metersphere.api.dto.automation.ApiScenarioDTO; import io.metersphere.api.dto.automation.ApiScenarioDTO;
import io.metersphere.api.dto.automation.ApiScenarioRequest; import io.metersphere.api.dto.automation.ApiScenarioRequest;
import io.metersphere.api.dto.automation.RunScenarioRequest; import io.metersphere.api.dto.automation.RunScenarioRequest;
import io.metersphere.api.dto.automation.TestPlanScenarioRequest; import io.metersphere.api.dto.automation.TestPlanScenarioRequest;
import io.metersphere.api.dto.definition.RunDefinitionRequest;
import io.metersphere.api.service.ApiAutomationService; import io.metersphere.api.service.ApiAutomationService;
import io.metersphere.api.service.ApiScenarioReportService; import io.metersphere.api.service.ApiScenarioReportService;
import io.metersphere.base.domain.TestCaseReviewScenario; import io.metersphere.base.domain.TestCaseReviewScenario;
import io.metersphere.base.domain.TestCaseReviewScenarioExample; import io.metersphere.base.domain.TestCaseReviewScenarioExample;
import io.metersphere.base.domain.TestPlanApiScenario;
import io.metersphere.base.domain.TestPlanApiScenarioExample;
import io.metersphere.base.mapper.TestCaseReviewScenarioMapper; import io.metersphere.base.mapper.TestCaseReviewScenarioMapper;
import io.metersphere.base.mapper.TestPlanApiScenarioMapper;
import io.metersphere.base.mapper.ext.ExtTestCaseReviewScenarioCaseMapper; import io.metersphere.base.mapper.ext.ExtTestCaseReviewScenarioCaseMapper;
import io.metersphere.base.mapper.ext.ExtTestPlanScenarioCaseMapper;
import io.metersphere.commons.constants.ApiRunMode; import io.metersphere.commons.constants.ApiRunMode;
import io.metersphere.commons.utils.ServiceUtils; import io.metersphere.commons.utils.ServiceUtils;
import io.metersphere.track.dto.RelevanceScenarioRequest; import io.metersphere.track.dto.RelevanceScenarioRequest;
@ -45,46 +39,15 @@ public class TestCaseReviewScenarioCaseService {
request.setProjectId(null); request.setProjectId(null);
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
List<ApiScenarioDTO> apiTestCases = extTestCaseReviewScenarioCaseMapper.list(request); List<ApiScenarioDTO> apiTestCases = extTestCaseReviewScenarioCaseMapper.list(request);
setApiScenarioProjectIds(apiTestCases);
if (CollectionUtils.isEmpty(apiTestCases)) { if (CollectionUtils.isEmpty(apiTestCases)) {
return apiTestCases; return apiTestCases;
} }
return apiTestCases; return apiTestCases;
} }
private void setApiScenarioProjectIds(List<ApiScenarioDTO> list) {
// 如果场景步骤涉及多项目则把涉及到的项目ID保存在projectIds属性
list.forEach(data -> {
List<String> idList = new ArrayList<>();
String definition = data.getScenarioDefinition();
if (org.apache.commons.lang3.StringUtils.isNotBlank(definition)) {
RunDefinitionRequest d = JSON.parseObject(definition, RunDefinitionRequest.class);
if (d != null) {
Map<String, String> map = d.getEnvironmentMap();
if (map != null) {
if (map.isEmpty()) {
List<String> ids = (List<String>) JSONPath.read(definition, "$..projectId");
idList.addAll(new HashSet<>(ids));
} else {
Set<String> set = d.getEnvironmentMap().keySet();
idList = new ArrayList<>(set);
}
} else {
// 兼容历史数据无EnvironmentMap直接赋值场景所属项目
idList.add(data.getProjectId());
}
}
}
data.setProjectIds(idList);
});
}
public List<ApiScenarioDTO> relevanceList(ApiScenarioRequest request) { public List<ApiScenarioDTO> relevanceList(ApiScenarioRequest request) {
request.setNotInTestPlan(true); request.setNotInTestPlan(true);
List<ApiScenarioDTO> list = apiAutomationService.listReview(request); List<ApiScenarioDTO> list = apiAutomationService.listReview(request);
setApiScenarioProjectIds(list);
return list; return list;
} }

View File

@ -42,46 +42,15 @@ public class TestPlanScenarioCaseService {
request.setProjectId(null); request.setProjectId(null);
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
List<ApiScenarioDTO> apiTestCases = extTestPlanScenarioCaseMapper.list(request); List<ApiScenarioDTO> apiTestCases = extTestPlanScenarioCaseMapper.list(request);
setApiScenarioProjectIds(apiTestCases);
if (CollectionUtils.isEmpty(apiTestCases)) { if (CollectionUtils.isEmpty(apiTestCases)) {
return apiTestCases; return apiTestCases;
} }
return apiTestCases; return apiTestCases;
} }
private void setApiScenarioProjectIds(List<ApiScenarioDTO> list) {
// 如果场景步骤涉及多项目则把涉及到的项目ID保存在projectIds属性
list.forEach(data -> {
List<String> idList = new ArrayList<>();
String definition = data.getScenarioDefinition();
if (org.apache.commons.lang3.StringUtils.isNotBlank(definition)) {
RunDefinitionRequest d = JSON.parseObject(definition, RunDefinitionRequest.class);
if (d != null) {
Map<String, String> map = d.getEnvironmentMap();
if (map != null) {
if (map.isEmpty()) {
List<String> ids = (List<String>) JSONPath.read(definition, "$..projectId");
idList.addAll(new HashSet<>(ids));
} else {
Set<String> set = d.getEnvironmentMap().keySet();
idList = new ArrayList<>(set);
}
} else {
// 兼容历史数据无EnvironmentMap直接赋值场景所属项目
idList.add(data.getProjectId());
}
}
}
data.setProjectIds(idList);
});
}
public List<ApiScenarioDTO> relevanceList(ApiScenarioRequest request) { public List<ApiScenarioDTO> relevanceList(ApiScenarioRequest request) {
request.setNotInTestPlan(true); request.setNotInTestPlan(true);
List<ApiScenarioDTO> list = apiAutomationService.list(request); List<ApiScenarioDTO> list = apiAutomationService.list(request);
setApiScenarioProjectIds(list);
return list; return list;
} }

View File

@ -439,7 +439,7 @@
}, },
handleBatchEdit() { handleBatchEdit() {
this.$refs.batchEdit.open(this.selectDataCounts); this.$refs.batchEdit.open(this.selectDataCounts);
this.$refs.batchEdit.setScenarioSelectRows(this.selectRows); this.$refs.batchEdit.setScenarioSelectRows(this.selectRows, "scenario");
}, },
handleBatchMove() { handleBatchMove() {
this.$refs.testBatchMove.open(this.moduleTree, [], this.moduleOptions); this.$refs.testBatchMove.open(this.moduleTree, [], this.moduleOptions);
@ -457,11 +457,7 @@
// //
if (form.type === 'projectEnv') { if (form.type === 'projectEnv') {
let param = {}; let param = {};
let map = new Map(); param.mapping = strMapToObj(form.map);
this.selectRows.forEach(row => {
map.set(row.id, row.projectIds);
})
param.mapping = strMapToObj(map);
param.envMap = strMapToObj(form.projectEnvMap); param.envMap = strMapToObj(form.projectEnvMap);
this.$post('/api/automation/batch/update/env', param, () => { this.$post('/api/automation/batch/update/env', param, () => {
this.$success(this.$t('commons.save_success')); this.$success(this.$t('commons.save_success'));
@ -519,11 +515,7 @@
this.planVisible = false; this.planVisible = false;
let map = new Map(); obj.mapping = strMapToObj(params[2]);
this.selectRows.forEach(row => {
map.set(row.id, row.projectIds);
})
obj.mapping = strMapToObj(map);
obj.envMap = strMapToObj(params[1]); obj.envMap = strMapToObj(params[1]);
this.$post("/api/automation/scenario/plan", obj, response => { this.$post("/api/automation/scenario/plan", obj, response => {

View File

@ -195,7 +195,8 @@ export default {
], ],
projectEnvMap: new Map(), projectEnvMap: new Map(),
projectList: [], projectList: [],
projectIds: new Set() projectIds: new Set(),
map: new Map(),
} }
}, },
watch: { watch: {
@ -221,7 +222,7 @@ export default {
if (!sign) { if (!sign) {
return false; return false;
} }
this.$emit('addTestPlan', this.selection, this.projectEnvMap); this.$emit('addTestPlan', this.selection, this.projectEnvMap, this.map);
} }
}, },
cancel(){ cancel(){
@ -237,7 +238,11 @@ export default {
setScenarioSelectRows(rows) { setScenarioSelectRows(rows) {
this.projectIds.clear(); this.projectIds.clear();
rows.forEach(row => { rows.forEach(row => {
row.projectIds.forEach(id => this.projectIds.add(id)); this.result = this.$get('/api/automation/getApiScenario/' + row.id, res => {
let data = res.data;
data.projectIds.forEach(d => this.projectIds.add(d));
this.map.set(row.id, data.projectIds);
})
}) })
}, },
initTableData() { initTableData() {

View File

@ -7,6 +7,7 @@
class="batch-edit-dialog" class="batch-edit-dialog"
:destroy-on-close="true" :destroy-on-close="true"
@close="handleClose" @close="handleClose"
v-loading="result.loading"
> >
<el-form :model="form" label-position="right" label-width="150px" size="medium" ref="form" :rules="rules"> <el-form :model="form" label-position="right" label-width="150px" size="medium" ref="form" :rules="rules">
<el-form-item :label="$t('test_track.case.batch_update', [size])" prop="type"> <el-form-item :label="$t('test_track.case.batch_update', [size])" prop="type">
@ -72,7 +73,10 @@
projectList: [], projectList: [],
projectIds: new Set(), projectIds: new Set(),
selectRows: new Set(), selectRows: new Set(),
projectEnvMap: new Map() projectEnvMap: new Map(),
map: new Map(),
isScenario: '',
result: {}
} }
}, },
methods: { methods: {
@ -84,6 +88,7 @@
if (!this.$refs.envPopover.checkEnv()) { if (!this.$refs.envPopover.checkEnv()) {
return false; return false;
} }
this.form.map = this.map;
} }
this.$emit("batchEdit", this.form); this.$emit("batchEdit", this.form);
this.dialogVisible = false; this.dialogVisible = false;
@ -113,12 +118,9 @@
this.projectIds.add(row.projectId) this.projectIds.add(row.projectId)
}) })
}, },
setScenarioSelectRows(rows) { setScenarioSelectRows(rows, sign) {
this.selectRows = rows; this.selectRows = rows;
this.projectIds.clear(); this.isScenario = sign;
this.selectRows.forEach(row => {
row.projectIds.forEach(id => this.projectIds.add(id));
})
}, },
handleClose() { handleClose() {
this.form = {}; this.form = {};
@ -127,6 +129,17 @@
}, },
changeType(val) { changeType(val) {
this.$set(this.form, "value", ""); this.$set(this.form, "value", "");
if (val === 'projectEnv' && this.isScenario !== '') {
this.projectIds.clear();
this.selectRows.forEach(row => {
let id = this.isScenario === 'scenario' ? row.id : row.caseId;
this.result = this.$get('/api/automation/getApiScenario/' + id, res => {
let data = res.data;
data.projectIds.forEach(d => this.projectIds.add(d));
this.map.set(row.id, data.projectIds);
})
})
}
this.filterable = val === "maintainer" || val === "executor"; this.filterable = val === "maintainer" || val === "executor";
this.options = this.valueArr[val]; this.options = this.valueArr[val];
this.typeArr.forEach(item => { this.typeArr.forEach(item => {

View File

@ -93,6 +93,7 @@
projectEnvMap: new Map(), projectEnvMap: new Map(),
projectList: [], projectList: [],
projectIds: new Set(), projectIds: new Set(),
map: new Map()
} }
}, },
watch: { watch: {
@ -159,8 +160,10 @@
initProjectIds() { initProjectIds() {
this.projectIds.clear(); this.projectIds.clear();
this.selectRows.forEach(row => { this.selectRows.forEach(row => {
row.projectIds.forEach(id => { this.result = this.$get('/api/automation/getApiScenario/' + row.id, res => {
this.projectIds.add(id); let data = res.data;
data.projectIds.forEach(d => this.projectIds.add(d));
this.map.set(row.id, data.projectIds);
}) })
}) })
}, },

View File

@ -104,12 +104,8 @@
} }
let param = {}; let param = {};
let url = '/api/automation/relevance'; let url = '/api/automation/relevance';
let rows = this.$refs.apiScenarioList.selectRows;
const envMap = this.$refs.apiScenarioList.projectEnvMap; const envMap = this.$refs.apiScenarioList.projectEnvMap;
let map = new Map(); let map = this.$refs.apiScenarioList.map;
rows.forEach(row => {
map.set(row.id, row.projectIds);
})
param.planId = this.planId; param.planId = this.planId;
param.mapping = strMapToObj(map); param.mapping = strMapToObj(map);
param.envMap = strMapToObj(envMap); param.envMap = strMapToObj(envMap);

View File

@ -358,15 +358,11 @@ export default {
}, },
handleBatchEdit() { handleBatchEdit() {
this.$refs.batchEdit.open(this.selectRows.size); this.$refs.batchEdit.open(this.selectRows.size);
this.$refs.batchEdit.setScenarioSelectRows(this.selectRows); this.$refs.batchEdit.setScenarioSelectRows(this.selectRows, "planScenario");
}, },
batchEdit(form) { batchEdit(form) {
let param = {}; let param = {};
let map = new Map(); param.mapping = strMapToObj(form.map);
this.selectRows.forEach(row => {
map.set(row.id, row.projectIds);
})
param.mapping = strMapToObj(map);
param.envMap = strMapToObj(form.projectEnvMap); param.envMap = strMapToObj(form.projectEnvMap);
if (this.planId) { if (this.planId) {
this.$post('/test/plan/scenario/case/batch/update/env', param, () => { this.$post('/test/plan/scenario/case/batch/update/env', param, () => {