|
|
@@ -38,11 +38,10 @@ public class SendDataHandlerTask {
|
|
|
|
|
|
@Value("${send.file-path}")
|
|
|
private String sendFilePath;
|
|
|
- @Value("${send.to-ip}")
|
|
|
+ @Value("${send.to-addr}")
|
|
|
private String sendToIp;
|
|
|
@Value("${send.need-backup}")
|
|
|
private boolean needBackup;
|
|
|
-
|
|
|
@Value("${send.enable}")
|
|
|
private boolean sendEnable;
|
|
|
@Value("${send.backup-path}")
|
|
|
@@ -54,14 +53,14 @@ public class SendDataHandlerTask {
|
|
|
/**
|
|
|
* 处理接收到的数据,每3分钟处理一次
|
|
|
*/
|
|
|
- @Scheduled(cron = "0 0/3 * * * ? ")
|
|
|
+ @Scheduled(cron = "0 0/1 * * * ? ")
|
|
|
public void handlerReceiveData() {
|
|
|
//启动压缩
|
|
|
if (compressEnable) {
|
|
|
for (String path : compressFilePath.split(",")) {
|
|
|
File file = new File(path);
|
|
|
if (!file.exists()) {
|
|
|
- boolean mkdirs = file.mkdirs();
|
|
|
+ file.mkdirs();
|
|
|
}
|
|
|
// 先解压
|
|
|
try (Stream<Path> paths = Files.walk(Paths.get(path))) {
|
|
|
@@ -74,11 +73,14 @@ public class SendDataHandlerTask {
|
|
|
log.info("压缩文件:{}", zip);
|
|
|
//删除zip
|
|
|
FileUtil.del(fileName.toFile());
|
|
|
+ } else {
|
|
|
+ //如果不是zip就复制到目标目录
|
|
|
+ FileUtil.move(fileName.toFile(), new File(compressZipPath + FileUtil.getName(fileName.toFile())), true);
|
|
|
}
|
|
|
}
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
- log.error("处理出现异常{}", e.getMessage());
|
|
|
+ log.error("获取压缩文件列表出现异常{}", e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -86,6 +88,7 @@ public class SendDataHandlerTask {
|
|
|
if (sendEnable) {
|
|
|
//检查网络,如果网络是通常就发送到接收端,如果没有网络就只打包。
|
|
|
if (!this.serverIsOnline()) {
|
|
|
+ log.error("请求网络{}异常.", sendToIp);
|
|
|
return;
|
|
|
}
|
|
|
try (Stream<Path> paths = Files.walk(Paths.get(sendFilePath))) {
|
|
|
@@ -93,14 +96,29 @@ public class SendDataHandlerTask {
|
|
|
log.info("发现有{}个待处理文件。", list.size());
|
|
|
for (Path filePath : list) {
|
|
|
try {
|
|
|
- httpSendFile.sendFile(filePath.toFile());
|
|
|
- if (needBackup) {
|
|
|
- //移动到目标目录
|
|
|
- File backupFile = new File(backupPath);
|
|
|
- if (!backupFile.exists()) {
|
|
|
- boolean mkdirs = backupFile.mkdirs();
|
|
|
+ boolean result = httpSendFile.sendFile(filePath.toFile());
|
|
|
+ if (result) {
|
|
|
+ if (needBackup) {
|
|
|
+ //移动到目标目录
|
|
|
+ File backupFile = new File(backupPath);
|
|
|
+ if (!backupFile.exists()) {
|
|
|
+ backupFile.mkdirs();
|
|
|
+ }
|
|
|
+ FileUtil.move(filePath.toFile(), new File(backupPath + 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);
|
|
|
}
|
|
|
- FileUtil.move(filePath.toFile(), new File(backupPath + FileUtil.getName(filePath)), true);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
@@ -122,7 +140,7 @@ public class SendDataHandlerTask {
|
|
|
*/
|
|
|
private boolean serverIsOnline() {
|
|
|
try {
|
|
|
- String res = HttpUtil.get("http://" + sendToIp + ":9002", 2000);
|
|
|
+ String res = HttpUtil.get("http://" + sendToIp, 2000);
|
|
|
return "OK".equals(res);
|
|
|
} catch (Exception e) {
|
|
|
return false;
|