浏览代码

场景上传改造

dsx 1 年之前
父节点
当前提交
858973ffb6

+ 5 - 0
src/main/java/com/fdkankan/contro/controller/SceneFileController.java

@@ -208,5 +208,10 @@ public class SceneFileController{
         return sceneFileBuildService.uploadFile(param);
     }
 
+    @PostMapping("/noticeBuild")
+    public ResultData noticeBuild(String params) throws Exception {
+        return sceneFileBuildService.uploadSuccessBuild(params);
+    }
+
 
 }

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

@@ -13,4 +13,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface IOrigFileUploadBatchService extends IService<OrigFileUploadBatch> {
 
+    OrigFileUploadBatch getWaitingBatchByUuid(String uuid);
+
 }

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

@@ -2,6 +2,7 @@ package com.fdkankan.contro.service;
 
 import com.fdkankan.contro.entity.OrigFileUpload;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.fdkankan.contro.entity.OrigFileUploadBatch;
 
 /**
  * <p>
@@ -13,4 +14,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface IOrigFileUploadService extends IService<OrigFileUpload> {
 
+//    OrigFileUploadBatch
+
+
 }

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

@@ -36,4 +36,6 @@ public interface ISceneFileBuildService extends IService<SceneFileBuild> {
     ResultData sendCallAlgorithm(SendCallAlgorithmParam param) throws Exception;
 
     ResultData uploadFile(SendCallAlgorithmParam param) throws Exception;
+
+    ResultData noticeBuild(String params) throws Exception;
 }

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

@@ -1,5 +1,7 @@
 package com.fdkankan.contro.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.fdkankan.common.constant.CommonSuccessStatus;
 import com.fdkankan.contro.entity.OrigFileUploadBatch;
 import com.fdkankan.contro.mapper.IOrigFileUploadBatchMapper;
 import com.fdkankan.contro.service.IOrigFileUploadBatchService;
@@ -17,4 +19,8 @@ import org.springframework.stereotype.Service;
 @Service
 public class OrigFileUploadBatchServiceImpl extends ServiceImpl<IOrigFileUploadBatchMapper, OrigFileUploadBatch> implements IOrigFileUploadBatchService {
 
+    @Override
+    public OrigFileUploadBatch getWaitingBatchByUuid(String uuid) {
+        return this.getOne(new LambdaQueryWrapper<OrigFileUploadBatch>().eq(OrigFileUploadBatch::getUuid, uuid).in(OrigFileUploadBatch::getStatus, 0,1));
+    }
 }

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

@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.lang.UUID;
 import cn.hutool.core.thread.ThreadUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.core.util.ZipUtil;
@@ -230,6 +231,7 @@ public class SceneFileBuildServiceImpl extends ServiceImpl<ISceneFileBuildMapper
     private IOrigFileUploadService origFileUploadService;
 
     @Autowired
+    private IOrigFileUploadBatchService origFileUploadBatchService;
 
     @Override
     public SceneFileBuild findByFileId(String fileId) {
@@ -2207,8 +2209,11 @@ public class SceneFileBuildServiceImpl extends ServiceImpl<ISceneFileBuildMapper
     }
 
     public static void main(String[] args) throws Exception {
-        final String s = AesUtil.encryptCBC("Aa123456", "0000000856753656", "pwel781esd6wglxm", AesUtil.ALMODE_CBC_NOPADDING);
-        System.out.println(s);
+//        final String s = AesUtil.encryptCBC("Aa123456", "0000000856753656", "pwel781esd6wglxm", AesUtil.ALMODE_CBC_NOPADDING);
+//        System.out.println(s);
+//        System.out.println(UUID.fastUUID());
+
+
     }
 
     @Override
@@ -2234,23 +2239,113 @@ public class SceneFileBuildServiceImpl extends ServiceImpl<ISceneFileBuildMapper
             throw new BusinessException(ErrorCode.PARAM_REQUIRED.code(), "fileName不能为空");
         }
 
-        // TODO: 2023/11/22  查询是否有等待通知计算的上传记录,如果有则加入,没有则新增
-        Long uploadOperId = null;
+        //查询是否有等待通知计算的上传批次记录,如果有则加入,没有则新增
+        OrigFileUploadBatch origFileUploadBatch = origFileUploadBatchService.getWaitingBatchByUuid(uuid);
+        if(Objects.isNull(origFileUploadBatch)){
+            origFileUploadBatch = new OrigFileUploadBatch();
+            origFileUploadBatch.setUuid(uuid);
+            origFileUploadBatch.setBatchId(UUID.fastUUID().toString().replace("-", ""));
+            origFileUploadBatchService.save(origFileUploadBatch);
+        }
 
+        //插入上传明细表
+        OrigFileUpload origFileUpload = new OrigFileUpload();
+        origFileUpload.setFileUrl(filePath);
+        origFileUpload.setFileName(fileName);
+        origFileUpload.setBatchId(origFileUploadBatch.getBatchId());
+        origFileUploadService.save(origFileUpload);
 
-        // TODO: 2023/11/23 插入上传明细表
+        if(fileName.equals("config.json")){
+            HttpUtil.downloadFile(filePath, sendCallAlgorithmPath.concat(uuid).concat("/config.json"));
+            if(!FileUtil.exist(sendCallAlgorithmPath.concat(uuid).concat("/config.json"))){
+                throw new BusinessException(ErrorCode.FAILURE_CODE_4002.code(), ErrorCode.FAILURE_CODE_4002.formatMessage("config.json"));
+            }
+        }
+        if(fileName.equals("data.fdage")){
+            HttpUtil.downloadFile(filePath, sendCallAlgorithmPath.concat(uuid).concat("/data.fdage"));
+            if(!FileUtil.exist(sendCallAlgorithmPath.concat(uuid).concat("/config.json"))){
+                throw new BusinessException(ErrorCode.FAILURE_CODE_4002.code(), ErrorCode.FAILURE_CODE_4002.formatMessage("data.fdage"));
+            }
+        }
 
+        return ResultData.ok();
+    }
 
+    @Override
+    public ResultData noticeBuild(String uuid) throws Exception {
+        log.info("通知计算,uuid:{} " + uuid);
 
+        String[] uuidArr = uuid.split("_");
 
+        String snCode = uuidArr[0];
+        //获取fileId
+        String fileId = this.getFileId(snCode, uuid);
+        StringBuilder prefixBuffer = new StringBuilder(snCode).append(File.separator).append(fileId).append(File.separator).append(uuid).append(File.separator);
 
+        String buildType = "V2";
+        Long cameraType = 13L;//默认为看见相机
 
+        Camera camera = cameraService.getBySnCode(snCode);
+        if(Objects.isNull(camera)){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_7010);
+        }
+        CameraDetail cameraDetail = cameraDetailService.getByCameraId(camera.getId());
+        if(Objects.isNull(cameraDetail)){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_7010);
+        }
+        Integer camType = cameraDetail.getType();
+        if(camType == 10 || camType == 11){//深时或者深光
+            cameraType = 14L;
+        }else{
+            cameraType = 10L;
+        }
 
+//        if(!fYunFileService.fileExist(ConstantFilePath.OSS_PREFIX + prefixBuffer + "data.fdage")){
+//            log.error("data.fdage文件不存在");
+//            throw new BusinessException(CameraConstant.FAILURE_6009);
+//        }
+//
+//        JSONObject fdageJson = JSONObject.parseObject(fYunFileService.getFileContent(ConstantFilePath.OSS_PREFIX + prefixBuffer + "data.fdage"));
+//        if(ObjectUtils.isEmpty(fdageJson)){
+//            log.info("data.fdage文件为空!");
+//            throw new BusinessException(CameraConstant.FAILURE_6009);
+//        }
+//        //根据videoVersion判断是V2还是V3版本的算法和页面
+//        if (fdageJson.containsKey("videoVersion") && StrUtil.isNotEmpty(fdageJson.getString("videoVersion"))) {
+//            if (fdageJson.getIntValue("videoVersion") >= 4) {
+//                buildType = "V3";
+//                cameraType = 11L;
+//            }
+//        }
+
+//        buildScene(fileId, prefixBuffer.toString(),fdageJson,buildType,cameraType);
 
+        return ResultData.ok();
+    }
 
+    public String getFileId(String snCode, String uuid) throws Exception {
 
+        // 检测是否有生成
+        String fileId = null;
+        SceneFileBuild sceneFileBuild = this.findByUnicode(uuid);
+        if(Objects.nonNull(sceneFileBuild)){
+            fileId = sceneFileBuild.getFileId();
+            return fileId;
+        }
 
+        fileId = new SnowflakeIdGenerator(0, 0).nextId() + "";
+        log.info("新场景,fileid:{}", fileId);
 
-        return ResultData.ok();
+        sceneFileBuild = new SceneFileBuild();
+        sceneFileBuild.setChildName(snCode);
+        sceneFileBuild.setFileId(fileId);
+        sceneFileBuild.setRecStatus("A");
+        sceneFileBuild.setUnicode(uuid);
+        sceneFileBuild.setCreateTime(new Date());
+        this.save(sceneFileBuild);
+
+        return fileId;
     }
+
+
 }