Browse Source

增加下载球幕视频接口

dsx 2 years ago
parent
commit
cee9a47db3

+ 12 - 0
src/main/java/com/fdkankan/openApi/controller/www/SceneController.java

@@ -112,5 +112,17 @@ public class SceneController extends BaseController {
     public ResultData getSceneViewUserFile(@RequestBody @Validated BaseSceneParamVo param) {
         return ResultData.ok(scenePlusService.getSceneViewUserFile(param.getSceneCode(), this.getUserId()));
     }
+
+    /**
+     * 获取球幕视频
+     * @return
+     */
+    @SaIgnore
+    @PostMapping("/getSceneVideo")
+    @RedisLimit(name = "scene/getSceneVideo", limitCount = 1, period = 60)
+    @ValidateApi(method = "scene:getSceneVideo")
+    public ResultData getSceneVideo(@RequestBody @Validated BaseSceneParamVo param) {
+        return ResultData.ok(scenePlusService.getSceneVideo(param.getSceneCode(), this.getUserId()));
+    }
 }
 

+ 2 - 0
src/main/java/com/fdkankan/openApi/service/www/IScenePlusService.java

@@ -38,4 +38,6 @@ public interface IScenePlusService extends IService<ScenePlus> {
     List<String> getScenePanoramicImageFiles(String sceneCode);
 
     ResultData getSceneViewUserFile(String sceneCode, Long userId);
+
+    ResultData getSceneVideo(String sceneCode, Long userId);
 }

+ 58 - 0
src/main/java/com/fdkankan/openApi/service/www/impl/ScenePlusServiceImpl.java

@@ -450,4 +450,62 @@ public class ScenePlusServiceImpl extends ServiceImpl<IScenePlusMapper, ScenePlu
 
         return ResultData.ok(fYunFileConfig.getHost().concat(usesZipOssPath));
     }
+
+    @Override
+    public ResultData getSceneVideo(String sceneCode, Long userId) {
+        ScenePlus scenePlus = this.getByNumAndUserId(userId, sceneCode);
+        if (Objects.isNull(scenePlus)) {
+            scenePlus = sceneCooperationService.getCooperaSceneByUserIdAndNum(userId, sceneCode);
+            if(Objects.isNull(scenePlus)){
+                throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
+            }
+        }
+        if(Objects.isNull(scenePlus.getCameraId())){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_7010);
+        }
+        CameraDetail cameraDetail = cameraDetailService.getByCameraId(scenePlus.getCameraId());
+        Integer cameraType = cameraDetail.getType();
+        if(laserCamTypeList.contains(cameraType)){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_4004);
+        }
+
+        String userOssPath = String.format(UploadFilePath.VIDEOS_VIEW_PATH, scenePlus.getNum());
+        List<String> userFileList = fYunFileService.listRemoteFiles(userOssPath);
+        if(CollUtil.isEmpty(userFileList)){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_5027);
+        }
+        String userDowbloadPath = String.format(ConstantFilePath.OPENAPI_DOWNLOAD_PATH, scenePlus.getNum());
+        String userLocalPath = userDowbloadPath.concat("video");
+        String zipName = scenePlus.getNum().concat("_video.zip");
+        String usesZipPath = userDowbloadPath.concat(zipName);
+        fYunFileService.downloadFileByCommand(userLocalPath, userOssPath);
+        String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, sceneCode);
+        if(fYunFileService.fileExist(dataViewPath.concat("Up.xml"))){
+            fYunFileService.downloadFile(dataViewPath.concat("Up.xml"), userLocalPath.concat("Up.xml"));
+        }
+        if(fYunFileService.fileExist(dataViewPath.concat("Up2.xml"))){
+            fYunFileService.downloadFile(dataViewPath.concat("Up2.xml"), userLocalPath.concat("Up2.xml"));
+        }
+        if(fYunFileService.fileExist(dataViewPath.concat("Up.txt"))){
+            fYunFileService.downloadFile(dataViewPath.concat("Up.txt"), userLocalPath.concat("Up.txt"));
+        }
+        if(fYunFileService.fileExist(dataViewPath.concat("Up2.txt"))){
+            fYunFileService.downloadFile(dataViewPath.concat("Up2.txt"), userLocalPath.concat("Up2.txt"));
+        }
+        String sceneJson = redisUtil.get(String.format(RedisKey.SCENE_JSON, sceneCode));
+        if(StrUtil.isEmpty(sceneJson)){
+            sceneJson = fYunFileService.getFileContent(dataViewPath.concat("scene.json"));
+        }
+        SceneJsonBean sceneJsonBean = JSON.parseObject(sceneJson, SceneJsonBean.class);
+        if(StrUtil.isEmpty(sceneJsonBean.getVideos())){
+            sceneJsonBean.setVideos("{}");
+        }
+        FileUtil.writeUtf8String(sceneJsonBean.getVideos(), userLocalPath.concat("mapping.json"));
+
+        ZipUtil.zip(userLocalPath, usesZipPath);
+        String usesZipOssPath = String.format("downloads/scene/%s/video/", scenePlus.getNum()).concat(zipName);
+        fYunFileService.uploadFileByCommand(usesZipPath, usesZipOssPath);
+
+        return ResultData.ok(fYunFileConfig.getHost().concat(usesZipOssPath));
+    }
 }