From ba005264e39fb327e05cf4801b8dd752a76a4436 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Mon, 11 Mar 2024 11:43:22 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E6=8A=A5=E5=91=8A=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E5=92=8Csql=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../definition/ApiReportController.java | 4 ++-- .../scenario/ApiScenarioReportController.java | 4 ++-- .../api/dto/report/ApiReportListDTO.java | 14 ++++++++++++++ .../api/dto/report/ApiScenarioReportListDTO.java | 14 ++++++++++++++ .../api/mapper/ExtApiReportMapper.xml | 16 +++++++++++++++- .../api/mapper/ExtApiScenarioReportMapper.xml | 16 +++++++++++++++- .../api/service/definition/ApiReportService.java | 14 +++++++++----- .../scenario/ApiScenarioReportService.java | 13 ++++++++----- .../api/controller/ApiReportControllerTests.java | 6 ++++++ 9 files changed, 85 insertions(+), 16 deletions(-) create mode 100644 backend/services/api-test/src/main/java/io/metersphere/api/dto/report/ApiReportListDTO.java create mode 100644 backend/services/api-test/src/main/java/io/metersphere/api/dto/report/ApiScenarioReportListDTO.java diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiReportController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiReportController.java index c312b44a6b..ec6a3cd25a 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiReportController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiReportController.java @@ -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> getPage(@Validated @RequestBody ApiReportPageRequest request) { + public Pager> getPage(@Validated @RequestBody ApiReportPageRequest request) { Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "start_time desc"); return PageUtils.setPageInfo(page, apiReportService.getPage(request)); diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioReportController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioReportController.java index 9748d6cd26..14124a9922 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioReportController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/scenario/ApiScenarioReportController.java @@ -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> getPage(@Validated @RequestBody ApiReportPageRequest request) { + public Pager> getPage(@Validated @RequestBody ApiReportPageRequest request) { Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "start_time desc"); return PageUtils.setPageInfo(page, apiScenarioReportService.getPage(request)); diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/report/ApiReportListDTO.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/report/ApiReportListDTO.java new file mode 100644 index 0000000000..3f08d5b2df --- /dev/null +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/report/ApiReportListDTO.java @@ -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; + +} diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/dto/report/ApiScenarioReportListDTO.java b/backend/services/api-test/src/main/java/io/metersphere/api/dto/report/ApiScenarioReportListDTO.java new file mode 100644 index 0000000000..d994d93421 --- /dev/null +++ b/backend/services/api-test/src/main/java/io/metersphere/api/dto/report/ApiScenarioReportListDTO.java @@ -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; + +} diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiReportMapper.xml b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiReportMapper.xml index f9f1c7d3e5..4a5b402e44 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiReportMapper.xml +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiReportMapper.xml @@ -116,7 +116,13 @@ and api_report.integrated in - + + + 1 + 0 + 0 + + and api_report.status in @@ -126,6 +132,14 @@ and api_report.trigger_mode in + + and api_report.create_user in + + + + and api_report.update_user in + + diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioReportMapper.xml b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioReportMapper.xml index 3fd00b5ffd..52e6249d8f 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioReportMapper.xml +++ b/backend/services/api-test/src/main/java/io/metersphere/api/mapper/ExtApiScenarioReportMapper.xml @@ -219,7 +219,13 @@ and api_scenario_report.integrated in - + + + 1 + 0 + 0 + + and api_scenario_report.status in @@ -229,6 +235,14 @@ and api_scenario_report.trigger_mode in + + and api_scenario_report.create_user in + + + + and api_scenario_report.update_user in + + diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiReportService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiReportService.java index bd58c72ded..7c10cce229 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiReportService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiReportService.java @@ -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 getPage(ApiReportPageRequest request) { + public List getPage(ApiReportPageRequest request) { List list = extApiReportMapper.list(request); + List results = new ArrayList<>(); //取所有的userid Set userSet = list.stream() .flatMap(apiReport -> Stream.of(apiReport.getUpdateUser(), apiReport.getDeleteUser(), apiReport.getCreateUser())) .collect(Collectors.toSet()); Map 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) { diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioReportService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioReportService.java index bdfcc48055..781528a3f5 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioReportService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/scenario/ApiScenarioReportService.java @@ -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 getPage(ApiReportPageRequest request) { + public List getPage(ApiReportPageRequest request) { List list = extApiScenarioReportMapper.list(request); + List result = new ArrayList<>(); //取所有的userid Set userSet = list.stream() .flatMap(scenarioReport -> Stream.of(scenarioReport.getUpdateUser(), scenarioReport.getDeleteUser(), scenarioReport.getCreateUser())) .collect(Collectors.toSet()); Map 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) { diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiReportControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiReportControllerTests.java index a5e5fa1b3e..0922ab7587 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiReportControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiReportControllerTests.java @@ -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);