فهرست منبع

加入线程处理

wangliang 4 روز پیش
والد
کامیت
204227d214

+ 1 - 28
src/main/java/com/qmth/cet/plug/api/CetPlugController.java

@@ -42,15 +42,6 @@ import java.util.concurrent.TimeUnit;
 public class CetPlugController {
     private final static Logger log = LoggerFactory.getLogger(CetPlugController.class);
 
-    @Value("${com.qmth.cet4.dir}")
-    String cet4Dir;
-
-    @Value("${com.qmth.cet6.dir}")
-    String cet6Dir;
-
-    @Value("${com.qmth.client.dir}")
-    String clientDir;
-
     @Resource
     LogicService logicService;
 
@@ -60,25 +51,7 @@ public class CetPlugController {
     @Aac(auth = false)
     public Result test() throws IOException, InterruptedException {
         log.info("test is come in");
-        long start = System.currentTimeMillis();
-        StringJoiner stringJoiner = new StringJoiner("");
-        String projectPath = System.getProperty("user.dir");
-        int cpuNum = Runtime.getRuntime().availableProcessors();
-        ExecutorService executor = Executors.newFixedThreadPool(Math.abs(cpuNum / 2));
-        if (Objects.nonNull(cet4Dir)) {
-            logicService.execFile(cet4Dir, projectPath, "cet4", executor);
-        }
-        if (Objects.nonNull(cet6Dir)) {
-            logicService.execFile(cet6Dir, projectPath, "cet6", executor);
-        }
-        executor.shutdown();
-        while (!executor.awaitTermination(1, TimeUnit.MINUTES)) {
-            log.info("线程池没有关闭");
-        }
-        log.info("线程池已经关闭");
-        long end = System.currentTimeMillis();
-        stringJoiner.add("============耗时============:").add((end - start) / 1000 + "").add("秒");
-        log.info("request:{}", stringJoiner.toString());
+        logicService.execLogic();
         return ResultUtil.ok();
     }
 }

+ 2 - 2
src/main/java/com/qmth/cet/plug/contant/SystemConstant.java

@@ -25,8 +25,8 @@ public class SystemConstant {
     public static final String PREFIX_URL_CET_PLUG = "/cet/plug";
     public static final String UPDATE_TIME = "updateTime";
     public static final String SUCCESS = "success";
-    public static final int MAX_QUERY_SIZE = 10;
-    public static final int LOCK_TIME_OUT = 1800000;
+    public static final int MAX_QUERY_SIZE = 1000;
+    public static final int LOCK_TIME_OUT = 1800000 * 2;
 
     /**
      * 获取nanoId

+ 8 - 0
src/main/java/com/qmth/cet/plug/service/ExeInvokerService.java

@@ -0,0 +1,8 @@
+package com.qmth.cet.plug.service;
+
+public interface ExeInvokerService {
+
+    boolean invokeExternalExe(String courseCode, String inputFilePath, String outputFilePath);
+}
+
+

+ 14 - 1
src/main/java/com/qmth/cet/plug/service/LogicService.java

@@ -19,6 +19,19 @@ public interface LogicService {
      * @param projectPath
      * @param rootDirName
      * @param executor
+     * @param cardPath
      */
-    void execFile(String fileName, String projectPath, String rootDirName, ExecutorService executor) throws IOException, InterruptedException;
+    void execFile(String fileName,
+                  String projectPath,
+                  String rootDirName,
+                  ExecutorService executor,
+                  String cardPath) throws IOException, InterruptedException;
+
+    /**
+     * 执行逻辑
+     *
+     * @throws IOException
+     * @throws InterruptedException
+     */
+    void execLogic() throws IOException, InterruptedException;
 }

+ 87 - 0
src/main/java/com/qmth/cet/plug/service/impl/ExeInvokerServiceImpl.java

@@ -0,0 +1,87 @@
+package com.qmth.cet.plug.service.impl;
+
+import com.qmth.cet.plug.service.ExeInvokerService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.concurrent.TimeUnit;
+
+@Service
+public class ExeInvokerServiceImpl implements ExeInvokerService {
+
+    private static final Logger logger = LoggerFactory.getLogger(ExeInvokerServiceImpl.class);
+
+    @Value("${com.qmth.client.dir}")
+    private String exePath;
+
+    /**
+     * @param courseCode     课程代码
+     * @param inputFilePath  待处理的文件路径
+     * @param outputFilePath 处理后的文件路径
+     */
+    @Override
+    public boolean invokeExternalExe(String courseCode, String inputFilePath, String outputFilePath) {
+        // 参数校验
+        if (courseCode == null || inputFilePath == null || outputFilePath == null) {
+            logger.error("参数不能为空");
+            return false;
+        }
+
+        if (exePath == null || exePath.trim().isEmpty()) {
+            logger.error("EXE路径未配置");
+            return false;
+        }
+
+        String[] commands = {exePath + File.separator + "omr.exe", courseCode, inputFilePath, outputFilePath};
+
+        Process process = null;
+        try {
+            ProcessBuilder processBuilder = new ProcessBuilder(commands);
+            processBuilder.directory(new File(exePath));
+            processBuilder.redirectErrorStream(true);
+            process = processBuilder.start();
+
+            StringBuilder output = new StringBuilder();
+            try (BufferedReader reader = new BufferedReader(
+                    new InputStreamReader(process.getInputStream()))) {
+                String line;
+                while ((line = reader.readLine()) != null) {
+                    output.append(line).append(System.lineSeparator());
+                }
+            }
+
+            // 设置超时时间,防止无限等待
+            boolean exited = process.waitFor(10, TimeUnit.MINUTES);
+            if (!exited) {
+                process.destroyForcibly();
+                logger.error("执行超时,已强制终止");
+                return false;
+            }
+
+            int exitCode = process.exitValue();
+            if (exitCode == 0) {
+                logger.info("执行成功!");
+                return true;
+            } else {
+                logger.error("执行失败!退出码:{},错误信息:{}", exitCode, output);
+                return false;
+            }
+        } catch (IOException | InterruptedException e) {
+            Thread.currentThread().interrupt(); // 重置中断状态
+            logger.error("调用EXE失败:{}", e.getMessage());
+            return false;
+        } finally {
+            // 显式关闭所有流
+            if (process != null) {
+                process.destroy();
+            }
+        }
+    }
+
+}

+ 238 - 80
src/main/java/com/qmth/cet/plug/service/impl/LogicServiceImpl.java

@@ -3,11 +3,13 @@ package com.qmth.cet.plug.service.impl;
 import com.qmth.cet.plug.contant.SystemConstant;
 import com.qmth.cet.plug.enums.ExceptionResultEnum;
 import com.qmth.cet.plug.lock.LockService;
+import com.qmth.cet.plug.service.ExeInvokerService;
 import com.qmth.cet.plug.service.LogicService;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
@@ -16,6 +18,8 @@ import java.io.*;
 import java.nio.charset.StandardCharsets;
 import java.util.*;
 import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 
@@ -30,9 +34,72 @@ import java.util.stream.Collectors;
 public class LogicServiceImpl implements LogicService {
     private final static Logger log = LoggerFactory.getLogger(LogicServiceImpl.class);
 
+    @Value("${com.qmth.cet4.dir}")
+    String cet4Dir;
+
+    @Value("${com.qmth.cet4.card}")
+    String cet4Card;
+
+    @Value("${com.qmth.cet6.dir}")
+    String cet6Dir;
+
+    @Value("${com.qmth.cet6.card}")
+    String cet6Card;
+
+    @Value("${com.qmth.fayu.dir}")
+    String fayuDir;
+
+    @Value("${com.qmth.fayu.card}")
+    String fayuCard;
+
+    @Value("${com.qmth.riyu4.dir}")
+    String riyu4Dir;
+
+    @Value("${com.qmth.riyu4.card}")
+    String riyu4Card;
+
+    @Value("${com.qmth.riyu6.dir}")
+    String riyu6Dir;
+
+    @Value("${com.qmth.riyu6.card}")
+    String riyu6Card;
+
+    @Value("${com.qmth.eyu4.dir}")
+    String eyu4Dir;
+
+    @Value("${com.qmth.eyu4.card}")
+    String eyu4Card;
+
+    @Value("${com.qmth.eyu6.dir}")
+    String eyu6Dir;
+
+    @Value("${com.qmth.eyu6.card}")
+    String eyu6Card;
+
+    @Value("${com.qmth.deyu4.dir}")
+    String deyu4Dir;
+
+    @Value("${com.qmth.deyu4.card}")
+    String deyu4Card;
+
+    @Value("${com.qmth.deyu6.dir}")
+    String deyu6Dir;
+
+    @Value("${com.qmth.deyu6.card}")
+    String deyu6Card;
+
+    @Value("${com.qmth.cpu.count}")
+    String cpuNumStr;
+
+    @Value("${com.qmth.overall.subdir}")
+    String overallSubdir;
+
     @Resource
     LockService lockService;
 
+    @Resource
+    ExeInvokerService exeInvokerService;
+
     /**
      * 执行解析数据
      *
@@ -40,12 +107,19 @@ public class LogicServiceImpl implements LogicService {
      * @param projectPath
      * @param rootDirName
      * @param executor
+     * @param cardPath
      */
     @Override
-    public void execFile(String fileName, String projectPath, String rootDirName, ExecutorService executor) throws IOException, InterruptedException {
+    public void execFile(String fileName, String projectPath, String rootDirName, ExecutorService executor, String cardPath) throws IOException, InterruptedException {
+        log.info("dirPath:{},cardPath:{}", fileName, cardPath);
         File mkdir = new File(fileName);
         if (!mkdir.exists()) {
-            throw ExceptionResultEnum.ERROR.exception(rootDirName + "目录不存在");
+//            throw ExceptionResultEnum.ERROR.exception(rootDirName + "目录不存在");
+            log.info("dirPath:[{}]未找到", fileName, cardPath);
+            return;
+        }
+        if (Objects.isNull(overallSubdir) || Objects.equals(overallSubdir, "")) {
+            throw ExceptionResultEnum.ERROR.exception("请配置全局子目录com.qmth.overall.subdir属性");
         }
         if (mkdir.isDirectory()) {
             File[] files = mkdir.listFiles();
@@ -55,9 +129,24 @@ public class LogicServiceImpl implements LogicService {
                     mkdirFileList = SystemConstant.analyzeDir(files[i], mkdirFileList);
                 }
                 log.info("mkdirFileList:{}", mkdirFileList);
+                //过滤子目录
+                overallSubdir = overallSubdir.replaceAll(",", ",");
+                String[] overallSubdirStrs = StringUtils.split(overallSubdir, ",");
+                List<File> mkdirFileTempList = new ArrayList<>(mkdirFileList.size());
+                for (File file : mkdirFileList) {
+                    String rootFilePath = file.getAbsolutePath();
+                    for (int i = 0; i < overallSubdirStrs.length; i++) {
+                        if (rootFilePath.endsWith(overallSubdirStrs[i])) {
+                            mkdirFileTempList.add(file);
+                        }
+                    }
+                }
+                if (!CollectionUtils.isEmpty(mkdirFileTempList)) {
+                    mkdirFileList.clear();
+                    mkdirFileList.addAll(mkdirFileTempList);
+                }
                 for (File file : mkdirFileList) {
-                    String rootPath = file.getAbsolutePath();
-                    rootPath = rootDirName + rootPath.replaceAll(fileName, "");
+                    String rootPath = rootDirName + fileName.substring(fileName.lastIndexOf(File.separator), fileName.length());
                     File root = new File(projectPath, rootPath);
                     if (!root.exists()) {
                         root.mkdirs();
@@ -68,12 +157,12 @@ public class LogicServiceImpl implements LogicService {
                     log.info("lockKey:{}", lockKey);
                     String finalRootPath = rootPath;
                     executor.submit(() -> {
-                        log.info("启动线程===>id:{},name:{}", Thread.currentThread().getId(), Thread.currentThread().getName());
+                        log.info("启动线程===>id:{},name:{}", Thread.currentThread().getId(), Thread.currentThread().getName());
                         for (; ; ) {
-                            boolean scanLock = lockService.lock(lockKey, lockKey, SystemConstant.LOCK_TIME_OUT);//30分钟
+                            boolean scanLock = lockService.lock(lockKey, lockKey, SystemConstant.LOCK_TIME_OUT);//60分钟
                             if (scanLock) {
                                 try {
-                                    this.scanTxtExecLogic(projectPath, finalRootPath, file);//扫描txt处理
+                                    this.scanTxtExecLogic(projectPath, finalRootPath, file, cardPath);//扫描txt处理
                                 } catch (Exception e) {
                                     log.error(SystemConstant.LOG_ERROR, e);
                                 } finally {
@@ -94,15 +183,80 @@ public class LogicServiceImpl implements LogicService {
         }
     }
 
+    /**
+     * 执行逻辑
+     *
+     * @throws IOException
+     * @throws InterruptedException
+     */
+    @Override
+    public void execLogic() throws IOException, InterruptedException {
+        log.info("execLogic is come in");
+        long start = System.currentTimeMillis();
+        StringJoiner stringJoiner = new StringJoiner("");
+        String projectPath = System.getProperty("user.dir");
+        int cpuNum = Runtime.getRuntime().availableProcessors();
+        if (Objects.nonNull(cpuNumStr) && !Objects.equals(cpuNumStr, "")) {
+            cpuNum = Integer.parseInt(cpuNumStr);
+        }
+        log.info("cpuNum:{}", cpuNum);
+        ExecutorService executor = Executors.newFixedThreadPool(Math.abs(cpuNum / 2));
+        if (Objects.nonNull(cet4Dir) && !Objects.equals(cet4Dir, "") &&
+                Objects.nonNull(cet4Card) && !Objects.equals(cet4Card, "")) {
+            this.execFile(cet4Dir, projectPath, "cet4", executor, cet4Card);
+        }
+        if (Objects.nonNull(cet6Dir) && !Objects.equals(cet6Dir, "") &&
+                Objects.nonNull(cet6Card) && !Objects.equals(cet6Card, "")) {
+            this.execFile(cet6Dir, projectPath, "cet6", executor, cet6Card);
+        }
+        if (Objects.nonNull(fayuDir) && !Objects.equals(fayuDir, "") &&
+                Objects.nonNull(fayuCard) && !Objects.equals(fayuCard, "")) {
+            this.execFile(fayuDir, projectPath, "fayu", executor, fayuCard);
+        }
+        if (Objects.nonNull(riyu4Dir) && !Objects.equals(riyu4Dir, "") &&
+                Objects.nonNull(riyu4Card) && !Objects.equals(riyu4Card, "")) {
+            this.execFile(riyu4Dir, projectPath, "riyu4", executor, riyu4Card);
+        }
+        if (Objects.nonNull(riyu6Dir) && !Objects.equals(riyu6Dir, "") &&
+                Objects.nonNull(riyu6Card) && !Objects.equals(riyu6Card, "")) {
+            this.execFile(riyu6Dir, projectPath, "riyu6", executor, riyu6Card);
+        }
+        if (Objects.nonNull(eyu4Dir) && !Objects.equals(eyu4Dir, "") &&
+                Objects.nonNull(eyu4Card) && !Objects.equals(eyu4Card, "")) {
+            this.execFile(eyu4Dir, projectPath, "eyu4", executor, eyu4Card);
+        }
+        if (Objects.nonNull(eyu6Dir) && !Objects.equals(eyu6Dir, "") &&
+                Objects.nonNull(eyu6Card) && !Objects.equals(eyu6Card, "")) {
+            this.execFile(eyu6Dir, projectPath, "eyu6", executor, eyu6Card);
+        }
+        if (Objects.nonNull(deyu4Dir) && !Objects.equals(deyu4Dir, "") &&
+                Objects.nonNull(deyu4Card) && !Objects.equals(deyu4Card, "")) {
+            this.execFile(deyu4Dir, projectPath, "deyu4", executor, deyu4Card);
+        }
+        if (Objects.nonNull(deyu6Dir) && !Objects.equals(deyu6Dir, "") &&
+                Objects.nonNull(deyu6Card) && !Objects.equals(deyu6Card, "")) {
+            this.execFile(deyu6Dir, projectPath, "deyu6", executor, deyu6Card);
+        }
+        executor.shutdown();
+        while (!executor.awaitTermination(1, TimeUnit.MINUTES)) {
+            log.info("线程池没有关闭");
+        }
+        log.info("线程池已经关闭");
+        long end = System.currentTimeMillis();
+        stringJoiner.add("============耗时============:").add((end - start) / 1000 + "").add("秒");
+        log.info("request:{}", stringJoiner.toString());
+    }
+
     /**
      * 扫描文件执行逻辑
      *
      * @param projectPath
      * @param rootPath
      * @param file
+     * @param cardPath
      * @throws IOException
      */
-    protected void scanTxtExecLogic(String projectPath, String rootPath, File file) throws IOException, InterruptedException {
+    protected void scanTxtExecLogic(String projectPath, String rootPath, File file, String cardPath) throws IOException, InterruptedException {
         //扫描txt处理
         File[] fileArray = file.listFiles();
         List<File> fileList = new ArrayList<>(Arrays.asList(fileArray));
@@ -149,7 +303,9 @@ public class LogicServiceImpl implements LogicService {
             }
 
             //temp临时目录
-            String tempDir = file.getAbsolutePath() + File.separator + "temp" + File.separator;
+            File tempDirFile = new File(projectPath, rootPath + File.separator + "temp");
+//            String tempDir = file.getAbsolutePath() + File.separator + "temp";
+            String tempDir = tempDirFile.getAbsolutePath();
             File tempFileDir = new File(tempDir);
             if (!tempFileDir.exists()) {
                 tempFileDir.mkdirs();
@@ -166,7 +322,7 @@ public class LogicServiceImpl implements LogicService {
                 } else {
                     IOUtils.write(scanSj.toString().getBytes(StandardCharsets.UTF_8), new FileOutputStream(tempScanTxt));
                 }
-                this.execCmd(tempScanTxt, tempScanResultTxt, projectPath, rootPath);
+                this.execCmd(cardPath, tempScanTxt, tempScanResultTxt, projectPath, rootPath);
             }
             if (max == size) {
                 break;
@@ -182,90 +338,92 @@ public class LogicServiceImpl implements LogicService {
     /**
      * 执行cmd
      *
+     * @param cardPath
      * @param tempScanTxt
      * @param tempScanResultTxt
      * @param projectPath
      * @param rootPath
      * @throws InterruptedException
+     * @throws IOException
      */
-    protected void execCmd(File tempScanTxt, File tempScanResultTxt, String projectPath, String rootPath) throws InterruptedException, IOException {
-        int randIntRange = new Random().nextInt(10);
-        Thread.sleep(1000 * randIntRange);
+    protected void execCmd(String cardPath, File tempScanTxt, File tempScanResultTxt, String projectPath, String rootPath) throws InterruptedException, IOException {
+//        int randIntRange = new Random().nextInt(10);
+//        Thread.sleep(1000 * randIntRange);
+//        ByteArrayOutputStream ou = new ByteArrayOutputStream();
+//        IOUtils.copy(new FileInputStream(tempScanTxt), ou);
+//        String string = new String(ou.toByteArray(), StandardCharsets.UTF_8);
+//        String[] strs = StringUtils.split(string, "\r\n");
+//        List<String> scanList = new ArrayList<>(Arrays.asList(strs));
+//        StringJoiner scanSj = new StringJoiner("\r\n");//全量扫描数据
+//        for (int i = 0; i < scanList.size(); i++) {
+//            String s = scanList.get(i);
+//            int range = new Random().nextInt(3);
+//            s += "," + range;
+//            scanSj.add(s);
+//            scanList.set(i, s);
+//        }
+//        IOUtils.write(scanSj.toString().getBytes(StandardCharsets.UTF_8), new FileOutputStream(tempScanResultTxt));
+
+        exeInvokerService.invokeExternalExe(cardPath, tempScanTxt.getAbsolutePath(), tempScanResultTxt.getAbsolutePath());
+        //读取扫描tempresult数据
         ByteArrayOutputStream ou = new ByteArrayOutputStream();
-        IOUtils.copy(new FileInputStream(tempScanTxt), ou);
+        IOUtils.copy(new FileInputStream(tempScanResultTxt), ou);
         String string = new String(ou.toByteArray(), StandardCharsets.UTF_8);
         String[] strs = StringUtils.split(string, "\r\n");
         List<String> scanList = new ArrayList<>(Arrays.asList(strs));
-        StringJoiner scanSj = new StringJoiner("\r\n");//全量扫描数据
-        for (int i = 0; i < scanList.size(); i++) {
-            String s = scanList.get(i);
-            //偶数
-            if (i % 2 == 0) {
-                s += ",0";
-                scanSj.add(s);
-            } else {
-                s += ",1";
-                scanSj.add(s);
-            }
-            scanList.set(i, s);
-        }
-        IOUtils.write(scanSj.toString().getBytes(StandardCharsets.UTF_8), new FileOutputStream(tempScanResultTxt));
 
-        //读取result数据
-        StringJoiner scanSuccessSj = new StringJoiner("\r\n");//全量扫描数据
-        StringJoiner scanErrorSj = new StringJoiner("\r\n");//全量扫描数据
+//        StringJoiner scanSuccessSj = new StringJoiner("\r\n");
+        StringJoiner scanCheckSj = new StringJoiner("\r\n");
         for (String s : scanList) {
-            if (s.endsWith("0")) {
-                scanSuccessSj.add(s);
-            } else if (s.endsWith("1")) {
-                scanErrorSj.add(s);
+            if (s.endsWith("1") || s.endsWith("2")) {
+                scanCheckSj.add(s);
             }
         }
-        this.successTxtExecLogic(projectPath, rootPath, scanSuccessSj);
-        this.errorTxtExecLogic(projectPath, rootPath, scanErrorSj);
+//        this.successTxtExecLogic(projectPath, rootPath, scanSuccessSj);
+        this.checkCsvExecLogic(projectPath, rootPath, scanCheckSj);
     }
 
-    /**
-     * 执行成功文件逻辑
-     *
-     * @param projectPath
-     * @param rootPath
-     * @throws IOException
-     */
-    protected void successTxtExecLogic(String projectPath, String rootPath, StringJoiner sj) throws IOException {
-        File successTxtFile = new File(projectPath, rootPath + File.separator + "success.txt");
-        if (!successTxtFile.exists()) {
-            successTxtFile.createNewFile();
-            IOUtils.write(sj.toString().getBytes(StandardCharsets.UTF_8), new FileOutputStream(successTxtFile));
-        } else {
-            //读取文件数据
-            ByteArrayOutputStream ou = new ByteArrayOutputStream();
-            IOUtils.copy(new FileInputStream(successTxtFile), ou);
-            String string = new String(ou.toByteArray(), StandardCharsets.UTF_8);
-            StringJoiner scanSj = new StringJoiner("\r\n");//全量扫描数据
-            scanSj.add(string);
-            String temp = new String(string);
-            String[] strs = StringUtils.split(temp, "\r\n");
-            List<String> scanList = new ArrayList<>(Arrays.asList(strs));
-            Map<String, String> scanMap = scanList.stream().collect(Collectors.toMap(m -> m, Function.identity()));
-
-            //读取传来的临时数据
-            String[] strsTemp = StringUtils.split(sj.toString(), "\r\n");
-            List<String> scanTempList = new ArrayList<>(Arrays.asList(strsTemp));
-
-            boolean write = false;
-            for (int y = 0; y < scanTempList.size(); y++) {
-                String path = scanTempList.get(y);
-                if (!scanMap.containsKey(path)) {
-                    scanSj.add(path);
-                    write = true;
-                }
-            }
-            if (write) {
-                IOUtils.write(scanSj.toString().getBytes(StandardCharsets.UTF_8), new FileOutputStream(successTxtFile));
-            }
-        }
-    }
+//    /**
+//     * 执行成功文件逻辑
+//     *
+//     * @param projectPath
+//     * @param rootPath
+//     * @throws IOException
+//     */
+//    protected void successTxtExecLogic(String projectPath, String rootPath, StringJoiner sj) throws IOException {
+//        File successTxtFile = new File(projectPath, rootPath + File.separator + "success.txt");
+//        if (!successTxtFile.exists()) {
+//            successTxtFile.createNewFile();
+//            IOUtils.write(sj.toString().getBytes(StandardCharsets.UTF_8), new FileOutputStream(successTxtFile));
+//        } else {
+//            //读取文件数据
+//            ByteArrayOutputStream ou = new ByteArrayOutputStream();
+//            IOUtils.copy(new FileInputStream(successTxtFile), ou);
+//            String string = new String(ou.toByteArray(), StandardCharsets.UTF_8);
+//            StringJoiner scanSj = new StringJoiner("\r\n");//全量扫描数据
+//            scanSj.add(string);
+//            String temp = new String(string);
+//            String[] strs = StringUtils.split(temp, "\r\n");
+//            List<String> scanList = new ArrayList<>(Arrays.asList(strs));
+//            Map<String, String> scanMap = scanList.stream().collect(Collectors.toMap(m -> m, Function.identity()));
+//
+//            //读取传来的临时数据
+//            String[] strsTemp = StringUtils.split(sj.toString(), "\r\n");
+//            List<String> scanTempList = new ArrayList<>(Arrays.asList(strsTemp));
+//
+//            boolean write = false;
+//            for (int y = 0; y < scanTempList.size(); y++) {
+//                String path = scanTempList.get(y);
+//                if (!scanMap.containsKey(path)) {
+//                    scanSj.add(path);
+//                    write = true;
+//                }
+//            }
+//            if (write) {
+//                IOUtils.write(scanSj.toString().getBytes(StandardCharsets.UTF_8), new FileOutputStream(successTxtFile));
+//            }
+//        }
+//    }
 
     /**
      * 执行错误文件逻辑
@@ -274,8 +432,8 @@ public class LogicServiceImpl implements LogicService {
      * @param rootPath
      * @throws IOException
      */
-    protected void errorTxtExecLogic(String projectPath, String rootPath, StringJoiner sj) throws IOException {
-        File errorTxtFile = new File(projectPath, rootPath + File.separator + "error.txt");
+    protected void checkCsvExecLogic(String projectPath, String rootPath, StringJoiner sj) throws IOException {
+        File errorTxtFile = new File(projectPath, rootPath + File.separator + "check.csv");
         if (!errorTxtFile.exists()) {
             errorTxtFile.createNewFile();
             IOUtils.write(sj.toString().getBytes(StandardCharsets.UTF_8), new FileOutputStream(errorTxtFile));

+ 21 - 1
src/main/java/com/qmth/cet/plug/start/StartRunning.java

@@ -1,10 +1,15 @@
 package com.qmth.cet.plug.start;
 
+import com.qmth.cet.plug.service.LogicService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.CommandLineRunner;
 import org.springframework.stereotype.Component;
 
+import javax.annotation.Resource;
+import java.util.Objects;
+
 /**
  * @Description: 服务启动时初始化运行,哪个微服务模块需要则拿此模版去用
  * @Param:
@@ -16,9 +21,24 @@ import org.springframework.stereotype.Component;
 public class StartRunning implements CommandLineRunner {
     private final static Logger log = LoggerFactory.getLogger(StartRunning.class);
 
+    @Resource
+    LogicService logicService;
+
+    @Value("${com.qmth.interval.time}")
+    String intervalTime;
+
     @Override
     public void run(String... args) throws Exception {
         log.info("服务器启动时执行 start");
-        log.info("服务器启动时执行 end");
+        intervalTime = Objects.isNull(intervalTime) || Objects.equals(intervalTime, "") ? "0" : intervalTime;
+        int intervalCount = Integer.parseInt(intervalTime);
+        if (intervalCount == 0) {
+            logicService.execLogic();
+        } else {
+            for (; ; ) {
+                logicService.execLogic();
+                Thread.sleep(1000 * intervalCount);
+            }
+        }
     }
 }

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

@@ -31,6 +31,26 @@ spring.jackson.time-zone=GMT+8
 com.qmth.logging.root-level=info
 com.qmth.logging.file-path=/Users/king/Downloads/cet-plug.log
 
+com.qmth.cpu.count=
 com.qmth.client.dir=/Users/king/Downloads
 com.qmth.cet4.dir=/Users/king/Downloads/cet4
-com.qmth.cet6.dir=/Users/king/Downloads/cet6
+com.qmth.cet4.card=/Users/king/Downloads/cet4
+com.qmth.cet6.dir=/Users/king/Downloads/cet6
+com.qmth.cet6.card=/Users/king/Downloads/cet6
+com.qmth.fayu.dir=/Users/king/Downloads/fayu
+com.qmth.fayu.card=/Users/king/Downloads/fayu
+com.qmth.riyu4.dir=/Users/king/Downloads/riyu4
+com.qmth.riyu4.card=/Users/king/Downloads/riyu4
+com.qmth.riyu6.dir=/Users/king/Downloads/riyu6
+com.qmth.riyu6.card=/Users/king/Downloads/riyu6
+com.qmth.eyu4.dir=/Users/king/Downloads/eyu4
+com.qmth.eyu4.card=/Users/king/Downloads/eyu4
+com.qmth.eyu6.dir=/Users/king/Downloads/eyu6
+com.qmth.eyu6.card=/Users/king/Downloads/eyu6
+com.qmth.deyu4.dir=/Users/king/Downloads/deyu4
+com.qmth.deyu4.card=/Users/king/Downloads/deyu4
+com.qmth.deyu6.dir=
+com.qmth.deyu6.card=/Users/king/Downloads/deyu6
+
+com.qmth.overall.subdir=scan01
+com.qmth.interval.time=1