From 1e6a09ca7236605143d2670a4288d86780041eb3 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Tue, 30 Jan 2024 10:20:14 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E7=94=A8=E4=BE=8B=E7=AE=A1=E7=90=86):?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=97=A5=E5=BF=97=E7=B1=BB=E5=9E=8B=E5=8A=A0?= =?UTF-8?q?sourceId?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CaseReviewController.java | 5 +++-- .../functional/service/CaseReviewService.java | 15 ++++++++------- .../controller/CaseReviewControllerTests.java | 9 +++++++-- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/CaseReviewController.java b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/CaseReviewController.java index 772d8661a4..19a571ba30 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/CaseReviewController.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/CaseReviewController.java @@ -3,6 +3,7 @@ package io.metersphere.functional.controller; import com.alibaba.excel.util.StringUtils; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; +import io.metersphere.functional.domain.CaseReview; import io.metersphere.functional.dto.CaseReviewDTO; import io.metersphere.functional.request.*; import io.metersphere.functional.service.CaseReviewLogService; @@ -64,7 +65,7 @@ public class CaseReviewController { @SendNotice(taskType = NoticeConstants.TaskType.CASE_REVIEW_TASK, event = NoticeConstants.Event.CREATE, target = "#targetClass.getMainCaseReview(#request)", targetClass = CaseReviewNoticeService.class) @RequiresPermissions(PermissionConstants.CASE_REVIEW_READ_ADD) @CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project") - public String addCaseReview(@Validated @RequestBody CaseReviewRequest request) { + public CaseReview addCaseReview(@Validated @RequestBody CaseReviewRequest request) { return caseReviewService.addCaseReview(request, SessionUtils.getUserId()); } @@ -74,7 +75,7 @@ public class CaseReviewController { @SendNotice(taskType = NoticeConstants.TaskType.CASE_REVIEW_TASK, event = NoticeConstants.Event.CREATE, target = "#targetClass.getMainCaseReview(#request)", targetClass = CaseReviewNoticeService.class) @RequiresPermissions(PermissionConstants.CASE_REVIEW_READ_ADD) @CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project") - public String copyCaseReview(@Validated @RequestBody CaseReviewCopyRequest request) { + public CaseReview copyCaseReview(@Validated @RequestBody CaseReviewCopyRequest request) { return caseReviewService.copyCaseReview(request, SessionUtils.getUserId()); } diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewService.java index f497d1da17..8b68780ac9 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewService.java @@ -203,13 +203,13 @@ public class CaseReviewService { * @param request 页面参数 * @param userId 当前操作人 */ - public String addCaseReview(CaseReviewRequest request, String userId) { + public CaseReview addCaseReview(CaseReviewRequest request, String userId) { String caseReviewId = IDGenerator.nextStr(); BaseAssociateCaseRequest baseAssociateCaseRequest = request.getBaseAssociateCaseRequest(); List caseIds = doSelectIds(baseAssociateCaseRequest, baseAssociateCaseRequest.getProjectId()); - addCaseReview(request, userId, caseReviewId, caseIds); + CaseReview caseReview = addCaseReview(request, userId, caseReviewId, caseIds); addAssociate(request, userId, caseReviewId, caseIds); - return caseReviewId; + return caseReview; } private void addAssociate(CaseReviewRequest request, String userId, String caseReviewId, List caseIds) { @@ -230,15 +230,15 @@ public class CaseReviewService { } } - public String copyCaseReview(CaseReviewCopyRequest request, String userId) { + public CaseReview copyCaseReview(CaseReviewCopyRequest request, String userId) { String caseReviewId = IDGenerator.nextStr(); CaseReviewFunctionalCaseExample caseReviewFunctionalCaseExample = new CaseReviewFunctionalCaseExample(); caseReviewFunctionalCaseExample.createCriteria().andReviewIdEqualTo(request.getCopyId()); List caseReviewFunctionalCases = caseReviewFunctionalCaseMapper.selectByExample(caseReviewFunctionalCaseExample); List caseIds = caseReviewFunctionalCases.stream().map(CaseReviewFunctionalCase::getCaseId).distinct().toList(); - addCaseReview(request, userId, caseReviewId, caseIds); + CaseReview caseReview = addCaseReview(request, userId, caseReviewId, caseIds); addAssociate(request, userId, caseReviewId, caseIds); - return caseReviewId; + return caseReview; } /** @@ -340,7 +340,7 @@ public class CaseReviewService { * @param userId 当前操作人 * @param caseReviewId 用例评审id */ - private void addCaseReview(CaseReviewRequest request, String userId, String caseReviewId, List caseIds) { + private CaseReview addCaseReview(CaseReviewRequest request, String userId, String caseReviewId, List caseIds) { CaseReview caseReview = new CaseReview(); caseReview.setId(caseReviewId); caseReview.setNum(getNextNum(request.getProjectId())); @@ -367,6 +367,7 @@ public class CaseReviewService { caseReview.setCreateUser(userId); caseReview.setUpdateUser(userId); caseReviewMapper.insert(caseReview); + return caseReview; } /** diff --git a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/CaseReviewControllerTests.java b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/CaseReviewControllerTests.java index 278ea7b485..cfe4bbb6bc 100644 --- a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/CaseReviewControllerTests.java +++ b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/CaseReviewControllerTests.java @@ -13,6 +13,7 @@ import io.metersphere.system.base.BaseTest; import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.system.domain.User; import io.metersphere.system.dto.sdk.request.PosRequest; +import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.utils.Pager; import jakarta.annotation.Resource; import org.apache.commons.collections.CollectionUtils; @@ -79,7 +80,9 @@ public class CaseReviewControllerTests extends BaseTest { @Sql(scripts = {"/dml/init_case_review.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED)) public void addCaseReviewSuccess() throws Exception { CaseReviewRequest caseReviewRequest = getCaseReviewAddRequest("创建评审1", CaseReviewPassRule.SINGLE.toString(), "CASE_REVIEW_TEST_GYQ_ID", false, true, null); - this.requestPostWithOk(ADD_CASE_REVIEW, caseReviewRequest); + MvcResult mvcResult = this.requestPostWithOkAndReturn(ADD_CASE_REVIEW, caseReviewRequest); + CaseReview caseReview = getResultData(mvcResult, CaseReview.class); + checkLog(caseReview.getId(), OperationLogType.ADD); List caseReviews = getCaseReviews("创建评审1"); Assertions.assertEquals(1, caseReviews.size()); String caseReviewId = caseReviews.get(0).getId(); @@ -95,7 +98,9 @@ public class CaseReviewControllerTests extends BaseTest { CaseReviewCopyRequest caseReviewCopyRequest = getCaseReviewAddRequest("创建评审1", CaseReviewPassRule.SINGLE.toString(), "CASE_REVIEW_TEST_GYQ_ID", false, true, null); caseReviewCopyRequest.setCopyId(caseReviewId); - this.requestPostWithOk(COPY_CASE_REVIEW, caseReviewCopyRequest); + MvcResult mvcResult1 = this.requestPostWithOkAndReturn(COPY_CASE_REVIEW, caseReviewCopyRequest); + CaseReview caseReview1 = getResultData(mvcResult1, CaseReview.class); + checkLog(caseReview1.getId(), OperationLogType.COPY); caseReviews = getCaseReviews("创建评审1"); Assertions.assertEquals(2, caseReviews.size()); List list = caseReviews.stream().map(CaseReview::getId).distinct().toList();