From 9f810c0c36299ae897779a869851dcb712a1df25 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Wed, 6 Dec 2023 17:38:16 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E7=94=A8=E4=BE=8B=E8=AF=84=E5=AE=A1):=20?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E8=AF=84=E5=AE=A1=E5=8E=86=E5=8F=B2=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ReviewFunctionalCaseController.java | 15 ++++++--- .../functional/dto/CaseReviewHistoryDTO.java | 19 +++++++++++ .../mapper/ExtCaseReviewHistoryMapper.java | 15 +++++++++ .../mapper/ExtCaseReviewHistoryMapper.xml | 26 +++++++++++++++ .../service/ReviewFunctionalCaseService.java | 13 ++++++++ .../ReviewFunctionalCaseControllerTests.java | 33 +++++++++++++++++++ 6 files changed, 117 insertions(+), 4 deletions(-) create mode 100644 backend/services/case-management/src/main/java/io/metersphere/functional/dto/CaseReviewHistoryDTO.java create mode 100644 backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewHistoryMapper.java create mode 100644 backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewHistoryMapper.xml diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/ReviewFunctionalCaseController.java b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/ReviewFunctionalCaseController.java index 0e7d5ae759..abf015cc04 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/ReviewFunctionalCaseController.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/ReviewFunctionalCaseController.java @@ -1,5 +1,6 @@ package io.metersphere.functional.controller; +import io.metersphere.functional.dto.CaseReviewHistoryDTO; import io.metersphere.functional.request.ReviewFunctionalCaseRequest; import io.metersphere.functional.service.ReviewFunctionalCaseService; import io.metersphere.sdk.constants.PermissionConstants; @@ -9,10 +10,9 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import java.util.List; @Tag(name = "用例管理-用例评审-评审功能用例") @RestController @@ -29,5 +29,12 @@ public class ReviewFunctionalCaseController { reviewFunctionalCaseService.saveReview(request, SessionUtils.getUserId()); } + @GetMapping("/get/list/{reviewId}/{caseId}") + @Operation(summary = "用例管理-用例评审-评审功能用例-获取用例评审历史") + @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ) + public List getCaseReviewHistoryList(@PathVariable String reviewId, @PathVariable String caseId) { + return reviewFunctionalCaseService.getCaseReviewHistoryList(reviewId, caseId); + } + } diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/dto/CaseReviewHistoryDTO.java b/backend/services/case-management/src/main/java/io/metersphere/functional/dto/CaseReviewHistoryDTO.java new file mode 100644 index 0000000000..34e226a599 --- /dev/null +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/dto/CaseReviewHistoryDTO.java @@ -0,0 +1,19 @@ +package io.metersphere.functional.dto; + +import io.metersphere.functional.domain.CaseReviewHistory; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +public class CaseReviewHistoryDTO extends CaseReviewHistory { + + @Schema(description = "评审人头像") + private String userLogo; + + @Schema(description = "评审人名") + private String userName; + + @Schema(description = "评审解析内容") + private String contentText; + +} diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewHistoryMapper.java b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewHistoryMapper.java new file mode 100644 index 0000000000..e12a39b9c2 --- /dev/null +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewHistoryMapper.java @@ -0,0 +1,15 @@ +package io.metersphere.functional.mapper; + +import io.metersphere.functional.dto.CaseReviewHistoryDTO; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * @author guoyuqi + */ +public interface ExtCaseReviewHistoryMapper { + + List list(@Param("caseId") String caseId, @Param("reviewId") String reviewId); + +} diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewHistoryMapper.xml b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewHistoryMapper.xml new file mode 100644 index 0000000000..b1527e2af3 --- /dev/null +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/mapper/ExtCaseReviewHistoryMapper.xml @@ -0,0 +1,26 @@ + + + + + + + + + \ No newline at end of file diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/ReviewFunctionalCaseService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/ReviewFunctionalCaseService.java index 787aa8612a..25f8b77c00 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/ReviewFunctionalCaseService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/ReviewFunctionalCaseService.java @@ -4,6 +4,7 @@ import io.metersphere.functional.constants.CaseReviewPassRule; import io.metersphere.functional.constants.CaseReviewStatus; import io.metersphere.functional.constants.FunctionalCaseReviewStatus; import io.metersphere.functional.domain.*; +import io.metersphere.functional.dto.CaseReviewHistoryDTO; import io.metersphere.functional.mapper.*; import io.metersphere.functional.request.ReviewFunctionalCaseRequest; import io.metersphere.sdk.exception.MSException; @@ -22,6 +23,7 @@ import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.nio.charset.StandardCharsets; import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; @@ -45,6 +47,9 @@ public class ReviewFunctionalCaseService { private NoticeSendService noticeSendService; @Resource private FunctionalCaseMapper functionalCaseMapper; + @Resource + private ExtCaseReviewHistoryMapper extCaseReviewHistoryMapper; + /** @@ -212,4 +217,12 @@ public class ReviewFunctionalCaseService { caseReviewHistory.setCreateTime(System.currentTimeMillis()); return caseReviewHistory; } + + public List getCaseReviewHistoryList(String reviewId, String caseId) { + List list = extCaseReviewHistoryMapper.list(caseId, reviewId); + for (CaseReviewHistoryDTO caseReviewHistoryDTO : list) { + caseReviewHistoryDTO.setContentText(new String(caseReviewHistoryDTO.getContent(),StandardCharsets.UTF_8)); + } + return list; + } } diff --git a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/ReviewFunctionalCaseControllerTests.java b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/ReviewFunctionalCaseControllerTests.java index 8535cbdacf..18d0a426d8 100644 --- a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/ReviewFunctionalCaseControllerTests.java +++ b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/ReviewFunctionalCaseControllerTests.java @@ -4,6 +4,7 @@ import io.metersphere.functional.constants.CaseReviewPassRule; import io.metersphere.functional.constants.CaseReviewStatus; import io.metersphere.functional.constants.FunctionalCaseReviewStatus; import io.metersphere.functional.domain.*; +import io.metersphere.functional.dto.CaseReviewHistoryDTO; import io.metersphere.functional.mapper.CaseReviewFunctionalCaseMapper; import io.metersphere.functional.mapper.CaseReviewHistoryMapper; import io.metersphere.functional.mapper.CaseReviewMapper; @@ -12,19 +13,27 @@ import io.metersphere.functional.request.ReviewFunctionalCaseRequest; import io.metersphere.project.domain.Notification; import io.metersphere.project.domain.NotificationExample; import io.metersphere.project.mapper.NotificationMapper; +import io.metersphere.sdk.constants.SessionConstants; +import io.metersphere.sdk.util.JSON; import io.metersphere.system.base.BaseTest; +import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.system.notice.constants.NoticeConstants; import jakarta.annotation.Resource; import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.*; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.MediaType; import org.springframework.test.context.jdbc.Sql; import org.springframework.test.context.jdbc.SqlConfig; +import org.springframework.test.web.servlet.MvcResult; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @@ -36,6 +45,7 @@ public class ReviewFunctionalCaseControllerTests extends BaseTest { private static final String SAVE_REVIEW = "/review/functional/case/save"; private static final String ADD_CASE_REVIEW = "/case/review/add"; + private static final String REVIEW_LIST = "/review/functional/case/get/list/"; @Resource private CaseReviewMapper caseReviewMapper; @@ -215,6 +225,29 @@ public class ReviewFunctionalCaseControllerTests extends BaseTest { } + @Test + @Order(4) + public void getListSuccess() throws Exception { + List caseReviews = getCaseReviews("创建用例评审1"); + String reviewId = caseReviews.get(0).getId(); + List gyqReviewCaseTest = getCaseReviewHistoryList("gyqReviewCaseTest", reviewId); + System.out.println(JSON.toJSONString(gyqReviewCaseTest)); + } + + + public List getCaseReviewHistoryList(String caseId,String reviewId) throws Exception { + MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get(REVIEW_LIST +"/"+reviewId +"/"+ caseId).header(SessionConstants.HEADER_TOKEN, sessionId) + .header(SessionConstants.CSRF_TOKEN, csrfToken) + .header(SessionConstants.CURRENT_PROJECT, projectId) + .contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn(); + String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); + ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); + return JSON.parseArray(JSON.toJSONString(resultHolder.getData()), CaseReviewHistoryDTO.class); + + } + private List addReview(String name, List caseIds, List reviewers) throws Exception { CaseReviewRequest caseReviewRequest = new CaseReviewRequest(); caseReviewRequest.setProjectId(projectId);