feat: 测试计划报告按配置导出
This commit is contained in:
parent
f19a571b4c
commit
ee5f101ca3
|
@ -32,6 +32,6 @@ public interface ExtTestPlanApiCaseMapper {
|
|||
|
||||
List<PlanReportCaseDTO> selectForPlanReport(String planId);
|
||||
|
||||
List<TestPlanFailureApiDTO> getFailureList(String planId);
|
||||
List<TestPlanFailureApiDTO> getFailureList(@Param("planId") String planId, @Param("status") String status);
|
||||
}
|
||||
|
||||
|
|
|
@ -259,7 +259,10 @@
|
|||
inner join
|
||||
api_test_case c
|
||||
on t.api_case_id = c.id
|
||||
and t.test_plan_id = #{request.planId} and t.status = 'error'
|
||||
and t.test_plan_id = #{planId}
|
||||
<if test="status != null">
|
||||
and t.status = 'error'
|
||||
</if>
|
||||
where t.test_plan_id = #{planId};
|
||||
</select>
|
||||
|
||||
|
|
|
@ -24,5 +24,5 @@ public interface ExtTestPlanLoadCaseMapper {
|
|||
|
||||
List<PlanReportCaseDTO> selectForPlanReport(String planId);
|
||||
|
||||
List<TestPlanLoadCaseDTO> getFailureCases(String planId);
|
||||
List<TestPlanLoadCaseDTO> getCases(@Param("planId") String planId, @Param("status") String status);
|
||||
}
|
||||
|
|
|
@ -178,11 +178,14 @@
|
|||
<select id="selectForPlanReport" resultType="io.metersphere.track.dto.PlanReportCaseDTO">
|
||||
select id,status from test_plan_load_case where test_plan_id = #{planId};
|
||||
</select>
|
||||
<select id="getFailureCases" resultType="io.metersphere.track.dto.TestPlanLoadCaseDTO">
|
||||
<select id="getCases" resultType="io.metersphere.track.dto.TestPlanLoadCaseDTO">
|
||||
select tplc.id, lt.id as caseId, lt.name, lt.num, lt.project_id,
|
||||
tplc.status ,tplc.create_user
|
||||
tplc.status ,tplc.create_user, tplc.load_report_id
|
||||
from test_plan_load_case tplc
|
||||
inner join load_test lt on tplc.load_case_id = lt.id and tplc.status = 'error'
|
||||
inner join load_test lt on tplc.load_case_id = lt.id
|
||||
<if test="status != null">
|
||||
and tplc.status = 'error'
|
||||
</if>
|
||||
where tplc.test_plan_id = #{planId}
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
@ -28,7 +28,7 @@ public interface ExtTestPlanScenarioCaseMapper {
|
|||
|
||||
List<PlanReportCaseDTO> selectForPlanReport(String planId);
|
||||
|
||||
List<TestPlanFailureScenarioDTO> getFailureList(String planId);
|
||||
List<TestPlanFailureScenarioDTO> getFailureList(@Param("planId") String planId, @Param("status") String status);
|
||||
|
||||
List<Integer> getUnderwaySteps(@Param("ids") List<String> underwayIds);
|
||||
}
|
||||
|
|
|
@ -208,8 +208,11 @@
|
|||
inner join
|
||||
api_scenario c
|
||||
on t.api_scenario_id = c.id and c.status != 'Trash'
|
||||
and t.test_plan_id = #{request.planId} and t.last_result = 'Fail'
|
||||
where t.test_plan_id = #{request.planId}
|
||||
and t.test_plan_id = #{planId}
|
||||
<if test="status != null">
|
||||
and t.last_result = 'Fail'
|
||||
</if>
|
||||
where t.test_plan_id = #{planId}
|
||||
</select>
|
||||
<select id="getUnderwaySteps" resultType="java.lang.Integer">
|
||||
select step_total from api_scenario c
|
||||
|
|
|
@ -61,5 +61,5 @@ public interface ExtTestPlanTestCaseMapper {
|
|||
|
||||
List<PlanReportCaseDTO> selectForPlanReport(String planId);
|
||||
|
||||
List<TestPlanCaseDTO> getFailureCases(String planId);
|
||||
List<TestPlanCaseDTO> getCases(@Param("planId") String planId, @Param("status") String status);
|
||||
}
|
||||
|
|
|
@ -466,14 +466,17 @@
|
|||
<select id="selectForPlanReport" resultType="io.metersphere.track.dto.PlanReportCaseDTO">
|
||||
select id,status from test_plan_test_case where plan_id = #{planId};
|
||||
</select>
|
||||
<select id="getFailureCases" resultType="io.metersphere.track.dto.TestPlanCaseDTO">
|
||||
<select id="getCases" resultType="io.metersphere.track.dto.TestPlanCaseDTO">
|
||||
select tptc.id, tc.id as caseId, tc.name, tc.priority, tc.num, tc.custom_num, tc.project_id,
|
||||
tc.node_id, tc.tags, tptc.actual_result,
|
||||
tptc.update_time, tptc.create_time,
|
||||
tptc.issues_count,
|
||||
tptc.issues_count, tptc.status,
|
||||
tptc.plan_id, tptc.executor
|
||||
from test_plan_test_case tptc
|
||||
inner join test_case tc on tptc.case_id = tc.id and tptc.status = 'Failure'
|
||||
inner join test_case tc on tptc.case_id = tc.id
|
||||
<if test="status != null">
|
||||
and tptc.status = 'Failure'
|
||||
</if>
|
||||
where tptc.plan_id = #{planId}
|
||||
</select>
|
||||
<update id="updateTestCaseStates" parameterType="java.lang.String">
|
||||
|
|
|
@ -75,13 +75,13 @@ public class ShareController {
|
|||
@GetMapping("/test/plan/api/case/list/failure/{shareId}/{planId}")
|
||||
public List<TestPlanFailureApiDTO> getApiFailureList(@PathVariable String shareId, @PathVariable String planId) {
|
||||
shareInfoService.validate(shareId, planId);
|
||||
return testPlanApiCaseService.getFailureList(planId);
|
||||
return testPlanApiCaseService.getFailureCases(planId);
|
||||
}
|
||||
|
||||
@GetMapping("/test/plan/scenario/case/list/failure/{shareId}/{planId}")
|
||||
public List<TestPlanFailureScenarioDTO> getScenarioFailureList(@PathVariable String shareId, @PathVariable String planId) {
|
||||
shareInfoService.validate(shareId, planId);
|
||||
return testPlanScenarioCaseService.getFailureList(planId);
|
||||
return testPlanScenarioCaseService.getFailureCases(planId);
|
||||
}
|
||||
|
||||
@GetMapping("/api/definition/report/getReport/{shareId}/{testId}")
|
||||
|
|
|
@ -35,7 +35,7 @@ public class TestPlanApiCaseController {
|
|||
|
||||
@GetMapping("/list/failure/{planId}")
|
||||
public List<TestPlanFailureApiDTO> getFailureList(@PathVariable String planId) {
|
||||
return testPlanApiCaseService.getFailureList(planId);
|
||||
return testPlanApiCaseService.getFailureCases(planId);
|
||||
}
|
||||
|
||||
@PostMapping("/selectAllTableRows")
|
||||
|
|
|
@ -33,7 +33,7 @@ public class TestPlanScenarioCaseController {
|
|||
|
||||
@GetMapping("/list/failure/{planId}")
|
||||
public List<TestPlanFailureScenarioDTO> getFailureList(@PathVariable String planId) {
|
||||
return testPlanScenarioCaseService.getFailureList(planId);
|
||||
return testPlanScenarioCaseService.getFailureCases(planId);
|
||||
}
|
||||
|
||||
@PostMapping("/selectAllTableRows")
|
||||
|
|
|
@ -27,9 +27,13 @@ public class TestPlanSimpleReportDTO {
|
|||
private TestPlanApiResultReportDTO apiResult;
|
||||
private TestPlanLoadResultReportDTO loadResult;
|
||||
|
||||
List<TestPlanCaseDTO> failureTestCases;
|
||||
List<TestPlanCaseDTO> functionFailureCases;
|
||||
List<TestPlanCaseDTO> functionAllCases;
|
||||
List<IssuesDao> issueList;
|
||||
List<TestPlanFailureApiDTO> apiFailureResult;
|
||||
List<TestPlanFailureApiDTO> apiAllCases;
|
||||
List<TestPlanFailureScenarioDTO> scenarioFailureResult;
|
||||
List<TestPlanFailureScenarioDTO> scenarioAllCases;
|
||||
List<TestPlanLoadCaseDTO> loadAllTestCases;
|
||||
List<TestPlanLoadCaseDTO> loadFailureTestCases;
|
||||
}
|
||||
|
|
|
@ -549,8 +549,17 @@ public class TestPlanApiCaseService {
|
|||
apiResult.setApiCaseData(statusResult);
|
||||
}
|
||||
|
||||
public List<TestPlanFailureApiDTO> getFailureList(String planId) {
|
||||
List<TestPlanFailureApiDTO> apiTestCases = extTestPlanApiCaseMapper.getFailureList(planId);
|
||||
public List<TestPlanFailureApiDTO> getFailureCases(String planId) {
|
||||
List<TestPlanFailureApiDTO> apiTestCases = extTestPlanApiCaseMapper.getFailureList(planId, "error");
|
||||
return buildCases(apiTestCases);
|
||||
}
|
||||
|
||||
public List<TestPlanFailureApiDTO> getAllCases(String planId) {
|
||||
List<TestPlanFailureApiDTO> apiTestCases = extTestPlanApiCaseMapper.getFailureList(planId, null);
|
||||
return buildCases(apiTestCases);
|
||||
}
|
||||
|
||||
public List<TestPlanFailureApiDTO> buildCases(List<TestPlanFailureApiDTO> apiTestCases) {
|
||||
if (CollectionUtils.isEmpty(apiTestCases)) {
|
||||
return apiTestCases;
|
||||
}
|
||||
|
|
|
@ -364,16 +364,25 @@ public class TestPlanLoadCaseService {
|
|||
loadResult.setCaseData(statusResult);
|
||||
}
|
||||
|
||||
public List<TestPlanLoadCaseDTO> getAllCases(String planId) {
|
||||
List<TestPlanLoadCaseDTO> cases = extTestPlanLoadCaseMapper.getCases(planId, null);
|
||||
return buildCases(cases);
|
||||
}
|
||||
|
||||
public List<TestPlanLoadCaseDTO> getFailureCases(String planId) {
|
||||
List<TestPlanLoadCaseDTO> failureCases = extTestPlanLoadCaseMapper.getFailureCases(planId);
|
||||
List<TestPlanLoadCaseDTO> failureCases = extTestPlanLoadCaseMapper.getCases(planId, "error");
|
||||
return buildCases(failureCases);
|
||||
}
|
||||
|
||||
public List<TestPlanLoadCaseDTO> buildCases(List<TestPlanLoadCaseDTO> cases) {
|
||||
// Map<String, Project> projectMap = ServiceUtils.getProjectMap(
|
||||
// failureCases.stream().map(TestPlanCaseDTO::getProjectId).collect(Collectors.toList()));
|
||||
Map<String, String> userNameMap = ServiceUtils.getUserNameMap(
|
||||
failureCases.stream().map(TestPlanLoadCaseDTO::getCreateUser).collect(Collectors.toList()));
|
||||
failureCases.forEach(item -> {
|
||||
cases.stream().map(TestPlanLoadCaseDTO::getCreateUser).collect(Collectors.toList()));
|
||||
cases.forEach(item -> {
|
||||
// item.setProjectName(projectMap.get(item.getProjectId()).getName());
|
||||
item.setUserName(userNameMap.get(item.getCreateUser()));
|
||||
});
|
||||
return failureCases;
|
||||
return cases;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -432,8 +432,19 @@ public class TestPlanScenarioCaseService {
|
|||
}
|
||||
}
|
||||
|
||||
public List<TestPlanFailureScenarioDTO> getFailureList(String planId) {
|
||||
List<TestPlanFailureScenarioDTO> apiTestCases = extTestPlanScenarioCaseMapper.getFailureList(planId);
|
||||
public List<TestPlanFailureScenarioDTO> getAllCases(String planId) {
|
||||
List<TestPlanFailureScenarioDTO> apiTestCases =
|
||||
extTestPlanScenarioCaseMapper.getFailureList(planId, null);
|
||||
return buildCases(apiTestCases);
|
||||
}
|
||||
|
||||
public List<TestPlanFailureScenarioDTO> getFailureCases(String planId) {
|
||||
List<TestPlanFailureScenarioDTO> apiTestCases =
|
||||
extTestPlanScenarioCaseMapper.getFailureList(planId, "Fail");
|
||||
return buildCases(apiTestCases);
|
||||
}
|
||||
|
||||
public List<TestPlanFailureScenarioDTO> buildCases(List<TestPlanFailureScenarioDTO> apiTestCases ) {
|
||||
if (CollectionUtils.isEmpty(apiTestCases)) {
|
||||
return apiTestCases;
|
||||
}
|
||||
|
|
|
@ -1356,35 +1356,141 @@ public class TestPlanService {
|
|||
|
||||
public void exportPlanReport(String planId, HttpServletResponse response) throws UnsupportedEncodingException {
|
||||
|
||||
TestPlanWithBLOBs testPlan = testPlanMapper.selectByPrimaryKey(planId);
|
||||
|
||||
String reportConfig = testPlan.getReportConfig();
|
||||
JSONObject config = null;
|
||||
if (StringUtils.isNotBlank(reportConfig)) {
|
||||
config = JSONObject.parseObject(reportConfig);
|
||||
}
|
||||
TestPlanSimpleReportDTO report = getReport(planId);
|
||||
|
||||
List<TestPlanCaseDTO> failureTestCases = testPlanTestCaseService.getFailureCases(planId);
|
||||
report.setFailureTestCases(failureTestCases);
|
||||
|
||||
List<IssuesDao> issueList = issuesService.getIssuesByPlanoId(planId);
|
||||
report.setIssueList(issueList);
|
||||
|
||||
List<TestPlanFailureApiDTO> apiFailureResult = testPlanApiCaseService.getFailureList(planId);
|
||||
apiFailureResult.forEach(item -> {
|
||||
APIReportResult dbResult = apiDefinitionService.getDbResult(item.getId());
|
||||
if (dbResult != null && StringUtils.isNotBlank(dbResult.getContent())) {
|
||||
item.setResponse(dbResult.getContent());
|
||||
if (checkReportConfig(config, "functional")) {
|
||||
List<TestPlanCaseDTO> allCases = null;
|
||||
if (checkReportConfig(config, "functional", "all")) {
|
||||
allCases = testPlanTestCaseService.getAllCases(planId);
|
||||
report.setFunctionAllCases(allCases);
|
||||
}
|
||||
});
|
||||
report.setApiFailureResult(apiFailureResult);
|
||||
if (checkReportConfig(config, "functional", "failure")) {
|
||||
List<TestPlanCaseDTO> failureCases = null;
|
||||
if (!CollectionUtils.isEmpty(allCases)) {
|
||||
failureCases = allCases.stream()
|
||||
.filter(i -> StringUtils.isNotBlank(i.getStatus())
|
||||
&& i.getStatus().equals("Failure"))
|
||||
.collect(Collectors.toList());
|
||||
} else {
|
||||
failureCases = testPlanTestCaseService.getFailureCases(planId);
|
||||
}
|
||||
report.setFunctionFailureCases(failureCases);
|
||||
}
|
||||
if (checkReportConfig(config, "functional", "issue")) {
|
||||
List<IssuesDao> issueList = issuesService.getIssuesByPlanoId(planId);
|
||||
report.setIssueList(issueList);
|
||||
}
|
||||
}
|
||||
|
||||
List<TestPlanFailureScenarioDTO> scenarioFailureResult = testPlanScenarioCaseService.getFailureList(planId);
|
||||
scenarioFailureResult.forEach((item) -> {
|
||||
item.setResponse(apiScenarioReportService.get(item.getReportId()));
|
||||
});
|
||||
report.setScenarioFailureResult(scenarioFailureResult);
|
||||
if (checkReportConfig(config, "api")) {
|
||||
List<TestPlanFailureApiDTO> apiAllCases = null;
|
||||
List<TestPlanFailureScenarioDTO> scenarioAllCases = null;
|
||||
if (checkReportConfig(config, "api", "all")) {
|
||||
// 接口
|
||||
apiAllCases = testPlanApiCaseService.getAllCases(planId);
|
||||
report.setApiAllCases(apiAllCases);
|
||||
apiAllCases.forEach(item -> {
|
||||
APIReportResult dbResult = apiDefinitionService.getDbResult(item.getId());
|
||||
if (dbResult != null && StringUtils.isNotBlank(dbResult.getContent())) {
|
||||
item.setResponse(dbResult.getContent());
|
||||
}
|
||||
});
|
||||
//场景
|
||||
scenarioAllCases = testPlanScenarioCaseService.getAllCases(planId);
|
||||
scenarioAllCases.forEach((item) -> {
|
||||
item.setResponse(apiScenarioReportService.get(item.getReportId()));
|
||||
});
|
||||
report.setScenarioAllCases(scenarioAllCases);
|
||||
}
|
||||
if (checkReportConfig(config, "api", "failure")) {
|
||||
// 接口
|
||||
List<TestPlanFailureApiDTO> apiFailureCases = null;
|
||||
if (!CollectionUtils.isEmpty(apiAllCases)) {
|
||||
apiFailureCases = apiAllCases.stream()
|
||||
.filter(i -> StringUtils.isNotBlank(i.getExecResult())
|
||||
&& i.getExecResult().equals("error"))
|
||||
.collect(Collectors.toList());
|
||||
} else {
|
||||
apiFailureCases = testPlanApiCaseService.getFailureCases(planId);
|
||||
}
|
||||
apiFailureCases.forEach(item -> {
|
||||
APIReportResult dbResult = apiDefinitionService.getDbResult(item.getId());
|
||||
if (dbResult != null && StringUtils.isNotBlank(dbResult.getContent())) {
|
||||
item.setResponse(dbResult.getContent());
|
||||
}
|
||||
});
|
||||
report.setApiFailureResult(apiFailureCases);
|
||||
|
||||
List<TestPlanLoadCaseDTO> loadFailureTestCases = testPlanLoadCaseService.getFailureCases(planId);
|
||||
report.setLoadFailureTestCases(loadFailureTestCases);
|
||||
// 场景
|
||||
List<TestPlanFailureScenarioDTO> scenarioFailureCases = null;
|
||||
if (!CollectionUtils.isEmpty(scenarioAllCases)) {
|
||||
scenarioFailureCases = scenarioAllCases.stream()
|
||||
.filter(i -> StringUtils.isNotBlank(i.getLastResult())
|
||||
&& i.getLastResult().equals("Fail"))
|
||||
.collect(Collectors.toList());
|
||||
} else {
|
||||
scenarioFailureCases = testPlanScenarioCaseService.getFailureCases(planId);
|
||||
}
|
||||
scenarioFailureCases.forEach((item) -> {
|
||||
item.setResponse(apiScenarioReportService.get(item.getReportId()));
|
||||
});
|
||||
report.setScenarioFailureResult(scenarioFailureCases);
|
||||
}
|
||||
}
|
||||
|
||||
if (checkReportConfig(config, "load")) {
|
||||
List<TestPlanLoadCaseDTO> allCases = null;
|
||||
if (checkReportConfig(config, "load", "all")) {
|
||||
allCases = testPlanLoadCaseService.getAllCases(planId);
|
||||
report.setLoadAllTestCases(allCases);
|
||||
}
|
||||
if (checkReportConfig(config, "load", "failure")) {
|
||||
List<TestPlanLoadCaseDTO> failureCases = null;
|
||||
if (!CollectionUtils.isEmpty(allCases)) {
|
||||
failureCases = allCases.stream()
|
||||
.filter(i -> StringUtils.isNotBlank(i.getStatus())
|
||||
&& i.getStatus().equals("error"))
|
||||
.collect(Collectors.toList());
|
||||
} else {
|
||||
failureCases = testPlanLoadCaseService.getFailureCases(planId);
|
||||
}
|
||||
report.setLoadFailureTestCases(failureCases);
|
||||
}
|
||||
}
|
||||
render(report, response);
|
||||
}
|
||||
|
||||
public Boolean checkReportConfig(JSONObject config, String key) {
|
||||
if (config == null) {
|
||||
return true;
|
||||
} else {
|
||||
JSONObject configItem = config.getJSONObject(key);
|
||||
return configItem.getBoolean("enable");
|
||||
}
|
||||
}
|
||||
|
||||
public Boolean checkReportConfig(JSONObject config, String key, String subKey) {
|
||||
if (config == null) {
|
||||
return true;
|
||||
} else {
|
||||
JSONObject configItem = config.getJSONObject(key);
|
||||
Boolean enable = configItem.getBoolean("enable");
|
||||
if (!enable) {
|
||||
return false;
|
||||
} else {
|
||||
JSONObject subConfig = configItem.getJSONObject("children").getJSONObject(subKey);
|
||||
return subConfig == null ? true : subConfig.getBoolean("enable");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void render(TestPlanSimpleReportDTO report, HttpServletResponse response) throws UnsupportedEncodingException {
|
||||
response.reset();
|
||||
response.setContentType("application/octet-stream");
|
||||
|
|
|
@ -382,16 +382,25 @@ public class TestPlanTestCaseService {
|
|||
}
|
||||
|
||||
public List<TestPlanCaseDTO> getFailureCases(String planId) {
|
||||
List<TestPlanCaseDTO> failureCases = extTestPlanTestCaseMapper.getFailureCases(planId);
|
||||
List<TestPlanCaseDTO> allCases = extTestPlanTestCaseMapper.getCases(planId, "Failure");
|
||||
return buildCaseInfo(allCases);
|
||||
}
|
||||
|
||||
public List<TestPlanCaseDTO> getAllCases(String planId) {
|
||||
List<TestPlanCaseDTO> allCases = extTestPlanTestCaseMapper.getCases(planId, null);
|
||||
return buildCaseInfo(allCases);
|
||||
}
|
||||
|
||||
public List<TestPlanCaseDTO> buildCaseInfo(List<TestPlanCaseDTO> cases) {
|
||||
Map<String, Project> projectMap = ServiceUtils.getProjectMap(
|
||||
failureCases.stream().map(TestPlanCaseDTO::getProjectId).collect(Collectors.toList()));
|
||||
cases.stream().map(TestPlanCaseDTO::getProjectId).collect(Collectors.toList()));
|
||||
Map<String, String> userNameMap = ServiceUtils.getUserNameMap(
|
||||
failureCases.stream().map(TestPlanCaseDTO::getExecutor).collect(Collectors.toList()));
|
||||
failureCases.forEach(item -> {
|
||||
cases.stream().map(TestPlanCaseDTO::getExecutor).collect(Collectors.toList()));
|
||||
cases.forEach(item -> {
|
||||
item.setProjectName(projectMap.get(item.getProjectId()).getName());
|
||||
item.setIsCustomNum(projectMap.get(item.getProjectId()).getCustomNum());
|
||||
item.setExecutorName(userNameMap.get(item.getExecutor()));
|
||||
});
|
||||
return failureCases;
|
||||
return cases;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ export default {
|
|||
methods: {
|
||||
getFailureTestCase() {
|
||||
if (this.isTemplate) {
|
||||
this.failureTestCases = this.report.failureTestCases;
|
||||
this.failureTestCases = this.report.functionFailureCases;
|
||||
} else if (this.isShare) {
|
||||
getSharePlanFunctionFailureCase(this.shareId, this.planId, (data) => {
|
||||
this.failureTestCases = data;
|
||||
|
|
|
@ -46,7 +46,7 @@ export default {
|
|||
confirm() {
|
||||
let param = {
|
||||
id: this.planId,
|
||||
reportConfig: JSON.stringify(this.config)
|
||||
reportConfig: JSON.stringify(this.editConfig)
|
||||
};
|
||||
editPlanReportConfig(param, () => {
|
||||
this.$emit('update:config', JSON.parse(JSON.stringify(this.editConfig)));
|
||||
|
|
Loading…
Reference in New Issue