refactor(功能用例): 修改功能用例需求列表返回接口
This commit is contained in:
parent
349fa22764
commit
c002a6b431
|
@ -2,7 +2,7 @@ package io.metersphere.functional.controller;
|
|||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import io.metersphere.functional.domain.FunctionalCaseDemand;
|
||||
import io.metersphere.functional.dto.FunctionalDemandDTO;
|
||||
import io.metersphere.functional.request.FunctionalCaseDemandRequest;
|
||||
import io.metersphere.functional.request.QueryDemandListRequest;
|
||||
import io.metersphere.functional.service.FunctionalCaseDemandService;
|
||||
|
@ -36,7 +36,7 @@ public class FunctionalCaseDemandController {
|
|||
@PostMapping("/page")
|
||||
@Operation(summary = "用例管理-功能用例-关联需求-获取已关联的需求列表")
|
||||
@RequiresPermissions(value = {PermissionConstants.FUNCTIONAL_CASE_READ,PermissionConstants.FUNCTIONAL_CASE_READ_ADD, PermissionConstants.FUNCTIONAL_CASE_READ_UPDATE, PermissionConstants.FUNCTIONAL_CASE_READ_DELETE}, logical = Logical.OR)
|
||||
public Pager<List<FunctionalCaseDemand>> listFunctionalCaseDemands(@Validated @RequestBody QueryDemandListRequest request) {
|
||||
public Pager<List<FunctionalDemandDTO>> listFunctionalCaseDemands(@Validated @RequestBody QueryDemandListRequest request) {
|
||||
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), true);
|
||||
return PageUtils.setPageInfo(page, functionalCaseDemandService.listFunctionalCaseDemands(request));
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
package io.metersphere.functional.dto;
|
||||
|
||||
import io.metersphere.functional.domain.FunctionalCaseDemand;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class FunctionalDemandDTO extends FunctionalCaseDemand {
|
||||
@Schema(description = "同平台需求展开项")
|
||||
private List<FunctionalCaseDemand> children;
|
||||
}
|
|
@ -10,6 +10,7 @@ import java.util.List;
|
|||
*/
|
||||
public interface ExtFunctionalCaseDemandMapper {
|
||||
|
||||
List<FunctionalCaseDemand> selectByKeyword(@Param("keyword") String keyword, @Param("caseId") String caseId);
|
||||
List<FunctionalCaseDemand> selectGroupByKeyword(@Param("keyword") String keyword, @Param("caseId") String caseId);
|
||||
List<FunctionalCaseDemand> selectByKeyword(@Param("keyword") String keyword, @Param("caseId") String caseId, @Param("platforms") List<String> platforms, @Param("ids") List<String> ids);
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="io.metersphere.functional.mapper.ExtFunctionalCaseDemandMapper">
|
||||
|
||||
<select id="selectByKeyword" resultType="io.metersphere.functional.domain.FunctionalCaseDemand">
|
||||
<select id="selectGroupByKeyword" resultType="io.metersphere.functional.domain.FunctionalCaseDemand">
|
||||
SELECT
|
||||
*
|
||||
FROM functional_case_demand
|
||||
|
@ -14,6 +14,32 @@
|
|||
)
|
||||
|
||||
</if>
|
||||
GROUP BY functional_case_demand.demand_platform
|
||||
</select>
|
||||
|
||||
<select id="selectByKeyword" resultType="io.metersphere.functional.domain.FunctionalCaseDemand">
|
||||
SELECT
|
||||
*
|
||||
FROM functional_case_demand
|
||||
WHERE functional_case_demand.case_id = #{caseId}
|
||||
<if test="keyword != null and keyword != ''">
|
||||
AND (
|
||||
functional_case_demand.demand_id = #{keyword} OR
|
||||
(functional_case_demand.demand_name LIKE CONCAT('%', #{keyword}, '%'))
|
||||
)
|
||||
</if>
|
||||
<if test="platforms != null and platforms.size() > 0">
|
||||
and functional_case_demand.demand_platform in
|
||||
<foreach collection="platforms" item="platform" open="(" separator="," close=")">
|
||||
#{platform}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="ids != null and ids.size() > 0">
|
||||
and functional_case_demand.id not in
|
||||
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</if>
|
||||
ORDER BY functional_case_demand.update_time DESC
|
||||
</select>
|
||||
|
||||
|
|
|
@ -2,11 +2,13 @@ package io.metersphere.functional.service;
|
|||
|
||||
import io.metersphere.functional.domain.FunctionalCaseDemand;
|
||||
import io.metersphere.functional.dto.DemandDTO;
|
||||
import io.metersphere.functional.dto.FunctionalDemandDTO;
|
||||
import io.metersphere.functional.mapper.ExtFunctionalCaseDemandMapper;
|
||||
import io.metersphere.functional.mapper.FunctionalCaseDemandMapper;
|
||||
import io.metersphere.functional.request.FunctionalCaseDemandRequest;
|
||||
import io.metersphere.functional.request.QueryDemandListRequest;
|
||||
import io.metersphere.sdk.exception.MSException;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.uid.IDGenerator;
|
||||
import jakarta.annotation.Resource;
|
||||
|
@ -19,7 +21,10 @@ import org.mybatis.spring.SqlSessionUtils;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author guoyuqi
|
||||
|
@ -40,8 +45,25 @@ public class FunctionalCaseDemandService {
|
|||
* @param request QueryDemandListRequest
|
||||
* @return List<FunctionalCaseDemand>
|
||||
*/
|
||||
public List<FunctionalCaseDemand> listFunctionalCaseDemands(QueryDemandListRequest request) {
|
||||
return extFunctionalCaseDemandMapper.selectByKeyword(request.getKeyword(), request.getCaseId());
|
||||
public List<FunctionalDemandDTO> listFunctionalCaseDemands(QueryDemandListRequest request) {
|
||||
List<FunctionalCaseDemand> functionalCaseDemands = extFunctionalCaseDemandMapper.selectGroupByKeyword(request.getKeyword(), request.getCaseId());
|
||||
List<String> platforms = functionalCaseDemands.stream().map(FunctionalCaseDemand::getDemandPlatform).distinct().toList();
|
||||
List<String> ids = functionalCaseDemands.stream().map(FunctionalCaseDemand::getId).distinct().toList();
|
||||
List<FunctionalCaseDemand> functionalCaseDemandChildList = extFunctionalCaseDemandMapper.selectByKeyword(request.getKeyword(), request.getCaseId(), platforms, ids);
|
||||
Map<String, List<FunctionalCaseDemand>> platformDemandMap = functionalCaseDemandChildList.stream().collect(Collectors.groupingBy(FunctionalCaseDemand::getDemandPlatform));
|
||||
List<FunctionalDemandDTO> list = new ArrayList<>();
|
||||
for (FunctionalCaseDemand functionalCaseDemand : functionalCaseDemands) {
|
||||
FunctionalDemandDTO functionalDemandDTO = new FunctionalDemandDTO();
|
||||
BeanUtils.copyBean(functionalDemandDTO,functionalCaseDemand);
|
||||
List<FunctionalCaseDemand> childrenDemands= platformDemandMap.get(functionalCaseDemand.getDemandPlatform());
|
||||
if (CollectionUtils.isNotEmpty(childrenDemands)) {
|
||||
functionalDemandDTO.setChildren(childrenDemands);
|
||||
} else {
|
||||
functionalDemandDTO.setChildren(new ArrayList<>());
|
||||
}
|
||||
list.add(functionalDemandDTO);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,6 +3,7 @@ package io.metersphere.functional.controller;
|
|||
import io.metersphere.functional.domain.FunctionalCaseDemand;
|
||||
import io.metersphere.functional.domain.FunctionalCaseDemandExample;
|
||||
import io.metersphere.functional.dto.DemandDTO;
|
||||
import io.metersphere.functional.dto.FunctionalDemandDTO;
|
||||
import io.metersphere.functional.mapper.FunctionalCaseDemandMapper;
|
||||
import io.metersphere.functional.request.FunctionalCaseDemandRequest;
|
||||
import io.metersphere.functional.request.QueryDemandListRequest;
|
||||
|
@ -67,6 +68,20 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
|
|||
functionalCaseDemandExample.createCriteria().andCaseIdEqualTo("DEMAND_TEST_FUNCTIONAL_CASE_ID");
|
||||
List<FunctionalCaseDemand> functionalCaseDemands = functionalCaseDemandMapper.selectByExample(functionalCaseDemandExample);
|
||||
Assertions.assertFalse(functionalCaseDemands.isEmpty());
|
||||
|
||||
functionalCaseDemandRequest = new FunctionalCaseDemandRequest();
|
||||
functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID");
|
||||
functionalCaseDemandRequest.setDemandPlatform("LOCAL");
|
||||
demandList = new ArrayList<>();
|
||||
demandDTO = new DemandDTO();
|
||||
demandDTO.setDemandName("手动加入孩子");
|
||||
demandList.add(demandDTO);
|
||||
functionalCaseDemandRequest.setDemandList(demandList);
|
||||
this.requestPostWithOkAndReturn(URL_DEMAND_ADD, functionalCaseDemandRequest);
|
||||
functionalCaseDemandExample = new FunctionalCaseDemandExample();
|
||||
functionalCaseDemandExample.createCriteria().andCaseIdEqualTo("DEMAND_TEST_FUNCTIONAL_CASE_ID");
|
||||
functionalCaseDemands = functionalCaseDemandMapper.selectByExample(functionalCaseDemandExample);
|
||||
Assertions.assertFalse(functionalCaseDemands.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -82,6 +97,20 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
|
|||
functionalCaseDemandExample.createCriteria().andCaseIdEqualTo("DEMAND_TEST_FUNCTIONAL_CASE_ID2");
|
||||
List<FunctionalCaseDemand> functionalCaseDemands = functionalCaseDemandMapper.selectByExample(functionalCaseDemandExample);
|
||||
Assertions.assertTrue(functionalCaseDemands.isEmpty());
|
||||
|
||||
functionalCaseDemandRequest = new FunctionalCaseDemandRequest();
|
||||
functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID3");
|
||||
functionalCaseDemandRequest.setDemandPlatform("LOCAL");
|
||||
demandList = new ArrayList<>();
|
||||
DemandDTO demandDTO = new DemandDTO();
|
||||
demandDTO.setDemandName("手动加入3");
|
||||
demandList.add(demandDTO);
|
||||
functionalCaseDemandRequest.setDemandList(demandList);
|
||||
this.requestPostWithOkAndReturn(URL_DEMAND_ADD, functionalCaseDemandRequest);
|
||||
functionalCaseDemandExample = new FunctionalCaseDemandExample();
|
||||
functionalCaseDemandExample.createCriteria().andCaseIdEqualTo("DEMAND_TEST_FUNCTIONAL_CASE_ID3");
|
||||
functionalCaseDemands = functionalCaseDemandMapper.selectByExample(functionalCaseDemandExample);
|
||||
Assertions.assertFalse(functionalCaseDemands.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -212,14 +241,17 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
|
|||
queryDemandListRequest.setPageSize(5);
|
||||
queryDemandListRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID");
|
||||
MvcResult mvcResult = this.requestPostWithOkAndReturn(URL_DEMAND_PAGE, queryDemandListRequest);
|
||||
Pager<List<FunctionalCaseDemand>> tableData = JSON.parseObject(JSON.toJSONString(
|
||||
Pager<List<FunctionalDemandDTO>> tableData = JSON.parseObject(JSON.toJSONString(
|
||||
JSON.parseObject(mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()),
|
||||
Pager.class);
|
||||
//返回值的页码和当前页码相同
|
||||
Assertions.assertEquals(tableData.getCurrent(), queryDemandListRequest.getCurrent());
|
||||
List<FunctionalDemandDTO> list = JSON.parseArray(JSON.toJSONString(tableData.getList()), FunctionalDemandDTO.class);
|
||||
for (FunctionalDemandDTO functionalDemandDTO : list) {
|
||||
Assertions.assertTrue(CollectionUtils.isNotEmpty(functionalDemandDTO.getChildren()));
|
||||
}
|
||||
//返回的数据量不超过规定要返回的数据量相同
|
||||
Assertions.assertTrue(JSON.parseArray(JSON.toJSONString(tableData.getList())).size() <= queryDemandListRequest.getPageSize());
|
||||
|
||||
queryDemandListRequest = new QueryDemandListRequest();
|
||||
queryDemandListRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID2");
|
||||
queryDemandListRequest.setCurrent(1);
|
||||
|
@ -232,20 +264,40 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
|
|||
Assertions.assertEquals(tableData.getCurrent(), queryDemandListRequest.getCurrent());
|
||||
//返回的数据量为空
|
||||
Assertions.assertTrue(CollectionUtils.isEmpty(tableData.getList()));
|
||||
|
||||
queryDemandListRequest = new QueryDemandListRequest();
|
||||
queryDemandListRequest.setCurrent(1);
|
||||
queryDemandListRequest.setPageSize(5);
|
||||
queryDemandListRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID3");
|
||||
mvcResult = this.requestPostWithOkAndReturn(URL_DEMAND_PAGE, queryDemandListRequest);
|
||||
tableData = JSON.parseObject(JSON.toJSONString(
|
||||
JSON.parseObject(mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()),
|
||||
Pager.class);
|
||||
//返回值的页码和当前页码相同
|
||||
Assertions.assertEquals(tableData.getCurrent(), queryDemandListRequest.getCurrent());
|
||||
//返回的数据量不超过规定要返回的数据量相同
|
||||
Assertions.assertTrue(JSON.parseArray(JSON.toJSONString(tableData.getList())).size() <= queryDemandListRequest.getPageSize());
|
||||
List<FunctionalDemandDTO> list1 = JSON.parseArray(JSON.toJSONString(tableData.getList()), FunctionalDemandDTO.class);
|
||||
for (FunctionalDemandDTO functionalDemandDTO : list1) {
|
||||
Assertions.assertTrue(CollectionUtils.isEmpty(functionalDemandDTO.getChildren()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
public void cancelDemand() throws Exception {
|
||||
FunctionalCaseDemandExample functionalCaseDemandExample = new FunctionalCaseDemandExample();
|
||||
functionalCaseDemandExample.createCriteria().andCaseIdEqualTo("DEMAND_TEST_FUNCTIONAL_CASE_ID");
|
||||
List<FunctionalCaseDemand> beforeList = functionalCaseDemandMapper.selectByExample(functionalCaseDemandExample);
|
||||
String id = getId("DEMAND_TEST_FUNCTIONAL_CASE_ID");
|
||||
mockMvc.perform(MockMvcRequestBuilders.get(URL_DEMAND_CANCEL+id).header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||
.header(SessionConstants.CSRF_TOKEN, csrfToken)
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk());
|
||||
FunctionalCaseDemandExample functionalCaseDemandExample = new FunctionalCaseDemandExample();
|
||||
functionalCaseDemandExample = new FunctionalCaseDemandExample();
|
||||
functionalCaseDemandExample.createCriteria().andCaseIdEqualTo("DEMAND_TEST_FUNCTIONAL_CASE_ID");
|
||||
List<FunctionalCaseDemand> functionalCaseDemands = functionalCaseDemandMapper.selectByExample(functionalCaseDemandExample);
|
||||
Assertions.assertTrue(CollectionUtils.isEmpty(functionalCaseDemands));
|
||||
List<FunctionalCaseDemand> after = functionalCaseDemandMapper.selectByExample(functionalCaseDemandExample);
|
||||
Assertions.assertTrue(beforeList.size()>after.size());
|
||||
checkLog("DEMAND_TEST_FUNCTIONAL_CASE_ID", OperationLogType.DISASSOCIATE);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,9 @@ VALUES ('DEMAND_TEST_FUNCTIONAL_CASE_ID', 1, 'DEMAND_TEST_MODULE_ID', 'project-c
|
|||
INSERT INTO functional_case(id, num, module_id, project_id, template_id, name, review_status, tags, case_edit_type, pos, version_id, ref_id, last_execute_result, deleted, public_case, latest, create_user, update_user, delete_user, create_time, update_time, delete_time)
|
||||
VALUES ('DEMAND_TEST_FUNCTIONAL_CASE_ID2', 1, 'DEMAND_TEST_MODULE_ID', 'project-case-demand-test', '100001', '关联需求测试', 'UN_REVIEWED', NULL, 'STEP', 0, 'v1.0.0', 'DEMAND_TEST_FUNCTIONAL_CASE_ID2', 'UN_EXECUTED', true, b'0', b'0', 'gyq', 'gyq', '', 1698058347559, 1698058347559, NULL);
|
||||
|
||||
INSERT INTO functional_case(id, num, module_id, project_id, template_id, name, review_status, tags, case_edit_type, pos, version_id, ref_id, last_execute_result, deleted, public_case, latest, create_user, update_user, delete_user, create_time, update_time, delete_time)
|
||||
VALUES ('DEMAND_TEST_FUNCTIONAL_CASE_ID3', 1, 'DEMAND_TEST_MODULE_ID', 'project-case-demand-test', '100001', '关联需求测试', 'UN_REVIEWED', NULL, 'STEP', 0, 'v1.0.0', 'DEMAND_TEST_FUNCTIONAL_CASE_ID3', 'UN_EXECUTED', true, b'0', b'0', 'gyq', 'gyq', '', 1698058347559, 1698058347559, NULL);
|
||||
|
||||
INSERT INTO functional_case_custom_field(case_id, field_id, value) VALUES ('DEMAND_TEST_FUNCTIONAL_CASE_ID', 'gyq_custom_id_demand1', '22');
|
||||
INSERT INTO functional_case_custom_field(case_id, field_id, value) VALUES ('DEMAND_TEST_FUNCTIONAL_CASE_ID', 'gyq_custom_id_demand2', '33');
|
||||
|
||||
|
|
Loading…
Reference in New Issue