|
|
@ -15,6 +15,7 @@ import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.PreDestroy;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.File;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Date;
|
|
|
@ -39,6 +40,13 @@ public class AmpliDownloadTask {
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
WebSocketServer webSocketServer;
|
|
|
|
WebSocketServer webSocketServer;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int shutdown = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PreDestroy
|
|
|
|
|
|
|
|
private void preDestroy() {
|
|
|
|
|
|
|
|
shutdown = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Scheduled(cron = "0 10 * * * ?")
|
|
|
|
@Scheduled(cron = "0 10 * * * ?")
|
|
|
|
public void downloadAll() {
|
|
|
|
public void downloadAll() {
|
|
|
|
List<RemoteConfig> configList = configService.listAll();
|
|
|
|
List<RemoteConfig> configList = configService.listAll();
|
|
|
@ -60,6 +68,9 @@ public class AmpliDownloadTask {
|
|
|
|
|
|
|
|
|
|
|
|
// 下载一个远端服务器
|
|
|
|
// 下载一个远端服务器
|
|
|
|
private void downloadServer(RemoteConfig config) throws Exception {
|
|
|
|
private void downloadServer(RemoteConfig config) throws Exception {
|
|
|
|
|
|
|
|
if (shutdown == 1) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
if (config.getActive() == null || config.getActive().intValue() == Constants.FALSE) {
|
|
|
|
if (config.getActive() == null || config.getActive().intValue() == Constants.FALSE) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -86,6 +97,9 @@ public class AmpliDownloadTask {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void downloadPath(String remotePath, RemoteConfig config, SFTPTool sftpTool) throws Exception {
|
|
|
|
private void downloadPath(String remotePath, RemoteConfig config, SFTPTool sftpTool) throws Exception {
|
|
|
|
|
|
|
|
if (shutdown == 1) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
String str = "abcd" + remotePath.replaceAll("/", "").replaceAll("\\\\", "");
|
|
|
|
String str = "abcd" + remotePath.replaceAll("/", "").replaceAll("\\\\", "");
|
|
|
|
str = str.substring(str.length() - 4);
|
|
|
|
str = str.substring(str.length() - 4);
|
|
|
|
String localPath = folder + "/" + config.getIp() + "/" + str;
|
|
|
|
String localPath = folder + "/" + config.getIp() + "/" + str;
|
|
|
@ -100,6 +114,9 @@ public class AmpliDownloadTask {
|
|
|
|
|
|
|
|
|
|
|
|
private void downloadFile(String remotePath, String filename,
|
|
|
|
private void downloadFile(String remotePath, String filename,
|
|
|
|
String localPath, RemoteConfig config, SFTPTool sftpTool) throws Exception {
|
|
|
|
String localPath, RemoteConfig config, SFTPTool sftpTool) throws Exception {
|
|
|
|
|
|
|
|
if (shutdown == 1) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
if (StringUtils.isBlank(config.getSuffix()) || filename.toLowerCase().endsWith(config.getSuffix().toLowerCase())) {
|
|
|
|
if (StringUtils.isBlank(config.getSuffix()) || filename.toLowerCase().endsWith(config.getSuffix().toLowerCase())) {
|
|
|
|
RemoteDownload item = new RemoteDownload();
|
|
|
|
RemoteDownload item = new RemoteDownload();
|
|
|
|
item.setConfigId(config.getId());
|
|
|
|
item.setConfigId(config.getId());
|
|
|
|