Преглед на файлове

增加错误日志收集
通知计算接口 增加相机文件完整性校验

dengsixing преди 6 месеца
родител
ревизия
2bff844bc6

+ 17 - 0
src/main/java/com/fdkankan/contro/mq/listener/AbstrackBuildSceneListener.java

@@ -1,5 +1,7 @@
 package com.fdkankan.contro.mq.listener;
 
+import cn.hutool.core.date.DatePattern;
+import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.exceptions.ExceptionUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.fdkankan.common.constant.CommonOperStatus;
@@ -7,7 +9,9 @@ import com.fdkankan.contro.constant.RedisConstants;
 import com.fdkankan.contro.mq.service.IBuildSceneService;
 import com.fdkankan.contro.service.ICommonService;
 import com.fdkankan.contro.service.ISceneBuildProcessLogService;
+import com.fdkankan.fyun.face.FYunFileServiceInterface;
 import com.fdkankan.model.constants.SceneBuildProcessType;
+import com.fdkankan.model.constants.UploadFilePath;
 import com.fdkankan.rabbitmq.bean.BuildSceneCallMessage;
 import com.fdkankan.rabbitmq.bean.BuildSceneResultMqMessage;
 import com.fdkankan.redis.util.RedisLockUtil;
@@ -17,8 +21,11 @@ import org.springframework.amqp.core.Message;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.ObjectUtils;
 
+import javax.annotation.Resource;
+import java.io.File;
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
+import java.util.Date;
 import java.util.HashMap;
 
 @Slf4j
@@ -30,6 +37,8 @@ public class AbstrackBuildSceneListener implements IBuildSceneListener {
     private ISceneBuildProcessLogService sceneBuildProcessLogService;
     @Autowired
     private ICommonService commonService;
+    @Resource
+    private FYunFileServiceInterface fileServiceInterface;
 
     @Override
     public void preHandle(Channel channel, String queueName, Message message, IBuildSceneService buildSceneService) throws IOException {
@@ -65,6 +74,10 @@ public class AbstrackBuildSceneListener implements IBuildSceneListener {
         }catch (Exception e){
             log.error("场景计算前置处理出错,num=" + num, e);
             sceneBuildProcessLogService.saveSceneBuildProcessLog(num, SceneBuildProcessType.PRE.code(), queueName, CommonOperStatus.FAILD.code(), ExceptionUtil.stacktraceToString(e, 3000));
+
+            String buildLogPath = String.format(UploadFilePath.BUILD_LOG_PATH, num);
+            String preLogPath = buildLogPath + "pre-error-" + DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN) + ".log";
+            fileServiceInterface.uploadFile(ExceptionUtil.stacktraceToString(e).getBytes(StandardCharsets.UTF_8), preLogPath);
         }
         log.info("准备场景计算资源完成,队列名:{},id:{},消息体:{}", queueName, messageId, msg);
         channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
@@ -96,6 +109,10 @@ public class AbstrackBuildSceneListener implements IBuildSceneListener {
         }catch (Exception e){
             log.error("场景计算结果处理出错,num=" + num, e);
             sceneBuildProcessLogService.saveSceneBuildProcessLog(num, SceneBuildProcessType.POST.code(), queueName, CommonOperStatus.FAILD.code(), ExceptionUtil.stacktraceToString(e, 3000));
+
+            String buildLogPath = String.format(UploadFilePath.BUILD_LOG_PATH, num);
+            String preLogPath = buildLogPath + "post-error-" + DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN) + ".log";
+            fileServiceInterface.uploadFile(ExceptionUtil.stacktraceToString(e).getBytes(StandardCharsets.UTF_8), preLogPath);
         }
         log.info("场景计算结果处理完成,队列名:{},id:{},消息体:{}", queueName, messageId, msg);
         channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);

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

@@ -0,0 +1,9 @@
+package com.fdkankan.contro.service;
+
+import com.alibaba.fastjson.JSONObject;
+
+public interface IJmgaService {
+
+    void checkFileWhole(String uuid, String dataSource, JSONObject fdageData);
+
+}

+ 86 - 0
src/main/java/com/fdkankan/contro/service/impl/JmgaServiceImpl.java

@@ -0,0 +1,86 @@
+package com.fdkankan.contro.service.impl;
+
+import cn.hutool.core.collection.CollUtil;
+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.fdkankan.common.constant.ErrorCode;
+import com.fdkankan.common.exception.BusinessException;
+import com.fdkankan.contro.entity.OrigFileUpload;
+import com.fdkankan.contro.entity.OrigFileUploadBatch;
+import com.fdkankan.contro.service.IJmgaService;
+import com.fdkankan.contro.service.IOrigFileUploadBatchService;
+import com.fdkankan.contro.service.IOrigFileUploadService;
+import com.fdkankan.fyun.face.FYunFileServiceInterface;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+@Slf4j
+@Service
+public class JmgaServiceImpl implements IJmgaService {
+
+    @Autowired
+    private IOrigFileUploadBatchService origFileUploadBatchService;
+
+    @Autowired
+    private IOrigFileUploadService origFileUploadService;
+    @Resource
+    private FYunFileServiceInterface fileServiceInterface;
+
+    @Override
+    public void checkFileWhole(String uuid, String dataSource, JSONObject fdageData) {
+
+        int camType = fdageData.getJSONObject("cam").getIntValue("type");
+
+        //从data.fdage中获取需要上传的文件列表
+        JSONArray points = fdageData.getJSONArray("points");
+        if(CollUtil.isEmpty(points)){
+            return;
+        }
+
+        List<String> fileList = new ArrayList<>();
+        for (Object point : points) {
+            JSONObject pointJson = (JSONObject) point;
+            if(camType == 5){//圆周率相机
+                String name = pointJson.getString("name");
+                fileList.add(name);
+            }else{//四维相机
+                JSONArray imgs = pointJson.getJSONArray("imgs");
+                if(CollUtil.isEmpty(imgs)){
+                    continue;
+                }
+                for (Object img : imgs) {
+                    JSONObject imgJson = (JSONObject) img;
+                    String name = imgJson.getString("name");
+                    fileList.add(name);
+                }
+            }
+        }
+
+        //查询当前待通知计算批次文件是否存在
+        List<OrigFileUploadBatch> batchList = origFileUploadBatchService.list(new LambdaQueryWrapper<OrigFileUploadBatch>().eq(OrigFileUploadBatch::getUuid, uuid));
+        if(CollUtil.isNotEmpty(batchList)){
+            Set<String> batchIds = batchList.stream().map(v -> v.getBatchId()).collect(Collectors.toSet());
+            List<OrigFileUpload> origFileList = origFileUploadService.list(new LambdaQueryWrapper<OrigFileUpload>().in(OrigFileUpload::getBatchId, batchIds));
+            //过滤出不存在的
+            fileList = fileList.stream().filter(v -> origFileList.stream().noneMatch(k -> k.getFileName().equals(v))).collect(Collectors.toList());
+        }
+
+//        //查询oss文件目录是否存在
+//        String homePath = SceneUtil.getHomePath(dataSource);
+//        List<String> ossKeyList = fileServiceInterface.listRemoteFiles(homePath);
+//        fileList = fileList.stream().filter(v->ossKeyList.stream().noneMatch(k->FileUtil.getName(k).equals(v))).collect(Collectors.toList());
+//
+        if(CollUtil.isNotEmpty(fileList)){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_4001, ErrorCode.FAILURE_CODE_4001.formatMessage(JSON.toJSONString(fileList)));
+        }
+    }
+}

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

@@ -244,6 +244,9 @@ public class SceneFileBuildServiceImpl extends ServiceImpl<ISceneFileBuildMapper
     @Autowired
     private IOrigFileUploadBatchService origFileUploadBatchService;
 
+    @Autowired
+    private IJmgaService jmgaService;
+
     @Override
     public SceneFileBuild findByFileId(String fileId) {
 
@@ -2409,6 +2412,9 @@ public class SceneFileBuildServiceImpl extends ServiceImpl<ISceneFileBuildMapper
             throw new RuntimeException("config.json 文件有误!");
         }
 
+        //校验
+        jmgaService.checkFileWhole(uuid, dataSource, fdageData);
+
         //调注册用户接口
         Map<String, Object> params = new HashMap<>();
         params.put("ryId", customUserId);