From 117a0c3d33109cdd89c44c7cd84b30a1b9faad06 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Tue, 2 Jul 2024 09:46:09 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=8A=9F=E8=83=BD=E7=94=A8=E4=BE=8B):=20?= =?UTF-8?q?=E5=B0=9D=E8=AF=95=E4=BF=AE=E5=A4=8D=E5=8A=9F=E8=83=BD=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=E8=84=91=E5=9B=BE=E4=BF=9D=E5=AD=98=E7=AB=8B=E5=8D=B3?= =?UTF-8?q?=E6=9F=A5=E7=9C=8B=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migration/3.1.0/ddl/V3.1.0_1__init.sql | 1 + .../migration/3.1.0/ddl/V3.1.0_2__ga_ddl.sql | 12 +++++++ .../migration/3.1.0/dml/V3.1.0_2_1__data.sql | 8 +++++ .../FunctionalCaseMinderController.java | 9 +++--- .../service/FunctionalCaseMinderService.java | 9 ++---- .../FunctionalCaseMinderControllerTest.java | 32 +++++++++---------- frontend/src/utils/index.ts | 27 ++++++++++++---- 7 files changed, 65 insertions(+), 33 deletions(-) create mode 100644 backend/framework/domain/src/main/resources/migration/3.1.0/ddl/V3.1.0_1__init.sql create mode 100644 backend/framework/domain/src/main/resources/migration/3.1.0/ddl/V3.1.0_2__ga_ddl.sql create mode 100644 backend/framework/domain/src/main/resources/migration/3.1.0/dml/V3.1.0_2_1__data.sql diff --git a/backend/framework/domain/src/main/resources/migration/3.1.0/ddl/V3.1.0_1__init.sql b/backend/framework/domain/src/main/resources/migration/3.1.0/ddl/V3.1.0_1__init.sql new file mode 100644 index 0000000000..d3fec9ab66 --- /dev/null +++ b/backend/framework/domain/src/main/resources/migration/3.1.0/ddl/V3.1.0_1__init.sql @@ -0,0 +1 @@ +select database(); \ No newline at end of file diff --git a/backend/framework/domain/src/main/resources/migration/3.1.0/ddl/V3.1.0_2__ga_ddl.sql b/backend/framework/domain/src/main/resources/migration/3.1.0/ddl/V3.1.0_2__ga_ddl.sql new file mode 100644 index 0000000000..69c208f153 --- /dev/null +++ b/backend/framework/domain/src/main/resources/migration/3.1.0/ddl/V3.1.0_2__ga_ddl.sql @@ -0,0 +1,12 @@ +-- set innodb lock wait timeout +SET SESSION innodb_lock_wait_timeout = 7200; + +DROP TABLE IF EXISTS functional_mind_insert_relation; + + + +-- set innodb lock wait timeout to default +SET SESSION innodb_lock_wait_timeout = DEFAULT; + + + diff --git a/backend/framework/domain/src/main/resources/migration/3.1.0/dml/V3.1.0_2_1__data.sql b/backend/framework/domain/src/main/resources/migration/3.1.0/dml/V3.1.0_2_1__data.sql new file mode 100644 index 0000000000..85112d68ab --- /dev/null +++ b/backend/framework/domain/src/main/resources/migration/3.1.0/dml/V3.1.0_2_1__data.sql @@ -0,0 +1,8 @@ +-- set innodb lock wait timeout +SET SESSION innodb_lock_wait_timeout = 7200; + +DROP TABLE IF EXISTS functional_minder_extra_node; + + +-- set innodb lock wait timeout to default +SET SESSION innodb_lock_wait_timeout = DEFAULT; \ No newline at end of file diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseMinderController.java b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseMinderController.java index d1a289d492..4b478f99d4 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseMinderController.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseMinderController.java @@ -65,7 +65,7 @@ public class FunctionalCaseMinderController { @Operation(summary = "用例管理-功能用例-脑图用例跟根据模块ID查询列表") @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ_MINDER) @CheckOwner(resourceId = "#request.getReviewId()", resourceType = "case_review") - public List getReviewMindFunctionalCase(@Validated @RequestBody FunctionalCaseReviewMindRequest request) { + public Pager> getReviewMindFunctionalCase(@Validated @RequestBody FunctionalCaseReviewMindRequest request) { String userId = StringUtils.EMPTY; if (request.isViewFlag()) { userId = SessionUtils.getUserId(); @@ -74,15 +74,16 @@ public class FunctionalCaseMinderController { if (request.isViewStatusFlag()) { viewStatusUserId = SessionUtils.getUserId(); } - return functionalCaseMinderService.getReviewMindFunctionalCase(request, false, userId, viewStatusUserId); + Page page = PageHelper.startPage(request.getCurrent(), 100 ); + return PageUtils.setPageInfo(page, functionalCaseMinderService.getReviewMindFunctionalCase(request, false, userId, viewStatusUserId)); } @PostMapping("/plan/list") @Operation(summary = "测试计划-功能用例-脑图用例跟根据模块ID查询列表") @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ_MINDER) @CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project") - public List getPlanFunctionalCaseMinderTree(@Validated @RequestBody FunctionalCasePlanMindRequest request) { - return functionalCaseMinderService.getPlanMindFunctionalCase(request, false); + public Pager> getPlanFunctionalCaseMinderTree(@Validated @RequestBody FunctionalCasePlanMindRequest request) { Page page = PageHelper.startPage(request.getCurrent(), 100 ); + return PageUtils.setPageInfo(page, functionalCaseMinderService.getPlanMindFunctionalCase(request, false)); } } diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseMinderService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseMinderService.java index f97c3b12b0..b6dc3f1dd4 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseMinderService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseMinderService.java @@ -35,7 +35,6 @@ import io.metersphere.system.mapper.CustomFieldMapper; import io.metersphere.system.mapper.UserMapper; import io.metersphere.system.notice.constants.NoticeConstants; import io.metersphere.system.service.CommonNoticeSendService; -import io.metersphere.system.uid.IDGenerator; import jakarta.annotation.Resource; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; @@ -752,7 +751,7 @@ public class FunctionalCaseMinderService { private MindAdditionalNode buildNode(FunctionalCaseMinderEditRequest request, String userId, MindAdditionalNodeRequest mindAdditionalNodeRequest, MindAdditionalNodeMapper additionalNodeMapper) { MindAdditionalNode mindAdditionalNode = new MindAdditionalNode(); - mindAdditionalNode.setId(IDGenerator.nextStr()); + mindAdditionalNode.setId(mindAdditionalNodeRequest.getId()); if (mindAdditionalNodeRequest.getName().length()>255) { mindAdditionalNodeRequest.setName(mindAdditionalNodeRequest.getName().substring(0,249)); } @@ -930,7 +929,7 @@ public class FunctionalCaseMinderService { @NotNull private FunctionalCaseModule buildModule(FunctionalCaseMinderEditRequest request, String userId, FunctionalCaseModuleEditRequest functionalCaseModuleEditRequest) { FunctionalCaseModule functionalCaseModule = new FunctionalCaseModule(); - functionalCaseModule.setId(IDGenerator.nextStr()); + functionalCaseModule.setId(functionalCaseModuleEditRequest.getId()); if (StringUtils.isBlank(functionalCaseModuleEditRequest.getName())) { throw new MSException(Translator.get("api_definition_module.name.not_blank")); } @@ -1101,8 +1100,6 @@ public class FunctionalCaseMinderService { private FunctionalCase addCase(FunctionalCaseMinderEditRequest request, String userId, FunctionalCaseChangeRequest functionalCaseChangeRequest, FunctionalCaseMapper caseMapper, Map sourceIdAndInsertModuleIdMap) { FunctionalCase functionalCase = new FunctionalCase(); BeanUtils.copyBean(functionalCase, functionalCaseChangeRequest); - String caseId = IDGenerator.nextStr(); - functionalCase.setId(caseId); if (StringUtils.isNotBlank(sourceIdAndInsertModuleIdMap.get(functionalCaseChangeRequest.getModuleId()))) { functionalCase.setModuleId(sourceIdAndInsertModuleIdMap.get(functionalCaseChangeRequest.getModuleId())); } @@ -1117,7 +1114,7 @@ public class FunctionalCaseMinderService { functionalCase.setNum(functionalCaseService.getNextNum(request.getProjectId())); functionalCase.setReviewStatus(FunctionalCaseReviewStatus.UN_REVIEWED.name()); functionalCase.setPos(LIMIT_POS); - functionalCase.setRefId(caseId); + functionalCase.setRefId(functionalCaseChangeRequest.getId()); functionalCase.setLastExecuteResult(ExecStatus.PENDING.name()); functionalCase.setLatest(true); functionalCase.setCreateUser(userId); diff --git a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseMinderControllerTest.java b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseMinderControllerTest.java index 751604473f..f63a5bebd3 100644 --- a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseMinderControllerTest.java +++ b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/FunctionalCaseMinderControllerTest.java @@ -381,11 +381,12 @@ public class FunctionalCaseMinderControllerTest extends BaseTest { request.setReviewId("TEST_MINDER_REVIEW_ID_GYQ"); request.setCurrent(1); MvcResult mvcResultPage = this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_REVIEW_LIST_URL, request); - String contentAsString = mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8); - ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); - List baseTreeNodes = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), FunctionalMinderTreeDTO.class); - Assertions.assertNotNull(baseTreeNodes); - Assertions.assertEquals(1, baseTreeNodes.size()); + Pager> tableData = JSON.parseObject(JSON.toJSONString( + JSON.parseObject(mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()), + Pager.class); + + Assertions.assertNotNull(tableData.getList()); + Assertions.assertEquals(1, tableData.getList().size()); request = new FunctionalCaseReviewMindRequest(); request.setProjectId("project-case-minder-test"); request.setModuleId("TEST_MINDER_MODULE_ID_GYQ4"); @@ -394,11 +395,11 @@ public class FunctionalCaseMinderControllerTest extends BaseTest { request.setViewStatusFlag(true); request.setCurrent(1); mvcResultPage = this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_REVIEW_LIST_URL, request); - contentAsString = mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8); - resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); - baseTreeNodes = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), FunctionalMinderTreeDTO.class); - Assertions.assertNotNull(baseTreeNodes); - Assertions.assertEquals(1, baseTreeNodes.size()); + tableData = JSON.parseObject(JSON.toJSONString( + JSON.parseObject(mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()), + Pager.class); + Assertions.assertNotNull(tableData.getList()); + Assertions.assertEquals(1, tableData.getList().size()); } @Test @@ -410,12 +411,11 @@ public class FunctionalCaseMinderControllerTest extends BaseTest { request.setPlanId("TEST_MINDER_PLAN_ID_1"); request.setCurrent(1); MvcResult mvcResultPage = this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_PLAN_LIST_URL, request); - String contentAsString = mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8); - ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); - List baseTreeNodes = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), FunctionalMinderTreeDTO.class); - Assertions.assertNotNull(baseTreeNodes); - Assertions.assertEquals(2, baseTreeNodes.size()); - System.out.println(baseTreeNodes); + Pager> tableData = JSON.parseObject(JSON.toJSONString( + JSON.parseObject(mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()), + Pager.class); + Assertions.assertNotNull(tableData.getList()); + Assertions.assertEquals(2, tableData.getList().size()); } } diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts index c92a7fc1c8..53f3333e4d 100644 --- a/frontend/src/utils/index.ts +++ b/frontend/src/utils/index.ts @@ -675,18 +675,31 @@ export const getHashParameters = (): Record => { return params; }; +let lastTimestamp = 0; +let sequence = 0; + /** * 生成 id 序列号 * @returns */ export const getGenerateId = () => { - return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => { - // eslint-disable-next-line no-bitwise - const r = (Math.random() * 16) | 0; - // eslint-disable-next-line no-bitwise - const v = c === 'x' ? r : (r & 0x3) | 0x8; - return v.toString(16); - }); + let timestamp = new Date().getTime(); + if (timestamp === lastTimestamp) { + sequence++; + if (sequence >= 100000) { + // 如果超过999,则重置为0,等待下一秒 + sequence = 0; + while (timestamp <= lastTimestamp) { + timestamp = new Date().getTime(); + } + } + } else { + sequence = 0; + } + + lastTimestamp = timestamp; + + return timestamp.toString() + sequence.toString().padStart(5, '0'); }; /**