فهرست منبع

Merge branch 'project-jmga-2.2.0' into project-jmga-dev

dengsixing 2 هفته پیش
والد
کامیت
ddda742c34
1فایلهای تغییر یافته به همراه89 افزوده شده و 61 حذف شده
  1. 89 61
      src/main/java/com/fdkankan/contro/service/impl/JmgaServiceImpl.java

+ 89 - 61
src/main/java/com/fdkankan/contro/service/impl/JmgaServiceImpl.java

@@ -406,67 +406,100 @@ public class JmgaServiceImpl implements IJmgaService {
 
     @Override
     public void updateSceneFailAndZipLog(String num, String failReason) throws IOException {
-        scenePlusService.update(new LambdaUpdateWrapper<ScenePlus>()
-                .set(ScenePlus::getSceneStatus, SceneStatus.FAILD.code())
-                .set(ScenePlus::getBuildFailReason, failReason)
-                .eq(ScenePlus::getNum, num));
-
-        String logBasePath = File.separator + "mnt" + File.separator + "logs" + File.separator;
-        String tmpPath = logBasePath + "tmp" + File.separator;
-        String logPath = tmpPath + num + "-" + Calendar.getInstance().getTimeInMillis() + File.separator;
-        String zipPath = tmpPath + num + "-" + Calendar.getInstance().getTimeInMillis() + ".zip";
-        FileUtil.mkdir(logPath);
-        //打包服务端日志
-        File[] ls = FileUtil.ls(logBasePath);
-        for (File l : ls) {
-            if(l.isFile() || !l.getName().startsWith("modeling-control")){
-                continue;
+        String logPath = null;
+        String zipPath = null;
+        try {
+            scenePlusService.update(new LambdaUpdateWrapper<ScenePlus>()
+                    .set(ScenePlus::getSceneStatus, SceneStatus.FAILD.code())
+                    .set(ScenePlus::getBuildFailReason, failReason)
+                    .eq(ScenePlus::getNum, num));
+
+            String logBasePath = File.separator + "mnt" + File.separator + "logs" + File.separator;
+            String tmpPath = logBasePath + "tmp" + File.separator;
+            logPath = tmpPath + num + "-" + Calendar.getInstance().getTimeInMillis() + File.separator;
+            zipPath = tmpPath + num + "-" + Calendar.getInstance().getTimeInMillis() + ".zip";
+            FileUtil.mkdir(logPath);
+            //打包服务端日志
+            // 获取所有以 modeling-control 开头的目录
+            File baseDir = new File(logBasePath);
+            List<File> allFiles = new ArrayList<>();
+            File[] modelingDirs = baseDir.listFiles(f ->
+                    f.isDirectory() && f.getName().startsWith("modeling-control")
+            );
+            if (modelingDirs != null) {
+                for (File dir : modelingDirs) {
+                    collectFiles(dir, allFiles);
+                }
             }
-            this.copyLog(l.getAbsolutePath(), logPath, "info","sql","error");
-        }
-        //打包算法日志
-        ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
-        ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
-        String consoleLogPath = scenePlusExt.getDataSource() + "/console.log";
-        String consoleOldLogPath = scenePlusExt.getDataSource() + "/console.old.log";
-        if(FileUtil.exist(consoleLogPath)){
-            FileUtil.copy(consoleLogPath, logPath,true);
-        }
-        if(FileUtil.exist(consoleOldLogPath)){
-            FileUtil.copy(consoleOldLogPath, logPath,true);
-        }
-        //打包数据库记录
-        String[] split = scenePlusExt.getDataSource().split("/");
-        String uuid = split[split.length -1];
-        List<OrigFileUploadBatch> batchList = origFileUploadBatchService.list(new LambdaQueryWrapper<OrigFileUploadBatch>().eq(OrigFileUploadBatch::getUuid, uuid));
-        if(CollUtil.isNotEmpty(batchList)){
-            EasyExcel.write(logPath.concat("origFileUploadBatch.xlsx"), OrigFileUploadBatch.class).sheet("origFileUploadBatch").doWrite(batchList);
-            List<String> batchIdList = batchList.stream().map(v -> v.getBatchId()).collect(Collectors.toList());
-            List<OrigFileUpload> uploadList = origFileUploadService.list(new LambdaQueryWrapper<OrigFileUpload>().in(OrigFileUpload::getBatchId, batchIdList));
-            if(CollUtil.isNotEmpty(uploadList)){
-                uploadList.stream().forEach(v->{
-                    v.setFileUrl(v.getFileUrl().replaceAll(ipv4Pattern, "ip"));
-                });
-                EasyExcel.write(logPath.concat("origFileUpload.xlsx"), OrigFileUpload.class).sheet("origFileUpload").doWrite(uploadList);
+            for (File l : allFiles) {
+                this.copyLog(l.getAbsolutePath(), logPath, "info","sql","error");
+            }
+            //打包算法日志
+            ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
+            ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
+            String consoleLogPath = scenePlusExt.getDataSource() + "/console.log";
+            String consoleOldLogPath = scenePlusExt.getDataSource() + "/console.old.log";
+            if(FileUtil.exist(consoleLogPath)){
+                FileUtil.copy(consoleLogPath, logPath,true);
+            }
+            if(FileUtil.exist(consoleOldLogPath)){
+                FileUtil.copy(consoleOldLogPath, logPath,true);
+            }
+            //打包数据库记录
+            String[] split = scenePlusExt.getDataSource().split("/");
+            String uuid = split[split.length -1];
+            List<OrigFileUploadBatch> batchList = origFileUploadBatchService.list(new LambdaQueryWrapper<OrigFileUploadBatch>().eq(OrigFileUploadBatch::getUuid, uuid));
+            if(CollUtil.isNotEmpty(batchList)){
+                EasyExcel.write(logPath.concat("origFileUploadBatch.xlsx"), OrigFileUploadBatch.class).sheet("origFileUploadBatch").doWrite(batchList);
+                List<String> batchIdList = batchList.stream().map(v -> v.getBatchId()).collect(Collectors.toList());
+                List<OrigFileUpload> uploadList = origFileUploadService.list(new LambdaQueryWrapper<OrigFileUpload>().in(OrigFileUpload::getBatchId, batchIdList));
+                if(CollUtil.isNotEmpty(uploadList)){
+                    uploadList.stream().forEach(v->{
+                        v.setFileUrl(v.getFileUrl().replaceAll(ipv4Pattern, "ip"));
+                    });
+                    EasyExcel.write(logPath.concat("origFileUpload.xlsx"), OrigFileUpload.class).sheet("origFileUpload").doWrite(uploadList);
+                }
+            }
+            List<SceneBuildProcessLog> processLogList = sceneBuildProcessLogService.listByNum(num);
+            if(CollUtil.isNotEmpty(processLogList)){
+                EasyExcel.write(logPath.concat("sceneBuildProcessLog.xlsx"), SceneBuildProcessLog.class).sheet("sceneBuildProcessLog").doWrite(processLogList);
+            }
+            List<BuildLog> buildLogList = buildLogService.list(new LambdaQueryWrapper<BuildLog>().eq(BuildLog::getSceneNum, num));
+            if(CollUtil.isNotEmpty(buildLogList)){
+                EasyExcel.write(logPath.concat("buildLog.xlsx"), BuildLog.class).sheet("buildLog").doWrite(buildLogList);
             }
-        }
-        List<SceneBuildProcessLog> processLogList = sceneBuildProcessLogService.listByNum(num);
-        if(CollUtil.isNotEmpty(processLogList)){
-            EasyExcel.write(logPath.concat("sceneBuildProcessLog.xlsx"), SceneBuildProcessLog.class).sheet("sceneBuildProcessLog").doWrite(processLogList);
-        }
-        List<BuildLog> buildLogList = buildLogService.list(new LambdaQueryWrapper<BuildLog>().eq(BuildLog::getSceneNum, num));
-        if(CollUtil.isNotEmpty(buildLogList)){
-            EasyExcel.write(logPath.concat("buildLog.xlsx"), BuildLog.class).sheet("buildLog").doWrite(buildLogList);
-        }
 
-        //上传日志,删除本地压缩包
-        ZipUtil.zip(logPath, zipPath, false);
-        String logName = "build_log/" + num + "/" + num + "-log.zip";
-        if(fYunFileService.fileExist(logName)){
-            fYunFileService.copyFileInBucket(logName, logName + "-bak-" + DateExtUtil.format(Calendar.getInstance().getTime(), DateExtUtil.dateStyle11));
+            //上传日志,删除本地压缩包
+            ZipUtil.zip(logPath, zipPath, false);
+            String logName = "build_log/" + num + "/" + num + "-log.zip";
+            if(fYunFileService.fileExist(logName)){
+                fYunFileService.copyFileInBucket(logName, logName + "-bak-" + DateExtUtil.format(Calendar.getInstance().getTime(), DateExtUtil.dateStyle11));
+            }
+            fYunFileService.uploadFile(zipPath, logName);
+        }catch (Exception e){
+            log.error("打包日志报错,num:{}", num, e);
+        }finally {
+            if(StrUtil.isNotEmpty(logPath) && FileUtil.exist(logPath)){
+                FileUtil.del(logPath);
+            }
+            if(StrUtil.isNotEmpty(zipPath) && FileUtil.exist(zipPath)){
+                FileUtil.del(zipPath);
+            }
         }
-        fYunFileService.uploadFile(zipPath, logName);
+    }
+
+    // 递归收集文件列表
+    private static void collectFiles(File dir, List<File> fileList) {
+        File[] files = dir.listFiles();
+        if (files == null) return;
 
+        for (File file : files) {
+            if (file.isDirectory()) {
+                collectFiles(file, fileList);
+            } else {
+                fileList.add(file);
+            }
+        }
     }
 
     private void copyLog(String serverPath, String tmpPath, String... levels) throws IOException {
@@ -485,11 +518,6 @@ public class JmgaServiceImpl implements IJmgaService {
                 String targetPath = file.getAbsolutePath().replace(FileUtil.getParent(serverPath, 1), tmpPath);
                 File targetLog = new File(targetPath);
                 targetLog.createNewFile();
-//                FileUtil.copy(file.getAbsolutePath(), targetPath, true);
-//                String content = FileUtil.readUtf8String(targetPath);
-//                content = content.replace("公安", "xx").replaceAll(ipv4Pattern, "ip");
-//                FileUtil.writeUtf8String(content, targetPath);
-
                 try (Stream<String> lines = Files.lines(Paths.get(file.getAbsolutePath()), StandardCharsets.UTF_8)) {
                     lines.map(line -> line.replace("公安", "xx").replaceAll(ipv4Pattern, "ip"))
                             .forEach(line -> FileUtil.appendUtf8String(line, targetLog)); // 或者进行其他处理