生成订单号换成雪花id

This commit is contained in:
谭凯凯 2025-01-03 21:51:48 +08:00 committed by Tankaikai
parent 9d26091e55
commit 6ed279aa34
1 changed files with 5 additions and 2 deletions

View File

@ -1,5 +1,7 @@
package com.sqx.modules.utils;
import cn.hutool.core.util.IdUtil;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.*;
@ -58,7 +60,7 @@ public class AliPayOrderUtil {
* @return
*/
public static String createOrderId() {
int machineId = 1;//最大支持1-9个集群机器部署
/*int machineId = 1;//最大支持1-9个集群机器部署
int hashCodeV = UUID.randomUUID().toString().hashCode();
if(hashCodeV < 0) {//有可能是负数
hashCodeV = - hashCodeV;
@ -66,7 +68,8 @@ public class AliPayOrderUtil {
// 0 代表前面补充0
// 4 代表长度为4
// d 代表参数为正数型
return machineId+String.format("%015d", hashCodeV);
return machineId+String.format("%015d", hashCodeV);*/
return IdUtil.getSnowflake(1, 1).nextIdStr();
}