fix:增加自动航线名称的逻辑
This commit is contained in:
parent
f553b46b7b
commit
e15423b9f7
|
|
@ -250,4 +250,57 @@ public class FileUtils
|
||||||
String encode = URLEncoder.encode(s, StandardCharsets.UTF_8.toString());
|
String encode = URLEncoder.encode(s, StandardCharsets.UTF_8.toString());
|
||||||
return encode.replaceAll("\\+", "%20");
|
return encode.replaceAll("\\+", "%20");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理文件名序号,生成不重复的文件名
|
||||||
|
*
|
||||||
|
* @param baseName 基础文件名
|
||||||
|
* @param existingNames 已存在的文件名列表
|
||||||
|
* @return 处理后的文件名
|
||||||
|
*/
|
||||||
|
public static String generateUniqueFileName(String baseName, java.util.List<String> existingNames)
|
||||||
|
{
|
||||||
|
if (existingNames == null || existingNames.isEmpty())
|
||||||
|
{
|
||||||
|
return baseName;
|
||||||
|
}
|
||||||
|
|
||||||
|
java.util.List<Integer> existingIndices = new java.util.ArrayList<>();
|
||||||
|
|
||||||
|
// 收集所有已存在的序号
|
||||||
|
for (String existingName : existingNames)
|
||||||
|
{
|
||||||
|
if (existingName != null)
|
||||||
|
{
|
||||||
|
// 匹配格式:文件名(数字)
|
||||||
|
java.util.regex.Pattern pattern = java.util.regex.Pattern.compile("^" + java.util.regex.Pattern.quote(baseName) + "\\s*\\((\\d+)\\)$");
|
||||||
|
java.util.regex.Matcher matcher = pattern.matcher(existingName);
|
||||||
|
if (matcher.find())
|
||||||
|
{
|
||||||
|
int index = Integer.parseInt(matcher.group(1));
|
||||||
|
existingIndices.add(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 排序序号列表
|
||||||
|
java.util.Collections.sort(existingIndices);
|
||||||
|
|
||||||
|
// 找到第一个可用的序号
|
||||||
|
int availableIndex = 1;
|
||||||
|
for (int index : existingIndices)
|
||||||
|
{
|
||||||
|
if (index == availableIndex)
|
||||||
|
{
|
||||||
|
availableIndex++;
|
||||||
|
}
|
||||||
|
else if (index > availableIndex)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成新的文件名
|
||||||
|
return baseName + " (" + availableIndex + ")";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue