refactor(接口测试): 优化报告显示参数和sql查询

This commit is contained in:
wxg0103 2024-03-11 11:43:22 +08:00 committed by 刘瑞斌
parent b88bd04cec
commit ba005264e3
9 changed files with 85 additions and 16 deletions

View File

@ -2,11 +2,11 @@ package io.metersphere.api.controller.definition;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.api.domain.ApiReport;
import io.metersphere.api.dto.definition.ApiReportBatchRequest;
import io.metersphere.api.dto.definition.ApiReportDTO;
import io.metersphere.api.dto.definition.ApiReportDetailDTO;
import io.metersphere.api.dto.definition.ApiReportPageRequest;
import io.metersphere.api.dto.report.ApiReportListDTO;
import io.metersphere.api.service.ApiReportShareService;
import io.metersphere.api.service.definition.ApiReportLogService;
import io.metersphere.api.service.definition.ApiReportService;
@ -42,7 +42,7 @@ public class ApiReportController {
@Operation(summary = "接口测试-接口报告-用例()")
@CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project")
@RequiresPermissions(PermissionConstants.PROJECT_API_REPORT_READ)
public Pager<List<ApiReport>> getPage(@Validated @RequestBody ApiReportPageRequest request) {
public Pager<List<ApiReportListDTO>> getPage(@Validated @RequestBody ApiReportPageRequest request) {
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(),
StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "start_time desc");
return PageUtils.setPageInfo(page, apiReportService.getPage(request));

View File

@ -2,9 +2,9 @@ package io.metersphere.api.controller.scenario;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.api.domain.ApiScenarioReport;
import io.metersphere.api.dto.definition.ApiReportBatchRequest;
import io.metersphere.api.dto.definition.ApiReportPageRequest;
import io.metersphere.api.dto.report.ApiScenarioReportListDTO;
import io.metersphere.api.dto.scenario.ApiScenarioReportDTO;
import io.metersphere.api.dto.scenario.ApiScenarioReportDetailDTO;
import io.metersphere.api.service.ApiReportShareService;
@ -42,7 +42,7 @@ public class ApiScenarioReportController {
@Operation(summary = "接口测试-接口报告-场景()")
@CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project")
@RequiresPermissions(PermissionConstants.PROJECT_API_REPORT_READ)
public Pager<List<ApiScenarioReport>> getPage(@Validated @RequestBody ApiReportPageRequest request) {
public Pager<List<ApiScenarioReportListDTO>> getPage(@Validated @RequestBody ApiReportPageRequest request) {
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(),
StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "start_time desc");
return PageUtils.setPageInfo(page, apiScenarioReportService.getPage(request));

View File

@ -0,0 +1,14 @@
package io.metersphere.api.dto.report;
import io.metersphere.api.domain.ApiReport;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
public class ApiReportListDTO extends ApiReport {
@Schema(description = "创建人")
private String createUserName;
@Schema(description = "更新人")
private String updateUserName;
}

View File

@ -0,0 +1,14 @@
package io.metersphere.api.dto.report;
import io.metersphere.api.domain.ApiScenarioReport;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
public class ApiScenarioReportListDTO extends ApiScenarioReport {
@Schema(description = "创建人")
private String createUserName;
@Schema(description = "更新人")
private String updateUserName;
}

View File

@ -116,7 +116,13 @@
<choose>
<when test="key=='integrated'">
and api_report.integrated in
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
<foreach collection="values" item="value" separator="," open="(" close=")">
<choose>
<when test="value == 'true'">1</when>
<when test="value == 'false'">0</when>
<otherwise>0</otherwise>
</choose>
</foreach>
</when>
<when test="key=='status'">
and api_report.status in
@ -126,6 +132,14 @@
and api_report.trigger_mode in
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
</when>
<when test="key=='createUser'">
and api_report.create_user in
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
</when>
<when test="key=='updateUSer'">
and api_report.update_user in
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
</when>
</choose>
</if>
</foreach>

View File

@ -219,7 +219,13 @@
<choose>
<when test="key=='integrated'">
and api_scenario_report.integrated in
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
<foreach collection="values" item="value" separator="," open="(" close=")">
<choose>
<when test="value == 'true'">1</when>
<when test="value == 'false'">0</when>
<otherwise>0</otherwise>
</choose>
</foreach>
</when>
<when test="key=='status'">
and api_scenario_report.status in
@ -229,6 +235,14 @@
and api_scenario_report.trigger_mode in
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
</when>
<when test="key=='createUser'">
and api_scenario_report.create_user in
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
</when>
<when test="key=='updateUSer'">
and api_scenario_report.update_user in
<include refid="io.metersphere.system.mapper.BaseMapper.filterInWrapper"/>
</when>
</choose>
</if>
</foreach>

View File

@ -2,6 +2,7 @@ package io.metersphere.api.service.definition;
import io.metersphere.api.domain.*;
import io.metersphere.api.dto.definition.*;
import io.metersphere.api.dto.report.ApiReportListDTO;
import io.metersphere.api.mapper.*;
import io.metersphere.api.utils.ApiDataUtils;
import io.metersphere.sdk.dto.api.result.RequestResult;
@ -79,19 +80,22 @@ public class ApiReportService {
}
}
public List<ApiReport> getPage(ApiReportPageRequest request) {
public List<ApiReportListDTO> getPage(ApiReportPageRequest request) {
List<ApiReport> list = extApiReportMapper.list(request);
List<ApiReportListDTO> results = new ArrayList<>();
//取所有的userid
Set<String> userSet = list.stream()
.flatMap(apiReport -> Stream.of(apiReport.getUpdateUser(), apiReport.getDeleteUser(), apiReport.getCreateUser()))
.collect(Collectors.toSet());
Map<String, String> userMap = userLoginService.getUserNameMap(new ArrayList<>(userSet));
list.forEach(apiReport -> {
apiReport.setCreateUser(userMap.get(apiReport.getCreateUser()));
apiReport.setUpdateUser(userMap.get(apiReport.getUpdateUser()));
apiReport.setDeleteUser(userMap.get(apiReport.getDeleteUser()));
ApiReportListDTO apiReportDTO = new ApiReportListDTO();
BeanUtils.copyBean(apiReportDTO, apiReport);
apiReportDTO.setCreateUserName(userMap.get(apiReport.getCreateUser()));
apiReportDTO.setUpdateUserName(userMap.get(apiReport.getUpdateUser()));
results.add(apiReportDTO);
});
return list;
return results;
}
public void rename(String id, String name, String userId) {

View File

@ -3,6 +3,7 @@ package io.metersphere.api.service.scenario;
import io.metersphere.api.domain.*;
import io.metersphere.api.dto.definition.ApiReportBatchRequest;
import io.metersphere.api.dto.definition.ApiReportPageRequest;
import io.metersphere.api.dto.report.ApiScenarioReportListDTO;
import io.metersphere.api.dto.scenario.ApiScenarioReportDTO;
import io.metersphere.api.dto.scenario.ApiScenarioReportDetailDTO;
import io.metersphere.api.dto.scenario.ApiScenarioReportStepDTO;
@ -82,19 +83,21 @@ public class ApiScenarioReportService {
}
}
public List<ApiScenarioReport> getPage(ApiReportPageRequest request) {
public List<ApiScenarioReportListDTO> getPage(ApiReportPageRequest request) {
List<ApiScenarioReport> list = extApiScenarioReportMapper.list(request);
List<ApiScenarioReportListDTO> result = new ArrayList<>();
//取所有的userid
Set<String> userSet = list.stream()
.flatMap(scenarioReport -> Stream.of(scenarioReport.getUpdateUser(), scenarioReport.getDeleteUser(), scenarioReport.getCreateUser()))
.collect(Collectors.toSet());
Map<String, String> userMap = userLoginService.getUserNameMap(new ArrayList<>(userSet));
list.forEach(scenarioReport -> {
scenarioReport.setCreateUser(userMap.get(scenarioReport.getCreateUser()));
scenarioReport.setUpdateUser(userMap.get(scenarioReport.getUpdateUser()));
scenarioReport.setDeleteUser(userMap.get(scenarioReport.getDeleteUser()));
ApiScenarioReportListDTO scenarioReportListDTO = new ApiScenarioReportListDTO();
BeanUtils.copyBean(scenarioReportListDTO, scenarioReport);
scenarioReportListDTO.setCreateUserName(userMap.get(scenarioReport.getCreateUser()));
scenarioReportListDTO.setUpdateUserName(userMap.get(scenarioReport.getUpdateUser()));
});
return list;
return result;
}
public void rename(String id, String name, String userId) {

View File

@ -90,6 +90,7 @@ public class ApiReportControllerTests extends BaseTest {
apiReport.setStatus(ApiReportStatus.SUCCESS.name());
} else if (i % 39 == 0) {
apiReport.setStatus(ApiReportStatus.ERROR.name());
apiReport.setIntegrated(true);
}
apiReport.setTriggerMode("api-trigger-mode" + i);
apiReport.setVersionId("api-version-id" + i);
@ -164,6 +165,11 @@ public class ApiReportControllerTests extends BaseTest {
list.forEach(apiReport -> {
Assertions.assertTrue(apiReport.getStatus().equals(ApiReportStatus.SUCCESS.name()) || apiReport.getStatus().equals(ApiReportStatus.ERROR.name()));
});
request.setFilter(new HashMap<>() {{
put("integrated", List.of("true"));
}});
mvcResult = responsePost(PAGE, request);
returnPager = parseObjectFromMvcResult(mvcResult, Pager.class);
//校验权限
requestPostPermissionTest(PermissionConstants.PROJECT_API_REPORT_READ, PAGE, request);