feat(功能用例): 获取用例已关联缺陷&前后置提供获取已关联ids集合接口

This commit is contained in:
WangXu10 2024-01-09 14:22:52 +08:00 committed by Craftsman
parent 13a43240e1
commit ecf3ca512b
16 changed files with 214 additions and 6 deletions

View File

@ -22,10 +22,10 @@ public class BugProviderDTO implements Serializable {
private String name;
@Schema(description = "处理人")
private String createUser;
private String handleUser;
@Schema(description = "处理人姓名")
private String createUserName;
private String handleUserName;
@Schema(description = "缺陷状态")
private String status;

View File

@ -0,0 +1,23 @@
package io.metersphere.dto;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
/**
* @author wx
*/
@Data
public class BugRelateCaseDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private String id;
private String title;
private String status;
}

View File

@ -1,6 +1,7 @@
package io.metersphere.provider;
import io.metersphere.dto.BugProviderDTO;
import io.metersphere.request.AssociateBugPageRequest;
import io.metersphere.request.AssociateBugRequest;
import io.metersphere.request.BugPageProviderRequest;
@ -48,4 +49,12 @@ public interface BaseAssociateBugProvider {
* @param id
*/
void disassociateBug(String id);
/**
* 获取用例已关联缺陷列表
*
* @param request
* @return
*/
List<BugProviderDTO> hasAssociateBugPage(AssociateBugPageRequest request);
}

View File

@ -0,0 +1,55 @@
package io.metersphere.request;
import com.google.common.base.CaseFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;
import java.util.Map;
/**
* @author wx
*/
@Data
@EqualsAndHashCode(callSuper = false)
public class AssociateBugPageRequest extends BaseProviderCondition {
@Schema(description = "用例id", requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank(message = "{functional_case.id.not_blank}")
private String caseId;
@Min(value = 1, message = "当前页码必须大于0")
@Schema(description = "当前页码")
private int current;
@Min(value = 5, message = "每页显示条数必须不小于5")
@Max(value = 500, message = "每页显示条数不能大于500")
@Schema(description = "每页显示条数")
private int pageSize;
@Schema(description = "排序字段model中的字段 : asc/desc")
private Map<@Valid @Pattern(regexp = "^[A-Za-z]+$") String, @Valid @NotBlank String> sort;
public String getSortString() {
if (sort == null || sort.isEmpty()) {
return null;
}
StringBuilder sb = new StringBuilder();
for (Map.Entry<String, String> entry : sort.entrySet()) {
String column = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, entry.getKey());
sb.append(column)
.append(StringUtils.SPACE)
.append(StringUtils.equalsIgnoreCase(entry.getValue(), "DESC") ? "DESC" : "ASC")
.append(",");
}
return sb.substring(0, sb.length() - 1);
}
}

View File

@ -193,7 +193,7 @@
SELECT
b.id id,
b.title title,
b.create_user createUser,
b.handle_user handleUser,
u.`name` name,
b.`status` status,
b.tag tag,

View File

@ -3,6 +3,8 @@ package io.metersphere.bug.mapper;
import io.metersphere.bug.dto.request.BugRelatedCasePageRequest;
import io.metersphere.bug.dto.response.BugRelateCaseCountDTO;
import io.metersphere.bug.dto.response.BugRelateCaseDTO;
import io.metersphere.dto.BugProviderDTO;
import io.metersphere.request.AssociateBugPageRequest;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -25,4 +27,6 @@ public interface ExtBugRelateCaseMapper {
* @return 缺陷关联用例列表
*/
List<BugRelateCaseDTO> list(@Param("request") BugRelatedCasePageRequest request);
List<BugProviderDTO> getAssociateBugs(@Param("request") AssociateBugPageRequest request);
}

View File

@ -19,4 +19,27 @@
and fc.name like concat('%', #{request.keyword}, '%')
</if>
</select>
<select id="getAssociateBugs" resultType="io.metersphere.dto.BugProviderDTO">
SELECT
brc.bug_id id,
b.title NAME,
b.handle_user handleUser,
b.`status`,
brc.test_plan_id
FROM
bug_relation_case brc
INNER JOIN bug b ON brc.bug_id = b.id
where b.deleted = false
<include refid="queryWhereConditionByProvider"/>
</select>
<sql id="queryWhereConditionByProvider">
<if test="request.caseId != null">
and brc.case_id = #{request.caseId}
</if>
<if test="request.keyword != null">
and b.title like concat('%', #{request.keyword},'%')
</if>
</sql>
</mapper>

View File

@ -4,9 +4,11 @@ package io.metersphere.bug.provider;
import io.metersphere.bug.domain.BugRelationCase;
import io.metersphere.bug.mapper.BugRelationCaseMapper;
import io.metersphere.bug.mapper.ExtBugMapper;
import io.metersphere.bug.mapper.ExtBugRelateCaseMapper;
import io.metersphere.bug.service.BugRelateCaseService;
import io.metersphere.dto.BugProviderDTO;
import io.metersphere.provider.BaseAssociateBugProvider;
import io.metersphere.request.AssociateBugPageRequest;
import io.metersphere.request.AssociateBugRequest;
import io.metersphere.request.BugPageProviderRequest;
import io.metersphere.system.uid.IDGenerator;
@ -26,11 +28,14 @@ public class AssociateBugProvider implements BaseAssociateBugProvider {
private BugRelationCaseMapper bugRelationCaseMapper;
@Resource
private BugRelateCaseService bugRelateCaseService;
@Resource
private ExtBugRelateCaseMapper extBugRelateCaseMapper;
@Override
public List<BugProviderDTO> getBugList(String sourceType, String sourceName, String bugColumnName, BugPageProviderRequest bugPageProviderRequest) {
return extBugMapper.listByProviderRequest(sourceType, sourceName, bugColumnName, bugPageProviderRequest, false);
//TODO 需要转义状态和处理人属性
}
@Override
@ -67,4 +72,10 @@ public class AssociateBugProvider implements BaseAssociateBugProvider {
public void disassociateBug(String id) {
bugRelateCaseService.unRelate(id);
}
@Override
public List<BugProviderDTO> hasAssociateBugPage(AssociateBugPageRequest request) {
return extBugRelateCaseMapper.getAssociateBugs(request);
//TODO 需要转义状态和处理人属性
}
}

View File

@ -2,6 +2,7 @@ package io.metersphere.bug.controller;
import io.metersphere.bug.provider.AssociateBugProvider;
import io.metersphere.dto.BugProviderDTO;
import io.metersphere.request.AssociateBugPageRequest;
import io.metersphere.request.AssociateBugRequest;
import io.metersphere.request.BugPageProviderRequest;
import io.metersphere.sdk.util.JSON;
@ -76,4 +77,14 @@ public class AssociateBugProviderTests extends BaseTest {
public void testDisassociateBug() throws Exception {
associateBugProvider.disassociateBug("wx_test_id_1");
}
@Test
@Order(5)
public void testAssociateBugPage() throws Exception {
AssociateBugPageRequest request = new AssociateBugPageRequest();
request.setCurrent(1);
request.setPageSize(10);
request.setCaseId("123");
associateBugProvider.hasAssociateBugPage(request);
}
}

View File

@ -38,14 +38,19 @@ public class FunctionalCaseRelationshipController {
@Resource
private FunctionalCaseRelationshipEdgeService functionalCaseRelationshipEdgeService;
@GetMapping("/get-ids/{caseId}")
@Operation(summary = "用例管理-功能用例-评审列表-评审详情-获取已关联用例id集合(关联用例弹窗前调用)")
@CheckOwner(resourceId = "#reviewId", resourceType = "case_review")
public List<String> getCaseIds(@PathVariable String caseId) {
return functionalCaseRelationshipEdgeService.getExcludeIds(caseId);
}
@PostMapping("/relate/page")
@Operation(summary = "用例管理-功能用例-用例详情-前后置关系-弹窗获取用例列表")
@RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ)
@CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project")
public Pager<List<FunctionalCasePageDTO>> getFunctionalCasePage(@Validated @RequestBody RelationshipPageRequest request) {
List<String> excludeIds = functionalCaseRelationshipEdgeService.getExcludeIds(request.getId());
request.setExcludeIds(excludeIds);
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(),
StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "pos desc");
return PageUtils.setPageInfo(page, functionalCaseService.getFunctionalCasePage(request, false));

View File

@ -120,4 +120,14 @@ public class FunctionalTestCaseController {
functionalTestCaseService.disassociateBug(id);
}
@PostMapping("/has/associate/bug/page")
@Operation(summary = "用例管理-功能用例-关联其他用例-获取已关联的缺陷列表")
@RequiresPermissions(value = {PermissionConstants.FUNCTIONAL_CASE_READ_ADD, PermissionConstants.FUNCTIONAL_CASE_READ_UPDATE, PermissionConstants.FUNCTIONAL_CASE_READ_DELETE}, logical = Logical.OR)
@CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project")
public Pager<List<BugProviderDTO>> getAssociateBugList(@Validated @RequestBody AssociateBugPageRequest request) {
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(),
StringUtils.isNotBlank(request.getSortString()) ? request.getSortString() : "create_time desc");
return PageUtils.setPageInfo(page, functionalTestCaseService.hasAssociateBugPage(request));
}
}

View File

@ -585,6 +585,12 @@
)
</when>
</choose>
<if test="request.excludeIds != null and request.excludeIds.size() > 0">
AND id not in
<foreach collection="request.excludeIds" item="excludeId" separator="," open="(" close=")">
#{excludeId}
</foreach>
</if>
GROUP BY module_id
</select>

View File

@ -47,6 +47,7 @@ public class FunctionalCaseRelationshipEdgeService {
List<FunctionalCaseRelationshipEdge> relationshipEdges = getRelationshipEdges(id);
List<String> ids = relationshipEdges.stream().map(FunctionalCaseRelationshipEdge::getTargetId).collect(Collectors.toList());
ids.addAll(relationshipEdges.stream().map(FunctionalCaseRelationshipEdge::getSourceId).collect(Collectors.toList()));
ids.add(id);
List<String> list = ids.stream().distinct().toList();
return list;
}

View File

@ -199,4 +199,8 @@ public class FunctionalTestCaseService {
public void disassociateBug(String id) {
baseAssociateBugProvider.disassociateBug(id);
}
public List<BugProviderDTO> hasAssociateBugPage(AssociateBugPageRequest request) {
return baseAssociateBugProvider.hasAssociateBugPage(request);
}
}

View File

@ -27,6 +27,7 @@ public class FunctionalCaseRelationshipControllerTests extends BaseTest {
public static final String ADD = "/functional/case/relationship/add";
public static final String PAGE = "/functional/case/relationship/page";
public static final String DELETE = "/functional/case/relationship/delete/";
public static final String IDS = "/functional/case/relationship/get-ids/";
@Test
@ -93,6 +94,9 @@ public class FunctionalCaseRelationshipControllerTests extends BaseTest {
request.setType("POST");
request.setSelectIds(List.of("wx_relationship_6"));
this.requestPostWithOkAndReturn(ADD, request);
request.setSelectIds(null);
this.requestPostWithOkAndReturn(ADD, request);
}
@ -148,4 +152,17 @@ public class FunctionalCaseRelationshipControllerTests extends BaseTest {
assertErrorCode(this.requestGet(DELETE + "test"), MsHttpResultCode.FAILED);
}
@Test
@Order(5)
public void testIds() throws Exception {
MvcResult postResult = this.requestGetWithOkAndReturn(IDS + "123");
// 获取返回值
String postReturnData = postResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder postResultHolder = JSON.parseObject(postReturnData, ResultHolder.class);
// 返回请求正常
Assertions.assertNotNull(postResultHolder);
//异常覆盖
assertErrorCode(this.requestGet(DELETE + "test"), MsHttpResultCode.FAILED);
}
}

View File

@ -60,6 +60,7 @@ public class FunctionalTestCaseControllerTests extends BaseTest {
private static final String URL_BUG_PAGE = "/functional/case/test/associate/bug/page";
private static final String URL_ASSOCIATE_BUG = "/functional/case/test/associate/bug";
private static final String URL_DISASSOCIATE_BUG = "/functional/case/test/disassociate/bug/";
private static final String URL_ASSOCIATE_BUG_PAGE = "/functional/case/test/has/associate/bug/page";
@Resource
@ -358,4 +359,32 @@ public class FunctionalTestCaseControllerTests extends BaseTest {
this.requestGetWithOkAndReturn(URL_DISASSOCIATE_BUG + "TEST");
this.requestGetWithOkAndReturn(URL_DISASSOCIATE_BUG + "1234");
}
@Test
@Order(11)
public void testAssociateBugPage() throws Exception {
AssociateBugPageRequest request = new AssociateBugPageRequest();
request.setCurrent(1);
request.setPageSize(10);
request.setCaseId("wx_2");
List<BugProviderDTO> list = new ArrayList<>();
BugProviderDTO bugProviderDTO = new BugProviderDTO();
bugProviderDTO.setId("123");
bugProviderDTO.setName("测试返回数据");
bugProviderDTO.setHandleUser("wx");
bugProviderDTO.setStatus("进行中");
bugProviderDTO.setHandleUserName("wx");
list.add(bugProviderDTO);
Mockito.when(baseAssociateBugProvider.hasAssociateBugPage(request)).thenReturn(list);
MvcResult mvcResult = this.requestPostWithOkAndReturn(URL_ASSOCIATE_BUG_PAGE, request);
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
List<BugProviderDTO> bugProviderDTOS = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), BugProviderDTO.class);
Assertions.assertNotNull(bugProviderDTOS);
request.setSort(new HashMap<>() {{
put("createTime", "desc");
}});
this.requestPostWithOkAndReturn(URL_ASSOCIATE_BUG_PAGE, request);
}
}