|
|
|
@ -35,6 +35,7 @@ import java.util.HashMap;
|
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.Set; |
|
|
|
|
import java.util.UUID; |
|
|
|
|
import java.util.regex.Matcher; |
|
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
|
|
|
@ -154,18 +155,20 @@ public class FineMarketClientHelper {
|
|
|
|
|
* */ |
|
|
|
|
private File createDestFile(File destDir, TemplateResource resource) { |
|
|
|
|
String fileName = resource.getName(); |
|
|
|
|
File finalDir = new File(StableUtils.pathJoin(FileCommonUtils.getAbsolutePath(destDir), fileName)); |
|
|
|
|
try { |
|
|
|
|
File finalDir = new File(StableUtils.pathJoin(FileCommonUtils.getAbsolutePath(destDir), fileName)); |
|
|
|
|
if (!finalDir.exists()) { |
|
|
|
|
finalDir.mkdir(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 获取文件名(含后缀)
|
|
|
|
|
fileName = resource.getFileName(); |
|
|
|
|
String prefix = fileName.substring(0, fileName.length() - 4); |
|
|
|
|
String suffix = fileName.substring(fileName.length() - 4); |
|
|
|
|
|
|
|
|
|
// 处理重复文件名
|
|
|
|
|
String fileNameFormat = "(%d)" + fileName; |
|
|
|
|
Pattern pattern = Pattern.compile("\\((\\d)\\)" + fileName); |
|
|
|
|
String fileNameFormat = prefix + "(%d)" + suffix; |
|
|
|
|
Pattern pattern = Pattern.compile(prefix + "\\((\\d)\\)" + suffix); |
|
|
|
|
int cnt = 0; |
|
|
|
|
|
|
|
|
|
File[] files = finalDir.listFiles(); |
|
|
|
@ -178,15 +181,14 @@ public class FineMarketClientHelper {
|
|
|
|
|
cnt++; |
|
|
|
|
fileName = String.format(fileNameFormat, cnt); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
File destFile = new File(StableUtils.pathJoin(FileCommonUtils.getAbsolutePath(finalDir), fileName)); |
|
|
|
|
destFile.createNewFile(); |
|
|
|
|
return destFile; |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
FineLoggerFactory.getLogger().error(e, e.getMessage()); |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
fileName = UUID.randomUUID() + fileName; |
|
|
|
|
File dest = new File(StableUtils.pathJoin(FileCommonUtils.getAbsolutePath(finalDir), fileName)); |
|
|
|
|
return dest; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static CloseableHttpResponse getDownloadHttpResponse(String url) throws Exception { |
|
|
|
|