|
@@ -1,4 +1,5 @@
|
|
package com.nokia.task;
|
|
package com.nokia.task;
|
|
|
|
+
|
|
import com.jcraft.jsch.JSchException;
|
|
import com.jcraft.jsch.JSchException;
|
|
import com.jcraft.jsch.SftpException;
|
|
import com.jcraft.jsch.SftpException;
|
|
import com.nokia.common.gpload.GploadUtil;
|
|
import com.nokia.common.gpload.GploadUtil;
|
|
@@ -14,6 +15,7 @@ import org.apache.commons.csv.CSVRecord;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
+
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.io.InputStreamReader;
|
|
import java.io.InputStreamReader;
|
|
@@ -54,18 +56,25 @@ public class LtePmTask {
|
|
@XxlJob("execHandlerPm4G")
|
|
@XxlJob("execHandlerPm4G")
|
|
public void cronTask() throws JSchException, SSHUtilException, IOException, SftpException {
|
|
public void cronTask() throws JSchException, SSHUtilException, IOException, SftpException {
|
|
System.out.println("已触发pm4G");
|
|
System.out.println("已触发pm4G");
|
|
|
|
+ log.info("1");
|
|
// 创建文件夹
|
|
// 创建文件夹
|
|
Files.createDirectories(Paths.get(downloadTargetDir));
|
|
Files.createDirectories(Paths.get(downloadTargetDir));
|
|
|
|
+ log.info("2");
|
|
Files.createDirectories(Paths.get(distinctTargetDir));
|
|
Files.createDirectories(Paths.get(distinctTargetDir));
|
|
|
|
+ log.info("3");
|
|
SSHUtil sshUtil = new SSHUtil(host, port, username, password);
|
|
SSHUtil sshUtil = new SSHUtil(host, port, username, password);
|
|
|
|
+ log.info("4");
|
|
// 获取文件列表
|
|
// 获取文件列表
|
|
List<String> list = sshUtil.ls(sourceDir);
|
|
List<String> list = sshUtil.ls(sourceDir);
|
|
|
|
+ log.info("5");
|
|
if (CollectionUtils.isEmpty(list)) {
|
|
if (CollectionUtils.isEmpty(list)) {
|
|
|
|
+ log.info("6");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
log.debug("扫描到的文件: {}", list);
|
|
log.debug("扫描到的文件: {}", list);
|
|
for (String s : list) {
|
|
for (String s : list) {
|
|
- String[] split = s.split("\\.");
|
|
|
|
|
|
+ String[] s1 = s.split("_");
|
|
|
|
+ String[] split = s1[3].split("\\.");
|
|
if (split[1].equals("csv")){
|
|
if (split[1].equals("csv")){
|
|
singleTask(split[0]);
|
|
singleTask(split[0]);
|
|
}
|
|
}
|
|
@@ -87,10 +96,11 @@ public class LtePmTask {
|
|
}
|
|
}
|
|
|
|
|
|
public void download(String hourString) throws JSchException, SSHUtilException, IOException, SftpException {
|
|
public void download(String hourString) throws JSchException, SSHUtilException, IOException, SftpException {
|
|
|
|
+ log.info("hourString: {}", hourString);
|
|
SSHUtil sshUtil = new SSHUtil(host, port, username, password);
|
|
SSHUtil sshUtil = new SSHUtil(host, port, username, password);
|
|
- String downloadFileName = hourString+".csv";
|
|
|
|
- String sourceFilePath=sourceDir + "/" + downloadFileName;
|
|
|
|
- File targetFile = new File(downloadTargetDir);
|
|
|
|
|
|
+ String downloadFileName = filePrefix + hourString + ".csv";
|
|
|
|
+ String sourceFilePath = sourceDir + "/" + downloadFileName;
|
|
|
|
+ File targetFile = new File(downloadTargetDir + downloadFileName);
|
|
if (!targetFile.exists()) {
|
|
if (!targetFile.exists()) {
|
|
targetFile.getParentFile().mkdirs();
|
|
targetFile.getParentFile().mkdirs();
|
|
}
|
|
}
|
|
@@ -98,16 +108,14 @@ public class LtePmTask {
|
|
boolean b = sshUtil.scpFrom(sourceFilePath, targetPath);
|
|
boolean b = sshUtil.scpFrom(sourceFilePath, targetPath);
|
|
if (b) {
|
|
if (b) {
|
|
log.debug("文件 {} 下载成功...", targetPath);
|
|
log.debug("文件 {} 下载成功...", targetPath);
|
|
- sshUtil.delete(sourceFilePath);
|
|
|
|
- System.out.println("删除成功--------------------");
|
|
|
|
|
|
+// sshUtil.delete(sourceFilePath);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public void distinct(String hourString) throws IOException {
|
|
public void distinct(String hourString) throws IOException {
|
|
- String fileName = hourString + ".csv";
|
|
|
|
- System.out.println(fileName+"---------------------------------");
|
|
|
|
- String inputFilePath = downloadTargetDir +fileName;
|
|
|
|
- String outputFilePath = distinctTargetDir+fileName;
|
|
|
|
|
|
+ String fileName = filePrefix + hourString + ".csv";
|
|
|
|
+ String inputFilePath = downloadTargetDir + fileName;
|
|
|
|
+ String outputFilePath = distinctTargetDir + fileName;
|
|
CSVFormat format = CSVFormat.DEFAULT.builder().build();
|
|
CSVFormat format = CSVFormat.DEFAULT.builder().build();
|
|
CSVParser records = format.parse(new InputStreamReader(Files.newInputStream(Paths.get(inputFilePath)), StandardCharsets.UTF_8));
|
|
CSVParser records = format.parse(new InputStreamReader(Files.newInputStream(Paths.get(inputFilePath)), StandardCharsets.UTF_8));
|
|
Map<String, CSVRecord> recordMap = new HashMap<>();
|
|
Map<String, CSVRecord> recordMap = new HashMap<>();
|