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 @@