|
|
|
@ -165,7 +165,7 @@ public class FtpSyncService { |
|
|
|
private boolean processTxtFile(FTPClient ftp, FTPFile file, FtpCityConfig city, |
|
|
|
Set<String> existingIds) throws Exception { |
|
|
|
String fileName = file.getName(); |
|
|
|
String sourcePath = city.getFtpSourceDir() + "/" + fileName; |
|
|
|
String sourcePath = joinPath(city.getFtpSourceDir(), fileName); |
|
|
|
logger.info("【FTP文件】开始处理: {}", fileName); |
|
|
|
|
|
|
|
byte[] txtBytes = FtpUtil.downloadFile(ftp, sourcePath); |
|
|
|
@ -200,7 +200,7 @@ public class FtpSyncService { |
|
|
|
|
|
|
|
// 移动到归档目录
|
|
|
|
try { |
|
|
|
String archivePath = city.getFtpArchiveDir() + "/" + fileName; |
|
|
|
String archivePath = joinPath(city.getFtpArchiveDir(), fileName); |
|
|
|
FtpUtil.ensureDir(ftp, city.getFtpArchiveDir()); |
|
|
|
FtpUtil.rename(ftp, sourcePath, archivePath); |
|
|
|
logger.info("【FTP文件】已归档: {} -> {}", sourcePath, archivePath); |
|
|
|
@ -275,7 +275,7 @@ public class FtpSyncService { |
|
|
|
String ossPath = FilePathUtil.buildOssPath(city.getCityCode(), callStartTime, recordFileName); |
|
|
|
|
|
|
|
// 下载录音文件(FTP路径:{ftp-record-dir}/{yyyyMMdd}/{filename})
|
|
|
|
String remoteRecordPath = city.getFtpRecordDir() + "/" + dateStr + "/" + recordFileName; |
|
|
|
String remoteRecordPath = joinPath(city.getFtpRecordDir(), dateStr, recordFileName); |
|
|
|
byte[] recordBytes = FtpUtil.downloadFile(ftp, remoteRecordPath); |
|
|
|
logger.info("【FTP行】下载录音: {} ({} 字节)", recordFileName, recordBytes.length); |
|
|
|
|
|
|
|
@ -373,4 +373,36 @@ public class FtpSyncService { |
|
|
|
return defaultValue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 拼接FTP路径,自动处理末尾斜杠,避免双斜杠 |
|
|
|
* |
|
|
|
* @param parts 路径片段 |
|
|
|
* @return 拼接后的路径,使用正斜杠(FTP标准路径分隔符) |
|
|
|
*/ |
|
|
|
private String joinPath(String... parts) { |
|
|
|
if (parts == null || parts.length == 0) { |
|
|
|
return ""; |
|
|
|
} |
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
for (int i = 0; i < parts.length; i++) { |
|
|
|
String part = parts[i]; |
|
|
|
if (part == null || part.isEmpty()) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
// 去掉末尾的斜杠(除了最后一个片段且本身就是斜杠的情况)
|
|
|
|
if (part.endsWith("/") && i < parts.length - 1) { |
|
|
|
part = part.substring(0, part.length() - 1); |
|
|
|
} |
|
|
|
// 去掉开头的斜杠(除了第一个片段)
|
|
|
|
if (i > 0 && part.startsWith("/")) { |
|
|
|
part = part.substring(1); |
|
|
|
} |
|
|
|
if (sb.length() > 0) { |
|
|
|
sb.append("/"); |
|
|
|
} |
|
|
|
sb.append(part); |
|
|
|
} |
|
|
|
return sb.toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
|