feat(测试计划): 报告批量导出日志

This commit is contained in:
WangXu10 2024-09-12 16:50:51 +08:00 committed by Craftsman
parent 8901e8b199
commit 2220eef35f
12 changed files with 152 additions and 58 deletions

View File

@ -112,10 +112,17 @@ public class ApiReportController {
return apiReportService.getDetail(reportId, stepId);
}
@GetMapping("/export/{reportId}")
@PostMapping("/export/{reportId}")
@Operation(summary = "接口测试-用例报告-导出日志")
@RequiresPermissions(PermissionConstants.PROJECT_API_REPORT_EXPORT)
public void exportLog(@PathVariable String reportId) {
apiReportService.exportLog(reportId, SessionUtils.getUserId());
apiReportService.exportLog(reportId, SessionUtils.getUserId(), SessionUtils.getCurrentProjectId());
}
@PostMapping("/batch-export")
@Operation(summary = "接口测试-用例报告-批量导出日志")
@RequiresPermissions(PermissionConstants.PROJECT_API_REPORT_EXPORT)
public void batchExportLog(@Validated @RequestBody ApiReportBatchRequest request) {
apiReportService.batchExportLog(request, SessionUtils.getUserId(), SessionUtils.getCurrentProjectId());
}
}

View File

@ -112,10 +112,17 @@ public class ApiScenarioReportController {
return apiScenarioReportService.getDetail(reportId, stepId);
}
@GetMapping("/export/{reportId}")
@PostMapping("/export/{reportId}")
@Operation(summary = "接口测试-场景报告-导出日志")
@RequiresPermissions(PermissionConstants.PROJECT_API_REPORT_EXPORT)
public void exportLog(@PathVariable String reportId) {
apiScenarioReportService.exportLog(reportId, SessionUtils.getUserId());
apiScenarioReportService.exportLog(reportId, SessionUtils.getUserId(), SessionUtils.getCurrentProjectId());
}
@PostMapping("/batch-export")
@Operation(summary = "接口测试-场景报告-导出日志")
@RequiresPermissions(PermissionConstants.PROJECT_API_REPORT_EXPORT)
public void batchExportLog(@Validated @RequestBody ApiReportBatchRequest request) {
apiScenarioReportService.batchExportLog(request, SessionUtils.getUserId(), SessionUtils.getCurrentProjectId());
}
}

View File

@ -88,18 +88,22 @@ public class ApiReportLogService {
operationLogService.batchAdd(logs);
}
public void exportLog(ApiReport report, String userId) {
Project project = projectMapper.selectByPrimaryKey(report.getProjectId());
public void exportLog(List<ApiReport> reports, String userId, String projectId, String path) {
Project project = projectMapper.selectByPrimaryKey(projectId);
List<LogDTO> logs = new ArrayList<>();
reports.forEach(report -> {
LogDTO dto = new LogDTO(
report.getProjectId(),
projectId,
project.getOrganizationId(),
report.getId(),
userId,
OperationLogType.EXPORT.name(),
OperationLogModule.API_REPORT,
report.getName());
dto.setPath("/api/report/case/export/" + report.getId());
dto.setMethod(HttpMethodConstants.GET.name());
operationLogService.add(dto);
dto.setPath(path);
dto.setMethod(HttpMethodConstants.POST.name());
logs.add(dto);
});
operationLogService.batchAdd(logs);
}
}

View File

@ -259,8 +259,18 @@ public class ApiReportService {
apiReportMapper.updateByPrimaryKeySelective(apiReport);
}
public void exportLog(String reportId, String userId) {
public void exportLog(String reportId, String userId, String projectId) {
ApiReport apiReport = apiReportMapper.selectByPrimaryKey(reportId);
Optional.ofNullable(apiReport).ifPresent(report -> apiReportLogService.exportLog(report, userId));
Optional.ofNullable(apiReport).ifPresent(report -> apiReportLogService.exportLog(List.of(report), userId, projectId, "/api/report/case/export/" + reportId));
}
public void batchExportLog(ApiReportBatchRequest request, String userId, String projectId) {
List<String> ids = doSelectIds(request);
if(CollectionUtils.isNotEmpty(ids)){
ApiReportExample example = new ApiReportExample();
example.createCriteria().andIdIn(ids);
List<ApiReport> reports = apiReportMapper.selectByExample(example);
apiReportLogService.exportLog(reports, userId, projectId, "/api/report/case/batch-export");
}
}
}

View File

@ -88,18 +88,22 @@ public class ApiScenarioReportLogService {
operationLogService.batchAdd(logs);
}
public void exportLog(ApiScenarioReport report, String userId) {
Project project = projectMapper.selectByPrimaryKey(report.getProjectId());
public void exportLog(List<ApiScenarioReport> reports, String userId, String projectId, String path) {
Project project = projectMapper.selectByPrimaryKey(projectId);
List<LogDTO> logs = new ArrayList<>();
reports.forEach(report -> {
LogDTO dto = new LogDTO(
report.getProjectId(),
projectId,
project.getOrganizationId(),
report.getId(),
userId,
OperationLogType.EXPORT.name(),
OperationLogModule.API_TEST_REPORT_SCENARIO,
report.getName());
dto.setPath("/api/report/scenario/export/" + report.getId());
dto.setMethod(HttpMethodConstants.GET.name());
operationLogService.add(dto);
dto.setPath(path);
dto.setMethod(HttpMethodConstants.POST.name());
logs.add(dto);
});
operationLogService.batchAdd(logs);
}
}

View File

@ -393,8 +393,18 @@ public class ApiScenarioReportService {
return apiScenarioReportMapper.selectByExample(reportExample);
}
public void exportLog(String reportId, String userId) {
public void exportLog(String reportId, String userId, String projectId) {
ApiScenarioReport apiScenarioReport = apiScenarioReportMapper.selectByPrimaryKey(reportId);
Optional.ofNullable(apiScenarioReport).ifPresent(report -> apiScenarioReportLogService.exportLog(report, userId));
Optional.ofNullable(apiScenarioReport).ifPresent(report -> apiScenarioReportLogService.exportLog(List.of(report), userId, projectId, "/api/report/scenario/export/" + reportId));
}
public void batchExportLog(ApiReportBatchRequest request, String userId, String projectId) {
List<String> ids = doSelectIds(request);
if(CollectionUtils.isNotEmpty(ids)){
ApiScenarioReportExample example = new ApiScenarioReportExample();
example.createCriteria().andIdIn(ids);
List<ApiScenarioReport> reports = apiScenarioReportMapper.selectByExample(example);
apiScenarioReportLogService.exportLog(reports, userId, projectId, "/api/report/scenario/batch-export");
}
}
}

View File

@ -80,7 +80,8 @@ public class ApiReportControllerTests extends BaseTest {
private static final String GET = BASIC + "/get/";
private static final String BATCH_DELETE = BASIC + "/batch/delete";
private static final String DETAIL = BASIC + "/get/detail/";
private static final String EXPORT_REPORT = BASIC + "/export/";
private static final String EXPORT_REPORT = BASIC + "/export/{0}";
private static final String BATCH_EXPORT_REPORT = BASIC + "/batch-export";
@Test
@ -491,6 +492,15 @@ public class ApiReportControllerTests extends BaseTest {
@Test
@Order(5)
public void testExportReport() throws Exception {
this.requestGet(EXPORT_REPORT + "api-report-id1");
this.requestPost(EXPORT_REPORT, null, "api-report-id1");
}
@Test
@Order(6)
public void testBatchExportReport() throws Exception {
ApiReportBatchRequest request = new ApiReportBatchRequest();
request.setProjectId(DEFAULT_PROJECT_ID);
request.setSelectAll(true);
this.requestPost(BATCH_EXPORT_REPORT, request);
}
}

View File

@ -87,7 +87,8 @@ public class ApiScenarioReportControllerTests extends BaseTest {
private static final String GET = BASIC + "/get/";
private static final String BATCH_DELETE = BASIC + "/batch/delete";
private static final String DETAIL = BASIC + "/get/detail/";
private static final String EXPORT_REPORT = BASIC + "/export/";
private static final String EXPORT_REPORT = BASIC + "/export/{0}";
private static final String BATCH_EXPORT_REPORT = BASIC + "/batch-export";
@Test
@Order(1)
@ -536,6 +537,15 @@ public class ApiScenarioReportControllerTests extends BaseTest {
@Test
@Order(9)
public void testExportReport() throws Exception {
this.requestGet(EXPORT_REPORT + "scenario-report-id1");
this.requestPost(EXPORT_REPORT, null, "scenario-report-id1");
}
@Test
@Order(10)
public void testBatchExportReport() throws Exception {
ApiReportBatchRequest request = new ApiReportBatchRequest();
request.setProjectId(DEFAULT_PROJECT_ID);
request.setSelectAll(true);
this.requestPost(BATCH_EXPORT_REPORT, request);
}
}

View File

@ -225,13 +225,21 @@ public class TestPlanReportController {
}
@GetMapping("/export/{reportId}")
@PostMapping("/export/{reportId}")
@Operation(summary = "测试计划-报告-导出日志")
@RequiresPermissions(PermissionConstants.TEST_PLAN_REPORT_READ_EXPORT)
public void exportLog(@PathVariable String reportId) {
testPlanReportService.exportLog(reportId, SessionUtils.getUserId());
testPlanReportService.exportLog(reportId, SessionUtils.getUserId(), SessionUtils.getCurrentProjectId());
}
@PostMapping("/batch-export")
@Operation(summary = "测试计划-报告-批量导出日志")
@RequiresPermissions(PermissionConstants.TEST_PLAN_REPORT_READ_EXPORT)
public void batchExportLog(@Validated @RequestBody TestPlanReportBatchRequest request) {
testPlanReportService.batchExportLog(request, SessionUtils.getUserId(), SessionUtils.getCurrentProjectId());
}
@PostMapping("/detail/{type}/collection/page")
@Operation(summary = "测试计划-报告-详情-测试集分页查询(不同用例类型)")
@RequiresPermissions(value = {PermissionConstants.TEST_PLAN_REPORT_READ, PermissionConstants.TEST_PLAN_READ_EXECUTE}, logical = Logical.OR)

View File

@ -137,18 +137,22 @@ public class TestPlanReportLogService {
operationLogService.add(log);
}
public void exportLog(TestPlanReport report, String userId) {
Project project = projectMapper.selectByPrimaryKey(report.getProjectId());
public void exportLog(List<TestPlanReport> reports, String userId, String projectId, String path) {
Project project = projectMapper.selectByPrimaryKey(projectId);
List<LogDTO> logs = new ArrayList<>();
reports.forEach(report -> {
LogDTO log = new LogDTO(
report.getProjectId(),
projectId,
project.getOrganizationId(),
report.getId(),
userId,
OperationLogType.EXPORT.name(),
report.getIntegrated() ? OperationLogModule.TEST_PLAN_GROUP_REPORT : OperationLogModule.TEST_PLAN_REPORT,
report.getName());
log.setMethod(HttpMethodConstants.GET.name());
log.setPath("/test-plan/report/export/" + report.getId());
operationLogService.add(log);
log.setMethod(HttpMethodConstants.POST.name());
log.setPath(path);
logs.add(log);
});
operationLogService.batchAdd(logs);
}
}

View File

@ -1284,8 +1284,18 @@ public class TestPlanReportService {
return modules.stream().collect(Collectors.toMap(TestPlanBaseModule::getId, TestPlanBaseModule::getName));
}
public void exportLog(String reportId, String userId) {
public void exportLog(String reportId, String userId, String projectId) {
TestPlanReport testPlanReport = testPlanReportMapper.selectByPrimaryKey(reportId);
Optional.ofNullable(testPlanReport).ifPresent(report -> testPlanReportLogService.exportLog(report, userId));
Optional.ofNullable(testPlanReport).ifPresent(report -> testPlanReportLogService.exportLog(List.of(report), userId, projectId, "/test-plan/report/export/" + reportId));
}
public void batchExportLog(TestPlanReportBatchRequest request, String userId, String projectId) {
List<String> reportIds = getBatchIds(request);
if (CollectionUtils.isNotEmpty(reportIds)) {
TestPlanReportExample example = new TestPlanReportExample();
example.createCriteria().andIdIn(reportIds);
List<TestPlanReport> reports = testPlanReportMapper.selectByExample(example);
testPlanReportLogService.exportLog(reports, userId, projectId, "/test-plan/report/batch-export");
}
}
}

View File

@ -72,7 +72,8 @@ public class TestPlanReportControllerTests extends BaseTest {
private static final String GET_SHARE_REPORT_API_REPORT_LIST = "/test-plan/report/share/detail/api-report";
private static final String GET_SHARE_REPORT_SCENARIO_REPORT_LIST = "/test-plan/report/share/detail/scenario-report";
private static final String GET_SHARE_REPORT_DETAIL_FUNCTIONAL_RESULT = "/test-plan/report/share/detail/functional/case/step";
private static final String GET_EXPORT_REPORT = "/test-plan/report/export/";
private static final String EXPORT_REPORT = "/test-plan/report/export/{0}";
private static final String BATCH_EXPORT_REPORT = "/test-plan/report/batch-export";
@Autowired
private TestPlanReportMapper testPlanReportMapper;
@ -487,7 +488,16 @@ public class TestPlanReportControllerTests extends BaseTest {
@Test
@Order(25)
void testExportReport() throws Exception {
this.requestGet(GET_EXPORT_REPORT + "test-plan-report-id-1");
this.requestGet(GET_EXPORT_REPORT + "test-plan-report-id-3");
this.requestPost(EXPORT_REPORT,null,"test-plan-report-id-1");
this.requestPost(EXPORT_REPORT,null,"test-plan-report-id-3");
}
@Test
@Order(26)
void testBatchExportReport() throws Exception {
TestPlanReportBatchRequest request = new TestPlanReportBatchRequest();
request.setProjectId("100001100001");
request.setSelectAll(true);
this.requestPost(BATCH_EXPORT_REPORT, request);
}
}