From fc396bf8aec4862978dfe8ebf77cc57994baafea Mon Sep 17 00:00:00 2001 From: yinq <1345442242@qq.com> Date: Tue, 10 Oct 2023 14:22:53 +0800 Subject: [PATCH] =?UTF-8?q?change=20-=20=E7=94=9F=E4=BA=A7=E8=AE=A1?= =?UTF-8?q?=E5=88=92-=E8=AE=A1=E5=88=92=E7=BC=96=E5=8F=B7=E7=94=9F?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/utils/uuid/PlanCodeUtils.java | 32 +++++++------------ 1 file changed, 12 insertions(+), 20 deletions(-) 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; - } - - - - - }