浏览代码

2.0.0-2.0.1

dengsixing 10 小时之前
父节点
当前提交
6a3915a5cc

+ 7 - 0
pom.xml

@@ -195,6 +195,13 @@
       <version>1.5.19</version>
     </dependency>
 
+
+    <dependency>
+      <groupId>com.alibaba</groupId>
+      <artifactId>easyexcel</artifactId>
+      <version>4.0.3</version>
+    </dependency>
+
   </dependencies>
   <build>
     <finalName>${artifactId}</finalName>

+ 111 - 0
src/main/java/com/fdkankan/contro/entity/BuildLog.java

@@ -0,0 +1,111 @@
+package com.fdkankan.contro.entity;
+
+import com.baomidou.mybatisplus.annotation.*;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * <p>
+ *
+ * </p>
+ *
+ * @author
+ * @since 2022-04-07
+ */
+@Getter
+@Setter
+@TableName("t_build_log")
+public class BuildLog implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 主键
+     */
+    @TableId(value = "id", type = IdType.AUTO)
+    private Long id;
+
+    /**
+     * 消息id
+     */
+    @TableField("message_id")
+    private String messageId;
+
+    /**
+     * 消息id
+     */
+    @TableField("content")
+    private String content;
+
+    /**
+     * 场景码
+     */
+    @TableField("scene_num")
+    private String sceneNum;
+
+    /**
+     * 资源路径
+     */
+    @TableField("data_source")
+    private String dataSource;
+
+    /**
+     * 主题名称
+     */
+    @TableField("queue_name")
+    private String queueName;
+
+    /**
+     * ModelingBuildStatus
+     */
+    @TableField("status")
+    private Integer status;
+
+    /**
+     * 服务器名称
+     */
+    @TableField("host_name")
+    private String hostName;
+
+    /**
+     * 计算类型
+     * 0:场景计算
+     * 1:标定算法,
+     * 2:只生激光场景OBJ文件
+     * 3:生成e57
+     */
+    @TableField("build_type")
+    private Integer buildType;
+
+    /**
+     * 计算耗时
+     */
+    @TableField("duration")
+    private Long duration;
+
+    /**
+     * 开始计算时间
+     */
+    @TableField("create_time")
+    private Date createTime;
+
+    /**
+     * 结束计算时间
+     */
+    @TableField("update_time")
+    private Date updateTime;
+
+    /**
+     * 结束计算时间
+     */
+    @TableField("result_queue_name")
+    private String resultQuequeName;
+
+    @TableField("rec_status")
+    @TableLogic(value = "A", delval = "I")
+    private String recStatus;
+
+}

+ 18 - 0
src/main/java/com/fdkankan/contro/mapper/IBuildLogMapper.java

@@ -0,0 +1,18 @@
+package com.fdkankan.contro.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.fdkankan.contro.entity.BuildLog;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author 
+ * @since 2022-04-07
+ */
+@Mapper
+public interface IBuildLogMapper extends BaseMapper<BuildLog> {
+
+}

+ 3 - 0
src/main/java/com/fdkankan/contro/mapper/ISceneBuildProcessLogMapper.java

@@ -4,6 +4,8 @@ import com.fdkankan.contro.entity.SceneBuildProcessLog;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Mapper;
 
+import java.util.List;
+
 /**
  * <p>
  * 场景计算流程状态表 Mapper 接口
@@ -15,4 +17,5 @@ import org.apache.ibatis.annotations.Mapper;
 @Mapper
 public interface ISceneBuildProcessLogMapper extends BaseMapper<SceneBuildProcessLog> {
 
+    List<SceneBuildProcessLog> listByNum(String num);
 }

+ 16 - 0
src/main/java/com/fdkankan/contro/mq/service/IBuildLogService.java

@@ -0,0 +1,16 @@
+package com.fdkankan.contro.mq.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.fdkankan.contro.entity.BuildLog;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author 
+ * @since 2022-04-07
+ */
+public interface IBuildLogService extends IService<BuildLog> {
+
+}

+ 20 - 0
src/main/java/com/fdkankan/contro/mq/service/impl/BuildLogServiceImpl.java

@@ -0,0 +1,20 @@
+package com.fdkankan.contro.mq.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fdkankan.contro.entity.BuildLog;
+import com.fdkankan.contro.mapper.IBuildLogMapper;
+import com.fdkankan.contro.mq.service.IBuildLogService;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author 
+ * @since 2022-04-07
+ */
+@Service
+public class BuildLogServiceImpl extends ServiceImpl<IBuildLogMapper, BuildLog> implements IBuildLogService {
+
+}

+ 3 - 12
src/main/java/com/fdkankan/contro/mq/service/impl/BuildSceneServiceImpl.java

@@ -314,10 +314,7 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
                 reason = "前置处理异常";
             }
 
-            scenePlusService.update(new LambdaUpdateWrapper<ScenePlus>()
-                    .set(ScenePlus::getSceneStatus, SceneStatus.FAILD.code())
-                    .set(ScenePlus::getBuildFailReason, reason)
-                    .eq(ScenePlus::getNum, num));
+            jmgaService.updateSceneFailAndZipLog(num, reason);
 
             this.sendFailToLaser(num);
 
@@ -468,10 +465,7 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
             if (!message.getBuildSuccess()) {
                 log.error("建模失败,修改状态为失败状态");
                 if(count < 1){
-                    scenePlusService.update(new LambdaUpdateWrapper<ScenePlus>()
-                            .set(ScenePlus::getSceneStatus, SceneStatus.FAILD.code())
-                            .set(ScenePlus::getBuildFailReason, "算法报错")
-                            .eq(ScenePlus::getNum, sceneCode));
+                    jmgaService.updateSceneFailAndZipLog(sceneCode, "算法报错");
 
                     this.sendFailToLaser(sceneCode);
 
@@ -697,10 +691,7 @@ public class BuildSceneServiceImpl implements IBuildSceneService {
         }catch (Exception e){
             log.error("场景计算结果处理出错,num"+sceneCode, e);
 
-            scenePlusService.update(new LambdaUpdateWrapper<ScenePlus>()
-                    .set(ScenePlus::getSceneStatus, SceneStatus.FAILD.code())
-                    .set(ScenePlus::getBuildFailReason, "后置处理异常")
-                    .eq(ScenePlus::getNum, sceneCode));
+            jmgaService.updateSceneFailAndZipLog(sceneCode, "后置处理异常");
 
             this.sendFailToLaser(sceneCode);
 

+ 2 - 0
src/main/java/com/fdkankan/contro/service/IJmgaService.java

@@ -17,4 +17,6 @@ public interface IJmgaService {
 
     void noticeBuildBd(String ossHost, String uuid, String dir);
 
+    void updateSceneFailAndZipLog(String num, String failReason);
+
 }

+ 4 - 0
src/main/java/com/fdkankan/contro/service/ISceneBuildProcessLogService.java

@@ -3,6 +3,8 @@ package com.fdkankan.contro.service;
 import com.fdkankan.contro.entity.SceneBuildProcessLog;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.util.List;
+
 /**
  * <p>
  * 场景计算流程状态表 服务类
@@ -17,4 +19,6 @@ public interface ISceneBuildProcessLogService extends IService<SceneBuildProcess
 
     public void saveSceneBuildProcessLog(String num, String process, String queueName, int status, String reason);
 
+    public List<SceneBuildProcessLog> listByNum(String num);
+
 }

+ 1 - 1
src/main/java/com/fdkankan/contro/service/impl/CommonServiceImpl.java

@@ -17,7 +17,7 @@ import com.fdkankan.common.constant.SpaceType;
 import com.fdkankan.common.util.FileUtils;
 import com.fdkankan.contro.bean.SceneJsonBean;
 import com.fdkankan.contro.constant.RedisKeyExt;
-import com.fdkankan.contro.controller.DetectType;
+import com.fdkankan.contro.constant.DetectType;
 import com.fdkankan.contro.entity.*;
 import com.fdkankan.contro.factory.UserEditData.UserEditDataHandler;
 import com.fdkankan.contro.factory.UserEditData.UserEditDataHandlerFactory;

+ 88 - 3
src/main/java/com/fdkankan/contro/service/impl/JmgaServiceImpl.java

@@ -6,18 +6,20 @@ import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.lang.UUID;
 import cn.hutool.core.util.ZipUtil;
 import cn.hutool.http.HttpUtil;
+import com.alibaba.excel.EasyExcel;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.fdkankan.common.constant.ErrorCode;
+import com.fdkankan.common.constant.SceneStatus;
 import com.fdkankan.common.exception.BusinessException;
 import com.fdkankan.common.util.CmdUtils;
 import com.fdkankan.contro.bean.SendCallAlgorithmDetail;
 import com.fdkankan.contro.constant.ZipConstant;
-import com.fdkankan.contro.entity.OrigFileUpload;
-import com.fdkankan.contro.entity.OrigFileUploadBatch;
-import com.fdkankan.contro.entity.User;
+import com.fdkankan.contro.entity.*;
+import com.fdkankan.contro.mq.service.IBuildLogService;
 import com.fdkankan.contro.service.*;
 import com.fdkankan.contro.vo.SendCallAlgorithmParam;
 import com.fdkankan.contro.vo.UploadSceneOrigParamVo;
@@ -55,6 +57,14 @@ public class JmgaServiceImpl implements IJmgaService {
     private ISceneFileBuildService sceneFileBuildService;
     @Autowired
     private IUserService userService;
+    @Autowired
+    private IScenePlusService scenePlusService;
+    @Autowired
+    private IScenePlusExtService scenePlusExtService;
+    @Autowired
+    private ISceneBuildProcessLogService sceneBuildProcessLogService;
+    @Autowired
+    private IBuildLogService buildLogService;
 
     @Override
     public void checkFileWhole(String uuid, String dataSource, JSONObject fdageData) {
@@ -260,4 +270,79 @@ public class JmgaServiceImpl implements IJmgaService {
             HttpUtil.post("http://127.0.0.1:8085/api/scene/file/sendCallAlgorithm", JSON.toJSONString(param));
         });
     }
+
+    @Override
+    public void updateSceneFailAndZipLog(String num, String failReason) {
+        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";
+        //打包服务端日志
+        File[] ls = FileUtil.ls(logBasePath);
+        for (File l : ls) {
+            if(l.isFile() || !l.getName().startsWith("modeling-control")){
+                continue;
+            }
+            this.copyLog(l.getAbsolutePath(), tmpPath, "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)){
+                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);
+        }
+
+        //上传日志,删除本地压缩包
+        ZipUtil.zip(logPath, zipPath, false);
+        fYunFileService.uploadFile(zipPath, "build_log/");
+
+    }
+
+    private void copyLog(String serverPath, String tmpPath, String... levels){
+        level: for (String level : levels) {
+            String infoPath = serverPath + File.separator + level + File.separator;
+            List<File> fileList = FileUtil.loopFiles(infoPath);
+            if(CollUtil.isEmpty(fileList)){
+                continue;
+            }
+            CollUtil.reverse(fileList);
+            for (File file : fileList) {
+                int i = fileList.indexOf(file);
+                if(i > 7){
+                    continue level;
+                }
+                FileUtil.copy(file.getAbsolutePath(), file.getAbsolutePath().replace(FileUtil.getParent(serverPath, 1), tmpPath), true);
+            }
+        }
+    }
 }

+ 7 - 1
src/main/java/com/fdkankan/contro/service/impl/SceneBuildProcessLogServiceImpl.java

@@ -1,12 +1,13 @@
 package com.fdkankan.contro.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fdkankan.contro.entity.SceneBuildProcessLog;
 import com.fdkankan.contro.mapper.ISceneBuildProcessLogMapper;
 import com.fdkankan.contro.service.ISceneBuildProcessLogService;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
 import java.util.Objects;
 
 /**
@@ -47,4 +48,9 @@ public class SceneBuildProcessLogServiceImpl extends ServiceImpl<ISceneBuildProc
         log.setReason(reason);
         this.saveOrUpdate(log);
     }
+
+    @Override
+    public List<SceneBuildProcessLog> listByNum(String num) {
+        return this.getBaseMapper().listByNum(num);
+    }
 }

+ 3 - 3
src/main/java/com/fdkankan/contro/service/impl/SceneFileBuildServiceImpl.java

@@ -2606,9 +2606,9 @@ public class SceneFileBuildServiceImpl extends ServiceImpl<ISceneFileBuildMapper
 
             log.error("通知计算报错,uuid:{}", uuid, e);
             if(StrUtil.isNotEmpty(sceneNum)){
-                scenePlusService.update(new LambdaUpdateWrapper<ScenePlus>()
-                        .set(ScenePlus::getSceneStatus, SceneStatus.FAILD.code())
-                        .eq(ScenePlus::getNum, sceneNum));
+
+                jmgaService.updateSceneFailAndZipLog(sceneNum, "通知计算报错");
+
                 String buildLogPath = String.format(UploadFilePath.BUILD_LOG_PATH, sceneNum);
                 String preLogPath = buildLogPath + "noticeBuild-error-" + DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN) + ".log";
                 fYunFileService.uploadFile(ExceptionUtil.stacktraceToString(e).getBytes(StandardCharsets.UTF_8), preLogPath);

+ 1 - 1
src/main/java/com/fdkankan/contro/service/impl/SceneMarkShapeServiceImpl.java

@@ -7,7 +7,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.fdkankan.contro.controller.DetectType;
+import com.fdkankan.contro.constant.DetectType;
 import com.fdkankan.contro.entity.SceneMarkShape;
 import com.fdkankan.contro.entity.SceneShapeEnum;
 import com.fdkankan.contro.mapper.MarkShapeMapper;

+ 16 - 0
src/main/java/com/fdkankan/contro/util/ExcelUtil.java

@@ -0,0 +1,16 @@
+package com.fdkankan.contro.util;
+
+import com.alibaba.excel.EasyExcel;
+
+import java.util.List;
+
+public class ExcelUtil {
+
+    public static <T> void simpleWrite(List<T> list, String fileName, Class<T> clazz) {
+        // 注意 simpleWrite在数据量不大的情况下可以使用(5000以内,具体也要看实际情况),数据量大参照 重复多次写入
+        // 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
+        // 如果这里想使用03 则 传入excelType参数即可
+        EasyExcel.write(fileName, clazz).sheet("模板").doWrite(list);
+    }
+
+}

+ 2 - 2
src/main/resources/logback-nacos.xml

@@ -17,9 +17,9 @@
 	<!-- 定义日志保留天数 -->
 	<property name="MAX_HISTORY" value="180"/>
 	<!-- 定义日志文件总大小 -->
-	<property name="TOTAL_SIZE_CAP" value="10GB"/>
+	<property name="TOTAL_SIZE_CAP" value="20GB"/>
 	<!-- 定义单个日志文件大小 -->
-	<property name="MAX_FILE_SIZE" value="100MB"/>
+	<property name="MAX_FILE_SIZE" value="200MB"/>
 
 
 	<!-- 输出到控制台 -->

+ 4 - 0
src/main/resources/mapper/contro/SceneBuildProcessLogMapper.xml

@@ -2,4 +2,8 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.fdkankan.contro.mapper.ISceneBuildProcessLogMapper">
 
+
+    <select id="listByNum" resultType="com.fdkankan.contro.entity.SceneBuildProcessLog">
+        select * from t_scene_build_process_log where num = #{num}
+    </select>
 </mapper>