fix: 尝试解决任务编号重复问题

https://github.com/metersphere/metersphere/issues/34056
This commit is contained in:
fit2-zhao 2024-11-08 10:13:41 +08:00 committed by Craftsman
parent 298208d0ef
commit 1aaa6c3515

View File

@ -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();
}
}