|
|
@ -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) { //包含日
|
|
|
|
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) { //包含月
|
|
|
|
} 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) { |
|
|
|
} 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); |
|
|
|
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)); |
|
|
|