|
@@ -44,8 +44,6 @@ public class PushCommon {
|
|
|
@Autowired
|
|
|
private IntegrationCompanyService integrationCompanyService;
|
|
|
@Autowired
|
|
|
- private MinIoService minIoService;
|
|
|
- @Autowired
|
|
|
private FileUtils fileUtils;
|
|
|
@Autowired
|
|
|
private SFTPUtil sftpUtil;
|
|
@@ -78,41 +76,19 @@ public class PushCommon {
|
|
|
recordService.save(record);
|
|
|
return false;
|
|
|
}
|
|
|
- // 获取指定目录下的短期原始数据(/jiayue/insu/file/init/J00269/)
|
|
|
+
|
|
|
+ // 获取文件路径
|
|
|
String filePath = initFilePath + stationCode + File.separatorChar;
|
|
|
- File files = new File(filePath);
|
|
|
- String[] fileNames = files.list();
|
|
|
- // 如果文件名列表为空
|
|
|
- if (fileNames == null || fileNames.length == 0) {
|
|
|
- log.info("指定目录下无文件");
|
|
|
- record.setState(StatusEnum.FILE_NULL.getSign());
|
|
|
- record.setStateContent(StatusEnum.FILE_NULL.getMsg());
|
|
|
- recordService.save(record);
|
|
|
- return false;
|
|
|
- }
|
|
|
- // 获取当天日期
|
|
|
+
|
|
|
+ // 获取当时时间
|
|
|
LocalDateTime today = LocalDateTime.now();
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
|
DateTimeFormatter formatterSeparator = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
String todaySeparatorStr = today.format(formatterSeparator);
|
|
|
String todayStr = today.format(formatter);
|
|
|
- // 转为list并根据日期筛选排序
|
|
|
- List<String> fileList = Arrays.stream(fileNames).collect(Collectors.toList());
|
|
|
- List<String> filterFileList = fileList.stream().filter(s -> s.contains(todayStr)).filter(s -> s.contains("DQ")).collect(Collectors.toList());
|
|
|
- // 如果筛选后无文件
|
|
|
- if (filterFileList.size() == 0) {
|
|
|
- log.info("无当日文件");
|
|
|
- record.setState(StatusEnum.FILE_NULL.getSign());
|
|
|
- record.setStateContent(StatusEnum.FILE_NULL.getMsg());
|
|
|
- recordService.save(record);
|
|
|
- return false;
|
|
|
- }
|
|
|
- filterFileList.sort(Collections.reverseOrder());
|
|
|
- // 获取原始文件
|
|
|
- File originalFile = new File(filterFileList.get(0));
|
|
|
- // 读取文件
|
|
|
- FileReader fileReader = new FileReader(filePath + originalFile);
|
|
|
- List<String> originalContents = fileReader.readLines();
|
|
|
+
|
|
|
+ // 获取已经下载的预测文件内容
|
|
|
+ List<String> originalContents = getInitFileLines(todayStr,filePath,record,"DQ");
|
|
|
|
|
|
List<Map<String, Object>> vList = new ArrayList<>();
|
|
|
String dataTime[];
|
|
@@ -150,7 +126,7 @@ public class PushCommon {
|
|
|
|
|
|
String fileType = todayStr + File.separatorChar + "dq";
|
|
|
// 文件数据开始时间
|
|
|
- String fileDateStr = DateUtil.format(DateUtil.beginOfDay(DateUtil.tomorrow()), "yyyyMMdd_HH:mm:ss");
|
|
|
+ String fileDateStr = DateUtil.format(DateUtil.beginOfDay(DateUtil.date()), "yyyyMMdd_HH:mm:ss");
|
|
|
// 推送数据至sftp
|
|
|
this.pushFileToSftp(record, vList, newFilePath, newFileName, templateName, station, fileType, companyCode, fileDateStr);
|
|
|
return true;
|
|
@@ -167,29 +143,20 @@ public class PushCommon {
|
|
|
* @return
|
|
|
*/
|
|
|
public Boolean pushNWPData(Station station, String companyCode, String newFilePath, String newFileName, String templateName) {
|
|
|
-
|
|
|
- JSONObject errMsg = new JSONObject();
|
|
|
-
|
|
|
// 获取场站编号
|
|
|
String stationCode = station.getStationCode();
|
|
|
Record record = new Record(CommonStant.RECORD_TYPE_PUSH_INIT_TO_SFTP, companyCode, stationCode, null, LocalDateTime.now(), LocalDateTime.now(), null, null);
|
|
|
record.setState(StatusEnum.SUCCESS.getSign());
|
|
|
|
|
|
- String beginDate = DateUtil.today();
|
|
|
- String endDate = DateUtil.format(DateUtil.tomorrow(), "yyyy-MM-dd");
|
|
|
-
|
|
|
- // 从minIo获取文件
|
|
|
- File originalFile = minIoService.downLoadFileFromMinIo(station, "nwp", beginDate, endDate, errMsg);
|
|
|
-
|
|
|
- if(originalFile==null){
|
|
|
- return false;
|
|
|
- }
|
|
|
+ // 获取文件路径
|
|
|
String filePath = initFilePath + stationCode + File.separatorChar;
|
|
|
|
|
|
- String path11 = originalFile.getAbsolutePath();
|
|
|
- // 读取文件
|
|
|
- FileReader fileReader = new FileReader(originalFile.getAbsolutePath());
|
|
|
- List<String> originalContents = fileReader.readLines();
|
|
|
+ // 获取当时时间
|
|
|
+ DateTime today = DateUtil.date();
|
|
|
+ String todayStr = today.toString("yyyyMMdd");
|
|
|
+
|
|
|
+ // 获取已经下载的预测文件内容
|
|
|
+ List<String> originalContents = getInitFileLines(todayStr,filePath,record,"NWP");
|
|
|
|
|
|
List<Map<String, Object>> vList = new ArrayList<>();
|
|
|
for (String originalContent : originalContents) {
|
|
@@ -231,8 +198,6 @@ public class PushCommon {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- DateTime today = DateUtil.date();
|
|
|
- String todayStr = today.toString("yyyyMMdd");
|
|
|
String fileDateStr = DateUtil.format(DateUtil.beginOfDay(DateUtil.tomorrow()), "yyyyMMdd_HH:mm:ss");
|
|
|
String fileType = todayStr + File.separatorChar + "nwp";
|
|
|
this.pushFileToSftp(record, vList, newFilePath, newFileName, templateName, station, fileType, companyCode, fileDateStr);
|
|
@@ -309,4 +274,44 @@ public class PushCommon {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取已经下载的预测原始文件内容
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<String> getInitFileLines(String todayStr,String filePath ,Record record ,String fileType){
|
|
|
+ List<String> originalContents = new ArrayList<>();
|
|
|
+ // 获取指定目录下的短期原始数据(/jiayue/insu/file/init/J00269/)
|
|
|
+ File files = new File(filePath);
|
|
|
+ String[] fileNames = files.list();
|
|
|
+ // 如果文件名列表为空
|
|
|
+ if (fileNames == null || fileNames.length == 0) {
|
|
|
+ log.info("指定目录下无文件");
|
|
|
+ record.setState(StatusEnum.FILE_NULL.getSign());
|
|
|
+ record.setStateContent(StatusEnum.FILE_NULL.getMsg());
|
|
|
+ recordService.save(record);
|
|
|
+ return originalContents;
|
|
|
+ }
|
|
|
+ // 获取当天日期
|
|
|
+
|
|
|
+ // 转为list并根据日期筛选排序
|
|
|
+ List<String> fileList = Arrays.stream(fileNames).collect(Collectors.toList());
|
|
|
+ List<String> filterFileList = fileList.stream().filter(s -> s.contains(todayStr)).filter(s -> s.contains(fileType)).collect(Collectors.toList());
|
|
|
+ // 如果筛选后无文件
|
|
|
+ if (filterFileList.size() == 0) {
|
|
|
+ log.info("无当日文件");
|
|
|
+ record.setState(StatusEnum.FILE_NULL.getSign());
|
|
|
+ record.setStateContent(StatusEnum.FILE_NULL.getMsg());
|
|
|
+ recordService.save(record);
|
|
|
+ return originalContents;
|
|
|
+ }
|
|
|
+ filterFileList.sort(Collections.reverseOrder());
|
|
|
+
|
|
|
+ // 获取原始文件
|
|
|
+ File originalFile = new File(filterFileList.get(0));
|
|
|
+ // 读取文件
|
|
|
+ FileReader fileReader = new FileReader(filePath + originalFile);
|
|
|
+ originalContents = fileReader.readLines();
|
|
|
+ return originalContents;
|
|
|
+ }
|
|
|
+
|
|
|
}
|