|
@@ -1,5 +1,4 @@
|
|
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;
|
|
@@ -15,7 +14,6 @@ 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;
|
|
@@ -25,8 +23,6 @@ import java.nio.file.Paths;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
-import java.util.regex.Matcher;
|
|
|
|
-import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
/*@Task*/
|
|
/*@Task*/
|
|
@@ -36,9 +32,9 @@ public class LtePmTask {
|
|
private String host;
|
|
private String host;
|
|
@Value("${lte.pm.download.port:22}")
|
|
@Value("${lte.pm.download.port:22}")
|
|
private Integer port;
|
|
private Integer port;
|
|
- @Value("${lte.pm.download.username:esbftp}")
|
|
|
|
|
|
+ @Value("${lte.pm.download.username:nokia}")
|
|
private String username;
|
|
private String username;
|
|
- @Value("${lte.pm.download.password:Esb2019ftp!}")
|
|
|
|
|
|
+ @Value("${lte.pm.download.password:Nokia*123}")
|
|
private String password;
|
|
private String password;
|
|
@Value("${lte.pm.download.sourceDir:/data/out2/pm_4g_hour}")
|
|
@Value("${lte.pm.download.sourceDir:/data/out2/pm_4g_hour}")
|
|
private String sourceDir;
|
|
private String sourceDir;
|
|
@@ -49,9 +45,11 @@ public class LtePmTask {
|
|
@Value("${lte.pm.distinct.targetDir:distinct/}")
|
|
@Value("${lte.pm.distinct.targetDir:distinct/}")
|
|
private String distinctTargetDir;
|
|
private String distinctTargetDir;
|
|
|
|
|
|
- /**
|
|
|
|
- * 扫描文件
|
|
|
|
- */
|
|
|
|
|
|
+ /* @XxlJob("execHandler")
|
|
|
|
+ public void Test(){
|
|
|
|
+ System.out.println("java------------------");
|
|
|
|
+ }
|
|
|
|
+*/
|
|
|
|
|
|
@XxlJob("execHandler")
|
|
@XxlJob("execHandler")
|
|
public void cronTask() throws JSchException, SSHUtilException, IOException, SftpException {
|
|
public void cronTask() throws JSchException, SSHUtilException, IOException, SftpException {
|
|
@@ -81,15 +79,16 @@ public class LtePmTask {
|
|
}*/
|
|
}*/
|
|
|
|
|
|
/*@AllowedTaskType({TaskType.TIMING, TaskType.IMMEDIATE})*/
|
|
/*@AllowedTaskType({TaskType.TIMING, TaskType.IMMEDIATE})*/
|
|
- public void singleTask(String hourString) throws JSchException, SSHUtilException, IOException {
|
|
|
|
- download();
|
|
|
|
- distinct();
|
|
|
|
|
|
+ public void singleTask(String hourString) throws JSchException, SSHUtilException, IOException, SftpException {
|
|
|
|
+ download(hourString);
|
|
|
|
+ distinct(hourString);
|
|
gpload(hourString);
|
|
gpload(hourString);
|
|
}
|
|
}
|
|
|
|
|
|
- public void download() throws JSchException, SSHUtilException, IOException {
|
|
|
|
|
|
+ public void download(String hourString) throws JSchException, SSHUtilException, IOException, SftpException {
|
|
SSHUtil sshUtil = new SSHUtil(host, port, username, password);
|
|
SSHUtil sshUtil = new SSHUtil(host, port, username, password);
|
|
- String sourceFilePath = sourceDir;
|
|
|
|
|
|
+ String downloadFileName = hourString+".csv";
|
|
|
|
+ String sourceFilePath=sourceDir + "/" + downloadFileName;
|
|
File targetFile = new File(downloadTargetDir);
|
|
File targetFile = new File(downloadTargetDir);
|
|
if (!targetFile.exists()) {
|
|
if (!targetFile.exists()) {
|
|
targetFile.getParentFile().mkdirs();
|
|
targetFile.getParentFile().mkdirs();
|
|
@@ -98,15 +97,16 @@ 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);
|
|
- String exec = sshUtil.exec(sourceDir);
|
|
|
|
- File file = new File(exec);
|
|
|
|
- file.delete();
|
|
|
|
|
|
+ sshUtil.delete(sourceFilePath);
|
|
|
|
+ System.out.println("删除成功--------------------");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public void distinct() throws IOException {
|
|
|
|
- String inputFilePath = downloadTargetDir ;
|
|
|
|
- String outputFilePath = distinctTargetDir;
|
|
|
|
|
|
+ public void distinct(String hourString) throws IOException {
|
|
|
|
+ String fileName = hourString + ".csv";
|
|
|
|
+ System.out.println(fileName+"---------------------------------");
|
|
|
|
+ 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<>();
|
|
@@ -125,7 +125,7 @@ public class LtePmTask {
|
|
}
|
|
}
|
|
|
|
|
|
public void gpload(String hourString) {
|
|
public void gpload(String hourString) {
|
|
- String gploadCommand = "sh /data1/pm/gpload/pm_lte_gpload.sh " + hourString;
|
|
|
|
|
|
+ String gploadCommand = "sh /data/xxl-job/pm_lte_gpload.sh " + hourString;
|
|
GploadResult gpload = GploadUtil.gpload(gploadCommand);
|
|
GploadResult gpload = GploadUtil.gpload(gploadCommand);
|
|
if (Boolean.TRUE.equals(gpload.getTaskStatus())) {
|
|
if (Boolean.TRUE.equals(gpload.getTaskStatus())) {
|
|
log.debug("gpload完成: {}", gpload);
|
|
log.debug("gpload完成: {}", gpload);
|