diff --git a/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/serialnumber/SerialNumberServiceImpl.java b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/serialnumber/SerialNumberServiceImpl.java index 2963d900..86715ac8 100644 --- a/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/serialnumber/SerialNumberServiceImpl.java +++ b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/serialnumber/SerialNumberServiceImpl.java @@ -114,21 +114,25 @@ public class SerialNumberServiceImpl implements SerialNumberService { pattern = currentDate.format(DateTimeFormatter.ofPattern(encodedRule.getPattern().replace("m", "M"))); } long millMinutes = 0; - if(encodedRule.getPattern().toLowerCase().indexOf("d") > 0) { //包含日 - LocalDateTime midnight = LocalDateTime.now().plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(1); - millMinutes = ChronoUnit.MINUTES.between(LocalDateTime.now(), midnight); - } else if(encodedRule.getPattern().toLowerCase().indexOf("m") > 0) { //包含月 - LocalDateTime midnight = LocalDateTime.now().plusMonths(1).plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(1); - millMinutes = ChronoUnit.MONTHS.between(LocalDateTime.now(), midnight); - } else if(encodedRule.getPattern().toLowerCase().indexOf("y") > 0) { - LocalDateTime midnight = LocalDateTime.now().plusYears(1).plusMonths(1).plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(1); - millMinutes = ChronoUnit.YEARS.between(LocalDateTime.now(), midnight); + if(encodedRule.getPattern() != null && !encodedRule.getPattern().isEmpty()) { + if (encodedRule.getPattern().toLowerCase().indexOf("d") > 0) { //包含日 + LocalDateTime midnight = LocalDateTime.now().plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(1); + millMinutes = ChronoUnit.MINUTES.between(LocalDateTime.now(), midnight); + } else if (encodedRule.getPattern().toLowerCase().indexOf("m") > 0) { //包含月 + LocalDateTime midnight = LocalDateTime.now().plusMonths(1).plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(1); + millMinutes = ChronoUnit.MONTHS.between(LocalDateTime.now(), midnight); + } else if (encodedRule.getPattern().toLowerCase().indexOf("y") > 0) { + LocalDateTime midnight = LocalDateTime.now().plusYears(1).plusMonths(1).plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(1); + millMinutes = ChronoUnit.YEARS.between(LocalDateTime.now(), midnight); + } } StringBuilder code = new StringBuilder(); Long increment = redisCache.incr(encodedRule.getRuleCode() + pattern, millMinutes); code.append(encodedRule.getPrefix()); code.append(pattern); - code.append(encodedRule.getSeparator()); + if(encodedRule.getSeparator() != null && !encodedRule.getSeparator().isEmpty()) { + code.append(encodedRule.getSeparator()); + } String incrementStr = increment.toString(); if (incrementStr.length() <= encodedRule.getLength()) { code.append(String.format("%0" + encodedRule.getLength() + "d", increment));