|
|
|
@ -39,7 +39,6 @@ public class JTemplateNameHelper {
|
|
|
|
|
} |
|
|
|
|
Collections.sort(reportNum); |
|
|
|
|
BigInteger idx = reportNum.size() > 0 ? reportNum.get(reportNum.size() - 1).add(BigInteger.valueOf(1)) : BigInteger.valueOf(1); |
|
|
|
|
|
|
|
|
|
idx = idx.add(BigInteger.valueOf(currentIndex)); |
|
|
|
|
currentIndex++; |
|
|
|
|
return prefix + idx; |
|
|
|
@ -54,35 +53,39 @@ public class JTemplateNameHelper {
|
|
|
|
|
* @Date 2021/4/9 11:13 |
|
|
|
|
**/ |
|
|
|
|
private static BigInteger getFileNameIndex(String prefix, String fileName) { |
|
|
|
|
if (fileName.length() <= prefix.length()) { |
|
|
|
|
//如果文件名长度小于等于前缀长度或者匹配前缀失败,直接返回就可以了
|
|
|
|
|
if ((prefix.length() >= fileName.length()) || (!StringUtils.equals(prefix, fileName.substring(0, prefix.length())))) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
char[] chars = new char[fileName.length()]; |
|
|
|
|
int i = 0; |
|
|
|
|
for (; i < fileName.length(); i++) { |
|
|
|
|
BigInteger integer = null; |
|
|
|
|
integer = matchFileNameIndex(prefix, fileName); |
|
|
|
|
return integer; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static BigInteger matchFileNameIndex(String prefix, String fileName) { |
|
|
|
|
StringBuilder result = new StringBuilder(); |
|
|
|
|
for (int i = prefix.length(); i < fileName.length(); i++) { |
|
|
|
|
char c = fileName.charAt(i); |
|
|
|
|
//匹配前缀
|
|
|
|
|
if (i < prefix.length()) { |
|
|
|
|
if (c != prefix.charAt(i)) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
if (isDot(c)) { |
|
|
|
|
break; |
|
|
|
|
} else { |
|
|
|
|
if (c == '.') { |
|
|
|
|
break; |
|
|
|
|
} else { |
|
|
|
|
//匹配0~9
|
|
|
|
|
if (c < 48 || c > 57) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
chars[i - prefix.length()] = c; |
|
|
|
|
if (isNotNumber(c)) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
result.append(c); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
String s = new String(chars).substring(0, i - prefix.length()); |
|
|
|
|
BigInteger integer = new BigInteger(s, 10); |
|
|
|
|
if (StringUtils.isBlank(s)) { |
|
|
|
|
if (StringUtils.isBlank(result.toString())) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
return integer; |
|
|
|
|
return new BigInteger(result.toString(), 10); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static boolean isNotNumber(char c) { |
|
|
|
|
return c < 48 || c > 57; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static boolean isDot(char c) { |
|
|
|
|
return c == '.'; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|