From f282b236ea901fe54862776c121feeba1708549c Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Thu, 22 Feb 2024 18:10:07 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=94=A8=E4=BE=8B=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=89=8B=E5=8A=A8=E5=88=9B=E5=BB=BA=E9=9C=80?= =?UTF-8?q?=E6=B1=82id=E4=B8=8D=E5=8F=AF=E9=87=8D=E5=A4=8D=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1036108 --user=郭雨琦 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001036108 --- .../3.0.0/ddl/V3.0.0_10__functional_case.sql | 2 +- .../service/FunctionalCaseDemandService.java | 12 ++-------- .../FunctionalCaseDemandControllerTests.java | 23 +++---------------- 3 files changed, 6 insertions(+), 31 deletions(-) diff --git a/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_10__functional_case.sql b/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_10__functional_case.sql index e768d3b421..783f0f05ab 100644 --- a/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_10__functional_case.sql +++ b/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_10__functional_case.sql @@ -187,7 +187,7 @@ CREATE TABLE IF NOT EXISTS functional_case_demand `id` VARCHAR(50) NOT NULL COMMENT 'ID', `case_id` VARCHAR(50) NOT NULL 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_url` VARCHAR(255) COMMENT '需求地址', `demand_platform` VARCHAR(64) NOT NULL DEFAULT 'LOCAL' COMMENT '需求所属平台', diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseDemandService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseDemandService.java index 95181b91ce..4318755404 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseDemandService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseDemandService.java @@ -68,7 +68,7 @@ public class FunctionalCaseDemandService { if (CollectionUtils.isEmpty(parentDemands)) { return new ArrayList<>(); } - Map functionalCaseDemandMap = parentDemands.stream().filter(t -> StringUtils.isNotBlank(t.getDemandId())).collect(Collectors.toMap(FunctionalCaseDemand::getDemandId, t -> t)); + Map> functionalCaseDemandMap = parentDemands.stream().filter(t -> StringUtils.isNotBlank(t.getDemandId())).collect(Collectors.groupingBy(FunctionalCaseDemand::getDemandId)); List ids = parentDemands.stream().map(FunctionalCaseDemand::getId).toList(); FunctionalCaseDemandExample functionalCaseDemandExample = new FunctionalCaseDemandExample(); functionalCaseDemandExample.createCriteria().andIdNotIn(ids); @@ -81,8 +81,7 @@ public class FunctionalCaseDemandService { if (functionalCaseDemandMap.containsKey(demand.getParent())) { FunctionalDemandDTO functionalDemandDTO = new FunctionalDemandDTO(); BeanUtils.copyBean(functionalDemandDTO, demand); - functionalCaseDemandMap.get(demand.getParent()).addChild(functionalDemandDTO); - functionalCaseDemandMap.put(demand.getDemandId(), functionalDemandDTO); + functionalCaseDemandMap.get(demand.getParent()).get(0).addChild(functionalDemandDTO); } else { notMatchedList.add(demand); } @@ -102,14 +101,7 @@ public class FunctionalCaseDemandService { if (checkDemandList(request.getDemandList())) return; SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); FunctionalCaseDemandMapper functionalCaseDemandMapper = sqlSession.getMapper(FunctionalCaseDemandMapper.class); - FunctionalCaseDemandExample functionalCaseDemandExample = new FunctionalCaseDemandExample(); - functionalCaseDemandExample.createCriteria().andCaseIdEqualTo(request.getCaseId()).andDemandPlatformEqualTo(request.getDemandPlatform()); - List existDemands = functionalCaseDemandMapper.selectByExample(functionalCaseDemandExample); - List existDemandIds = existDemands.stream().map(FunctionalCaseDemand::getDemandId).toList(); 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); } diff --git a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseDemandControllerTests.java b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseDemandControllerTests.java index 4179fa9fe3..e6a311b4b7 100644 --- a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseDemandControllerTests.java +++ b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseDemandControllerTests.java @@ -113,6 +113,7 @@ public class FunctionalCaseDemandControllerTests extends BaseTest { functionalCaseDemandRequest.setDemandPlatform("Metersphere"); demandList = new ArrayList<>(); demandDTO = new DemandDTO(); + demandDTO.setDemandId("111"); demandDTO.setDemandName("手动加入孩子超长名字看看能不能截到255的速度和温度都会为fdhfjhdsfjhdsfjdshfjdsfhdsfhufkfjdfkgdgbdfjgdfgjbdfjbdfgjbdfgjkbdfjkgbdfjkgbdfjkbgdfjkbgdfjbgdfjgbdfjgbdfjbgdfjgbdfjgbdfjkgbdfjkgbdfkjgb返回武汉无法回我fhdfjdsfhsdhfdsfhdsjfhsdjfhdsfjdshfjdshfjdshfjdshfdjsfhdsjfhdjfhdsjfhdjksfhsdjfdsjfhdjfhdsjfh"); demandList.add(demandDTO); functionalCaseDemandRequest.setDemandList(demandList); @@ -197,6 +198,7 @@ public class FunctionalCaseDemandControllerTests extends BaseTest { List demandList = new ArrayList<>(); DemandDTO demandDTO = new DemandDTO(); demandDTO.setDemandName("手动加入2"); + demandDTO.setDemandId("111"); demandList.add(demandDTO); functionalCaseDemandRequest.setDemandList(demandList); this.requestPostWithOkAndReturn(URL_DEMAND_UPDATE, functionalCaseDemandRequest); @@ -244,7 +246,7 @@ public class FunctionalCaseDemandControllerTests extends BaseTest { functionalCaseDemandExample = new FunctionalCaseDemandExample(); functionalCaseDemandExample.createCriteria().andCaseIdEqualTo("DEMAND_TEST_FUNCTIONAL_CASE_ID"); functionalCaseDemands = functionalCaseDemandMapper.selectByExample(functionalCaseDemandExample); - Assertions.assertNull(functionalCaseDemands.get(0).getDemandId()); + Assertions.assertNotNull(functionalCaseDemands.get(0).getDemandId()); functionalCaseDemandRequest = new FunctionalCaseDemandRequest(); functionalCaseDemandRequest.setId("hehe"); @@ -396,25 +398,6 @@ public class FunctionalCaseDemandControllerTests extends BaseTest { functionalCaseDemandExample = new FunctionalCaseDemandExample(); functionalCaseDemandExample.createCriteria().andCaseIdEqualTo("DEMAND_TEST_FUNCTIONAL_CASE_ID2").andDemandPlatformEqualTo("TAPD"); List 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 functionalCaseDemandNew = functionalCaseDemandMapper.selectByExample(functionalCaseDemandExample); - - Assertions.assertEquals(functionalCaseDemandOld.size(), functionalCaseDemandNew.size()); } @Test