From 4e4f17f195daf96b1caab47af924bef407891671 Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Wed, 13 Dec 2023 11:29:07 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=8A=9F=E8=83=BD=E7=94=A8=E4=BE=8B):=20?= =?UTF-8?q?=E8=AF=84=E5=AE=A1=E8=AF=A6=E6=83=85=E9=A1=B5=E9=9D=A2=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../request/FunctionalCaseAddRequest.java | 3 ++ .../CaseReviewFunctionalCaseService.java | 27 ++++++++++++ .../functional/service/CaseReviewService.java | 14 +++--- .../service/FunctionalCaseService.java | 19 +++++++- ...seReviewFunctionalCaseControllerTests.java | 43 +++++++++++++++++-- 5 files changed, 94 insertions(+), 12 deletions(-) diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/request/FunctionalCaseAddRequest.java b/backend/services/case-management/src/main/java/io/metersphere/functional/request/FunctionalCaseAddRequest.java index 0f67a8aad7..002b259aee 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/request/FunctionalCaseAddRequest.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/request/FunctionalCaseAddRequest.java @@ -71,5 +71,8 @@ public class FunctionalCaseAddRequest implements Serializable { @Schema(description = "关联文件ID集合") private List relateFileMetaIds; + @Schema(description = "评审id") + private String reviewId; + } diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewFunctionalCaseService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewFunctionalCaseService.java index 85f88b9721..99a042525d 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewFunctionalCaseService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewFunctionalCaseService.java @@ -1,6 +1,8 @@ package io.metersphere.functional.service; +import io.metersphere.functional.constants.FunctionalCaseReviewStatus; +import io.metersphere.functional.domain.CaseReviewFunctionalCase; import io.metersphere.functional.domain.CaseReviewFunctionalCaseExample; import io.metersphere.functional.dto.ReviewFunctionalCaseDTO; import io.metersphere.functional.dto.ReviewsDTO; @@ -13,6 +15,7 @@ import io.metersphere.functional.request.ReviewFunctionalCasePageRequest; import io.metersphere.project.domain.ProjectVersion; import io.metersphere.project.mapper.ExtBaseProjectVersionMapper; import io.metersphere.system.dto.sdk.BaseTreeNode; +import io.metersphere.system.uid.IDGenerator; import jakarta.annotation.Resource; import org.apache.commons.collections.CollectionUtils; import org.springframework.stereotype.Service; @@ -43,6 +46,8 @@ public class CaseReviewFunctionalCaseService { private ExtCaseReviewFunctionalCaseUserMapper extCaseReviewFunctionalCaseUserMapper; @Resource private CaseReviewFunctionalCaseMapper caseReviewFunctionalCaseMapper; + @Resource + private CaseReviewService caseReviewService; /** * 通过评审id获取关联的用例id集合 @@ -116,4 +121,26 @@ public class CaseReviewFunctionalCaseService { return request.getSelectIds(); } } + + + /** + * 评审详情页面 创建用例并关联 + * + * @param caseId + * @param userId + * @param reviewId + */ + public void addCaseReviewFunctionalCase(String caseId, String userId, String reviewId) { + CaseReviewFunctionalCase reviewFunctionalCase = new CaseReviewFunctionalCase(); + reviewFunctionalCase.setId(IDGenerator.nextStr()); + reviewFunctionalCase.setCaseId(caseId); + reviewFunctionalCase.setReviewId(reviewId); + reviewFunctionalCase.setStatus(FunctionalCaseReviewStatus.UN_REVIEWED.toString()); + reviewFunctionalCase.setCreateUser(userId); + reviewFunctionalCase.setCreateTime(System.currentTimeMillis()); + reviewFunctionalCase.setUpdateTime(System.currentTimeMillis()); + reviewFunctionalCase.setPos(caseReviewService.getCaseFunctionalCaseNextPos(reviewId)); + caseReviewFunctionalCaseMapper.insertSelective(reviewFunctionalCase); + + } } \ No newline at end of file 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 fbd17d4364..9e192f4525 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 @@ -213,7 +213,7 @@ public class CaseReviewService { //保存和评审人的关系 addCaseReviewUser(request, caseReviewId, mapper); //保存和用例的关系 - addCaseReviewFunctionalCase(caseIds, request.getProjectId(), userId, caseReviewId, caseReviewFunctionalCaseMapper); + addCaseReviewFunctionalCase(caseIds, userId, caseReviewId, caseReviewFunctionalCaseMapper); //保存用例和用例评审人的关系 addCaseReviewFunctionalCaseUser(caseIds, request.getReviewers(), caseReviewId, caseReviewFunctionalCaseUserMapper); sqlSession.flushStatements(); @@ -353,7 +353,7 @@ public class CaseReviewService { * * @param caseReviewId 用例评审id */ - private CaseReview checkCaseReview(String caseReviewId) { + public CaseReview checkCaseReview(String caseReviewId) { CaseReview caseReview = caseReviewMapper.selectByPrimaryKey(caseReviewId); if (caseReview == null) { throw new MSException(CaseManagementResultCode.CASE_REVIEW_NOT_FOUND); @@ -391,13 +391,13 @@ public class CaseReviewService { * 保存用例评审和功能用例的关系 * * @param caseIds 功能用例Ids - * @param projectId 项目ID * @param userId 当前操作人 * @param caseReviewId 用例评审id * @param caseReviewFunctionalCaseMapper caseReviewFunctionalCaseMapper */ - private void addCaseReviewFunctionalCase(List caseIds, String projectId, String userId, String caseReviewId, CaseReviewFunctionalCaseMapper caseReviewFunctionalCaseMapper) { + private void addCaseReviewFunctionalCase(List caseIds, String userId, String caseReviewId, CaseReviewFunctionalCaseMapper caseReviewFunctionalCaseMapper) { if (CollectionUtils.isNotEmpty(caseIds)) { + Long nextPos = getCaseFunctionalCaseNextPos(caseReviewId); caseIds.forEach(caseId -> { CaseReviewFunctionalCase caseReviewFunctionalCase = new CaseReviewFunctionalCase(); caseReviewFunctionalCase.setReviewId(caseReviewId); @@ -407,7 +407,7 @@ public class CaseReviewService { caseReviewFunctionalCase.setCreateTime(System.currentTimeMillis()); caseReviewFunctionalCase.setUpdateTime(System.currentTimeMillis()); caseReviewFunctionalCase.setId(IDGenerator.nextStr()); - caseReviewFunctionalCase.setPos(getCaseFunctionalCaseNextPos(caseReviewId)); + caseReviewFunctionalCase.setPos(nextPos + POS_STEP); caseReviewFunctionalCaseMapper.insert(caseReviewFunctionalCase); }); } @@ -460,7 +460,7 @@ public class CaseReviewService { CaseReviewFunctionalCaseUserMapper caseReviewFunctionalCaseUserMapper = sqlSession.getMapper(CaseReviewFunctionalCaseUserMapper.class); try { //保存和用例的关系 - addCaseReviewFunctionalCase(caseRealIds, request.getProjectId(), userId, caseReviewId, caseReviewFunctionalCaseMapper); + addCaseReviewFunctionalCase(caseRealIds, userId, caseReviewId, caseReviewFunctionalCaseMapper); //保存用例和用例评审人的关系 addCaseReviewFunctionalCaseUser(caseRealIds, request.getReviewers(), caseReviewId, caseReviewFunctionalCaseUserMapper); sqlSession.flushStatements(); @@ -582,7 +582,7 @@ public class CaseReviewService { BigDecimal passCount = BigDecimal.valueOf(passList.size()); BigDecimal totalCount = BigDecimal.valueOf(caseReview.getCaseCount()); BigDecimal passRate; - if (totalCount.compareTo(BigDecimal.ZERO)==0) { + if (totalCount.compareTo(BigDecimal.ZERO) == 0) { passRate = BigDecimal.ZERO; } else { passRate = passCount.divide(totalCount, 2, RoundingMode.HALF_UP); 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 92fa6bdc2b..c64c09dcf6 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 @@ -72,7 +72,7 @@ public class FunctionalCaseService { private FunctionalCaseFollowerMapper functionalCaseFollowerMapper; @Resource - private DeleteFunctionalCaseService deleteFunctionalCaseService; + private CaseReviewService caseReviewService; @Resource SqlSessionFactory sqlSessionFactory; @@ -83,6 +83,9 @@ public class FunctionalCaseService { @Resource private FunctionalCaseModuleService functionalCaseModuleService; + @Resource + private CaseReviewFunctionalCaseService caseReviewFunctionalCaseService; + private static final String CASE_MODULE_COUNT_ALL = "all"; private static final String ADD_FUNCTIONAL_CASE_FILE_LOG_URL = "/functional/case/add"; @@ -102,11 +105,25 @@ public class FunctionalCaseService { functionalCaseAttachmentService.association(request.getRelateFileMetaIds(), caseId, userId, ADD_FUNCTIONAL_CASE_FILE_LOG_URL, request.getProjectId()); } + addCaseReviewCase(request.getReviewId(), caseId, userId); return functionalCase; } + /** + * 添加用例评审和用例关联关系 + * + * @param reviewId reviewId + */ + private void addCaseReviewCase(String reviewId, String caseId, String userId) { + if (StringUtils.isNotBlank(reviewId)) { + caseReviewService.checkCaseReview(reviewId); + caseReviewFunctionalCaseService.addCaseReviewFunctionalCase(caseId, userId, reviewId); + } + } + + /** * 添加功能用例 * diff --git a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/CaseReviewFunctionalCaseControllerTests.java b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/CaseReviewFunctionalCaseControllerTests.java index 8dd70a0a9a..084e5592a5 100644 --- a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/CaseReviewFunctionalCaseControllerTests.java +++ b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/CaseReviewFunctionalCaseControllerTests.java @@ -1,19 +1,23 @@ package io.metersphere.functional.controller; import io.metersphere.functional.request.BaseReviewCaseBatchRequest; +import io.metersphere.functional.request.FunctionalCaseAddRequest; import io.metersphere.functional.request.FunctionalCasePageRequest; import io.metersphere.functional.request.ReviewFunctionalCasePageRequest; +import io.metersphere.sdk.util.JSON; import io.metersphere.system.base.BaseTest; +import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.system.dto.sdk.BaseCondition; -import org.junit.jupiter.api.MethodOrderer; -import org.junit.jupiter.api.Order; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestMethodOrder; +import org.junit.jupiter.api.*; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.mock.web.MockMultipartFile; import org.springframework.test.context.jdbc.Sql; import org.springframework.test.context.jdbc.SqlConfig; +import org.springframework.test.web.servlet.MvcResult; +import org.springframework.util.LinkedMultiValueMap; +import java.nio.charset.StandardCharsets; import java.util.*; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @@ -26,6 +30,7 @@ public class CaseReviewFunctionalCaseControllerTests extends BaseTest { public static final String REVIEW_CASE_PAGE = "/case/review/detail/page"; public static final String BATCH_DELETE_URL = "/case/review/detail/batch/disassociate"; + public static final String FUNCTIONAL_CASE_ADD_URL = "/functional/case/add"; @Test @Order(1) @@ -105,4 +110,34 @@ public class CaseReviewFunctionalCaseControllerTests extends BaseTest { } + + @Test + @Order(5) + public void testCaseReviewAddCase() throws Exception { + //新增 + FunctionalCaseAddRequest request = creatFunctionalCase(); + LinkedMultiValueMap paramMap = new LinkedMultiValueMap<>(); + List files = new ArrayList<>(); + paramMap.add("request", JSON.toJSONString(request)); + paramMap.add("files", files); + MvcResult mvcResult = this.requestMultipartWithOkAndReturn(FUNCTIONAL_CASE_ADD_URL, paramMap); + // 获取返回值 + String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); + ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class); + // 返回请求正常 + Assertions.assertNotNull(resultHolder); + } + + + private FunctionalCaseAddRequest creatFunctionalCase() { + FunctionalCaseAddRequest functionalCaseAddRequest = new FunctionalCaseAddRequest(); + functionalCaseAddRequest.setProjectId(DEFAULT_PROJECT_ID); + functionalCaseAddRequest.setTemplateId("default_template_id"); + functionalCaseAddRequest.setName("测试评审详情创建用例"); + functionalCaseAddRequest.setCaseEditType("STEP"); + functionalCaseAddRequest.setModuleId("TEST_MODULE_ID"); + functionalCaseAddRequest.setReviewId("wx_review_id_1"); + return functionalCaseAddRequest; + } + }