fix: 修复测试计划执行性能测试时、批量修改环境时只能操作当前页面数据的问题

修复测试计划执行性能测试时、批量修改环境时只能操作当前页面数据的问题
This commit is contained in:
song-tianyang 2021-04-26 18:59:21 +08:00 committed by 刘瑞斌
parent 1b8812d1cd
commit d325e065c3
14 changed files with 204 additions and 107 deletions

View File

@ -55,9 +55,9 @@
where 1 where 1
<if test="request.ids != null and request.ids.size() > 0"> <if test="request.ids != null and request.ids.size() > 0">
<if test="request.projectId != null and request.projectId!=''"> <if test="request.projectId != null and request.projectId!=''">
and and a.projectId = #{request.projectId}
</if> </if>
t.id in and t.id in
<foreach collection="request.ids" item="caseId" separator="," open="(" close=")"> <foreach collection="request.ids" item="caseId" separator="," open="(" close=")">
#{caseId} #{caseId}
</foreach> </foreach>

View File

@ -10,6 +10,9 @@ public interface ExtTestPlanLoadCaseMapper {
List<String> selectIdsNotInPlan(@Param("request") LoadCaseRequest request); List<String> selectIdsNotInPlan(@Param("request") LoadCaseRequest request);
List<TestPlanLoadCaseDTO> selectTestPlanLoadCaseList(@Param("request") LoadCaseRequest request); List<TestPlanLoadCaseDTO> selectTestPlanLoadCaseList(@Param("request") LoadCaseRequest request);
List<TestPlanLoadCaseDTO> selectByIdIn(@Param("request") LoadCaseRequest request);
void updateCaseStatus(@Param("reportId") String reportId, @Param("status") String status); void updateCaseStatus(@Param("reportId") String reportId, @Param("status") String status);
List<String> getStatusByTestPlanId(@Param("planId") String planId); List<String> getStatusByTestPlanId(@Param("planId") String planId);

View File

@ -68,6 +68,35 @@
</foreach> </foreach>
</if> </if>
</select> </select>
<select id="selectByIdIn" resultType="io.metersphere.track.dto.TestPlanLoadCaseDTO">
select tplc.id,
u.name as userName,
tplc.create_time,
tplc.update_time,
tplc.test_plan_id,
tplc.load_case_id,
lt.status,
lt.num,
tplc.status as caseStatus,
lt.name as caseName,
tplc.load_report_id,
p.name as projectName
from test_plan_load_case tplc
inner join load_test lt on tplc.load_case_id = lt.id
inner join user u on lt.user_id = u.id
inner join project p on lt.project_id = p.id
WHERE tplc.id in
<foreach collection="request.ids" item="value" separator="," open="(" close=")">
#{value}
</foreach>
<if test="request.orders != null and request.orders.size() > 0">
order by
<foreach collection="request.orders" separator="," item="order">
tplc.${order.name} ${order.type}
</foreach>
</if>
</select>
<select id="selectTestPlanLoadCaseId" resultType="java.lang.String"> <select id="selectTestPlanLoadCaseId" resultType="java.lang.String">
select tplc.id select tplc.id
from test_plan_load_case tplc from test_plan_load_case tplc

View File

@ -36,9 +36,9 @@
where 1 where 1
<if test="request.ids != null and request.ids.size() > 0"> <if test="request.ids != null and request.ids.size() > 0">
<if test="request.projectId != null and request.projectId!=''"> <if test="request.projectId != null and request.projectId!=''">
and and c.project_id = #{request.projectId}
</if> </if>
t.id in and t.id in
<foreach collection="request.ids" item="caseId" separator="," open="(" close=")"> <foreach collection="request.ids" item="caseId" separator="," open="(" close=")">
#{caseId} #{caseId}
</foreach> </foreach>

View File

@ -8,7 +8,6 @@ import io.metersphere.api.dto.definition.TestPlanApiCaseDTO;
import io.metersphere.commons.constants.RoleConstants; import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.utils.PageUtils; import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager; import io.metersphere.commons.utils.Pager;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.track.request.testcase.TestPlanApiCaseBatchRequest; import io.metersphere.track.request.testcase.TestPlanApiCaseBatchRequest;
import io.metersphere.track.service.TestPlanApiCaseService; import io.metersphere.track.service.TestPlanApiCaseService;
import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.Logical;
@ -31,6 +30,12 @@ public class TestPlanApiCaseController {
return PageUtils.setPageInfo(page, testPlanApiCaseService.list(request)); return PageUtils.setPageInfo(page, testPlanApiCaseService.list(request));
} }
@PostMapping("/selectAllTableRows")
public List<TestPlanApiCaseDTO> selectAllTableRows(@RequestBody TestPlanApiCaseBatchRequest request) {
return testPlanApiCaseService.selectAllTableRows(request);
}
@PostMapping("/relevance/list/{goPage}/{pageSize}") @PostMapping("/relevance/list/{goPage}/{pageSize}")
public Pager<List<ApiTestCaseDTO>> relevanceList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiTestCaseRequest request) { public Pager<List<ApiTestCaseDTO>> relevanceList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiTestCaseRequest request) {
return testPlanApiCaseService.relevanceList(goPage, pageSize, request); return testPlanApiCaseService.relevanceList(goPage, pageSize, request);

View File

@ -42,6 +42,11 @@ public class TestPlanLoadCaseController {
return PageUtils.setPageInfo(page, testPlanLoadCaseService.list(request)); return PageUtils.setPageInfo(page, testPlanLoadCaseService.list(request));
} }
@PostMapping("/selectAllTableRows")
public List<TestPlanLoadCaseDTO> selectAllTableRows(@RequestBody LoadCaseReportBatchRequest request) {
return testPlanLoadCaseService.selectAllTableRows(request);
}
@GetMapping("/delete/{id}") @GetMapping("/delete/{id}")
public void delete(@PathVariable String id) { public void delete(@PathVariable String id) {
testPlanLoadCaseService.delete(id); testPlanLoadCaseService.delete(id);

View File

@ -31,6 +31,11 @@ public class TestPlanScenarioCaseController {
return PageUtils.setPageInfo(page, testPlanScenarioCaseService.list(request)); return PageUtils.setPageInfo(page, testPlanScenarioCaseService.list(request));
} }
@PostMapping("/selectAllTableRows")
public List<ApiScenarioDTO> selectAllTableRows(@RequestBody TestPlanScenarioCaseBatchRequest request) {
return testPlanScenarioCaseService.selectAllTableRows(request);
}
@PostMapping("/relevance/list/{goPage}/{pageSize}") @PostMapping("/relevance/list/{goPage}/{pageSize}")
public Pager<List<ApiScenarioDTO>> relevanceList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiScenarioRequest request) { public Pager<List<ApiScenarioDTO>> relevanceList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiScenarioRequest request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true); Page<Object> page = PageHelper.startPage(goPage, pageSize, true);

View File

@ -11,6 +11,7 @@ import java.util.Map;
@Getter @Getter
@Setter @Setter
public class LoadCaseRequest extends TestPlanLoadCase { public class LoadCaseRequest extends TestPlanLoadCase {
private List<String> ids;
private String projectId; private String projectId;
private List<String> caseIds; private List<String> caseIds;
private String name; private String name;

View File

@ -105,6 +105,9 @@ public class TestPlanApiCaseService {
List<String> deleteIds = request.getIds(); List<String> deleteIds = request.getIds();
if(request.getCondition()!=null && request.getCondition().isSelectAll()){ if(request.getCondition()!=null && request.getCondition().isSelectAll()){
deleteIds = this.selectIds(request.getCondition()); deleteIds = this.selectIds(request.getCondition());
if (request.getCondition() != null && request.getCondition().getUnSelectIds() != null) {
deleteIds.removeAll(request.getCondition().getUnSelectIds());
}
} }
if (CollectionUtils.isEmpty(deleteIds)) { if (CollectionUtils.isEmpty(deleteIds)) {
@ -168,4 +171,21 @@ public class TestPlanApiCaseService {
return testPlanApiCaseMapper.selectByExample(example).get(0).getStatus(); return testPlanApiCaseMapper.selectByExample(example).get(0).getStatus();
} }
public List<TestPlanApiCaseDTO> selectAllTableRows(TestPlanApiCaseBatchRequest request) {
List<String> ids = request.getIds();
if (request.getCondition() != null && request.getCondition().isSelectAll()) {
ids = this.selectIds(request.getCondition());
if (request.getCondition() != null && request.getCondition().getUnSelectIds() != null) {
ids.removeAll(request.getCondition().getUnSelectIds());
}
}
if (ids == null || ids.isEmpty()) {
return new ArrayList<>();
}
ApiTestCaseRequest selectReq = new ApiTestCaseRequest();
selectReq.setIds(ids);
List<TestPlanApiCaseDTO> returnList = extTestPlanApiCaseMapper.list(selectReq);
return returnList;
}
} }

View File

@ -224,4 +224,33 @@ public class TestPlanLoadCaseService {
public List<String> getStatus(String planId) { public List<String> getStatus(String planId) {
return extTestPlanLoadCaseMapper.getStatusByTestPlanId(planId); return extTestPlanLoadCaseMapper.getStatusByTestPlanId(planId);
} }
public List<TestPlanLoadCaseDTO> selectAllTableRows(LoadCaseReportBatchRequest request) {
List<String> ids = request.getIds();
if (request.getCondition() != null && request.getCondition().isSelectAll()) {
ids = this.selectTestPlanLoadCaseIds(request.getCondition());
if (request.getCondition().getUnSelectIds() != null) {
ids.removeAll(request.getCondition().getUnSelectIds());
}
}
if (ids == null || ids.isEmpty()) {
return new ArrayList<>();
}
List<OrderRequest> orders = request.getCondition().getOrders();
if (orders == null || orders.size() < 1) {
OrderRequest orderRequest = new OrderRequest();
orderRequest.setName("create_time");
orderRequest.setType("desc");
orders = new ArrayList<>();
orders.add(orderRequest);
}
LoadCaseRequest tableReq = new LoadCaseRequest();
tableReq.setIds(ids);
tableReq.setOrders(orders);
List<TestPlanLoadCaseDTO> list = extTestPlanLoadCaseMapper.selectByIdIn(tableReq);
return list;
}
} }

View File

@ -74,6 +74,9 @@ public class TestPlanScenarioCaseService {
List<String> ids = request.getIds(); List<String> ids = request.getIds();
if(request.getCondition()!=null && request.getCondition().isSelectAll()){ if(request.getCondition()!=null && request.getCondition().isSelectAll()){
ids = this.selectIds(request.getCondition()); ids = this.selectIds(request.getCondition());
if (request.getCondition() != null && request.getCondition().getUnSelectIds() != null) {
ids.removeAll(request.getCondition().getUnSelectIds());
}
} }
if (CollectionUtils.isEmpty(ids)) { if (CollectionUtils.isEmpty(ids)) {
@ -180,4 +183,20 @@ public class TestPlanScenarioCaseService {
} }
public List<ApiScenarioDTO> selectAllTableRows(TestPlanScenarioCaseBatchRequest request) {
List<String> ids = request.getIds();
if (request.getCondition() != null && request.getCondition().isSelectAll()) {
ids = this.selectIds(request.getCondition());
if (request.getCondition() != null && request.getCondition().getUnSelectIds() != null) {
ids.removeAll(request.getCondition().getUnSelectIds());
}
}
if (ids == null || ids.isEmpty()) {
return new ArrayList<>();
}
TestPlanScenarioRequest tableRequest = new TestPlanScenarioRequest();
tableRequest.setIds(ids);
return extTestPlanScenarioCaseMapper.list(tableRequest);
}
} }

View File

@ -501,58 +501,67 @@ export default {
return new Promise((resolve) => { return new Promise((resolve) => {
let index = 1; let index = 1;
this.runData = []; this.runData = [];
// if (this.condition != null && this.condition.selectAll) {
this.orderBySelectRows(this.selectRows); let selectAllRowParams = buildBatchParam(this);
this.selectRows.forEach(row => { selectAllRowParams.ids = Array.from(this.selectRows).map(row => row.id);
this.$get('/api/testcase/get/' + row.caseId, (response) => { this.$post('/test/plan/api/case/selectAllTableRows', selectAllRowParams, response => {
let apiCase = response.data; let dataRows = response.data;
let request = JSON.parse(apiCase.request); //
request.name = row.id; this.orderBySelectRows(dataRows);
request.id = row.id; dataRows.forEach(row => {
request.useEnvironment = row.environmentId; this.$get('/api/testcase/get/' + row.caseId, (response) => {
this.runData.unshift(request); let apiCase = response.data;
if (this.selectRows.length === index) { let request = JSON.parse(apiCase.request);
resolve(); request.name = row.id;
} request.id = row.id;
index++; request.useEnvironment = row.environmentId;
this.runData.unshift(request);
if (dataRows.length === index) {
resolve();
}
index++;
});
});
}); });
}); } else {
//
this.orderBySelectRows(this.selectRows);
this.selectRows.forEach(row => {
this.$get('/api/testcase/get/' + row.caseId, (response) => {
let apiCase = response.data;
let request = JSON.parse(apiCase.request);
request.name = row.id;
request.id = row.id;
request.useEnvironment = row.environmentId;
this.runData.unshift(request);
if (this.selectRows.length === index) {
resolve();
}
index++;
});
});
}
}); });
}, },
batchEdit(form) { batchEdit(form) {
let param = {}; let param = {};
// //
if (form.type === 'projectEnv') { if (form.type === 'projectEnv') {
if(this.condition != null && this.condition.selectAll){ let selectAllRowParams = buildBatchParam(this);
this.$alert(this.$t('commons.option_cannot_spread_pages'), '', { selectAllRowParams.ids = Array.from(this.selectRows).map(row => row.id);
confirmButtonText: this.$t('commons.confirm'), this.$post('/test/plan/api/case/selectAllTableRows', selectAllRowParams, response => {
callback: (action) => { let dataRows = response.data;
if (action === 'confirm') {
let map = new Map();
param.projectEnvMap = strMapToObj(form.projectEnvMap);
this.selectRows.forEach(row => {
map[row.id] = row.projectId;
})
param.selectRows = map;
this.$post('/test/plan/api/case/batch/update/env', param, () => {
this.$success(this.$t('commons.save_success'));
this.initTable();
});
}
}
});
}else {
let map = new Map(); let map = new Map();
param.projectEnvMap = strMapToObj(form.projectEnvMap); param.projectEnvMap = strMapToObj(form.projectEnvMap);
this.selectRows.forEach(row => { dataRows.forEach(row => {
map[row.id] = row.projectId; map[row.id] = row.projectId;
}) });
param.selectRows = map; param.selectRows = map;
this.$post('/test/plan/api/case/batch/update/env', param, () => { this.$post('/test/plan/api/case/batch/update/env', param, () => {
this.$success(this.$t('commons.save_success')); this.$success(this.$t('commons.save_success'));
this.initTable(); this.initTable();
}); });
} });
} else { } else {
// //
} }
@ -568,26 +577,11 @@ export default {
this.selectRows = array; this.selectRows = array;
}, },
handleBatchExecute() { handleBatchExecute() {
if(this.condition != null && this.condition.selectAll) { this.getData().then(() => {
this.$alert(this.$t('commons.option_cannot_spread_pages'), '', { if (this.runData && this.runData.length > 0) {
confirmButtonText: this.$t('commons.confirm'), this.$refs.runMode.open();
callback: (action) => { }
if (action === 'confirm') { });
this.getData().then(() => {
if (this.runData && this.runData.length > 0) {
this.$refs.runMode.open();
}
});
}
}
})
}else {
this.getData().then(() => {
if (this.runData && this.runData.length > 0) {
this.$refs.runMode.open();
}
});
}
}, },
handleRunBatch(config) { handleRunBatch(config) {
let testPlan = new TestPlan(); let testPlan = new TestPlan();

View File

@ -423,42 +423,30 @@ export default {
}); });
}, },
handleBatchEdit() { handleBatchEdit() {
this.$refs.batchEdit.open(this.selectRows.size); if (this.condition != null && this.condition.selectAll) {
this.$refs.batchEdit.setScenarioSelectRows(this.selectRows, "planScenario"); let selectAllRowParams = buildBatchParam(this);
selectAllRowParams.ids = Array.from(this.selectRows).map(row => row.id);
this.$post('/test/plan/scenario/case/selectAllTableRows', selectAllRowParams, response => {
let dataRows = response.data;
this.$refs.batchEdit.open(dataRows.size);
this.$refs.batchEdit.setScenarioSelectRows(dataRows, "planScenario");
});
} else {
this.$refs.batchEdit.open(this.selectRows.size);
this.$refs.batchEdit.setScenarioSelectRows(this.selectRows, "planScenario");
}
}, },
batchEdit(form) { batchEdit(form) {
let param = {}; let param = {};
param.mapping = strMapToObj(form.map); param.mapping = strMapToObj(form.map);
param.envMap = strMapToObj(form.projectEnvMap); param.envMap = strMapToObj(form.projectEnvMap);
if(this.condition != null && this.condition.selectAll){ if (this.planId) {
this.$alert(this.$t('commons.option_cannot_spread_pages'), '', { this.$post('/test/plan/scenario/case/batch/update/env', param, () => {
confirmButtonText: this.$t('commons.confirm'), this.$success(this.$t('commons.save_success'));
callback: (action) => { this.search();
if (action === 'confirm') {
if (this.planId) {
this.$post('/test/plan/scenario/case/batch/update/env', param, () => {
this.$success(this.$t('commons.save_success'));
this.search();
})
}
}
}
}); });
}else {
if (this.planId) {
this.$post('/test/plan/scenario/case/batch/update/env', param, () => {
this.$success(this.$t('commons.save_success'));
this.search();
})
}
} }
// if (this.reviewId) {
// this.$post('/test/case/review/scenario/case/batch/update/env', param, () => {
// this.$success(this.$t('commons.save_success'));
// this.search();
// })
// }
}, },
isSelectDataAll(data) { isSelectDataAll(data) {
this.condition.selectAll = data; this.condition.selectAll = data;

View File

@ -251,23 +251,22 @@ export default {
runBatch(config){ runBatch(config){
this.orderBySelectRows(this.selectRows); this.orderBySelectRows(this.selectRows);
if(this.condition != null && this.condition.selectAll){ if(this.condition != null && this.condition.selectAll){
this.$alert(this.$t('commons.option_cannot_spread_pages'), '', { let selectAllRowParams = buildBatchParam(this);
confirmButtonText: this.$t('commons.confirm'), selectAllRowParams.ids = Array.from(this.selectRows).map(row => row.id);
callback: (action) => { this.$post('/test/plan/load/case/selectAllTableRows', selectAllRowParams, response => {
if (action === 'confirm') { let dataRows = response.data;
let runArr = []; let runArr = [];
this.selectRows.forEach(loadCase => { dataRows.forEach(loadCase => {
runArr.push( { runArr.push({
id: loadCase.loadCaseId, id: loadCase.loadCaseId,
testPlanLoadId: loadCase.id, testPlanLoadId: loadCase.id,
triggerMode: 'CASE' triggerMode: 'CASE'
}) });
}); });
let obj = {config:config,requests:runArr,userId:getCurrentUser().id}; let obj = {config: config, requests: runArr, userId: getCurrentUser().id};
this._runBatch(obj); this._runBatch(obj);
this.refreshStatus(); this.initTable();
} this.refreshStatus();
}
}); });
}else { }else {
let runArr = []; let runArr = [];