|
@@ -1,5 +1,7 @@
|
|
|
package com.nokia.task;
|
|
|
+
|
|
|
import com.jcraft.jsch.JSchException;
|
|
|
+import com.jcraft.jsch.SftpException;
|
|
|
import com.nokia.common.gpload.GploadUtil;
|
|
|
import com.nokia.common.gpload.entity.GploadResult;
|
|
|
import com.nokia.common.ssh.SSHUtil;
|
|
@@ -12,18 +14,24 @@ import org.apache.commons.csv.CSVPrinter;
|
|
|
import org.apache.commons.csv.CSVRecord;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+
|
|
|
import java.io.File;
|
|
|
-import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStreamReader;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Paths;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+
|
|
|
@Slf4j
|
|
|
/*@Task*/
|
|
|
@Component
|
|
|
public class LtePmTask {
|
|
|
-
|
|
|
@Value("${lte.pm.download.host:10.17.180.55}")
|
|
|
private String host;
|
|
|
@Value("${lte.pm.download.port:22}")
|
|
@@ -42,24 +50,47 @@ public class LtePmTask {
|
|
|
private String distinctTargetDir;
|
|
|
|
|
|
|
|
|
- @XxlJob("execHandler")
|
|
|
- public void xxlJobCall(){
|
|
|
- System.out.println("java-----------");
|
|
|
- }
|
|
|
+// @XxlJob("execHandler")
|
|
|
+// public void xxlJobCall(){
|
|
|
+// System.out.println("java-----------");
|
|
|
+// }
|
|
|
|
|
|
/**
|
|
|
* 扫描文件
|
|
|
*/
|
|
|
- @XxlJob("")
|
|
|
- public void scan() throws JSchException, SSHUtilException, IOException {
|
|
|
+// @XxlJob("")
|
|
|
+// public void scan() throws JSchException, SSHUtilException, IOException {
|
|
|
+// SSHUtil sshUtil = new SSHUtil(host, port, username, password);
|
|
|
+// String exec = sshUtil.exec(sourceDir);
|
|
|
+// File targetFile = new File(exec);
|
|
|
+// String[] list = targetFile.list();
|
|
|
+// for (String s : list) {
|
|
|
+// String[] split = s.split("\\.");
|
|
|
+// if (split[1].equals("csv")){
|
|
|
+// singleTask(split[0]);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+ @XxlJob("execHandler")
|
|
|
+ public void cronTask() throws JSchException, SSHUtilException, IOException, SftpException {
|
|
|
+ final Pattern p = Pattern.compile("(?<=" + filePrefix + ")\\d{10}(?=.csv)");
|
|
|
+ // 创建文件夹
|
|
|
+ Files.createDirectories(Paths.get(downloadTargetDir));
|
|
|
+ Files.createDirectories(Paths.get(distinctTargetDir));
|
|
|
SSHUtil sshUtil = new SSHUtil(host, port, username, password);
|
|
|
- String exec = sshUtil.exec(sourceDir);
|
|
|
- File targetFile = new File(exec);
|
|
|
- String[] list = targetFile.list();
|
|
|
- for (String s : list) {
|
|
|
- String[] split = s.split("\\.");
|
|
|
- if (split[1].equals("csv")){
|
|
|
- singleTask(split[0]);
|
|
|
+ // 获取文件列表
|
|
|
+ List<String> list = sshUtil.ls(sourceDir);
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ log.debug("扫描到的文件: {}", list);
|
|
|
+ for (String t : list) {
|
|
|
+ Matcher m = p.matcher(t);
|
|
|
+ if (m.find()) {
|
|
|
+ String hourString = m.group(0);
|
|
|
+ singleTask(hourString);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -99,7 +130,7 @@ public class LtePmTask {
|
|
|
String inputFilePath = downloadTargetDir ;
|
|
|
String outputFilePath = distinctTargetDir;
|
|
|
CSVFormat format = CSVFormat.DEFAULT.builder().build();
|
|
|
- CSVParser records = format.parse(new InputStreamReader(new FileInputStream(inputFilePath), StandardCharsets.UTF_8));
|
|
|
+ CSVParser records = format.parse(new InputStreamReader(Files.newInputStream(Paths.get(inputFilePath)), StandardCharsets.UTF_8));
|
|
|
Map<String, CSVRecord> recordMap = new HashMap<>();
|
|
|
int count = 0;
|
|
|
for (CSVRecord record : records) {
|
|
@@ -118,7 +149,7 @@ public class LtePmTask {
|
|
|
public void gpload(String hourString) {
|
|
|
String gploadCommand = "sh /data1/pm/gpload/pm_lte_gpload.sh " + hourString;
|
|
|
GploadResult gpload = GploadUtil.gpload(gploadCommand);
|
|
|
- if (gpload.getTaskStatus()) {
|
|
|
+ if (Boolean.TRUE.equals(gpload.getTaskStatus())) {
|
|
|
log.debug("gpload完成: {}", gpload);
|
|
|
} else {
|
|
|
log.error("gpload 失败: {}", gpload.getMessage());
|