fix:FileNameByStandardForm使用ftp改为本地目录

This commit is contained in:
xiaoguangbin 2024-07-17 09:49:56 +08:00
parent 277485ddda
commit 9bbdd5eb5d

View File

@ -891,39 +891,44 @@ public class PHDFileUtil extends AbstractLogOrReport {
List<String> fileNames = new LinkedList<>();
String station = sampleFileName.substring(0, 9);
//连接ftp
FTPClient ftpClient = ftpUtil.LoginFTP();
if (Objects.isNull(ftpClient)){
return fileNames;
}
// FTPClient ftpClient = ftpUtil.LoginFTP();
// if (Objects.isNull(ftpClient)){
// return fileNames;
// }
try {
//被动模式
ftpClient.enterLocalPassiveMode();
//设置文件类型--二进制文件
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
//
ftpClient.setControlEncoding("UTF-8");
ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE);
//切换文件路径
ftpClient.changeWorkingDirectory(filePath);
//获取路径下所有文件信息
List<FTPFile> ftpFiles = Arrays.asList(ftpClient.listFiles());
// ftpClient.enterLocalPassiveMode();
// //设置文件类型--二进制文件
// ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
// //
// ftpClient.setControlEncoding("UTF-8");
// ftpClient.setFileTransferMode(FTPClient.STREAM_TRANSFER_MODE);
// //切换文件路径
// ftpClient.changeWorkingDirectory(filePath);
// //获取路径下所有文件信息
// List<FTPFile> ftpFiles = Arrays.asList(ftpClient.listFiles());
File file = new File(filePath);
List<File> ftpFiles = Arrays.asList(file.listFiles());
if (CollectionUtils.isNotEmpty(ftpFiles)){
fileNames = ftpFiles.stream().filter(item-> item.getName().contains(station)).map(FTPFile::getName).collect(Collectors.toList());
fileNames = ftpFiles.stream().filter(item-> item.getName().contains(station)).map(File::getName).collect(Collectors.toList());
}
} catch (IOException e) {
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
try {
ftpClient.disconnect();
} catch (IOException e) {
throw new RuntimeException(e);
}
// try {
// ftpClient.disconnect();
// } catch (IOException e) {
// throw new RuntimeException(e);
// }
}
return fileNames;
}
public String GetMatchFile(String tmpFileName, List<String> fileNames, String type) {
String matchFileName = "";
if (StringUtils.isBlank(tmpFileName)) {
return matchFileName;
}
fileNames = fileNames.stream().filter(item-> item.contains(type)).sorted().collect(Collectors.toList());
//用于比较的字符串
String fileCompare = tmpFileName.substring(0,23);