diff --git a/aucma-common/src/main/java/com/aucma/common/utils/uuid/PlanCodeUtils.java b/aucma-common/src/main/java/com/aucma/common/utils/uuid/PlanCodeUtils.java index 8c03cd8..b47f386 100644 --- a/aucma-common/src/main/java/com/aucma/common/utils/uuid/PlanCodeUtils.java +++ b/aucma-common/src/main/java/com/aucma/common/utils/uuid/PlanCodeUtils.java @@ -23,33 +23,31 @@ import java.util.concurrent.TimeUnit; public class PlanCodeUtils { - - public String getPlanCode(){ + public static String getPlanCode() { LocalDate date = LocalDate.now(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyMMdd"); - String format = date.format(formatter); + String format = "plan_code:" + date.format(formatter); //以当日日期作为key if (!SpringUtils.getBean(RedisCache.class).hasKey(format)) { - SpringUtils.getBean(RedisCache.class).setCacheObject(format,1); - SpringUtils.getBean(RedisCache.class).expire(format,getSecondsNextEarlyMorning(), TimeUnit.SECONDS); - } - else{ + SpringUtils.getBean(RedisCache.class).setCacheObject(format, 1); + SpringUtils.getBean(RedisCache.class).expire(format, getSecondsNextEarlyMorning(), TimeUnit.SECONDS); + } else { //获取当前的value在+1 Object cacheObject = SpringUtils.getBean(RedisCache.class).getCacheObject(format); - String s = String.valueOf(cacheObject); - Integer integer = Integer.valueOf(s); - integer = integer+1; - SpringUtils.getBean(RedisCache.class).setCacheObject(format,integer); + String value = String.valueOf(cacheObject); + Integer integer = Integer.parseInt(value) + 1; + SpringUtils.getBean(RedisCache.class).setCacheObject(format, integer); + SpringUtils.getBean(RedisCache.class).expire(format, getSecondsNextEarlyMorning(), TimeUnit.SECONDS); } Object cacheObject = SpringUtils.getBean(RedisCache.class).getCacheObject(format); //转成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点时间的秒数 - public Long getSecondsNextEarlyMorning() { + public static Long getSecondsNextEarlyMorning() { Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_YEAR, 1); cal.set(Calendar.HOUR_OF_DAY, 0); @@ -57,13 +55,7 @@ public class PlanCodeUtils { cal.set(Calendar.MINUTE, 0); cal.set(Calendar.MILLISECOND, 0); return (cal.getTimeInMillis() - System.currentTimeMillis()) / 1000; - } - - - - - }