fix(用例管理): 修复用例关联需求名称太长会报错问题

--bug=1036056 --user=郭雨琦 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001036056
This commit is contained in:
guoyuqi 2024-02-22 12:30:39 +08:00 committed by Craftsman
parent 553627c755
commit a23419ddea
3 changed files with 22 additions and 6 deletions

View File

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

View File

@ -102,15 +102,14 @@ public class FunctionalCaseDemandService {
if (checkDemandList(request.getDemandList())) return;
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
FunctionalCaseDemandMapper functionalCaseDemandMapper = sqlSession.getMapper(FunctionalCaseDemandMapper.class);
List<String> demandIds = request.getDemandList().stream().map(DemandDTO::getDemandId).toList();
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();
List<String> notRepeatDemandIds = demandIds.stream().filter(t -> !existDemandIds.contains(t)).toList();
Map<String, DemandDTO> demandDTOMap = request.getDemandList().stream().collect(Collectors.toMap(DemandDTO::getDemandId, t -> t));
for (String notRepeatDemandId : notRepeatDemandIds) {
DemandDTO demandDTO = demandDTOMap.get(notRepeatDemandId);
for (DemandDTO demandDTO : request.getDemandList()) {
if (StringUtils.isNotBlank(demandDTO.getDemandId()) && existDemandIds.contains(demandDTO.getDemandId())) {
continue;
}
FunctionalCaseDemand functionalCaseDemand = buildFunctionalCaseDemand(request.getCaseId(), request.getDemandPlatform(), userId, demandDTO);
functionalCaseDemandMapper.insert(functionalCaseDemand);
}
@ -168,6 +167,9 @@ public class FunctionalCaseDemandService {
if (StringUtils.isBlank(demandDTO.getDemandName())) {
throw new MSException(Translator.get("case.demand.name.not.exist"));
}
if (demandDTO.getDemandName().length()>255) {
demandDTO.setDemandName(demandDTO.getDemandName().substring(0,255));
}
functionalCaseDemand.setDemandName(demandDTO.getDemandName());
if (StringUtils.isNotBlank(demandDTO.getDemandUrl())) {
functionalCaseDemand.setDemandUrl(demandDTO.getDemandUrl());

View File

@ -107,6 +107,20 @@ public class FunctionalCaseDemandControllerTests extends BaseTest {
functionalCaseDemandExample.createCriteria().andCaseIdEqualTo("DEMAND_TEST_FUNCTIONAL_CASE_ID");
functionalCaseDemands = functionalCaseDemandMapper.selectByExample(functionalCaseDemandExample);
Assertions.assertFalse(functionalCaseDemands.isEmpty());
functionalCaseDemandRequest = new FunctionalCaseDemandRequest();
functionalCaseDemandRequest.setCaseId("DEMAND_TEST_FUNCTIONAL_CASE_ID");
functionalCaseDemandRequest.setDemandPlatform("Metersphere");
demandList = new ArrayList<>();
demandDTO = new DemandDTO();
demandDTO.setDemandName("手动加入孩子超长名字看看能不能截到255的速度和温度都会为fdhfjhdsfjhdsfjdshfjdsfhdsfhufkfjdfkgdgbdfjgdfgjbdfjbdfgjbdfgjkbdfjkgbdfjkgbdfjkbgdfjkbgdfjbgdfjgbdfjgbdfjbgdfjgbdfjgbdfjkgbdfjkgbdfkjgb返回武汉无法回我fhdfjdsfhsdhfdsfhdsjfhsdjfhdsfjdshfjdshfjdshfjdshfdjsfhdsjfhdjfhdsjfhdjksfhsdjfdsjfhdjfhdsjfh");
demandList.add(demandDTO);
functionalCaseDemandRequest.setDemandList(demandList);
this.requestPostWithOkAndReturn(URL_DEMAND_ADD, functionalCaseDemandRequest);
functionalCaseDemandExample = new FunctionalCaseDemandExample();
functionalCaseDemandExample.createCriteria().andCaseIdEqualTo("DEMAND_TEST_FUNCTIONAL_CASE_ID").andDemandNameLike("%手动加入孩子超长名字%");
functionalCaseDemands = functionalCaseDemandMapper.selectByExample(functionalCaseDemandExample);
Assertions.assertFalse(functionalCaseDemands.isEmpty());
}
@Test