|
@@ -122,54 +122,56 @@ public class SftpFileParsing {
|
|
|
for (String fileName : fileNames) {
|
|
|
try {
|
|
|
String sftpFileNameDir = ftpUrl + "/" + fileName;
|
|
|
- String destFileNameDir = PARSING_FILE_TEMP_DIR.getPath() + File.separator + fileName;
|
|
|
- //下载文件到临时目录
|
|
|
- sftp.get(sftpFileNameDir, destFileNameDir);
|
|
|
- File file = FileUtils.getFile(PARSING_FILE_TEMP_DIR, fileName);
|
|
|
- ParsingLog parsingLog = new ParsingLog();
|
|
|
- Date now = new Date();
|
|
|
- parsingLog.setParsingTime(now);
|
|
|
- parsingLog.setFileName(fileName);
|
|
|
- ParsingResultDto parsingResultDto = parsingInterface.parsing(file, electricField.getStationCode());
|
|
|
- parsingLog.setParsingDescribe(parsingResultDto.getMessage());
|
|
|
- parsingLog.setFileType(parsingType.getFileType());
|
|
|
- parsingLog.setDataSources(DataSourcesEnum.E1);
|
|
|
- parsingLog.setStationCode(electricField.getStationCode());
|
|
|
- if (parsingResultDto.getStatus().equals("fail")) {
|
|
|
- try {
|
|
|
- File failFileDir = new File(PARSING_FILE_FAIL_DIR.getPath() + File.separator + DateFormatUtils.format(now, "yyyy-MM-dd") + File.separator + electricField.getStationCode() + File.separator + parsingType.getFileType().name());
|
|
|
- File failFile = new File(failFileDir.getPath() + File.separator + fileName);
|
|
|
- if (failFile.exists()) {
|
|
|
- failFile.delete();
|
|
|
- log.error("已有过解析失败文件,错误文件将覆盖!场站编号:{},文件名称:{}", electricField.getStationCode(), fileName);
|
|
|
+ if (sftp.getClient().stat(sftpFileNameDir).getSize() > 0) {
|
|
|
+ String destFileNameDir = PARSING_FILE_TEMP_DIR.getPath() + File.separator + fileName;
|
|
|
+ //下载文件到临时目录
|
|
|
+ sftp.get(sftpFileNameDir, destFileNameDir);
|
|
|
+ File file = FileUtils.getFile(PARSING_FILE_TEMP_DIR, fileName);
|
|
|
+ ParsingLog parsingLog = new ParsingLog();
|
|
|
+ Date now = new Date();
|
|
|
+ parsingLog.setParsingTime(now);
|
|
|
+ parsingLog.setFileName(fileName);
|
|
|
+ ParsingResultDto parsingResultDto = parsingInterface.parsing(file, electricField.getStationCode());
|
|
|
+ parsingLog.setParsingDescribe(parsingResultDto.getMessage());
|
|
|
+ parsingLog.setFileType(parsingType.getFileType());
|
|
|
+ parsingLog.setDataSources(DataSourcesEnum.E1);
|
|
|
+ parsingLog.setStationCode(electricField.getStationCode());
|
|
|
+ if (parsingResultDto.getStatus().equals("fail")) {
|
|
|
+ try {
|
|
|
+ File failFileDir = new File(PARSING_FILE_FAIL_DIR.getPath() + File.separator + DateFormatUtils.format(now, "yyyy-MM-dd") + File.separator + electricField.getStationCode() + File.separator + parsingType.getFileType().name());
|
|
|
+ File failFile = new File(failFileDir.getPath() + File.separator + fileName);
|
|
|
+ if (failFile.exists()) {
|
|
|
+ failFile.delete();
|
|
|
+ log.error("已有过解析失败文件,错误文件将覆盖!场站编号:{},文件名称:{}", electricField.getStationCode(), fileName);
|
|
|
+ }
|
|
|
+ ParsingFileUtil.move(file.getAbsolutePath(), failFileDir.getAbsolutePath(), true);
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("解析文件失败后文件移动失败!场站编号:{},文件名称:{}", electricField.getStationCode(), fileName, e);
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
- ParsingFileUtil.move(file.getAbsolutePath(), failFileDir.getAbsolutePath(), true);
|
|
|
- } catch (IOException e) {
|
|
|
- log.error("解析文件失败后文件移动失败!场站编号:{},文件名称:{}", electricField.getStationCode(), fileName, e);
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- file.delete();//失败删除本地文件
|
|
|
- sftp.delFile(sftpFileNameDir);//失败删除sftp文件
|
|
|
- parsingLog.setParsingFileStatus("失败");
|
|
|
- LogUtil.info(DataSourcesEnum.E3, AlarmEnum.E4, LogUtil.format("无法解析场站端文件:{}", fileName), electricField.getStationCode());
|
|
|
- } else {
|
|
|
- sftp.delFile(ftpUrl + "/" + fileName);//成功删除ftp上的文件
|
|
|
- try {
|
|
|
- File successFileDir = new File(PARSING_FILE_SUCCESS_DIR.getPath() + File.separator + DateFormatUtils.format(now, "yyyy-MM-dd") + File.separator + electricField.getStationCode() + File.separator + parsingType.getFileType().name());
|
|
|
- File successFile = new File(successFileDir.getPath() + File.separator + fileName);
|
|
|
- if (successFile.exists()) {
|
|
|
- successFile.delete();
|
|
|
- log.error("已有过解析成功文件,成功文件将覆盖!场站编号:{},文件名称:{}", electricField.getStationCode(), fileName);
|
|
|
+ file.delete();//失败删除本地文件
|
|
|
+ sftp.delFile(sftpFileNameDir);//失败删除sftp文件
|
|
|
+ parsingLog.setParsingFileStatus("失败");
|
|
|
+ LogUtil.info(DataSourcesEnum.E3, AlarmEnum.E4, LogUtil.format("无法解析场站端文件:{}", fileName), electricField.getStationCode());
|
|
|
+ } else {
|
|
|
+ sftp.delFile(ftpUrl + "/" + fileName);//成功删除ftp上的文件
|
|
|
+ try {
|
|
|
+ File successFileDir = new File(PARSING_FILE_SUCCESS_DIR.getPath() + File.separator + DateFormatUtils.format(now, "yyyy-MM-dd") + File.separator + electricField.getStationCode() + File.separator + parsingType.getFileType().name());
|
|
|
+ File successFile = new File(successFileDir.getPath() + File.separator + fileName);
|
|
|
+ if (successFile.exists()) {
|
|
|
+ successFile.delete();
|
|
|
+ log.error("已有过解析成功文件,成功文件将覆盖!场站编号:{},文件名称:{}", electricField.getStationCode(), fileName);
|
|
|
+ }
|
|
|
+ ParsingFileUtil.move(file.getAbsolutePath(), successFileDir.getAbsolutePath(), true);
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("解析文件成功后文件移动失败!场站编号:{},文件名称:{}", electricField.getStationCode(), fileName, e);
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
- ParsingFileUtil.move(file.getAbsolutePath(), successFileDir.getAbsolutePath(), true);
|
|
|
- } catch (IOException e) {
|
|
|
- log.error("解析文件成功后文件移动失败!场站编号:{},文件名称:{}", electricField.getStationCode(), fileName, e);
|
|
|
- e.printStackTrace();
|
|
|
+ file.delete();//失败删除本地文件,等待下次下载
|
|
|
+ parsingLog.setParsingFileStatus("成功");
|
|
|
}
|
|
|
- file.delete();//失败删除本地文件,等待下次下载
|
|
|
- parsingLog.setParsingFileStatus("成功");
|
|
|
+ parsingLogs.add(parsingLog);
|
|
|
}
|
|
|
- parsingLogs.add(parsingLog);
|
|
|
} catch (Exception e) {
|
|
|
LogUtil.info(DataSourcesEnum.E3, AlarmEnum.E4, LogUtil.format("无法解析场站端文件:{}", fileName), electricField.getStationCode());
|
|
|
log.error("下载并解析文件{}时异常", fileName, e);
|
|
@@ -186,9 +188,6 @@ public class SftpFileParsing {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 压缩前一日解析文件并上传至sftp服务器,本地不保留
|
|
|
*/
|
|
@@ -212,7 +211,7 @@ public class SftpFileParsing {
|
|
|
String zipFileName = dirYesToday + "_" + channelElectricField.getStationCode() + "_FAIL.zip";
|
|
|
String zipPath = PARSING_FILE_FAIL_DIR.getPath() + File.separator + zipFileName;
|
|
|
if (ZipUtil.zip(failFileDir.getAbsolutePath(), zipPath) && new File(zipPath).exists()) {
|
|
|
- SftpUtil.upload(sftpTool.getSftp(), channelElectricField.getSftpBackupUrl(), zipPath, zipFileName,true);
|
|
|
+ SftpUtil.upload(sftpTool.getSftp(), channelElectricField.getSftpBackupUrl(), zipPath, zipFileName, true);
|
|
|
}
|
|
|
}
|
|
|
File successFileDir = new File(successSrc + File.separator + channelElectricField.getStationCode());
|
|
@@ -220,7 +219,7 @@ public class SftpFileParsing {
|
|
|
String zipFileName = dirYesToday + "_" + channelElectricField.getStationCode() + "_SUCCESS.zip";
|
|
|
String zipPath = PARSING_FILE_SUCCESS_DIR.getPath() + File.separator + zipFileName;
|
|
|
if (ZipUtil.zip(successFileDir.getAbsolutePath(), zipPath) && new File(zipPath).exists()) {
|
|
|
- SftpUtil.upload(sftpTool.getSftp(), channelElectricField.getSftpBackupUrl(), zipPath, zipFileName,true);
|
|
|
+ SftpUtil.upload(sftpTool.getSftp(), channelElectricField.getSftpBackupUrl(), zipPath, zipFileName, true);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -232,6 +231,4 @@ public class SftpFileParsing {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
}
|