|
|
@ -124,23 +124,18 @@ public class SerialNumberServiceImpl implements SerialNumberService { |
|
|
|
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); |
|
|
|
} |
|
|
|
boolean flag = true; |
|
|
|
String code; |
|
|
|
do { |
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
Long increment = redisCache.incr(encodedRule.getRuleCode() + pattern, millMinutes); |
|
|
|
sb.append(encodedRule.getPrefix()); |
|
|
|
sb.append(pattern); |
|
|
|
sb.append(encodedRule.getSeparator()); |
|
|
|
String incrementStr = increment.toString(); |
|
|
|
if (incrementStr.length() <= encodedRule.getLength()) { |
|
|
|
sb.append(String.format("%0" + encodedRule.getLength() + "d", increment)); |
|
|
|
} else { |
|
|
|
throw exception(SERIAL_NUMBER_NOT_ENOUGH); |
|
|
|
} |
|
|
|
code = sb.toString(); |
|
|
|
} while (flag); |
|
|
|
return code; |
|
|
|
StringBuilder code = new StringBuilder(); |
|
|
|
Long increment = redisCache.incr(encodedRule.getRuleCode() + pattern, millMinutes); |
|
|
|
code.append(encodedRule.getPrefix()); |
|
|
|
code.append(pattern); |
|
|
|
code.append(encodedRule.getSeparator()); |
|
|
|
String incrementStr = increment.toString(); |
|
|
|
if (incrementStr.length() <= encodedRule.getLength()) { |
|
|
|
code.append(String.format("%0" + encodedRule.getLength() + "d", increment)); |
|
|
|
} else { |
|
|
|
throw exception(SERIAL_NUMBER_NOT_ENOUGH); |
|
|
|
} |
|
|
|
return code.toString(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|