diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewLogService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewLogService.java index 136c0b5686..762fac21fe 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewLogService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewLogService.java @@ -13,11 +13,15 @@ import io.metersphere.functional.request.BaseAssociateCaseRequest; import io.metersphere.functional.request.BaseReviewCaseBatchRequest; import io.metersphere.functional.request.CaseReviewAssociateRequest; import io.metersphere.functional.request.CaseReviewRequest; +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.apache.commons.collections.CollectionUtils; import org.springframework.stereotype.Service; @@ -46,6 +50,10 @@ public class CaseReviewLogService { private CaseReviewFunctionalCaseMapper caseReviewFunctionalCaseMapper; @Resource private ExtFunctionalCaseMapper extFunctionalCaseMapper; + @Resource + private ProjectMapper projectMapper; + @Resource + private OperationLogService operationLogService; /** * 新增用例评审 日志 @@ -243,4 +251,19 @@ public class CaseReviewLogService { } } + public void createCaseAndAssociateLog(CaseReview caseReview, FunctionalCase functionalCase, String userId) { + Project project = projectMapper.selectByPrimaryKey(caseReview.getProjectId()); + LogDTO dto = LogDTOBuilder.builder() + .projectId(caseReview.getProjectId()) + .organizationId(project.getOrganizationId()) + .type(OperationLogType.ASSOCIATE.name()) + .module(OperationLogModule.CASE_REVIEW_DETAIL) + .method(HttpMethodConstants.POST.name()) + .path("/functional/case/add") + .sourceId(caseReview.getId()) + .content(functionalCase.getName()) + .createUser(userId) + .build().getLogDTO(); + operationLogService.add(dto); + } } diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java index 78c10fb8f6..fb8f67b518 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java @@ -178,6 +178,8 @@ public class FunctionalCaseService { private ProjectService projectService; @Resource private FunctionalCaseNoticeService functionalCaseNoticeService; + @Resource + private CaseReviewLogService caseReviewLogService;; public FunctionalCase addFunctionalCase(FunctionalCaseAddRequest request, List files, String userId, String organizationId) { String caseId = IDGenerator.nextStr(); @@ -201,7 +203,7 @@ public class FunctionalCaseService { copyAttachment(request, userId, uploadFileIds, caseId); } LogUtils.info("保存用例的文件操作完成"); - addCaseReviewCase(request.getReviewId(), caseId, userId); + addCaseReviewCase(request.getReviewId(), functionalCase, userId); //记录日志 FunctionalCaseHistoryLogDTO historyLogDTO = getAddLogModule(functionalCase); @@ -276,10 +278,11 @@ public class FunctionalCaseService { * * @param reviewId reviewId */ - private void addCaseReviewCase(String reviewId, String caseId, String userId) { + private void addCaseReviewCase(String reviewId, FunctionalCase functionalCase, String userId) { if (StringUtils.isNotBlank(reviewId)) { - caseReviewService.checkCaseReview(reviewId); - caseReviewFunctionalCaseService.addCaseReviewFunctionalCase(caseId, userId, reviewId); + CaseReview caseReview = caseReviewService.checkCaseReview(reviewId); + caseReviewFunctionalCaseService.addCaseReviewFunctionalCase(functionalCase.getId(), userId, reviewId); + caseReviewLogService.createCaseAndAssociateLog(caseReview, functionalCase, userId); } } diff --git a/backend/services/case-management/src/test/resources/dml/init_review_functional_case_test.sql b/backend/services/case-management/src/test/resources/dml/init_review_functional_case_test.sql index 984604712a..649595bf13 100644 --- a/backend/services/case-management/src/test/resources/dml/init_review_functional_case_test.sql +++ b/backend/services/case-management/src/test/resources/dml/init_review_functional_case_test.sql @@ -120,6 +120,8 @@ INSERT INTO project (id, num, organization_id, name, description, create_user, u VALUES ('wx_test_project_review_one', null, 'organization-associate-case-test', '评审跨项目关联用例', '系统默认创建的项目', 'admin', 'admin', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), ('wx_test_project_review_two', null, 'organization-associate-case-test', '评审跨项目关联用例2', '系统默认创建的项目', + 'admin', 'admin', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), + ('wx_test_project', null, 'organization-associate-case-test', '评审跨项目关联用例3', '系统默认创建的项目', 'admin', 'admin', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000);