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