You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1018 B
33 lines
1018 B
package com.qs.serve.common.util;
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
import com.qs.serve.common.framework.redis.RedisService;
|
|
import org.springframework.beans.BeansException;
|
|
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDateTime;
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
/**
|
|
* 生成编号
|
|
* @author YenHex
|
|
* @since 2023/6/25
|
|
*/
|
|
public class CodeGenUtil {
|
|
|
|
public static String generate(String key,int perch){
|
|
try {
|
|
RedisService redisService = SpringUtils.getBean(RedisService.class);
|
|
LocalDate localDateTime = LocalDate.now();
|
|
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
String localTime = df.format(localDateTime);
|
|
Integer value = redisService.getInteger(key)+1;
|
|
String appendStr = String.format("%0"+perch+"d", value);
|
|
return localTime + appendStr;
|
|
} catch (BeansException e) {
|
|
e.printStackTrace();
|
|
}
|
|
return IdUtil.getSnowflakeNextIdStr();
|
|
}
|
|
|
|
}
|
|
|