fix(用例管理): 修复手动创建需求id不可重复问题

--bug=1036108 --user=郭雨琦 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001036108
This commit is contained in:
guoyuqi 2024-02-22 18:10:07 +08:00 committed by 刘瑞斌
parent 90d0dabd6e
commit f282b236ea
3 changed files with 6 additions and 31 deletions

View File

@ -187,7 +187,7 @@ CREATE TABLE IF NOT EXISTS functional_case_demand
`id` VARCHAR(50) NOT NULL COMMENT 'ID', `id` VARCHAR(50) NOT NULL COMMENT 'ID',
`case_id` VARCHAR(50) NOT NULL COMMENT '功能用例ID', `case_id` VARCHAR(50) NOT NULL COMMENT '功能用例ID',
`parent` VARCHAR(50) NOT NULL DEFAULT 'NONE' COMMENT '父需求id', `parent` VARCHAR(50) NOT NULL DEFAULT 'NONE' COMMENT '父需求id',
`demand_id` VARCHAR(50) COMMENT '需求ID', `demand_id` VARCHAR(255) COMMENT '需求ID',
`demand_name` VARCHAR(255) NOT NULL DEFAULT 'NONE' COMMENT '需求标题', `demand_name` VARCHAR(255) NOT NULL DEFAULT 'NONE' COMMENT '需求标题',
`demand_url` VARCHAR(255) COMMENT '需求地址', `demand_url` VARCHAR(255) COMMENT '需求地址',
`demand_platform` VARCHAR(64) NOT NULL DEFAULT 'LOCAL' COMMENT '需求所属平台', `demand_platform` VARCHAR(64) NOT NULL DEFAULT 'LOCAL' COMMENT '需求所属平台',

View File

@ -68,7 +68,7 @@ public class FunctionalCaseDemandService {
if (CollectionUtils.isEmpty(parentDemands)) { if (CollectionUtils.isEmpty(parentDemands)) {
return new ArrayList<>(); return new ArrayList<>();
} }
Map<String, FunctionalDemandDTO> functionalCaseDemandMap = parentDemands.stream().filter(t -> StringUtils.isNotBlank(t.getDemandId())).collect(Collectors.toMap(FunctionalCaseDemand::getDemandId, t -> t)); Map<String, List<FunctionalDemandDTO>> functionalCaseDemandMap = parentDemands.stream().filter(t -> StringUtils.isNotBlank(t.getDemandId())).collect(Collectors.groupingBy(FunctionalCaseDemand::getDemandId));
List<String> ids = parentDemands.stream().map(FunctionalCaseDemand::getId).toList(); List<String> ids = parentDemands.stream().map(FunctionalCaseDemand::getId).toList();
FunctionalCaseDemandExample functionalCaseDemandExample = new FunctionalCaseDemandExample(); FunctionalCaseDemandExample functionalCaseDemandExample = new FunctionalCaseDemandExample();
functionalCaseDemandExample.createCriteria().andIdNotIn(ids); functionalCaseDemandExample.createCriteria().andIdNotIn(ids);
@ -81,8 +81,7 @@ public class FunctionalCaseDemandService {
if (functionalCaseDemandMap.containsKey(demand.getParent())) { if (functionalCaseDemandMap.containsKey(demand.getParent())) {
FunctionalDemandDTO functionalDemandDTO = new FunctionalDemandDTO(); FunctionalDemandDTO functionalDemandDTO = new FunctionalDemandDTO();
BeanUtils.copyBean(functionalDemandDTO, demand); BeanUtils.copyBean(functionalDemandDTO, demand);
functionalCaseDemandMap.get(demand.getParent()).addChild(functionalDemandDTO); functionalCaseDemandMap.get(demand.getParent()).get(0).addChild(functionalDemandDTO);
functionalCaseDemandMap.put(demand.getDemandId(), functionalDemandDTO);
} else { } else {
notMatchedList.add(demand); notMatchedList.add(demand);
} }
@ -102,14 +101,7 @@ public class FunctionalCaseDemandService {
if (checkDemandList(request.getDemandList())) return; if (checkDemandList(request.getDemandList())) return;
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
FunctionalCaseDemandMapper functionalCaseDemandMapper = sqlSession.getMapper(FunctionalCaseDemandMapper.class); FunctionalCaseDemandMapper functionalCaseDemandMapper = sqlSession.getMapper(FunctionalCaseDemandMapper.class);
FunctionalCaseDemandExample functionalCaseDemandExample = new FunctionalCaseDemandExample();
functionalCaseDemandExample.createCriteria().andCaseIdEqualTo(request.getCaseId()).andDemandPlatformEqualTo(request.getDemandPlatform());
List<FunctionalCaseDemand> existDemands = functionalCaseDemandMapper.selectByExample(functionalCaseDemandExample);
List<String> existDemandIds = existDemands.stream().map(FunctionalCaseDemand::getDemandId).toList();
for (DemandDTO demandDTO : request.getDemandList()) { for (DemandDTO demandDTO : request.getDemandList()) {
if (StringUtils.isNotBlank(demandDTO.getDemandId()) && existDemandIds.contains(demandDTO.getDemandId())) {
continue;
}
FunctionalCaseDemand functionalCaseDemand = buildFunctionalCaseDemand(request.getCaseId(), request.getDemandPlatform(), userId, demandDTO); FunctionalCaseDemand functionalCaseDemand = buildFunctionalCaseDemand(request.getCaseId(), request.getDemandPlatform(), userId, demandDTO);
functionalCaseDemandMapper.insert(functionalCaseDemand); functionalCaseDemandMapper.insert(functionalCaseDemand);
} }

View File

@ -113,6 +113,7 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
functionalCaseDemandRequest.setDemandPlatform("Metersphere"); functionalCaseDemandRequest.setDemandPlatform("Metersphere");
demandList = new ArrayList<>(); demandList = new ArrayList<>();
demandDTO = new DemandDTO(); demandDTO = new DemandDTO();
demandDTO.setDemandId("111");
demandDTO.setDemandName("手动加入孩子超长名字看看能不能截到255的速度和温度都会为fdhfjhdsfjhdsfjdshfjdsfhdsfhufkfjdfkgdgbdfjgdfgjbdfjbdfgjbdfgjkbdfjkgbdfjkgbdfjkbgdfjkbgdfjbgdfjgbdfjgbdfjbgdfjgbdfjgbdfjkgbdfjkgbdfkjgb返回武汉无法回我fhdfjdsfhsdhfdsfhdsjfhsdjfhdsfjdshfjdshfjdshfjdshfdjsfhdsjfhdjfhdsjfhdjksfhsdjfdsjfhdjfhdsjfh"); demandDTO.setDemandName("手动加入孩子超长名字看看能不能截到255的速度和温度都会为fdhfjhdsfjhdsfjdshfjdsfhdsfhufkfjdfkgdgbdfjgdfgjbdfjbdfgjbdfgjkbdfjkgbdfjkgbdfjkbgdfjkbgdfjbgdfjgbdfjgbdfjbgdfjgbdfjgbdfjkgbdfjkgbdfkjgb返回武汉无法回我fhdfjdsfhsdhfdsfhdsjfhsdjfhdsfjdshfjdshfjdshfjdshfdjsfhdsjfhdjfhdsjfhdjksfhsdjfdsjfhdjfhdsjfh");
demandList.add(demandDTO); demandList.add(demandDTO);
functionalCaseDemandRequest.setDemandList(demandList); functionalCaseDemandRequest.setDemandList(demandList);
@ -197,6 +198,7 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
List<DemandDTO> demandList = new ArrayList<>(); List<DemandDTO> demandList = new ArrayList<>();
DemandDTO demandDTO = new DemandDTO(); DemandDTO demandDTO = new DemandDTO();
demandDTO.setDemandName("手动加入2"); demandDTO.setDemandName("手动加入2");
demandDTO.setDemandId("111");
demandList.add(demandDTO); demandList.add(demandDTO);
functionalCaseDemandRequest.setDemandList(demandList); functionalCaseDemandRequest.setDemandList(demandList);
this.requestPostWithOkAndReturn(URL_DEMAND_UPDATE, functionalCaseDemandRequest); this.requestPostWithOkAndReturn(URL_DEMAND_UPDATE, functionalCaseDemandRequest);
@ -244,7 +246,7 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
functionalCaseDemandExample = new FunctionalCaseDemandExample(); functionalCaseDemandExample = new FunctionalCaseDemandExample();
functionalCaseDemandExample.createCriteria().andCaseIdEqualTo("DEMAND_TEST_FUNCTIONAL_CASE_ID"); functionalCaseDemandExample.createCriteria().andCaseIdEqualTo("DEMAND_TEST_FUNCTIONAL_CASE_ID");
functionalCaseDemands = functionalCaseDemandMapper.selectByExample(functionalCaseDemandExample); functionalCaseDemands = functionalCaseDemandMapper.selectByExample(functionalCaseDemandExample);
Assertions.assertNull(functionalCaseDemands.get(0).getDemandId()); Assertions.assertNotNull(functionalCaseDemands.get(0).getDemandId());
functionalCaseDemandRequest = new FunctionalCaseDemandRequest(); functionalCaseDemandRequest = new FunctionalCaseDemandRequest();
functionalCaseDemandRequest.setId("hehe"); functionalCaseDemandRequest.setId("hehe");
@ -396,25 +398,6 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
functionalCaseDemandExample = new FunctionalCaseDemandExample(); functionalCaseDemandExample = new FunctionalCaseDemandExample();
functionalCaseDemandExample.createCriteria().andCaseIdEqualTo("DEMAND_TEST_FUNCTIONAL_CASE_ID2").andDemandPlatformEqualTo("TAPD"); functionalCaseDemandExample.createCriteria().andCaseIdEqualTo("DEMAND_TEST_FUNCTIONAL_CASE_ID2").andDemandPlatformEqualTo("TAPD");
List<FunctionalCaseDemand> functionalCaseDemandOld = functionalCaseDemandMapper.selectByExample(functionalCaseDemandExample); List<FunctionalCaseDemand> functionalCaseDemandOld = functionalCaseDemandMapper.selectByExample(functionalCaseDemandExample);
functionalCaseDemandRequest = new FunctionalCaseDemandRequest();
functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID2");
functionalCaseDemandRequest.setDemandPlatform("TAPD");
demandList = new ArrayList<>();
DemandDTO demandDTO3 = new DemandDTO();
demandDTO3.setDemandId("100003");
demandDTO3.setParent("100002");
demandDTO3.setDemandName("手动加入Tapd2");
demandList.add(demandDTO3);
functionalCaseDemandRequest.setDemandList(demandList);
this.requestPostWithOkAndReturn(URL_DEMAND_ADD, functionalCaseDemandRequest);
functionalCaseDemandExample = new FunctionalCaseDemandExample();
functionalCaseDemandExample.createCriteria().andCaseIdEqualTo("DEMAND_TEST_FUNCTIONAL_CASE_ID2").andDemandPlatformEqualTo("TAPD");
List<FunctionalCaseDemand> functionalCaseDemandNew = functionalCaseDemandMapper.selectByExample(functionalCaseDemandExample);
Assertions.assertEquals(functionalCaseDemandOld.size(), functionalCaseDemandNew.size());
} }
@Test @Test