feat(功能用例): 用例详情已关联前置用例&后置用例列表分页查询
This commit is contained in:
parent
15b744be34
commit
32aca6799b
|
@ -4,8 +4,10 @@ import com.alibaba.excel.util.StringUtils;
|
|||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import io.metersphere.functional.dto.FunctionalCasePageDTO;
|
||||
import io.metersphere.functional.dto.FunctionalCaseRelationshipDTO;
|
||||
import io.metersphere.functional.request.RelationshipAddRequest;
|
||||
import io.metersphere.functional.request.RelationshipPageRequest;
|
||||
import io.metersphere.functional.request.RelationshipRequest;
|
||||
import io.metersphere.functional.service.FunctionalCaseRelationshipEdgeService;
|
||||
import io.metersphere.functional.service.FunctionalCaseService;
|
||||
import io.metersphere.sdk.constants.PermissionConstants;
|
||||
|
@ -55,7 +57,7 @@ public class FunctionalCaseRelationshipController {
|
|||
@PostMapping("/add")
|
||||
@Operation(summary = "用例管理-功能用例-用例详情-前后置关系-添加前后置关系")
|
||||
@RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ_UPDATE)
|
||||
@CheckOwner(resourceId = "#request.getCaseId()", resourceType = "project")
|
||||
@CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project")
|
||||
public void add(@Validated @RequestBody RelationshipAddRequest request) {
|
||||
List<String> excludeIds = functionalCaseRelationshipEdgeService.getExcludeIds(request.getId());
|
||||
request.setExcludeIds(excludeIds);
|
||||
|
@ -64,4 +66,14 @@ public class FunctionalCaseRelationshipController {
|
|||
functionalCaseRelationshipEdgeService.add(request, ids, SessionUtils.getUserId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/page")
|
||||
@Operation(summary = "用例管理-功能用例-用例详情-前后置关系-列表查询")
|
||||
@RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ_UPDATE)
|
||||
@CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project")
|
||||
public Pager<List<FunctionalCaseRelationshipDTO>> getRelationshipCase(@Validated @RequestBody RelationshipRequest request) {
|
||||
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize());
|
||||
return PageUtils.setPageInfo(page, functionalCaseRelationshipEdgeService.getFunctionalCasePage(request));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package io.metersphere.functional.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author wx
|
||||
*/
|
||||
@Data
|
||||
public class FunctionalCaseRelationshipDTO implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "id")
|
||||
private String id;
|
||||
|
||||
@Schema(description = "用例名称")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "版本")
|
||||
private String versionId;
|
||||
|
||||
@Schema(description = "版本名称")
|
||||
private String versionName;
|
||||
|
||||
@Schema(description = "创建人名称")
|
||||
private String userName;
|
||||
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
package io.metersphere.functional.mapper;
|
||||
|
||||
import io.metersphere.functional.dto.FunctionalCaseRelationshipDTO;
|
||||
import io.metersphere.functional.request.RelationshipRequest;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -8,4 +10,6 @@ public interface ExtFunctionalCaseRelationshipEdgeMapper {
|
|||
|
||||
|
||||
List<String> getGraphIds(@Param("ids") List<String> ids);
|
||||
|
||||
List<FunctionalCaseRelationshipDTO> list(@Param("request") RelationshipRequest request, @Param("sort") String sort);
|
||||
}
|
||||
|
|
|
@ -16,5 +16,45 @@
|
|||
</foreach>
|
||||
</select>
|
||||
|
||||
|
||||
<select id="list" parameterType="io.metersphere.functional.request.RelationshipRequest" resultType="io.metersphere.functional.dto.FunctionalCaseRelationshipDTO">
|
||||
SELECT
|
||||
fc.id id,
|
||||
fc.NAME name,
|
||||
fc.version_id versionId,
|
||||
pv.`name` versionName,
|
||||
u.`name` userName
|
||||
FROM
|
||||
functional_case_relationship_edge fcre
|
||||
<if test="request.type != null and request.type != ''">
|
||||
<choose>
|
||||
<when test="request.type == 'PRE'">
|
||||
INNER JOIN functional_case fc ON fcre.target_id = fc.id
|
||||
</when>
|
||||
<when test="request.type == 'POST'">
|
||||
INNER JOIN functional_case fc ON fcre.source_id = fc.id
|
||||
</when>
|
||||
</choose>
|
||||
</if>
|
||||
INNER JOIN `user` u ON fc.create_user = u.id
|
||||
INNER JOIN project_version pv ON pv.id = fc.version_id
|
||||
WHERE
|
||||
fc.deleted = false
|
||||
<if test="request.type != null and request.type != ''">
|
||||
<choose>
|
||||
<when test="request.type == 'PRE'">
|
||||
AND fcre.source_id = #{request.id}
|
||||
</when>
|
||||
<when test="request.type == 'POST'">
|
||||
AND fcre.target_id = #{request.id}
|
||||
</when>
|
||||
</choose>
|
||||
</if>
|
||||
order by
|
||||
<if test="sort != null and sort != ''">
|
||||
fc.${sort}
|
||||
</if>
|
||||
<if test="sort == null or sort == ''">
|
||||
fcre.create_time desc
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
|
@ -0,0 +1,31 @@
|
|||
package io.metersphere.functional.request;
|
||||
|
||||
import io.metersphere.system.dto.sdk.BasePageRequest;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author wx
|
||||
*/
|
||||
@Data
|
||||
public class RelationshipRequest extends BasePageRequest implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Schema(description = "用例id", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{functional_case.id.not_blank}")
|
||||
private String id;
|
||||
|
||||
@Schema(description = "类型前置/后置", requiredMode = Schema.RequiredMode.REQUIRED, allowableValues = {"PRE", "POST"})
|
||||
@NotBlank(message = "{functional_case_relationship_edge.type.not_blank}")
|
||||
private String type;
|
||||
|
||||
@Schema(description = "项目ID", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotBlank(message = "{functional_case.project_id.not_blank}")
|
||||
private String projectId;
|
||||
}
|
|
@ -9,9 +9,11 @@ package io.metersphere.functional.service;
|
|||
|
||||
import io.metersphere.functional.domain.FunctionalCaseRelationshipEdge;
|
||||
import io.metersphere.functional.domain.FunctionalCaseRelationshipEdgeExample;
|
||||
import io.metersphere.functional.dto.FunctionalCaseRelationshipDTO;
|
||||
import io.metersphere.functional.mapper.ExtFunctionalCaseRelationshipEdgeMapper;
|
||||
import io.metersphere.functional.mapper.FunctionalCaseRelationshipEdgeMapper;
|
||||
import io.metersphere.functional.request.RelationshipAddRequest;
|
||||
import io.metersphere.functional.request.RelationshipRequest;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.uid.IDGenerator;
|
||||
|
@ -219,4 +221,12 @@ public class FunctionalCaseRelationshipEdgeService {
|
|||
edge.setUpdateTime(System.currentTimeMillis());
|
||||
return edge;
|
||||
}
|
||||
|
||||
public List<FunctionalCaseRelationshipDTO> getFunctionalCasePage(RelationshipRequest request) {
|
||||
List<FunctionalCaseRelationshipDTO> list = extFunctionalCaseRelationshipEdgeMapper.list(request, request.getSortString());
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ package io.metersphere.functional.controller;
|
|||
|
||||
import io.metersphere.functional.request.RelationshipAddRequest;
|
||||
import io.metersphere.functional.request.RelationshipPageRequest;
|
||||
import io.metersphere.functional.request.RelationshipRequest;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.system.base.BaseTest;
|
||||
import io.metersphere.system.controller.handler.ResultHolder;
|
||||
|
@ -24,6 +25,7 @@ public class FunctionalCaseRelationshipControllerTests extends BaseTest {
|
|||
|
||||
public static final String RELATE_PAGE = "/functional/case/relationship/relate/page";
|
||||
public static final String ADD = "/functional/case/relationship/add";
|
||||
public static final String PAGE = "/functional/case/relationship/page";
|
||||
|
||||
|
||||
@Test
|
||||
|
@ -85,4 +87,40 @@ public class FunctionalCaseRelationshipControllerTests extends BaseTest {
|
|||
Assertions.assertNotNull(postResultHolder);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
public void testRelationshipList() throws Exception {
|
||||
//分页查询前置用例列表
|
||||
RelationshipRequest request = new RelationshipRequest();
|
||||
request.setId("wx_relationship_1");
|
||||
request.setProjectId("wx_relationship");
|
||||
request.setType("PRE");
|
||||
request.setCurrent(1);
|
||||
request.setPageSize(10);
|
||||
MvcResult mvcResult = this.requestPostWithOkAndReturn(PAGE, request);
|
||||
// 获取返回值
|
||||
String returnData = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
||||
// 返回请求正常
|
||||
Assertions.assertNotNull(resultHolder);
|
||||
|
||||
|
||||
//分页查询后置用例列表
|
||||
request.setId("wx_relationship_4");
|
||||
request.setType("POST");
|
||||
MvcResult postResult = this.requestPostWithOkAndReturn(PAGE, request);
|
||||
// 获取返回值
|
||||
String postReturnData = postResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
ResultHolder postResultHolder = JSON.parseObject(postReturnData, ResultHolder.class);
|
||||
// 返回请求正常
|
||||
Assertions.assertNotNull(postResultHolder);
|
||||
|
||||
|
||||
//增加覆盖率
|
||||
request.setId("wx_relationship_1");
|
||||
request.setType("POST");
|
||||
this.requestPostWithOkAndReturn(PAGE, request);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,3 +35,7 @@ VALUES ('wx_relationship_1', 'STEP', '1111', '', '', 'TEST'),
|
|||
INSERT INTO functional_case_relationship_edge(id, source_id, target_id, graph_id, create_user, update_time, create_time)
|
||||
VALUES ('relationship_1', 'wx_relationship_1', 'wx_relationship_2', '1', 'admin', 1698058347559, 1698058347559),
|
||||
('relationship_3', 'wx_relationship_2', 'wx_relationship_3', '1', 'admin', 1698058347559, 1698058347559);
|
||||
|
||||
|
||||
INSERT INTO project_version(id, project_id, name, description, status, latest, publish_time, start_time, end_time, create_time, create_user)
|
||||
VALUES ('v1.0.0', 'wx_relationship', 'v1.0', NULL, 'open', b'1', 1698810592000, 1698810592000, 1698810592000, 1698810592000, 'admin');
|
||||
|
|
Loading…
Reference in New Issue