Bladeren bron

发送计算接口增加相机校验,filepath字段改为链接

dsx 2 jaren geleden
bovenliggende
commit
0fde02023d
1 gewijzigde bestanden met toevoegingen van 22 en 6 verwijderingen
  1. 22 6
      src/main/java/com/fdkankan/contro/service/impl/SceneFileBuildServiceImpl.java

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

@@ -6,6 +6,7 @@ import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.core.util.ZipUtil;
+import cn.hutool.http.HttpUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -66,6 +67,8 @@ public class SceneFileBuildServiceImpl extends ServiceImpl<ISceneFileBuildMapper
 
     private static final String SPLICE = "#";
 
+    private static final String sendCallAlgorithmPath = "/mnt/sendCallAlgorithm/";
+
     @Value("${main.url}")
     private String mainUrl;
     @Value("${fyun.type}")
@@ -861,6 +864,20 @@ public class SceneFileBuildServiceImpl extends ServiceImpl<ISceneFileBuildMapper
 
         String zipFileName = filePath.substring(filePath.lastIndexOf("/") + 1);
         String zipName = FileUtil.mainName(zipFileName);
+        String snCode = zipName.split("_")[0];
+
+        Camera camera = cameraService.getByChildName(snCode);
+        if(Objects.isNull(camera)){
+            throw new BusinessException(ErrorCode.CAMERA_BIND_NO_EXIST.code(), "相机未入库");
+        }
+
+        String parentPath = sendCallAlgorithmPath.concat(zipName);
+        String localFilePath = parentPath.concat(File.separator).concat(zipFileName);
+        if(FileUtil.exist(parentPath)){
+            FileUtil.del(parentPath);
+        }
+        FileUtil.mkParentDirs(localFilePath);
+        HttpUtil.downloadFile(filePath, localFilePath);
 
         ScenePre scenePre = new ScenePre();
         scenePre.setZipPath(filePath);
@@ -870,22 +887,21 @@ public class SceneFileBuildServiceImpl extends ServiceImpl<ISceneFileBuildMapper
         scenePreService.save(scenePre);
 
         // 异步解压资源文件上传
-        String finalFilePath = FileUtil.getParent(filePath, 1);
         CompletableFuture.runAsync(() -> {
             try {
                 log.info("开始异步解压文件");
-                ZipFile zipFile = new ZipFile(new File(filePath));
+                ZipFile zipFile = new ZipFile(new File(localFilePath));
                 if (zipFile.isEncrypted()) {
                     String pwd = zipFileName.substring(0, 5).concat(zipFileName.substring(0, 5));
                     zipFile.setPassword(pwd);
-                    zipFile.extractAll(finalFilePath);
+                    zipFile.extractAll(parentPath);
                 } else {
-                    ZipUtil.unzip(filePath, finalFilePath);
+                    ZipUtil.unzip(localFilePath, parentPath);
                 }
 
                 // 读取本地文件并校验文件
                 // 读取config.json
-                String configJsonPath = finalFilePath.concat(File.separator).concat(zipName).concat(File.separator).concat("config.json");
+                String configJsonPath = parentPath.concat(File.separator).concat(zipName).concat(File.separator).concat("config.json");
                 log.info("config.json路径:{}", configJsonPath);
                 if(!FileUtil.exist(configJsonPath)){
                     throw new RuntimeException("config.json 文件有误!");
@@ -911,7 +927,7 @@ public class SceneFileBuildServiceImpl extends ServiceImpl<ISceneFileBuildMapper
                 scenePreService.updateById(scenePre);
                 log.info("异步开始上传文件");
                 // 上传oaas
-                fYunFileService.uploadFileByCommand(finalFilePath.concat(File.separator).concat(zipName), ConstantFilePath.OSS_PREFIX.concat(subFolder));
+                fYunFileService.uploadFileByCommand(parentPath.concat(File.separator).concat(zipName), ConstantFilePath.OSS_PREFIX.concat(subFolder));
 
                 scenePre.setOssPath(ConstantFilePath.OSS_PREFIX.concat(subFolder));