From a505ef78eab58c4b3a4e16a98a1a934cb8240eb3 Mon Sep 17 00:00:00 2001 From: liuchen864 <23082234@qq.com> Date: Thu, 16 Nov 2023 17:58:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=92=8C=E5=88=86=E9=9A=94?= =?UTF-8?q?=E7=AC=A6=E5=8F=AF=E4=B8=BA=E7=A9=BA=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../serialnumber/SerialNumberServiceImpl.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) 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));