|
@@ -21,6 +21,8 @@ import java.io.*;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Paths;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
@@ -59,6 +61,15 @@ public class FileAnalysisService extends BaseService {
|
|
|
|
|
|
HolidayCalendarService holidayCalendarService;
|
|
|
|
|
|
+ private final String deleteFilelog = "文件删除异常";
|
|
|
+
|
|
|
+ private final String format = "yyyy-MM-dd HH:mm:ss";
|
|
|
+
|
|
|
+ private final String systemErrorLog = "系统错误: ";
|
|
|
+
|
|
|
+ private final String errorLog = "error";
|
|
|
+
|
|
|
+ private final String analysisFaild = "文件解析失败";
|
|
|
public static void mvFile(File file, String fdPath) {
|
|
|
try {
|
|
|
FileUtils.copyFile(file, new File(fdPath), true);
|
|
@@ -104,7 +115,6 @@ public class FileAnalysisService extends BaseService {
|
|
|
for (ElectricField electricField : electricFieldList) {
|
|
|
eList.add(electricField.getStationCode());
|
|
|
}
|
|
|
- //String path = FileUtil.getDownloadFilePath() + File.separator + "new";
|
|
|
String path = FileUtil.getDownloadFilePath();
|
|
|
//downloadFile
|
|
|
File dirFile = new File(path);
|
|
@@ -116,21 +126,24 @@ public class FileAnalysisService extends BaseService {
|
|
|
for (String stationCode : eList) {
|
|
|
// downLoadFile/场站编号/new
|
|
|
String dirFiles = dirFile.getPath() + File.separator + stationCode + File.separator + "new";
|
|
|
- //String dirFiles = "/Users/wanghongchen/fsdownload"+File.separator+ stationCode+ File.separator + "new";
|
|
|
File filePath = new File(dirFiles);
|
|
|
if (!filePath.exists()) {
|
|
|
filePath.mkdirs();
|
|
|
}
|
|
|
Collection<File> files = FileUtils.listFiles(filePath, new String[]{"RB"}, false);
|
|
|
String dayStr = new SimpleDateFormat("yyyyMMdd").format(new Date());//当前时间格式化为年月日
|
|
|
- if (files.size() > 0) {
|
|
|
+ if (files.isEmpty()) {
|
|
|
for (File file : files) {
|
|
|
flag = false;
|
|
|
String fileName = file.getName();
|
|
|
if (!fileName.contains(dayStr)) {
|
|
|
- file.delete();
|
|
|
- log.info(fileName + "不是当天的文件,删除!");
|
|
|
- break;
|
|
|
+ try {
|
|
|
+ Files.delete(Paths.get(file.getPath()));
|
|
|
+ log.info(fileName + "不是当天的文件,删除!");
|
|
|
+ break;
|
|
|
+ }catch (IOException e2){
|
|
|
+ log.info(deleteFilelog,e2);
|
|
|
+ }
|
|
|
}
|
|
|
if (fileName.length() < 30) {
|
|
|
//假期文件
|
|
@@ -281,10 +294,7 @@ public class FileAnalysisService extends BaseService {
|
|
|
//NWP文件按照Tab方式截取
|
|
|
String[] datas = lineTxt.split("\t");
|
|
|
if (datas.length == 35 && datas[0].startsWith("#")) {
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
- //过滤当天的数据
|
|
|
- //if (sdf.parse(datas[5]).getTime() >= TimeUtils.getMillisecondsSubDay() + 24 * 60 * 60 *
|
|
|
- // 1000) {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat(format);
|
|
|
nwpData = new Nwp();
|
|
|
|
|
|
//将截取的文件放入nwpData中
|
|
@@ -321,20 +331,23 @@ public class FileAnalysisService extends BaseService {
|
|
|
nwpData.setWd170(new BigDecimal(datas[34]).setScale(2, RoundingMode.HALF_UP));
|
|
|
nwpData.setStationCode(stationCode);
|
|
|
listNwp.add(nwpData);
|
|
|
- //}
|
|
|
}
|
|
|
}
|
|
|
} catch (IOException | ParseException | RuntimeException e) {
|
|
|
- log.error("系统错误:", e);
|
|
|
+ log.error(systemErrorLog, e);
|
|
|
// 进行告警
|
|
|
- File destFile = new File(file.getPath().replaceFirst("new", "error"));
|
|
|
+ File destFile = new File(file.getPath().replaceFirst("new", systemErrorLog));
|
|
|
if (destFile.exists()) {
|
|
|
- destFile.delete();
|
|
|
+ try {
|
|
|
+ Files.delete(Paths.get(destFile.getPath()));
|
|
|
+ }catch (IOException e2){
|
|
|
+ log.info(deleteFilelog,e2);
|
|
|
+ }
|
|
|
}
|
|
|
try {
|
|
|
FileUtils.moveFile(file, destFile);
|
|
|
} catch (IOException e1) {
|
|
|
- log.error(file.getName() + "文件解析失败", e);
|
|
|
+ log.error(file.getName() + analysisFaild, e);
|
|
|
}
|
|
|
} finally {
|
|
|
close(bufferedReaderNwp, readNwp);
|
|
@@ -350,7 +363,7 @@ public class FileAnalysisService extends BaseService {
|
|
|
* @return 样例集合
|
|
|
*/
|
|
|
private List<HolidayCalendar> fileAnalysisJqTerm(File file) {
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat(format);
|
|
|
List<HolidayCalendar> holidayCalendars = new ArrayList<>();
|
|
|
// 当文件未被使用时,进行解析上报
|
|
|
if (file.renameTo(file)) {
|
|
@@ -377,18 +390,22 @@ public class FileAnalysisService extends BaseService {
|
|
|
}
|
|
|
}
|
|
|
} catch (IOException | ParseException | RuntimeException e) {
|
|
|
- log.error("系统错误:", e);
|
|
|
+ log.error(systemErrorLog, e);
|
|
|
// 进行告警
|
|
|
|
|
|
|
|
|
- File destFile = new File(file.getPath().replaceFirst("new", "error"));
|
|
|
+ File destFile = new File(file.getPath().replaceFirst("new", systemErrorLog));
|
|
|
if (destFile.exists()) {
|
|
|
- destFile.delete();
|
|
|
+ try {
|
|
|
+ Files.delete(Paths.get(destFile.getPath()));
|
|
|
+ }catch (IOException e2){
|
|
|
+ log.info(deleteFilelog,e2);
|
|
|
+ }
|
|
|
}
|
|
|
try {
|
|
|
FileUtils.moveFile(file, destFile);
|
|
|
} catch (IOException e1) {
|
|
|
- log.error(file.getName() + "文件解析失败", e);
|
|
|
+ log.error(file.getName() + analysisFaild, e);
|
|
|
}
|
|
|
} finally {
|
|
|
close(bufferedReader, read);
|
|
@@ -405,7 +422,7 @@ public class FileAnalysisService extends BaseService {
|
|
|
* @return 样例集合
|
|
|
*/
|
|
|
private List<ForecastPowerShortTerm> fileAnalysisShortTerm(File file, Long currentDate, String stationCode) {
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat(format);
|
|
|
List<ForecastPowerShortTerm> forecastPowerShortTerm = new ArrayList<>();
|
|
|
// 当文件未被使用时,进行解析上报
|
|
|
if (file.renameTo(file)) {
|
|
@@ -419,11 +436,7 @@ public class FileAnalysisService extends BaseService {
|
|
|
while ((stringLine = bufferedReader.readLine()) != null) {
|
|
|
String[] string_arr = stringLine.split("\t");
|
|
|
|
|
|
- if (string_arr.length == 4 && string_arr[0].startsWith("#")) {
|
|
|
- if (StringUtils.isNotEmpty(string_arr[2])) {
|
|
|
- //过滤当天的数据
|
|
|
- //if (sdf.parse(string_arr[2]).getTime() >= TimeUtils.getMillisecondsSubDay() + 24 * 60 *
|
|
|
- // 60 * 1000) {
|
|
|
+ if (string_arr.length == 4 && string_arr[0].startsWith("#") && StringUtils.isNotEmpty(string_arr[2])) {
|
|
|
stf = new ForecastPowerShortTerm();
|
|
|
stf.setFpValue(new BigDecimal(string_arr[3] + ""));
|
|
|
stf.setForecastTime(sdf.parse(string_arr[2]).getTime());
|
|
@@ -431,21 +444,23 @@ public class FileAnalysisService extends BaseService {
|
|
|
stf.setPredictionModelEnum(PredictionModelEnum.E1);
|
|
|
stf.setStationCode(stationCode);
|
|
|
forecastPowerShortTerm.add(stf);
|
|
|
- // }
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
} catch (IOException | ParseException | RuntimeException e) {
|
|
|
- log.error("系统错误:", e);
|
|
|
+ log.error(systemErrorLog, e);
|
|
|
// 进行告警
|
|
|
- File destFile = new File(file.getPath().replaceFirst("new", "error"));
|
|
|
+ File destFile = new File(file.getPath().replaceFirst("new", systemErrorLog));
|
|
|
if (destFile.exists()) {
|
|
|
- destFile.delete();
|
|
|
+ try {
|
|
|
+ Files.delete(Paths.get(destFile.getPath()));
|
|
|
+ }catch (IOException e2){
|
|
|
+ log.info(deleteFilelog,e2);
|
|
|
+ }
|
|
|
}
|
|
|
try {
|
|
|
FileUtils.moveFile(file, destFile);
|
|
|
} catch (IOException e1) {
|
|
|
- log.error(file.getName() + "文件解析失败", e);
|
|
|
+ log.error(file.getName() +analysisFaild, e);
|
|
|
}
|
|
|
} finally {
|
|
|
close(bufferedReader, read);
|
|
@@ -464,7 +479,11 @@ public class FileAnalysisService extends BaseService {
|
|
|
File destFile = new File(file.getPath().replaceFirst("new", "backupsTemp"));
|
|
|
log.info("move file :{}, dest file:{}", file, destFile);
|
|
|
if (destFile.exists()) {
|
|
|
- destFile.delete();
|
|
|
+ try {
|
|
|
+ Files.delete(Paths.get(destFile.getPath()));
|
|
|
+ }catch (IOException e2){
|
|
|
+ log.info(deleteFilelog,e2);
|
|
|
+ }
|
|
|
}
|
|
|
try {
|
|
|
FileUtils.moveFile(file, destFile);
|
|
@@ -508,14 +527,18 @@ public class FileAnalysisService extends BaseService {
|
|
|
* @param file 文件
|
|
|
*/
|
|
|
private void moveFileError(File file) {
|
|
|
- File destFile = new File(file.getPath().replaceFirst("new", "error"));
|
|
|
+ File destFile = new File(file.getPath().replaceFirst("new", systemErrorLog));
|
|
|
if (destFile.exists()) {
|
|
|
- destFile.delete();
|
|
|
+ try {
|
|
|
+ Files.delete(Paths.get(destFile.getPath()));
|
|
|
+ }catch (IOException e2){
|
|
|
+ log.info(deleteFilelog,e2);
|
|
|
+ }
|
|
|
}
|
|
|
try {
|
|
|
FileUtils.moveFile(file, destFile);
|
|
|
} catch (IOException e) {
|
|
|
- log.error(file.getName() + "文件解析失败", e);
|
|
|
+ log.error(file.getName() + analysisFaild, e);
|
|
|
}
|
|
|
}
|
|
|
|