change - 生产计划-计划编号生成

master
yinq 1 year ago
parent 6842982f9a
commit fc396bf8ae

@ -23,23 +23,21 @@ 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
@ -49,7 +47,7 @@ public class PlanCodeUtils {
} }
//判断当前时间距离第二天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;
} }
} }

Loading…
Cancel
Save