From 1f04a8423f23e05fe1c83261f37e15c87101d74e Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Mon, 29 Jan 2024 18:59:13 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E7=94=A8=E4=BE=8B=E7=AE=A1=E7=90=86):?= =?UTF-8?q?=20=E5=A4=8D=E5=88=B6=E7=94=A8=E4=BE=8B=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/FunctionalCaseService.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java index 27ff4ae3d0..523702948b 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseService.java @@ -651,13 +651,14 @@ public class FunctionalCaseService { List caseAttachments = attachmentMap.get(s); List fileAssociationList = fileAssociationMap.get(s); List customFields = customFieldMap.get(s); + Long num = functionalCase.getNum(); Optional.ofNullable(functionalCase).ifPresent(functional -> { functional.setId(id); functional.setRefId(id); functional.setModuleId(request.getModuleId()); functional.setNum(getNextNum(request.getProjectId())); - functional.setName(getCopyName(functionalCase.getName())); + functional.setName(getCopyName(functionalCase.getName(), num, functional.getNum())); functional.setReviewStatus(FunctionalCaseReviewStatus.UN_REVIEWED.name()); functional.setPos(nextOrder.get()); functional.setLastExecuteResult(FunctionalCaseExecuteResult.UN_EXECUTED.name()); @@ -697,12 +698,18 @@ public class FunctionalCaseService { } } - private String getCopyName(String name) { - String copyName = "copy_" + name + "_" + UUID.randomUUID().toString().substring(0, 4); - if (copyName.length() > 255) { - copyName = copyName.substring(0, 250) + copyName.substring(copyName.length() - 5); + private String getCopyName(String name, long oldNum, long newNum) { + if (!StringUtils.startsWith(name, "copy_")) { + name = "copy_" + name; } - return copyName; + if (name.length() > 250) { + name = name.substring(0, 200) + "..."; + } + if (StringUtils.endsWith(name, "_" + oldNum)) { + name = StringUtils.substringBeforeLast(name, "_" + oldNum); + } + name = name + "_" + newNum; + return name; }