|
|
@ -23,33 +23,31 @@ import java.util.concurrent.TimeUnit;
|
|
|
|
public class PlanCodeUtils {
|
|
|
|
public class PlanCodeUtils {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static String getPlanCode() {
|
|
|
|
public String getPlanCode(){
|
|
|
|
|
|
|
|
LocalDate date = LocalDate.now();
|
|
|
|
LocalDate date = LocalDate.now();
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyMMdd");
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyMMdd");
|
|
|
|
String format = date.format(formatter);
|
|
|
|
String format = "plan_code:" + date.format(formatter);
|
|
|
|
//以当日日期作为key
|
|
|
|
//以当日日期作为key
|
|
|
|
if (!SpringUtils.getBean(RedisCache.class).hasKey(format)) {
|
|
|
|
if (!SpringUtils.getBean(RedisCache.class).hasKey(format)) {
|
|
|
|
SpringUtils.getBean(RedisCache.class).setCacheObject(format,1);
|
|
|
|
SpringUtils.getBean(RedisCache.class).setCacheObject(format, 1);
|
|
|
|
SpringUtils.getBean(RedisCache.class).expire(format,getSecondsNextEarlyMorning(), TimeUnit.SECONDS);
|
|
|
|
SpringUtils.getBean(RedisCache.class).expire(format, getSecondsNextEarlyMorning(), TimeUnit.SECONDS);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
else{
|
|
|
|
|
|
|
|
//获取当前的value在+1
|
|
|
|
//获取当前的value在+1
|
|
|
|
Object cacheObject = SpringUtils.getBean(RedisCache.class).getCacheObject(format);
|
|
|
|
Object cacheObject = SpringUtils.getBean(RedisCache.class).getCacheObject(format);
|
|
|
|
String s = String.valueOf(cacheObject);
|
|
|
|
String value = String.valueOf(cacheObject);
|
|
|
|
Integer integer = Integer.valueOf(s);
|
|
|
|
Integer integer = Integer.parseInt(value) + 1;
|
|
|
|
integer = integer+1;
|
|
|
|
SpringUtils.getBean(RedisCache.class).setCacheObject(format, integer);
|
|
|
|
SpringUtils.getBean(RedisCache.class).setCacheObject(format,integer);
|
|
|
|
SpringUtils.getBean(RedisCache.class).expire(format, getSecondsNextEarlyMorning(), TimeUnit.SECONDS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Object cacheObject = SpringUtils.getBean(RedisCache.class).getCacheObject(format);
|
|
|
|
Object cacheObject = SpringUtils.getBean(RedisCache.class).getCacheObject(format);
|
|
|
|
//转成string在转成int
|
|
|
|
//转成string在转成int
|
|
|
|
String code = String.format("%04d",Integer.valueOf(String.valueOf(cacheObject)));
|
|
|
|
String code = String.format("%04d", Integer.valueOf(String.valueOf(cacheObject)));
|
|
|
|
|
|
|
|
|
|
|
|
return date.format(formatter)+code;
|
|
|
|
return date.format(formatter) + code;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//判断当前时间距离第二天0点时间的秒数
|
|
|
|
//判断当前时间距离第二天0点时间的秒数
|
|
|
|
public Long getSecondsNextEarlyMorning() {
|
|
|
|
public static Long getSecondsNextEarlyMorning() {
|
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
|
cal.add(Calendar.DAY_OF_YEAR, 1);
|
|
|
|
cal.add(Calendar.DAY_OF_YEAR, 1);
|
|
|
|
cal.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
|
cal.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
@ -57,13 +55,7 @@ public class PlanCodeUtils {
|
|
|
|
cal.set(Calendar.MINUTE, 0);
|
|
|
|
cal.set(Calendar.MINUTE, 0);
|
|
|
|
cal.set(Calendar.MILLISECOND, 0);
|
|
|
|
cal.set(Calendar.MILLISECOND, 0);
|
|
|
|
return (cal.getTimeInMillis() - System.currentTimeMillis()) / 1000;
|
|
|
|
return (cal.getTimeInMillis() - System.currentTimeMillis()) / 1000;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|