fix(任务中心): 修复删除接口定时任务,日志错误问题

--bug=1048117 --user=王旭 【接口测试】定义-导入接口-定时导入-定时任务列表-删除定时任务,查看日志,操作对象错误 https://www.tapd.cn/55049933/s/1598997
This commit is contained in:
WangXu10 2024-10-28 11:35:12 +08:00 committed by Craftsman
parent bdc539a4a1
commit 6dc3614ec1
3 changed files with 26 additions and 6 deletions

View File

@ -3,7 +3,9 @@ package io.metersphere.api.controller.definition;
import io.metersphere.api.dto.definition.ApiScheduleDTO; import io.metersphere.api.dto.definition.ApiScheduleDTO;
import io.metersphere.api.dto.definition.request.ApiScheduleRequest; import io.metersphere.api.dto.definition.request.ApiScheduleRequest;
import io.metersphere.api.service.definition.ApiDefinitionScheduleService; import io.metersphere.api.service.definition.ApiDefinitionScheduleService;
import io.metersphere.sdk.constants.HttpMethodConstants;
import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.security.CheckOwner; import io.metersphere.system.security.CheckOwner;
import io.metersphere.system.utils.SessionUtils; import io.metersphere.system.utils.SessionUtils;
import io.metersphere.validation.groups.Created; import io.metersphere.validation.groups.Created;
@ -51,7 +53,7 @@ public class ApiDefinitionScheduleController {
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_IMPORT) @RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_IMPORT)
@CheckOwner(resourceId = "#id", resourceType = "schedule") @CheckOwner(resourceId = "#id", resourceType = "schedule")
public void deleteSchedule(@PathVariable String id) { 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}") @GetMapping(value = "/get/{id}")

View File

@ -33,6 +33,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
import java.util.Optional;
@Service @Service
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@ -110,7 +111,7 @@ public class ApiDefinitionScheduleService {
example.createCriteria().andProjectIdEqualTo(projectId).andSwaggerUrlEqualTo(url); example.createCriteria().andProjectIdEqualTo(projectId).andSwaggerUrlEqualTo(url);
List<ApiDefinitionSwagger> apiDefinitionSwaggers = apiDefinitionSwaggerMapper.selectByExample(example); List<ApiDefinitionSwagger> apiDefinitionSwaggers = apiDefinitionSwaggerMapper.selectByExample(example);
if (CollectionUtils.isNotEmpty(apiDefinitionSwaggers)) { 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); 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); Schedule schedule = checkScheduleExit(id);
apiDefinitionSwaggerMapper.deleteByPrimaryKey(schedule.getResourceId()); apiDefinitionSwaggerMapper.deleteByPrimaryKey(schedule.getResourceId());
scheduleService.deleteByResourceId(schedule.getResourceId(), SwaggerUrlImportJob.class.getName()); 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) { private Schedule checkScheduleExit(String id) {

View File

@ -14,7 +14,7 @@
<ms-base-table v-bind="propsRes" no-disable v-on="propsEvent"> <ms-base-table v-bind="propsRes" no-disable v-on="propsEvent">
<template #status="{ record }"> <template #status="{ record }">
<a-switch <a-switch
v-model:modelValue="record.enable" v-model:model-value="record.enable"
type="line" type="line"
size="small" size="small"
:before-change="() => handleBeforeEnableChange(record)" :before-change="() => handleBeforeEnableChange(record)"
@ -39,7 +39,7 @@
import { MsTableColumn } from '@/components/pure/ms-table/type'; import { MsTableColumn } from '@/components/pure/ms-table/type';
import useTable from '@/components/pure/ms-table/useTable'; import useTable from '@/components/pure/ms-table/useTable';
import { switchDefinitionSchedule } from '@/api/modules/api-test/management'; import { deleteDefinitionSchedule, switchDefinitionSchedule } from '@/api/modules/api-test/management';
import { getScheduleProApiCaseList, projectDeleteSchedule } from '@/api/modules/taskCenter/project'; import { getScheduleProApiCaseList, projectDeleteSchedule } from '@/api/modules/taskCenter/project';
import { useI18n } from '@/hooks/useI18n'; import { useI18n } from '@/hooks/useI18n';
import useModal from '@/hooks/useModal'; import useModal from '@/hooks/useModal';
@ -175,7 +175,7 @@
maskClosable: false, maskClosable: false,
onBeforeOk: async () => { onBeforeOk: async () => {
try { try {
await projectDeleteSchedule(record.id); await deleteDefinitionSchedule(record.id);
Message.success(t('common.deleteSuccess')); Message.success(t('common.deleteSuccess'));
loadTaskList(); loadTaskList();
} catch (error) { } catch (error) {