From 6dc3614ec1fe6f4e7265500addcb0af879d7db10 Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Mon, 28 Oct 2024 11:35:12 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E4=BB=BB=E5=8A=A1=E4=B8=AD=E5=BF=83):=20?= =?UTF-8?q?=20=E4=BF=AE=E5=A4=8D=E5=88=A0=E9=99=A4=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=EF=BC=8C=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1048117 --user=王旭 【接口测试】定义-导入接口-定时导入-定时任务列表-删除定时任务,查看日志,操作对象错误 https://www.tapd.cn/55049933/s/1598997 --- .../ApiDefinitionScheduleController.java | 4 +++- .../ApiDefinitionScheduleService.java | 22 +++++++++++++++++-- .../components/importTaskDrawer.vue | 6 ++--- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDefinitionScheduleController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDefinitionScheduleController.java index 63dd09cf88..6a235f3046 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDefinitionScheduleController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDefinitionScheduleController.java @@ -3,7 +3,9 @@ package io.metersphere.api.controller.definition; import io.metersphere.api.dto.definition.ApiScheduleDTO; import io.metersphere.api.dto.definition.request.ApiScheduleRequest; import io.metersphere.api.service.definition.ApiDefinitionScheduleService; +import io.metersphere.sdk.constants.HttpMethodConstants; import io.metersphere.sdk.constants.PermissionConstants; +import io.metersphere.system.log.constants.OperationLogModule; import io.metersphere.system.security.CheckOwner; import io.metersphere.system.utils.SessionUtils; import io.metersphere.validation.groups.Created; @@ -51,7 +53,7 @@ public class ApiDefinitionScheduleController { @RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_IMPORT) @CheckOwner(resourceId = "#id", resourceType = "schedule") public void deleteSchedule(@PathVariable String id) { - apiDefinitionScheduleService.deleteSchedule(id); + apiDefinitionScheduleService.deleteSchedule(id, SessionUtils.getUserId(), "/api/definition/schedule/delete/", HttpMethodConstants.GET.name(), OperationLogModule.API_TEST_MANAGEMENT_DEFINITION); } @GetMapping(value = "/get/{id}") diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionScheduleService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionScheduleService.java index a23f0c4974..fc55e11807 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionScheduleService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionScheduleService.java @@ -33,6 +33,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; +import java.util.Optional; @Service @Transactional(rollbackFor = Exception.class) @@ -110,7 +111,7 @@ public class ApiDefinitionScheduleService { example.createCriteria().andProjectIdEqualTo(projectId).andSwaggerUrlEqualTo(url); List apiDefinitionSwaggers = apiDefinitionSwaggerMapper.selectByExample(example); if (CollectionUtils.isNotEmpty(apiDefinitionSwaggers)) { - throw new MSException(Translator.get("api_import_url_is_exist")); + throw new MSException(Translator.get("api_import_url_is_exist")); } } @@ -182,10 +183,27 @@ public class ApiDefinitionScheduleService { SwaggerUrlImportJob.getTriggerKey(schedule.getResourceId()), SwaggerUrlImportJob.class); } - public void deleteSchedule(String id) { + public void deleteSchedule(String id, String userId, String path, String method, String module) { Schedule schedule = checkScheduleExit(id); apiDefinitionSwaggerMapper.deleteByPrimaryKey(schedule.getResourceId()); scheduleService.deleteByResourceId(schedule.getResourceId(), SwaggerUrlImportJob.class.getName()); + saveLog(schedule, userId, path, method, module, OperationLogType.DELETE.name()); + } + + private void saveLog(Schedule schedule, String userId, String path, String method, String module, String type) { + Optional.ofNullable(schedule).ifPresent(item -> { + LogDTO dto = new LogDTO( + item.getProjectId(), + projectMapper.selectByPrimaryKey(item.getProjectId()).getOrganizationId(), + item.getResourceId(), + userId, + type, + module, + Translator.get("api_import_schedule") + ": " + item.getName()); + dto.setPath(path); + dto.setMethod(method); + operationLogService.add(dto); + }); } private Schedule checkScheduleExit(String id) { diff --git a/frontend/src/views/api-test/management/components/importTaskDrawer.vue b/frontend/src/views/api-test/management/components/importTaskDrawer.vue index 3210f0c1d6..752d7eb4be 100644 --- a/frontend/src/views/api-test/management/components/importTaskDrawer.vue +++ b/frontend/src/views/api-test/management/components/importTaskDrawer.vue @@ -14,7 +14,7 @@