perf: 优化路径配置

dev
huangfeng 9 months ago
parent 1c7839afa6
commit b059da1d20

@ -16,6 +16,6 @@ import java.util.List;
public class BizConfig { public class BizConfig {
private String rsakey; private String rsakey;
private String datapath;
} }

@ -1,6 +1,7 @@
package com.xydl.cac.task; package com.xydl.cac.task;
import com.jcraft.jsch.ChannelSftp; import com.jcraft.jsch.ChannelSftp;
import com.xydl.cac.config.BizConfig;
import com.xydl.cac.entity.*; import com.xydl.cac.entity.*;
import com.xydl.cac.service.RemoteConfigService; import com.xydl.cac.service.RemoteConfigService;
import com.xydl.cac.service.RemoteDownloadService; import com.xydl.cac.service.RemoteDownloadService;
@ -9,7 +10,6 @@ import com.xydl.cac.util.DingTalkPushUtil;
import com.xydl.cac.util.SFTPTool; import com.xydl.cac.util.SFTPTool;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled; 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;
@ -22,11 +22,13 @@ import java.util.Vector;
@Service @Service
@Slf4j @Slf4j
public class SftpDownloadTask { public class AmpliDownloadTask {
@Value("${cac.data-path}") String nginxPath = "/data";
public String dataPath; String folder = "/ampli";
@Resource
BizConfig bizConfig;
@Resource @Resource
RemoteConfigService configService; RemoteConfigService configService;
@Resource @Resource
@ -36,7 +38,7 @@ public class SftpDownloadTask {
@Resource @Resource
WebSocketServer webSocketServer; WebSocketServer webSocketServer;
@Scheduled(cron = "0 3 * * * ?") @Scheduled(cron = "0 10 * * * ?")
public void downloadAll() { public void downloadAll() {
List<RemoteConfig> configList = configService.listAll(); List<RemoteConfig> configList = configService.listAll();
if (!CollectionUtils.isEmpty(configList)) { if (!CollectionUtils.isEmpty(configList)) {
@ -84,8 +86,8 @@ public class SftpDownloadTask {
private void downloadPath(String remotePath, RemoteConfig config, SFTPTool sftpTool) throws Exception { private void downloadPath(String remotePath, RemoteConfig config, SFTPTool sftpTool) throws Exception {
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 = "/ampli/" + config.getIp() + "/" + str; String localPath = folder + "/" + config.getIp() + "/" + str;
File dir = new File(dataPath + localPath); File dir = new File(bizConfig.getDatapath() + localPath);
dir.mkdirs(); dir.mkdirs();
Vector<ChannelSftp.LsEntry> files = sftpTool.listFiles(remotePath); Vector<ChannelSftp.LsEntry> files = sftpTool.listFiles(remotePath);
@ -105,11 +107,11 @@ public class SftpDownloadTask {
boolean exist = downloadService.exist(item); boolean exist = downloadService.exist(item);
if (!exist) { if (!exist) {
String localFilePath = localPath + "/" + filename; String localFilePath = localPath + "/" + filename;
sftpTool.download(filename, dataPath + localFilePath); sftpTool.download(filename, bizConfig.getDatapath() + localFilePath);
if (config.getTodel() != null && config.getTodel().intValue() == 1) { if (config.getTodel() != null && config.getTodel().intValue() == 1) {
sftpTool.delete(filename); sftpTool.delete(filename);
} }
item.setPath("/data" + localFilePath); item.setPath(nginxPath + localFilePath);
item.setCreateTime(new Date()); item.setCreateTime(new Date());
downloadService.add(item); downloadService.add(item);
} }

@ -30,7 +30,7 @@ spring:
size: 5 size: 5
cac: cac:
data-path: /home/xydl/ncac/data datapath: /home/xydl/ncac/data
i2: i2:
enable: false enable: false
url: http://192.168.1.190:8080/busi-back-ws/service/XydlService url: http://192.168.1.190:8080/busi-back-ws/service/XydlService

@ -30,7 +30,7 @@ spring:
size: 5 size: 5
cac: cac:
data-path: /home/xydl/ncac/data datapath: /home/xydl/ncac/data
i2: i2:
enable: false enable: false
url: http://192.168.1.190:8080/busi-back-ws/service/XydlService url: http://192.168.1.190:8080/busi-back-ws/service/XydlService

Loading…
Cancel
Save