From 1aaa6c3515d3d78444ae7ceb8df7f6a13118ba56 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Fri, 8 Nov 2024 10:13:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B0=9D=E8=AF=95=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=BC=96=E5=8F=B7=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 https://github.com/metersphere/metersphere/issues/34056 --- .../java/io/metersphere/system/uid/NumGenerator.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/uid/NumGenerator.java b/backend/services/system-setting/src/main/java/io/metersphere/system/uid/NumGenerator.java index f31b49e389..c877d6c9c7 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/uid/NumGenerator.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/uid/NumGenerator.java @@ -37,14 +37,19 @@ public class NumGenerator { */ public static long nextNum(String prefix, ApplicationNumScope scope) { RIdGenerator idGenerator = redisson.getIdGenerator(prefix + "_" + scope.name()); + // 二级的用例 if (SUB_NUM.contains(scope)) { // 每次都尝试初始化,容量为1,只有一个线程可以初始化成功 - idGenerator.tryInit(1, LIMIT); + if (!idGenerator.isExists()) { + idGenerator.tryInit(1, LIMIT); + } return Long.parseLong(prefix.split("_")[1] + StringUtils.leftPad(String.valueOf(idGenerator.nextId()), 3, "0")); } else { // 每次都尝试初始化,容量为1,只有一个线程可以初始化成功 - idGenerator.tryInit(INIT, LIMIT); + if (!idGenerator.isExists()) { + idGenerator.tryInit(INIT, LIMIT); + } return idGenerator.nextId(); } }