From 31d9ae57ab48de56005b89e6c2eadb1bcf4f0f2f Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Fri, 8 Nov 2024 15:25:38 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B):=20?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E8=AF=84=E5=AE=A1=E6=96=B0=E5=A2=9E=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E6=93=8D=E4=BD=9C=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CaseReviewModuleController.java | 4 +- .../service/CaseReviewModuleLogService.java | 106 ++++++++++++++++++ .../service/CaseReviewModuleService.java | 36 +----- .../CaseReviewModuleControllerTests.java | 1 - .../log/constants/OperationLogModule.java | 2 + 5 files changed, 115 insertions(+), 34 deletions(-) create mode 100644 backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewModuleLogService.java diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/CaseReviewModuleController.java b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/CaseReviewModuleController.java index 5ef8dbd557..604dbbb652 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/CaseReviewModuleController.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/CaseReviewModuleController.java @@ -38,7 +38,7 @@ public class CaseReviewModuleController { @RequiresPermissions(PermissionConstants.CASE_REVIEW_READ_ADD) @CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project") public String add(@RequestBody @Validated CaseReviewModuleCreateRequest request) { - return caseReviewModuleService.add(request, SessionUtils.getUserId()); + return caseReviewModuleService.add(request, SessionUtils.getUserId()); } @PostMapping("/update") @@ -62,7 +62,7 @@ public class CaseReviewModuleController { @RequiresPermissions(PermissionConstants.CASE_REVIEW_READ_DELETE) @CheckOwner(resourceId = "#moduleId", resourceType = "case_review_module") public void deleteNode(@PathVariable String moduleId) { - caseReviewModuleService.deleteModule(moduleId); + caseReviewModuleService.deleteModule(moduleId, SessionUtils.getUserId()); } } diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewModuleLogService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewModuleLogService.java new file mode 100644 index 0000000000..cde1c97621 --- /dev/null +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewModuleLogService.java @@ -0,0 +1,106 @@ +package io.metersphere.functional.service; + +import io.metersphere.functional.domain.CaseReview; +import io.metersphere.functional.domain.CaseReviewModule; +import io.metersphere.project.domain.Project; +import io.metersphere.project.mapper.ProjectMapper; +import io.metersphere.sdk.constants.HttpMethodConstants; +import io.metersphere.sdk.util.JSON; +import io.metersphere.system.dto.builder.LogDTOBuilder; +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.log.service.OperationLogService; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.List; + +@Service +@Transactional(rollbackFor = Exception.class) +public class CaseReviewModuleLogService { + private static final String CASE_REVIEW_MODULE = "/case/review/module"; + private static final String ADD = CASE_REVIEW_MODULE + "/add"; + private static final String UPDATE = CASE_REVIEW_MODULE + "/update"; + @Resource + private ProjectMapper projectMapper; + @Resource + private OperationLogService operationLogService; + + /** + * 评审新增模块日志 + * + * @param caseReviewModule + * @param userId + */ + public void addModuleLog(CaseReviewModule caseReviewModule, String userId) { + Project project = projectMapper.selectByPrimaryKey(caseReviewModule.getProjectId()); + LogDTO dto = LogDTOBuilder.builder() + .projectId(caseReviewModule.getProjectId()) + .organizationId(project.getOrganizationId()) + .type(OperationLogType.ADD.name()) + .module(OperationLogModule.CASE_MANAGEMENT_REVIEW_REVIEW_MODULE) + .method(HttpMethodConstants.POST.name()) + .path(ADD) + .sourceId(caseReviewModule.getId()) + .content(caseReviewModule.getName()) + .originalValue(JSON.toJSONBytes(caseReviewModule)) + .createUser(userId) + .build().getLogDTO(); + operationLogService.add(dto); + } + + /** + * 评审更新模块日志 + * + * @param updateModule + * @param operator + */ + public void updateModuleLog(CaseReviewModule updateModule, String operator) { + Project project = projectMapper.selectByPrimaryKey(updateModule.getProjectId()); + LogDTO dto = LogDTOBuilder.builder() + .projectId(project.getId()) + .organizationId(project.getOrganizationId()) + .type(OperationLogType.UPDATE.name()) + .module(OperationLogModule.CASE_MANAGEMENT_REVIEW_REVIEW_MODULE) + .method(HttpMethodConstants.POST.name()) + .path(UPDATE) + .sourceId(updateModule.getId()) + .content(updateModule.getName()) + .originalValue(JSON.toJSONBytes(updateModule)) + .createUser(operator) + .build().getLogDTO(); + operationLogService.add(dto); + } + + + /** + * 评审删除模块日志 + * + * @param caseReviews + * @param projectId + * @param userId + * @param path + */ + public void batchDelLog(List caseReviews, String projectId, String userId, String path) { + Project project = projectMapper.selectByPrimaryKey(projectId); + List dtoList = new ArrayList<>(); + caseReviews.forEach(item -> { + LogDTO dto = new LogDTO( + projectId, + project.getOrganizationId(), + item.getId(), + userId, + OperationLogType.DELETE.name(), + OperationLogModule.CASE_MANAGEMENT_REVIEW_REVIEW_MODULE, + item.getName()); + dto.setPath(path); + dto.setMethod(HttpMethodConstants.GET.name()); + dto.setOriginalValue(JSON.toJSONBytes(item)); + dtoList.add(dto); + }); + operationLogService.batchAdd(dtoList); + } +} diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewModuleService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewModuleService.java index e4efd8b38f..ae6f3843da 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewModuleService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewModuleService.java @@ -18,17 +18,11 @@ import io.metersphere.functional.request.CaseReviewModuleUpdateRequest; import io.metersphere.project.dto.ModuleCountDTO; import io.metersphere.project.dto.NodeSortDTO; import io.metersphere.project.service.ModuleTreeService; -import io.metersphere.sdk.constants.HttpMethodConstants; import io.metersphere.sdk.constants.ModuleConstants; import io.metersphere.sdk.exception.MSException; -import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.Translator; import io.metersphere.system.dto.sdk.BaseTreeNode; import io.metersphere.system.dto.sdk.request.NodeMoveRequest; -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.log.service.OperationLogService; import io.metersphere.system.uid.IDGenerator; import jakarta.annotation.Resource; import org.apache.commons.collections4.CollectionUtils; @@ -59,10 +53,8 @@ public class CaseReviewModuleService extends ModuleTreeService { private ExtCaseReviewMapper extCaseReviewMapper; @Resource private DeleteCaseReviewService deleteCaseReviewService; - - @Resource - private OperationLogService operationLogService; + private CaseReviewModuleLogService caseReviewModuleLogService; public List getTree(String projectId) { List fileModuleList = extCaseReviewModuleMapper.selectBaseByProjectId(projectId); @@ -82,6 +74,7 @@ public class CaseReviewModuleService extends ModuleTreeService { caseReviewModule.setCreateUser(userId); caseReviewModule.setUpdateUser(userId); caseReviewModuleMapper.insert(caseReviewModule); + caseReviewModuleLogService.addModuleLog(caseReviewModule, userId); return caseReviewModule.getId(); } @@ -97,6 +90,7 @@ public class CaseReviewModuleService extends ModuleTreeService { updateModule.setCreateUser(null); updateModule.setCreateTime(null); caseReviewModuleMapper.updateByPrimaryKeySelective(updateModule); + caseReviewModuleLogService.updateModuleLog(updateModule, userId); } public void moveNode(NodeMoveRequest request, String userId) { @@ -122,34 +116,14 @@ public class CaseReviewModuleService extends ModuleTreeService { super.sort(nodeSortDTO); } - public void deleteModule(String moduleId) { + public void deleteModule(String moduleId, String userId) { CaseReviewModule deleteModule = caseReviewModuleMapper.selectByPrimaryKey(moduleId); if (deleteModule != null) { List caseReviews = this.deleteModuleByIds(Collections.singletonList(moduleId), new ArrayList<>(), deleteModule.getProjectId()); - batchDelLog(caseReviews, deleteModule.getProjectId()); + caseReviewModuleLogService.batchDelLog(caseReviews, deleteModule.getProjectId(), userId, "/case/review/module/delete/" + moduleId); } } - public void batchDelLog(List caseReviews, String projectId) { - List dtoList = new ArrayList<>(); - caseReviews.forEach(item -> { - LogDTO dto = new LogDTO( - projectId, - "", - item.getId(), - item.getCreateUser(), - OperationLogType.DELETE.name(), - OperationLogModule.CASE_MANAGEMENT_REVIEW_REVIEW, - item.getName()); - - dto.setPath("/case/review/module/delete/"); - dto.setMethod(HttpMethodConstants.GET.name()); - dto.setOriginalValue(JSON.toJSONBytes(item)); - dtoList.add(dto); - }); - operationLogService.batchAdd(dtoList); - } - public List deleteModuleByIds(List deleteIds, List caseReviews, String projectId) { if (CollectionUtils.isEmpty(deleteIds)) { return caseReviews; diff --git a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/CaseReviewModuleControllerTests.java b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/CaseReviewModuleControllerTests.java index 5bb761c424..f5a4df213b 100644 --- a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/CaseReviewModuleControllerTests.java +++ b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/CaseReviewModuleControllerTests.java @@ -701,7 +701,6 @@ public class CaseReviewModuleControllerTests extends BaseTest { //service层判断:测试删除空集合 caseReviewModuleService.deleteModuleByIds(new ArrayList<>(),new ArrayList<>(), project.getId()); - checkLog(caseReview.getId(), OperationLogType.DELETE, URL_MODULE_TREE_DELETE); } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/log/constants/OperationLogModule.java b/backend/services/system-setting/src/main/java/io/metersphere/system/log/constants/OperationLogModule.java index d14922474e..1ee9defd92 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/log/constants/OperationLogModule.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/log/constants/OperationLogModule.java @@ -151,6 +151,8 @@ public class OperationLogModule { public static final String CASE_MANAGEMENT_REVIEW_REVIEW = "CASE_MANAGEMENT_REVIEW_REVIEW"; //评审详情 public static final String CASE_REVIEW_DETAIL = "CASE_MANAGEMENT_REVIEW_DETAIL"; + //模块 + public static final String CASE_MANAGEMENT_REVIEW_REVIEW_MODULE = "CASE_MANAGEMENT_REVIEW_REVIEW_MODULE"; //接口调试 public static final String API_TEST_DEBUG_MANAGEMENT_DEBUG = "API_TEST_DEBUG_MANAGEMENT_DEBUG";