Explorar o código

fix: 20220823

weijianghai %!s(int64=2) %!d(string=hai) anos
pai
achega
5a172a9151

+ 6 - 0
src/main/java/com/nokia/common/ssh/SSHUtil.java

@@ -52,10 +52,15 @@ public class SSHUtil {
      * 获取文件列表
      */
     public List<String> ls(String path) throws JSchException, SftpException {
+        log.info("ls1");
         session = getConnectSession();
+        log.info("ls2");
         channelSftp = (ChannelSftp) session.openChannel("sftp");
+        log.info("ls3");
         channelSftp.connect();
+        log.info("ls4");
         List<String> fileNameList = new ArrayList<>();
+        log.info("ls5");
         Vector fileList = channelSftp.ls(path);
         for (Object o : fileList) {
             String fileName = ((ChannelSftp.LsEntry) o).getFilename();
@@ -281,6 +286,7 @@ public class SSHUtil {
     }
 
     private Session getConnectSession() throws JSchException {
+        log.info("user: {}, host: {}, port: {}", targetServer.getUser(), targetServer.getHost(), targetServer.getPort());
         jSch = new JSch();
         session = jSch.getSession(targetServer.getUser(), targetServer.getHost(), targetServer.getPort());
         session.setPassword(targetServer.getPassword());

+ 76 - 77
src/main/java/com/nokia/config/XxlJobConfig.java

@@ -1,77 +1,76 @@
-//package com.nokia.config;
-//
-//import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
-//import org.slf4j.Logger;
-//import org.slf4j.LoggerFactory;
-//import org.springframework.beans.factory.annotation.Value;
-//import org.springframework.context.annotation.Bean;
-//import org.springframework.context.annotation.Configuration;
-//
-///**
-// * xxl-job config
-// *
-// * @author xuxueli 2017-04-28
-// */
-//@Configuration
-//public class XxlJobConfig {
-//    private Logger logger = LoggerFactory.getLogger(com.nokia.config.XxlJobConfig.class);
-//
-//    @Value("${xxl.job.admin.addresses}")
-//    private String adminAddresses;
-//
-//    @Value("${xxl.job.accessToken}")
-//    private String accessToken;
-//
-//    @Value("${xxl.job.executor.appname}")
-//    private String appname;
-//
-//    @Value("${xxl.job.executor.address}")
-//    private String address;
-//
-//    @Value("${xxl.job.executor.ip}")
-//    private String ip;
-//
-//    @Value("${xxl.job.executor.port}")
-//    private int port;
-//
-//    @Value("${xxl.job.executor.logpath}")
-//    private String logPath;
-//
-//    @Value("${xxl.job.executor.logretentiondays}")
-//    private int logRetentionDays;
-//
-//
-//    @Bean
-//    public XxlJobSpringExecutor xxlJobExecutor() {
-//        logger.info(">>>>>>>>>>> xxl-job config init.");
-//        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
-//        xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
-//        xxlJobSpringExecutor.setAppname(appname);
-//        xxlJobSpringExecutor.setAddress(address);
-//        xxlJobSpringExecutor.setIp(ip);
-//        xxlJobSpringExecutor.setPort(port);
-//        xxlJobSpringExecutor.setAccessToken(accessToken);
-//        xxlJobSpringExecutor.setLogPath(logPath);
-//        xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
-//        return xxlJobSpringExecutor;
-//    }
-//
-//    /**
-//     * 针对多网卡、容器内部署等情况,可借助 "spring-cloud-commons" 提供的 "InetUtils" 组件灵活定制注册IP;
-//     *
-//     *      1、引入依赖:
-//     *          <dependency>
-//     *             <groupId>org.springframework.cloud</groupId>
-//     *             <artifactId>spring-cloud-commons</artifactId>
-//     *             <version>${version}</version>
-//     *         </dependency>
-//     *
-//     *      2、配置文件,或者容器启动变量
-//     *          spring.cloud.inetutils.preferred-networks: 'xxx.xxx.xxx.'
-//     *
-//     *      3、获取IP
-//     *          String ip_ = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
-//     */
-//
-//
-//}
+package com.nokia.config;
+
+import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * xxl-job config
+ *
+ * @author xuxueli 2017-04-28
+ */
+@Slf4j
+@Configuration
+public class XxlJobConfig {
+
+    @Value("${xxl.job.admin.addresses}")
+    private String adminAddresses;
+
+    @Value("${xxl.job.accessToken}")
+    private String accessToken;
+
+    @Value("${xxl.job.executor.appname}")
+    private String appname;
+
+    @Value("${xxl.job.executor.address}")
+    private String address;
+
+    @Value("${xxl.job.executor.ip}")
+    private String ip;
+
+    @Value("${xxl.job.executor.port}")
+    private int port;
+
+    @Value("${xxl.job.executor.logpath}")
+    private String logPath;
+
+    @Value("${xxl.job.executor.logretentiondays}")
+    private int logRetentionDays;
+
+
+    @Bean
+    public XxlJobSpringExecutor xxlJobExecutor() {
+        log.info(">>>>>>>>>>> xxl-job config init.");
+        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
+        xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
+        xxlJobSpringExecutor.setAppname(appname);
+        xxlJobSpringExecutor.setAddress(address);
+        xxlJobSpringExecutor.setIp(ip);
+        xxlJobSpringExecutor.setPort(port);
+        xxlJobSpringExecutor.setAccessToken(accessToken);
+        xxlJobSpringExecutor.setLogPath(logPath);
+        xxlJobSpringExecutor.setLogRetentionDays(logRetentionDays);
+        return xxlJobSpringExecutor;
+    }
+
+    /**
+     * 针对多网卡、容器内部署等情况,可借助 "spring-cloud-commons" 提供的 "InetUtils" 组件灵活定制注册IP;
+     *
+     *      1、引入依赖:
+     *          <dependency>
+     *             <groupId>org.springframework.cloud</groupId>
+     *             <artifactId>spring-cloud-commons</artifactId>
+     *             <version>${version}</version>
+     *         </dependency>
+     *
+     *      2、配置文件,或者容器启动变量
+     *          spring.cloud.inetutils.preferred-networks: 'xxx.xxx.xxx.'
+     *
+     *      3、获取IP
+     *          String ip_ = inetUtils.findFirstNonLoopbackHostInfo().getIpAddress();
+     */
+
+
+}

+ 18 - 10
src/main/java/com/nokia/task/LtePmTask.java

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

+ 1 - 4
src/main/resources/application.properties

@@ -14,10 +14,7 @@ spring.web.resources.static-locations=classpath:/dist
 # 任务调度的线程池大小
 scheduling.scheduler.pool.size=3
 # pm下载相关配置
-pm.download.directory=D:\\download
-pm.webdriver.chrome.driver=C:\\Users\\DELL\\Desktop\\chromedriver.exe
-pm.driver.options.headless=false
-pm.download.timeoutSeconds=120
+
 ### xxl-job admin address list, such as "http://address" or "http://address01,http://address02"
 xxl.job.admin.addresses=http://192.168.10.7:8087/xxl-job-admin
 ### xxl-job, access token