From a52a69a99e0c1a5c73b422aa49e59d4ed647a19e Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Wed, 14 Aug 2024 14:34:12 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=94=A8=E4=BE=8B=E5=AF=BC=E5=87=BA=E6=9C=AA?= =?UTF-8?q?=E7=94=9F=E6=88=90=E6=97=A5=E5=BF=97=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1045099 --user=王旭 【测试用例】用例导出为xmind/excel-未生成系统日志 https://www.tapd.cn/55049933/s/1562443 --- .../controller/FunctionalCaseController.java | 6 +++--- .../service/FunctionalCaseFileService.java | 13 +++++++++---- .../service/FunctionalCaseLogService.java | 12 +++++------- .../service/FunctionalCaseXmindService.java | 13 +++++++++---- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseController.java b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseController.java index 3482a718dd..8a6a10c83e 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseController.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseController.java @@ -237,7 +237,7 @@ public class FunctionalCaseController { @CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project") public FunctionalCaseImportResponse preCheckXMind(@RequestPart("request") FunctionalCaseImportRequest request, @RequestPart(value = "file", required = false) MultipartFile file) { SessionUser user = SessionUtils.getUser(); - return functionalCaseFileService.preCheckXMind(request,user, file); + return functionalCaseFileService.preCheckXMind(request, user, file); } @@ -274,7 +274,7 @@ public class FunctionalCaseController { @Operation(summary = "用例管理-功能用例-excel导出") @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ_EXPORT) public String testCaseExport(@Validated @RequestBody FunctionalCaseExportRequest request) { - return functionalCaseFileService.export(SessionUtils.getUserId(), request); + return functionalCaseFileService.export(SessionUtils.getUserId(), request, SessionUtils.getCurrentOrganizationId()); } @GetMapping("/stop/{taskId}") @@ -314,7 +314,7 @@ public class FunctionalCaseController { @Operation(summary = "用例管理-功能用例-xmind导出") @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ_EXPORT) public String caseExportXmind(@Validated @RequestBody FunctionalCaseExportRequest request) { - return functionalCaseXmindService.exportFunctionalCaseXmind(request, SessionUtils.getUserId()); + return functionalCaseXmindService.exportFunctionalCaseXmind(request, SessionUtils.getUserId(), SessionUtils.getCurrentOrganizationId()); } @GetMapping(value = "/check/export-task") diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseFileService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseFileService.java index 436d6298de..0a5163cd4c 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseFileService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseFileService.java @@ -48,6 +48,8 @@ import io.metersphere.system.dto.sdk.TemplateCustomFieldDTO; import io.metersphere.system.dto.sdk.TemplateDTO; import io.metersphere.system.excel.domain.ExcelErrData; import io.metersphere.system.excel.utils.EasyExcelExporter; +import io.metersphere.system.log.dto.LogDTO; +import io.metersphere.system.log.service.OperationLogService; import io.metersphere.system.manager.ExportTaskManager; import io.metersphere.system.mapper.SystemParameterMapper; import io.metersphere.system.service.FileService; @@ -111,6 +113,8 @@ public class FunctionalCaseFileService { private ExportTaskMapper exportTaskMapper; private static final String XLSX = "xlsx"; private static final String ZIP = "zip"; + @Resource + private OperationLogService operationLogService; /** * 下载excel导入模板 @@ -403,10 +407,10 @@ public class FunctionalCaseFileService { } } - public String export(String userId, FunctionalCaseExportRequest request) { + public String export(String userId, FunctionalCaseExportRequest request, String orgId) { try { exportCheck(request, userId); - ExportTask exportTask = exportTaskManager.exportAsyncTask(request.getProjectId(), request.getFileId(), userId, ExportConstants.ExportType.CASE.toString(), request, t -> exportFunctionalCaseZip(request, userId)); + ExportTask exportTask = exportTaskManager.exportAsyncTask(request.getProjectId(), request.getFileId(), userId, ExportConstants.ExportType.CASE.toString(), request, t -> exportFunctionalCaseZip(request, userId, orgId)); return exportTask.getId(); } catch (InterruptedException e) { LogUtils.error("导出失败:" + e); @@ -427,7 +431,7 @@ public class FunctionalCaseFileService { * * @param request */ - public String exportFunctionalCaseZip(FunctionalCaseExportRequest request, String userId) { + public String exportFunctionalCaseZip(FunctionalCaseExportRequest request, String userId, String orgId) { File tmpDir = null; String fileType = ""; try { @@ -454,7 +458,8 @@ public class FunctionalCaseFileService { fileType = XLSX; uploadFileToMinio(fileType, singeFile, request.getFileId()); } - functionalCaseLogService.exportExcelLog(request); + LogDTO logDTO = functionalCaseLogService.exportExcelLog(request, "excel", userId, orgId); + operationLogService.add(logDTO); List exportTasks = getExportTasks(request.getProjectId(), userId); String taskId; if (CollectionUtils.isNotEmpty(exportTasks)) { diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseLogService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseLogService.java index e522ea5794..623b6d9ac7 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseLogService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseLogService.java @@ -17,7 +17,6 @@ import io.metersphere.sdk.util.JSON; import io.metersphere.system.log.constants.OperationLogModule; import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.dto.LogDTO; -import io.metersphere.system.mapper.CustomFieldMapper; import jakarta.annotation.Resource; import org.apache.commons.collections.CollectionUtils; import org.jetbrains.annotations.NotNull; @@ -180,7 +179,7 @@ public class FunctionalCaseLogService { } return dtoList; } - + /** * 恢复项目 * @@ -429,18 +428,17 @@ public class FunctionalCaseLogService { } - - public LogDTO exportExcelLog(FunctionalCaseExportRequest request) { + public LogDTO exportExcelLog(FunctionalCaseExportRequest request, String url, String userId, String orgId) { LogDTO dto = new LogDTO( request.getProjectId(), - null, + orgId, request.getFileId(), - null, + userId, OperationLogType.EXPORT.name(), OperationLogModule.FUNCTIONAL_CASE, ""); dto.setHistory(true); - dto.setPath("/functional/case/export/excel"); + dto.setPath("/functional/case/export/" + url); dto.setMethod(HttpMethodConstants.POST.name()); return dto; } diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseXmindService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseXmindService.java index acfd15338d..48f20ddaa6 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseXmindService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseXmindService.java @@ -19,6 +19,8 @@ import io.metersphere.sdk.util.Translator; import io.metersphere.system.constants.ExportConstants; import io.metersphere.system.dto.sdk.BaseTreeNode; import io.metersphere.system.dto.sdk.TemplateCustomFieldDTO; +import io.metersphere.system.log.dto.LogDTO; +import io.metersphere.system.log.service.OperationLogService; import io.metersphere.system.manager.ExportTaskManager; import io.metersphere.system.uid.IDGenerator; import jakarta.annotation.Resource; @@ -61,6 +63,8 @@ public class FunctionalCaseXmindService { @Resource private FunctionalCaseLogService functionalCaseLogService; private static final String XMIND = "xmind"; + @Resource + private OperationLogService operationLogService; public void downloadXmindTemplate(String projectId, HttpServletResponse response) { List customFields = functionalCaseFileService.getCustomFields(projectId); @@ -96,10 +100,10 @@ public class FunctionalCaseXmindService { * * @param request */ - public String exportFunctionalCaseXmind(FunctionalCaseExportRequest request, String userId) { + public String exportFunctionalCaseXmind(FunctionalCaseExportRequest request, String userId, String orgId) { try { functionalCaseFileService.exportCheck(request, userId); - ExportTask exportTask = exportTaskManager.exportAsyncTask(request.getProjectId(), request.getFileId(), userId, ExportConstants.ExportType.CASE.toString(), request, t -> exportXmind(request, userId)); + ExportTask exportTask = exportTaskManager.exportAsyncTask(request.getProjectId(), request.getFileId(), userId, ExportConstants.ExportType.CASE.toString(), request, t -> exportXmind(request, userId, orgId)); return exportTask.getId(); } catch (InterruptedException e) { LogUtils.error("导出失败:" + e); @@ -108,7 +112,7 @@ public class FunctionalCaseXmindService { } - private String exportXmind(FunctionalCaseExportRequest request, String userId) { + private String exportXmind(FunctionalCaseExportRequest request, String userId, String orgId) { //获取导出的ids集合 List ids = functionalCaseService.doSelectIds(request, request.getProjectId()); if (CollectionUtils.isEmpty(ids)) { @@ -128,7 +132,8 @@ public class FunctionalCaseXmindService { XmindExportUtil.export(xmindData, request, tmpFile, templateCustomFields); functionalCaseFileService.uploadFileToMinio(XMIND, tmpFile, request.getFileId()); - functionalCaseLogService.exportExcelLog(request); + LogDTO logDTO = functionalCaseLogService.exportExcelLog(request, "xmind", userId, orgId); + operationLogService.add(logDTO); List exportTasks = functionalCaseFileService.getExportTasks(request.getProjectId(), userId); String taskId; if (CollectionUtils.isNotEmpty(exportTasks)) {