解决高并发下交易号重复生成的bug

This commit is contained in:
谭凯凯 2025-01-06 14:59:02 +08:00 committed by Tankaikai
parent f9e32bff7b
commit 8ca771ff6e
1 changed files with 4 additions and 4 deletions

View File

@ -1,6 +1,7 @@
package com.sqx.modules.utils;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.lang.Singleton;
import cn.hutool.core.lang.Snowflake;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
@ -70,9 +71,8 @@ public class AliPayOrderUtil {
// d 代表参数为正数型
return machineId+String.format("%015d", hashCodeV);*/
// return IdUtil.getSnowflake(1, 1).nextIdStr();
UUID uuid = UUID.randomUUID();
return uuid.toString().replace("-", "");
// 经测试高并发下单机生成ID的速度能达到每秒10万以上无ID重复的风险
return Singleton.get(Snowflake.class).nextIdStr();
}