From c00bf37336c9ba0d26874524acb768c70275b9c8 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Tue, 7 May 2024 17:49:02 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E4=BB=BB=E5=8A=A1=E4=B8=AD=E5=BF=83?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../3.0.0/ddl/V3.0.0_12__beta_ddl.sql | 4 +++ .../api/service/ApiTaskCenterService.java | 4 +-- .../controller/TaskCenterController.java | 18 ++++++------ .../dto/taskcenter/enums/ScheduleTagType.java | 19 ++----------- .../system/service/TaskCenterService.java | 28 +++++++++++++------ .../TaskCenterScheduleControllerTests.java | 4 --- 6 files changed, 38 insertions(+), 39 deletions(-) diff --git a/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_12__beta_ddl.sql b/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_12__beta_ddl.sql index 47b9545e18..38cbebd454 100644 --- a/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_12__beta_ddl.sql +++ b/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_12__beta_ddl.sql @@ -15,6 +15,10 @@ ALTER TABLE test_plan_config ADD COLUMN test_planning BIT NOT NULL DEFAULT 0 CO ALTER TABLE api_definition_mock ADD COLUMN update_user VARCHAR(50) COMMENT '更新人'; +ALTER TABLE operation_history MODIFY COLUMN module VARCHAR(100); + +ALTER TABLE operation_log MODIFY COLUMN module VARCHAR(100); + -- set innodb lock wait timeout to default SET SESSION innodb_lock_wait_timeout = DEFAULT; diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiTaskCenterService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiTaskCenterService.java index a6b4cfa736..b1057111fa 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiTaskCenterService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiTaskCenterService.java @@ -281,11 +281,11 @@ public class ApiTaskCenterService { extApiReportMapper.updateReportStatus(subList, System.currentTimeMillis(), userId); extApiReportMapper.updateApiCaseStatus(subList); //记录日志 - saveLog(subList, userId, path, method, module, TaskCenterResourceType.API_CASE.toString()); + saveLog(subList, userId, path, method, StringUtils.join(module, "_REAL_TIME_API_CASE"), TaskCenterResourceType.API_CASE.toString()); } else if (request.getModuleType().equals(TaskCenterResourceType.API_SCENARIO.toString())) { extApiScenarioReportMapper.updateReportStatus(subList, System.currentTimeMillis(), userId); extApiScenarioReportMapper.updateApiScenario(subList); - saveLog(subList, userId, path, method, module, TaskCenterResourceType.API_SCENARIO.toString()); + saveLog(subList, userId, path, method, StringUtils.join(module,"_REAL_TIME_API_SCENARIO"), TaskCenterResourceType.API_SCENARIO.toString()); } } }); diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/TaskCenterController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/TaskCenterController.java index 183de073b8..47574d6337 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/TaskCenterController.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/TaskCenterController.java @@ -66,7 +66,7 @@ public class TaskCenterController { @CheckOwner(resourceId = "#id", resourceType = "schedule") public void delete(@PathVariable String moduleType, @PathVariable String id) { hasPermission(SYSTEM, moduleType); - taskCenterService.delete(id, SessionUtils.getUserId(), "/task/center/system/schedule/delete/", OperationLogModule.SETTING_SYSTEM_TASK_CENTER); + taskCenterService.delete(id, moduleType, SessionUtils.getUserId(), "/task/center/system/schedule/delete/", OperationLogModule.SETTING_SYSTEM_TASK_CENTER); } @GetMapping("/org/schedule/delete/{moduleType}/{id}") @@ -74,7 +74,7 @@ public class TaskCenterController { @CheckOwner(resourceId = "#id", resourceType = "schedule") public void deleteOrg(@PathVariable String moduleType, @PathVariable String id) { hasPermission(ORG, moduleType); - taskCenterService.delete(id, SessionUtils.getUserId(), "/task/center/org/schedule/delete/", OperationLogModule.SETTING_ORGANIZATION_TASK_CENTER); + taskCenterService.delete(id, moduleType,SessionUtils.getUserId(), "/task/center/org/schedule/delete/", OperationLogModule.SETTING_ORGANIZATION_TASK_CENTER); } @GetMapping("/project/schedule/delete/{moduleType}/{id}") @@ -82,7 +82,7 @@ public class TaskCenterController { @CheckOwner(resourceId = "#id", resourceType = "schedule") public void deleteProject(@PathVariable String moduleType, @PathVariable String id) { hasPermission(PROJECT, moduleType); - taskCenterService.delete(id, SessionUtils.getUserId(), "/task/center/project/schedule/delete/", OperationLogModule.PROJECT_MANAGEMENT_TASK_CENTER); + taskCenterService.delete(id, moduleType,SessionUtils.getUserId(), "/task/center/project/schedule/delete/", OperationLogModule.PROJECT_MANAGEMENT_TASK_CENTER); } @GetMapping("/system/schedule/switch/{moduleType}/{id}") @@ -90,7 +90,7 @@ public class TaskCenterController { @CheckOwner(resourceId = "#id", resourceType = "schedule") public void enable(@PathVariable String moduleType, @PathVariable String id) { hasPermission(SYSTEM, moduleType); - taskCenterService.enable(id, SessionUtils.getUserId(), "/task/center/system/schedule/switch/", OperationLogModule.SETTING_SYSTEM_TASK_CENTER); + taskCenterService.enable(id, moduleType,SessionUtils.getUserId(), "/task/center/system/schedule/switch/", OperationLogModule.SETTING_SYSTEM_TASK_CENTER); } @@ -99,7 +99,7 @@ public class TaskCenterController { @CheckOwner(resourceId = "#id", resourceType = "schedule") public void enableOrg(@PathVariable String moduleType, @PathVariable String id) { hasPermission(ORG, moduleType); - taskCenterService.enable(id, SessionUtils.getUserId(), "/task/center/org/schedule/switch/", OperationLogModule.SETTING_ORGANIZATION_TASK_CENTER); + taskCenterService.enable(id, moduleType,SessionUtils.getUserId(), "/task/center/org/schedule/switch/", OperationLogModule.SETTING_ORGANIZATION_TASK_CENTER); } @GetMapping("/project/schedule/switch/{moduleType}/{id}") @@ -107,7 +107,7 @@ public class TaskCenterController { @CheckOwner(resourceId = "#id", resourceType = "schedule") public void enableProject(@PathVariable String moduleType, @PathVariable String id) { hasPermission(PROJECT, moduleType); - taskCenterService.enable(id, SessionUtils.getUserId(), "/task/center/project/schedule/switch/", OperationLogModule.PROJECT_MANAGEMENT_TASK_CENTER); + taskCenterService.enable(id, moduleType,SessionUtils.getUserId(), "/task/center/project/schedule/switch/", OperationLogModule.PROJECT_MANAGEMENT_TASK_CENTER); } @PostMapping("/system/schedule/update/{moduleType}/{id}") @@ -115,7 +115,7 @@ public class TaskCenterController { @CheckOwner(resourceId = "#id", resourceType = "schedule") public void update(@PathVariable String moduleType, @PathVariable String id, @RequestBody Object cron) { hasPermission(SYSTEM, moduleType); - taskCenterService.update(id, cron.toString(), SessionUtils.getUserId(), "/task/center/system/schedule/update/", OperationLogModule.SETTING_SYSTEM_TASK_CENTER); + taskCenterService.update(id, moduleType,cron.toString(), SessionUtils.getUserId(), "/task/center/system/schedule/update/", OperationLogModule.SETTING_SYSTEM_TASK_CENTER); } @PostMapping("/org/schedule/update/{moduleType}/{id}") @@ -123,7 +123,7 @@ public class TaskCenterController { @CheckOwner(resourceId = "#id", resourceType = "schedule") public void updateOrg(@PathVariable String moduleType, @PathVariable String id, @RequestBody Object cron) { hasPermission(ORG, moduleType); - taskCenterService.update(id, cron.toString(), SessionUtils.getUserId(), "/task/center/org/schedule/update/", OperationLogModule.SETTING_ORGANIZATION_TASK_CENTER); + taskCenterService.update(id, moduleType,cron.toString(), SessionUtils.getUserId(), "/task/center/org/schedule/update/", OperationLogModule.SETTING_ORGANIZATION_TASK_CENTER); } @PostMapping("/project/schedule/update/{moduleType}/{id}") @@ -131,7 +131,7 @@ public class TaskCenterController { @CheckOwner(resourceId = "#id", resourceType = "schedule") public void updateProject(@PathVariable String moduleType, @PathVariable String id, @RequestBody Object cron) { hasPermission(PROJECT, moduleType); - taskCenterService.update(id, cron.toString(), SessionUtils.getUserId(), "/task/center/project/schedule/update/", OperationLogModule.PROJECT_MANAGEMENT_TASK_CENTER); + taskCenterService.update(id, moduleType,cron.toString(), SessionUtils.getUserId(), "/task/center/project/schedule/update/", OperationLogModule.PROJECT_MANAGEMENT_TASK_CENTER); } @PostMapping("/system/schedule/batch-enable") diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/taskcenter/enums/ScheduleTagType.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/taskcenter/enums/ScheduleTagType.java index 2ecf31269b..9bf83b0aab 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/taskcenter/enums/ScheduleTagType.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/taskcenter/enums/ScheduleTagType.java @@ -1,27 +1,14 @@ package io.metersphere.system.dto.taskcenter.enums; -import java.util.List; - /** * @author: LAN * @date: 2024/1/22 16:41 * @version: 1.0 */ public enum ScheduleTagType { - API_IMPORT("API_IMPORT"), - API_SCENARIO("API_SCENARIO"), - UI_SCENARIO("UI_TEST"), - LOAD_TEST("LOAD_TEST"), - TEST_PLAN("TEST_PLAN"); + API_IMPORT, + API_SCENARIO, + TEST_PLAN; - private List names; - - ScheduleTagType(String... names) { - this.names = List.of(names); - } - - public List getNames() { - return names; - } } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/TaskCenterService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/TaskCenterService.java index 33bd1cc10d..b60138582a 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/TaskCenterService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/TaskCenterService.java @@ -189,13 +189,22 @@ public class TaskCenterService { return organization; } - public void delete(String id, String userId, String path, String module) { + public void delete(String id,String moduleType, String userId, String path, String module) { Schedule schedule = checkScheduleExit(id); - if (ScheduleTagType.API_IMPORT.getNames().contains(schedule.getResourceType())) { + String logModule = getLogModule(moduleType, module); + if (StringUtils.equals(schedule.getResourceType(), ScheduleTagType.API_IMPORT.name())) { extSwaggerMapper.deleteByPrimaryKey(schedule.getResourceId()); } scheduleService.deleteByResourceId(schedule.getResourceId(), schedule.getJob()); - saveLog(List.of(schedule), userId, path, HttpMethodConstants.GET.name(), module, OperationLogType.DELETE.name()); + saveLog(List.of(schedule), userId, path, HttpMethodConstants.GET.name(), logModule, OperationLogType.DELETE.name()); + } + + private static String getLogModule(String moduleType, String module) { + return switch (ScheduleTagType.valueOf(moduleType)) { + case ScheduleTagType.API_IMPORT -> StringUtils.join(module, "_TIME_API_IMPORT"); + case ScheduleTagType.API_SCENARIO -> StringUtils.join(module, "_TIME_API_SCENARIO"); + default -> throw new MSException(Translator.get("module_type_error")); + }; } private Schedule checkScheduleExit(String id) { @@ -206,23 +215,25 @@ public class TaskCenterService { return schedule; } - public void enable(String id, String userId, String path, String module) { + public void enable(String id,String moduleType, String userId, String path, String module) { Schedule schedule = checkScheduleExit(id); schedule.setEnable(!schedule.getEnable()); scheduleService.editSchedule(schedule); scheduleService.addOrUpdateCronJob(schedule, new JobKey(schedule.getKey(), schedule.getJob()), new TriggerKey(schedule.getKey(), schedule.getJob()), BaseScheduleJob.class); apiScheduleNoticeService.sendScheduleNotice(schedule, userId); - saveLog(List.of(schedule), userId, path, HttpMethodConstants.GET.name(), module, OperationLogType.UPDATE.name()); + String logModule = getLogModule(moduleType, module); + saveLog(List.of(schedule), userId, path, HttpMethodConstants.GET.name(), logModule, OperationLogType.UPDATE.name()); } - public void update(String id, String cron, String userId, String path, String module) { + public void update(String id,String moduleType, String cron, String userId, String path, String module) { Schedule schedule = checkScheduleExit(id); schedule.setValue(cron); scheduleService.editSchedule(schedule); scheduleService.addOrUpdateCronJob(schedule, new JobKey(schedule.getKey(), schedule.getJob()), new TriggerKey(schedule.getKey(), schedule.getJob()), schedule.getJob().getClass()); - saveLog(List.of(schedule), userId, path, HttpMethodConstants.POST.name(), module, OperationLogType.UPDATE.name()); + String logModule = getLogModule(moduleType, module); + saveLog(List.of(schedule), userId, path, HttpMethodConstants.POST.name(), logModule, OperationLogType.UPDATE.name()); } private void saveLog(List scheduleList, String userId, String path, String method, String module, String operationType) { @@ -293,7 +304,8 @@ public class TaskCenterService { }); SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); apiScheduleNoticeService.batchSendNotice(projectId, scheduleList, userMapper.selectByPrimaryKey(userId), enable ? NoticeConstants.Event.OPEN : NoticeConstants.Event.CLOSE); - saveLog(scheduleList, userId, path, HttpMethodConstants.POST.name(), module, OperationLogType.UPDATE.name()); + String logModule = getLogModule(request.getScheduleTagType(), module); + saveLog(scheduleList, userId, path, HttpMethodConstants.POST.name(), logModule, OperationLogType.UPDATE.name()); } public void batchEnableProject(TaskCenterScheduleBatchRequest request, String userId, String projectId, String path, String module, boolean enable) { diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/TaskCenterScheduleControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/TaskCenterScheduleControllerTests.java index 34981fd061..0c38a91a60 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/TaskCenterScheduleControllerTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/TaskCenterScheduleControllerTests.java @@ -164,10 +164,6 @@ class TaskCenterScheduleControllerTests extends BaseTest { this.requestGet("/task/center/system/schedule/delete/" + "API_IMPORT/" + scheduleId); Schedule schedule = scheduleMapper.selectByPrimaryKey(scheduleId); Assertions.assertNull(schedule); - if (ScheduleTagType.API_IMPORT.getNames().contains(oldSchedule.getType())) { - int count = extSwaggerMapper.selectByPrimaryKey(oldSchedule.getResourceId()); - Assertions.assertTrue(count > 0); - } this.requestGet("/task/center/org/schedule/delete/" + "API_IMPORT/" + "4"); this.requestGet("/task/center/project/schedule/delete/" + "API_SCENARIO/" + "2"); this.requestGet("/task/center/system/schedule/delete/" + "API_SCENARIO/" + "schedule-121", ERROR_REQUEST_MATCHER);