fix(功能用例): 修复接口连调发现的问题

This commit is contained in:
guoyuqi 2024-01-08 18:47:29 +08:00 committed by 刘瑞斌
parent 276ac224f2
commit 0ef5e7a6bf
10 changed files with 61 additions and 28 deletions

View File

@ -74,8 +74,8 @@ public class CaseReviewController {
@SendNotice(taskType = NoticeConstants.TaskType.CASE_REVIEW_TASK, event = NoticeConstants.Event.CREATE, target = "#targetClass.getMainCaseReview(#request)", targetClass = CaseReviewNoticeService.class) @SendNotice(taskType = NoticeConstants.TaskType.CASE_REVIEW_TASK, event = NoticeConstants.Event.CREATE, target = "#targetClass.getMainCaseReview(#request)", targetClass = CaseReviewNoticeService.class)
@RequiresPermissions(PermissionConstants.CASE_REVIEW_READ_ADD) @RequiresPermissions(PermissionConstants.CASE_REVIEW_READ_ADD)
@CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project") @CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project")
public void copyCaseReview(@Validated @RequestBody CaseReviewRequest request) { public String copyCaseReview(@Validated @RequestBody CaseReviewCopyRequest request) {
caseReviewService.addCaseReview(request, SessionUtils.getUserId()); return caseReviewService.copyCaseReview(request, SessionUtils.getUserId());
} }
@PostMapping("/edit") @PostMapping("/edit")

View File

@ -10,7 +10,7 @@ import java.util.List;
public class CaseReviewDTO extends CaseReview { public class CaseReviewDTO extends CaseReview {
@Schema(description = "评审人") @Schema(description = "评审人")
private List<String> reviewers; private List<CaseReviewUserDTO> reviewers;
@Schema(description = "通过数") @Schema(description = "通过数")
private int passCount; private int passCount;
@ -29,4 +29,8 @@ public class CaseReviewDTO extends CaseReview {
@Schema(description = "关注标识") @Schema(description = "关注标识")
private Boolean followFlag; private Boolean followFlag;
@Schema(description = "所属模块名称")
private String moduleName;
} }

View File

@ -9,4 +9,7 @@ public class CaseReviewUserDTO extends CaseReviewUser {
@Schema(description = "用户名") @Schema(description = "用户名")
private String userName; private String userName;
@Schema(description = "头像")
private String avatar;
} }

View File

@ -16,7 +16,7 @@ public class FunctionalCaseReviewDTO extends CaseReviewFunctionalCase {
@NotBlank(message = "{case_review_functional_case.review_name.not_blank}") @NotBlank(message = "{case_review_functional_case.review_name.not_blank}")
private String reviewName; private String reviewName;
@Schema(description = "用例评审状态", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "用例评审状态:未开始(PREPARED)/进行中(UNDERWAY)/已完成(COMPLETED)/已归档(ARCHIVED)", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{case_review_functional_case.review_status.not_blank}") @NotBlank(message = "{case_review_functional_case.review_status.not_blank}")
private String reviewStatus; private String reviewStatus;

View File

@ -4,7 +4,7 @@
<select id="list" resultType="io.metersphere.functional.dto.FunctionalCaseReviewDTO"> <select id="list" resultType="io.metersphere.functional.dto.FunctionalCaseReviewDTO">
SELECT SELECT
cr.num as reviewNum, cr.name as reviewName, cr.status as reviewStatus, cf.status, cf.update_time cf.*, cr.num as reviewNum, cr.name as reviewName, cr.status as reviewStatus
FROM FROM
case_review_functional_case cf left join case_review cr on cf.review_id = cr.id case_review_functional_case cf left join case_review cr on cf.review_id = cr.id
where cf.case_id = #{request.caseId} where cf.case_id = #{request.caseId}

View File

@ -28,9 +28,9 @@
<select id="list" resultType="io.metersphere.functional.dto.CaseReviewDTO"> <select id="list" resultType="io.metersphere.functional.dto.CaseReviewDTO">
SELECT SELECT
* case_review.* , case_review_module.name as moduleName
FROM FROM
case_review case_review left join case_review_module on case_review.module_id = case_review_module.id
where case_review.project_id = #{request.projectId} where case_review.project_id = #{request.projectId}
<choose> <choose>
<when test='request.searchMode == "AND"'> <when test='request.searchMode == "AND"'>

View File

@ -4,9 +4,10 @@
<select id="getReviewUser" resultType="io.metersphere.functional.dto.CaseReviewUserDTO"> <select id="getReviewUser" resultType="io.metersphere.functional.dto.CaseReviewUserDTO">
SELECT SELECT
cu.user_id ,cu.review_id, u.name as userName cu.user_id ,cu.review_id, u.name as userName, ue.avatar as avatar
FROM FROM
case_review_user cu left join user u on cu.user_id = u.id case_review_user cu left join user u on cu.user_id = u.id
left join user_extend ue on cu.user_id = ue.id
WHERE WHERE
cu.review_id in cu.review_id in
<foreach collection="reviewIds" item="id" open="(" separator="," close=")"> <foreach collection="reviewIds" item="id" open="(" separator="," close=")">

View File

@ -0,0 +1,13 @@
package io.metersphere.functional.request;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
@Data
public class CaseReviewCopyRequest extends CaseReviewRequest{
@Schema(description = "被复制的用例评审id", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{case_review_copy_request.copy_id.not_blank}")
private String copyId;
}

View File

@ -97,9 +97,9 @@ public class CaseReviewService {
} }
List<String> reviewIds = list.stream().map(CaseReview::getId).toList(); List<String> reviewIds = list.stream().map(CaseReview::getId).toList();
Map<String, List<CaseReviewFunctionalCase>> reviewCaseMap = getReviewCaseMap(reviewIds); Map<String, List<CaseReviewFunctionalCase>> reviewCaseMap = getReviewCaseMap(reviewIds);
Map<String, List<CaseReviewUserDTO>> reviewUserMap = getReviewUserMap(reviewIds); List<CaseReviewUserDTO> reviewUsers = getReviewUsers(reviewIds);
for (CaseReviewDTO caseReviewDTO : list) { for (CaseReviewDTO caseReviewDTO : list) {
buildCaseReviewDTO(caseReviewDTO, reviewCaseMap, reviewUserMap); buildCaseReviewDTO(caseReviewDTO, reviewCaseMap, reviewUsers);
} }
return list; return list;
@ -110,9 +110,8 @@ public class CaseReviewService {
* *
* @param caseReviewDTO caseReviewDTO * @param caseReviewDTO caseReviewDTO
* @param reviewCaseMap 用例和评审的关系map * @param reviewCaseMap 用例和评审的关系map
* @param reviewUserMap 评审和评审人的关系map
*/ */
private static void buildCaseReviewDTO(CaseReviewDTO caseReviewDTO, Map<String, List<CaseReviewFunctionalCase>> reviewCaseMap, Map<String, List<CaseReviewUserDTO>> reviewUserMap) { private static void buildCaseReviewDTO(CaseReviewDTO caseReviewDTO, Map<String, List<CaseReviewFunctionalCase>> reviewCaseMap, List<CaseReviewUserDTO> reviewUsers) {
String caseReviewId = caseReviewDTO.getId(); String caseReviewId = caseReviewDTO.getId();
List<CaseReviewFunctionalCase> caseReviewFunctionalCaseList = reviewCaseMap.get(caseReviewId); List<CaseReviewFunctionalCase> caseReviewFunctionalCaseList = reviewCaseMap.get(caseReviewId);
if (CollectionUtils.isEmpty(caseReviewFunctionalCaseList)) { if (CollectionUtils.isEmpty(caseReviewFunctionalCaseList)) {
@ -124,15 +123,9 @@ public class CaseReviewService {
} else { } else {
buildAboutCaseCount(caseReviewDTO, caseReviewFunctionalCaseList); buildAboutCaseCount(caseReviewDTO, caseReviewFunctionalCaseList);
} }
caseReviewDTO.setReviewers(reviewUsers);
buildReviewers(caseReviewDTO, reviewUserMap);
} }
private static void buildReviewers(CaseReviewDTO caseReviewDTO, Map<String, List<CaseReviewUserDTO>> reviewUserMap) {
List<CaseReviewUserDTO> caseReviewUserDTOS = reviewUserMap.get(caseReviewDTO.getId());
List<String> userNames = caseReviewUserDTOS.stream().map(CaseReviewUserDTO::getUserName).toList();
caseReviewDTO.setReviewers(userNames);
}
/** /**
* 构建用例相关的各种数量 * 构建用例相关的各种数量
@ -176,9 +169,8 @@ public class CaseReviewService {
* @param reviewIds 评审ids * @param reviewIds 评审ids
* @return Map * @return Map
*/ */
private Map<String, List<CaseReviewUserDTO>> getReviewUserMap(List<String> reviewIds) { private List<CaseReviewUserDTO> getReviewUsers(List<String> reviewIds) {
List<CaseReviewUserDTO> reviewUser = extCaseReviewUserMapper.getReviewUser(reviewIds); return extCaseReviewUserMapper.getReviewUser(reviewIds);
return reviewUser.stream().collect(Collectors.groupingBy(CaseReviewUserDTO::getReviewId));
} }
@ -205,6 +197,11 @@ public class CaseReviewService {
BaseAssociateCaseRequest baseAssociateCaseRequest = request.getBaseAssociateCaseRequest(); BaseAssociateCaseRequest baseAssociateCaseRequest = request.getBaseAssociateCaseRequest();
List<String> caseIds = doSelectIds(baseAssociateCaseRequest, baseAssociateCaseRequest.getProjectId()); List<String> caseIds = doSelectIds(baseAssociateCaseRequest, baseAssociateCaseRequest.getProjectId());
addCaseReview(request, userId, caseReviewId, caseIds); addCaseReview(request, userId, caseReviewId, caseIds);
addAssociate(request, userId, caseReviewId, caseIds);
return caseReviewId;
}
private void addAssociate(CaseReviewRequest request, String userId, String caseReviewId, List<String> caseIds) {
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
CaseReviewUserMapper mapper = sqlSession.getMapper(CaseReviewUserMapper.class); CaseReviewUserMapper mapper = sqlSession.getMapper(CaseReviewUserMapper.class);
CaseReviewFunctionalCaseMapper caseReviewFunctionalCaseMapper = sqlSession.getMapper(CaseReviewFunctionalCaseMapper.class); CaseReviewFunctionalCaseMapper caseReviewFunctionalCaseMapper = sqlSession.getMapper(CaseReviewFunctionalCaseMapper.class);
@ -220,6 +217,16 @@ public class CaseReviewService {
} finally { } finally {
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
} }
}
public String copyCaseReview(CaseReviewCopyRequest request, String userId) {
String caseReviewId = IDGenerator.nextStr();
CaseReviewFunctionalCaseExample caseReviewFunctionalCaseExample = new CaseReviewFunctionalCaseExample();
caseReviewFunctionalCaseExample.createCriteria().andReviewIdEqualTo(request.getCopyId());
List<CaseReviewFunctionalCase> caseReviewFunctionalCases = caseReviewFunctionalCaseMapper.selectByExample(caseReviewFunctionalCaseExample);
List<String> caseIds = caseReviewFunctionalCases.stream().map(CaseReviewFunctionalCase::getCaseId).distinct().toList();
addCaseReview(request, userId, caseReviewId, caseIds);
addAssociate(request, userId, caseReviewId, caseIds);
return caseReviewId; return caseReviewId;
} }
@ -262,6 +269,7 @@ public class CaseReviewService {
if (CollectionUtils.isNotEmpty(request.getTags())) { if (CollectionUtils.isNotEmpty(request.getTags())) {
caseReview.setTags(request.getTags()); caseReview.setTags(request.getTags());
} }
caseReview.setDescription(request.getDescription());
caseReview.setStartTime(request.getStartTime()); caseReview.setStartTime(request.getStartTime());
caseReview.setEndTime(request.getEndTime()); caseReview.setEndTime(request.getEndTime());
caseReview.setUpdateTime(System.currentTimeMillis()); caseReview.setUpdateTime(System.currentTimeMillis());
@ -340,6 +348,7 @@ public class CaseReviewService {
} else { } else {
caseReview.setCaseCount(caseIds.size()); caseReview.setCaseCount(caseIds.size());
} }
caseReview.setDescription(request.getDescription());
caseReview.setStartTime(request.getStartTime()); caseReview.setStartTime(request.getStartTime());
caseReview.setEndTime(request.getEndTime()); caseReview.setEndTime(request.getEndTime());
caseReview.setCreateTime(System.currentTimeMillis()); caseReview.setCreateTime(System.currentTimeMillis());
@ -516,8 +525,8 @@ public class CaseReviewService {
Boolean isFollow = checkFollow(id, userId); Boolean isFollow = checkFollow(id, userId);
caseReviewDTO.setFollowFlag(isFollow); caseReviewDTO.setFollowFlag(isFollow);
Map<String, List<CaseReviewFunctionalCase>> reviewCaseMap = getReviewCaseMap(List.of(id)); Map<String, List<CaseReviewFunctionalCase>> reviewCaseMap = getReviewCaseMap(List.of(id));
Map<String, List<CaseReviewUserDTO>> reviewUserMap = getReviewUserMap(List.of(id)); List<CaseReviewUserDTO> reviewUsers = getReviewUsers(List.of(id));
buildCaseReviewDTO(caseReviewDTO, reviewCaseMap, reviewUserMap); buildCaseReviewDTO(caseReviewDTO, reviewCaseMap, reviewUsers);
return caseReviewDTO; return caseReviewDTO;
} }
@ -584,4 +593,6 @@ public class CaseReviewService {
public String getReviewPassRule(String id) { public String getReviewPassRule(String id) {
return extCaseReviewMapper.getReviewPassRule(id); return extCaseReviewMapper.getReviewPassRule(id);
} }
} }

View File

@ -93,8 +93,9 @@ public class CaseReviewControllerTests extends BaseTest {
Assertions.assertEquals(1, caseReviewFunctionalCases.size()); Assertions.assertEquals(1, caseReviewFunctionalCases.size());
caseReviewRequest = getCaseReviewAddRequest("创建评审1", CaseReviewPassRule.SINGLE.toString(), "CASE_REVIEW_TEST_GYQ_ID", false, true, null); CaseReviewCopyRequest caseReviewCopyRequest = getCaseReviewAddRequest("创建评审1", CaseReviewPassRule.SINGLE.toString(), "CASE_REVIEW_TEST_GYQ_ID", false, true, null);
this.requestPostWithOk(COPY_CASE_REVIEW, caseReviewRequest); caseReviewCopyRequest.setCopyId(caseReviewId);
this.requestPostWithOk(COPY_CASE_REVIEW, caseReviewCopyRequest);
caseReviews = getCaseReviews("创建评审1"); caseReviews = getCaseReviews("创建评审1");
Assertions.assertEquals(2, caseReviews.size()); Assertions.assertEquals(2, caseReviews.size());
List<String> list = caseReviews.stream().map(CaseReview::getId).distinct().toList(); List<String> list = caseReviews.stream().map(CaseReview::getId).distinct().toList();
@ -109,8 +110,8 @@ public class CaseReviewControllerTests extends BaseTest {
} }
@NotNull @NotNull
private static CaseReviewRequest getCaseReviewAddRequest(String name, String reviewPassRule, String caseId, boolean tag, boolean reviewer, String id) { private static CaseReviewCopyRequest getCaseReviewAddRequest(String name, String reviewPassRule, String caseId, boolean tag, boolean reviewer, String id) {
CaseReviewRequest caseReviewRequest = new CaseReviewRequest(); CaseReviewCopyRequest caseReviewRequest = new CaseReviewCopyRequest();
if (StringUtils.isNotBlank(id)) { if (StringUtils.isNotBlank(id)) {
caseReviewRequest.setId(id); caseReviewRequest.setId(id);
} }