feat:订单编号生成 订单编号
This commit is contained in:
@@ -194,6 +194,8 @@ public class RedisConstant {
|
||||
*/
|
||||
public static final String COOLINGPERIOD_FIRSTLOGIN_KEY = "coolingPeriodFirstLoginCache:{0}";
|
||||
|
||||
public static final String REDIS_KEY_PREFIX = "daily_id:{0}";
|
||||
|
||||
/**
|
||||
* 七天
|
||||
*/
|
||||
|
||||
@@ -34,6 +34,7 @@ public class CoolDateUtils {
|
||||
public static final String DATE_FORMAT_SEC_5 = "yyyy.MM.dd HH:mm";
|
||||
public static final String DATE_FORMAT_SEC_6 = "yyyy.MM.dd";
|
||||
public static final String DATE_FORMAT_SEC_7 = "yyyy/MM/dd HH:mm";
|
||||
public static final String DATE_FORMAT_SEC_8 = "yyyyMMdd";
|
||||
|
||||
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
|
||||
@@ -136,6 +137,14 @@ public class CoolDateUtils {
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前日期 yyyyMMdd
|
||||
* @return
|
||||
*/
|
||||
public static final String getToday(){
|
||||
DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern(DATE_FORMAT_SEC_8);
|
||||
return LocalDate.now().format(DATE_FORMATTER);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前日期字符串 (yyyy-MM-dd)
|
||||
|
||||
@@ -6,6 +6,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
|
||||
/**
|
||||
* redis常量工具类
|
||||
@@ -113,4 +115,8 @@ public class RedisConstantUtil {
|
||||
return active + "_" + RedisConstant.GET_AI_MODULE + eid;
|
||||
}
|
||||
|
||||
public String getPaymentReceiptCode(String today){
|
||||
return active + "_" + MessageFormat.format(RedisConstant.REDIS_KEY_PREFIX, today);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.cool.store.utils;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
@@ -14,6 +17,10 @@ import java.util.Random;
|
||||
*/
|
||||
public class UUIDUtils {
|
||||
|
||||
private static final String ID_PREFIX = "12";
|
||||
|
||||
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern(CoolDateUtils.DATE_FORMAT_SEC_8);
|
||||
|
||||
/**
|
||||
* 简化的UUID,去掉了横线,使用性能更好的ThreadLocalRandom生成UUID
|
||||
*/
|
||||
@@ -29,22 +36,8 @@ public class UUIDUtils {
|
||||
return uuid;
|
||||
}
|
||||
// 生成 UUID 方法
|
||||
public static String generateCustomUUID() {
|
||||
// 获取当前时间戳(毫秒)
|
||||
long timestamp = System.currentTimeMillis();
|
||||
|
||||
// 生成4位随机数字(0000 - 9999)
|
||||
int randomNumber = new Random().nextInt(10000);
|
||||
String randomDigits = String.format("%04d", randomNumber);
|
||||
|
||||
// 生成2个随机大写字母
|
||||
String randomLetters = "";
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < 2; i++) {
|
||||
char c = (char) ('A' + random.nextInt(26));
|
||||
randomLetters += c;
|
||||
}
|
||||
|
||||
return timestamp + randomDigits + randomLetters;
|
||||
public static String generateCustomUUID(Integer randomCount) {
|
||||
String today = LocalDate.now().format(DATE_FORMATTER);
|
||||
return ID_PREFIX + today + String.format("%04d", randomCount);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user