|
|
@@ -56,7 +56,7 @@ public class SendDataHandlerTask {
|
|
|
/**
|
|
|
* 处理接收到的数据,每3分钟处理一次
|
|
|
*/
|
|
|
- @Scheduled(cron = "0 0/1 * * * ? ")
|
|
|
+ @Scheduled(initialDelay = 20000, fixedDelay = 60000)
|
|
|
public void handlerReceiveData() {
|
|
|
//启动压缩
|
|
|
if (compressEnable) {
|
|
|
@@ -69,16 +69,22 @@ public class SendDataHandlerTask {
|
|
|
try (Stream<Path> paths = Files.walk(Paths.get(path))) {
|
|
|
List<Path> fileNames = paths.filter(Files::isRegularFile).collect(Collectors.toList());
|
|
|
for (Path fileName : fileNames) {
|
|
|
+ File currentFile = fileName.toFile();
|
|
|
+ long lastModified = currentFile.lastModified();
|
|
|
+ if (lastModified + 3 * 60 * 1000L > System.currentTimeMillis()) {
|
|
|
+ log.info("文件 {} 正在降温,预计需要 {} 分钟", fileName, (lastModified + 3 * 60 * 1000L - System.currentTimeMillis()) / 1000L / 60L);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
String suffix = FileUtil.getSuffix(fileName.toFile());
|
|
|
//如果不是压缩包,将文件压缩在zip
|
|
|
if (!"zip".equals(suffix)) {
|
|
|
//TODO 文件可能没写完
|
|
|
File zip = ZipUtil.zip(fileName.toFile().getAbsolutePath(), compressZipPath + FileUtil.getName(fileName.toFile()).replace(FileUtil.getSuffix(fileName.toFile()), "zip"));
|
|
|
- log.info("压缩文件:{}", zip);
|
|
|
+ log.info("压缩文件:{}", zip.getName());
|
|
|
//删除源文件
|
|
|
FileUtil.del(fileName.toFile());
|
|
|
} else {
|
|
|
- //如果不是zip就复制到目标目录
|
|
|
+ //如果是zip就复制到目标目录
|
|
|
FileUtil.move(fileName.toFile(), new File(compressZipPath + FileUtil.getName(fileName.toFile())), true);
|
|
|
}
|
|
|
}
|
|
|
@@ -88,6 +94,10 @@ public class SendDataHandlerTask {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ @Scheduled(initialDelay = 20000, fixedDelay = 30000)
|
|
|
+ public void handleSend() {
|
|
|
//是否启动发送
|
|
|
if (sendEnable) {
|
|
|
//检查网络,如果网络是通常就发送到接收端,如果没有网络就只打包。
|
|
|
@@ -97,46 +107,81 @@ public class SendDataHandlerTask {
|
|
|
}
|
|
|
try (Stream<Path> paths = Files.walk(Paths.get(sendFilePath))) {
|
|
|
List<Path> list = paths.filter(Files::isRegularFile).collect(Collectors.toList());
|
|
|
- log.info("发现有{}个待处理文件。", list.size());
|
|
|
- for (Path filePath : list) {
|
|
|
- String suffix = FileUtil.getSuffix(filePath.toFile());
|
|
|
- if (!"zip".equals(suffix)) {
|
|
|
- continue;
|
|
|
+ list = list.stream().filter((path)->!path.toFile().getName().startsWith("NC")).collect(Collectors.toList());
|
|
|
+ log.info("NormalFile >>>>>> 发现有{}个待处理的文件。", list.size());
|
|
|
+ sendFile(list);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error("处理出现异常{}", e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发送NC文件,大文件
|
|
|
+ */
|
|
|
+ @Scheduled(initialDelay = 20000, fixedDelay = 30000)
|
|
|
+ public void handleSendBigFile() {
|
|
|
+ //是否启动发送
|
|
|
+ if (sendEnable) {
|
|
|
+ //检查网络,如果网络是通常就发送到接收端,如果没有网络就只打包。
|
|
|
+ if (!this.serverIsOnline()) {
|
|
|
+ log.error("请求网络{}异常.", sendToIp);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try (Stream<Path> paths = Files.walk(Paths.get(sendFilePath))) {
|
|
|
+ List<Path> list = paths.filter(Files::isRegularFile).collect(Collectors.toList());
|
|
|
+ list = list.stream().filter((path)->path.toFile().getName().startsWith("NC")).collect(Collectors.toList());
|
|
|
+ log.info("BigFile >>>>>> 发现有{}个待处理的大文件。", list.size());
|
|
|
+ sendFile(list);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ log.error("处理出现异常{}", e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void sendFile(List<Path> list) {
|
|
|
+ for (Path filePath : list) {
|
|
|
+ String suffix = FileUtil.getSuffix(filePath.toFile());
|
|
|
+ if (!"zip".equals(suffix)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ File currentFile = filePath.toFile();
|
|
|
+ long lastModified = currentFile.lastModified();
|
|
|
+ if (lastModified + 2 * 60 * 1000L > System.currentTimeMillis()) {
|
|
|
+ log.info("文件 {} 正在降温,预计需要 {} 分钟", filePath, (lastModified + 2 * 60 * 1000L - System.currentTimeMillis()) / 1000L / 60L);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ boolean result = httpSendFile.sendFile(filePath.toFile());
|
|
|
+ if (result) {
|
|
|
+ if (needBackup) {
|
|
|
+ //移动到目标目录
|
|
|
+ File backupFile = new File(getBackupPath());
|
|
|
+ if (!backupFile.exists()) {
|
|
|
+ backupFile.mkdirs();
|
|
|
+ }
|
|
|
+ FileUtil.move(filePath.toFile(), new File(getBackupPath() + FileUtil.getName(filePath)), true);
|
|
|
+ } else {
|
|
|
+ //如果不备份就删除
|
|
|
+ FileUtil.del(filePath);
|
|
|
}
|
|
|
- try {
|
|
|
- boolean result = httpSendFile.sendFile(filePath.toFile());
|
|
|
- if (result) {
|
|
|
- if (needBackup) {
|
|
|
- //移动到目标目录
|
|
|
- File backupFile = new File(getBackupPath());
|
|
|
- if (!backupFile.exists()) {
|
|
|
- backupFile.mkdirs();
|
|
|
- }
|
|
|
- FileUtil.move(filePath.toFile(), new File(getBackupPath() + FileUtil.getName(filePath)), true);
|
|
|
- } else {
|
|
|
- //如果不备份就删除
|
|
|
- FileUtil.del(filePath);
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (needBackup) {
|
|
|
- String errorPath = backupPath + "error" + File.pathSeparator;
|
|
|
- //移动到目标目录
|
|
|
- File backupFile = new File(errorPath);
|
|
|
- if (!backupFile.exists()) {
|
|
|
- backupFile.mkdirs();
|
|
|
- }
|
|
|
- FileUtil.move(filePath.toFile(), new File(errorPath + FileUtil.getName(filePath)), true);
|
|
|
- }
|
|
|
+ } else {
|
|
|
+ if (needBackup) {
|
|
|
+ String errorPath = backupPath + "error" + File.pathSeparator;
|
|
|
+ //移动到目标目录
|
|
|
+ File backupFile = new File(errorPath);
|
|
|
+ if (!backupFile.exists()) {
|
|
|
+ backupFile.mkdirs();
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- log.error("出现异常:{}", e.getMessage());
|
|
|
- log.error("异常文件:{}", filePath.getFileName());
|
|
|
+ FileUtil.move(filePath.toFile(), new File(errorPath + FileUtil.getName(filePath)), true);
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- log.error("处理出现异常{}", e.getMessage());
|
|
|
+ log.error("出现异常:{}", e.getMessage());
|
|
|
+ log.error("异常文件:{}", filePath.getFileName());
|
|
|
}
|
|
|
}
|
|
|
}
|