Browse Source

添加拷贝场景逻辑

tianboguang 3 years ago
parent
commit
ea3e74ed0c

+ 9 - 0
4dkankan-center-scene/src/main/java/com/fdkankan/scene/controller/SceneController.java

@@ -114,6 +114,15 @@ public class SceneController extends BaseController{
         return sceneFileBuildService.rebuildScene(num);
     }
 
+    /**
+     * 场景模型重新计算
+     */
+    @PostMapping(value = "/copyScene")
+    public ResultData copyScene(@RequestParam("num") String num,@RequestParam("newNum") String newNum) throws Exception {
+        sceneService.copyScene(num,newNum);
+        return ResultData.ok();
+    }
+
 
     /**
      * 场景模型重新计算

+ 2 - 0
4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/ISceneService.java

@@ -103,4 +103,6 @@ public interface ISceneService extends IService<Scene> {
     ResultData deleteScene(String sceneNum) throws IOException;
 
     Long getSceneCount(Long cameraId, Long userId);
+
+    void copyScene(String num,String newNum) throws IOException;
 }

+ 94 - 0
4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/impl/SceneServiceImpl.java

@@ -33,6 +33,7 @@ import com.fdkankan.scene.mapper.ISceneProMapper;
 import com.fdkankan.scene.service.*;
 import com.fdkankan.scene.vo.*;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.joda.time.DateTime;
 import org.springframework.beans.BeanUtils;
@@ -86,6 +87,22 @@ public class SceneServiceImpl extends ServiceImpl<ISceneMapper, Scene> implement
     PlatformUserClient platformUserClient;
     @Autowired
     ISceneService sceneService;
+
+    @Autowired
+    private IScenePlusService scenePlusService;
+
+    @Autowired
+    private IScenePlusExtService scenePlusExtService;
+
+    @Autowired
+    private ISceneEditInfoService sceneEditInfoService;
+
+    @Autowired
+    private ISceneEditInfoExtService sceneEditInfoExtService;
+
+    @Autowired
+    private ISceneEditControlsService sceneEditControlsService;
+
     @Autowired
     private ISceneDataDownloadService sceneDataDownloadService;
 
@@ -1319,4 +1336,81 @@ public class SceneServiceImpl extends ServiceImpl<ISceneMapper, Scene> implement
         }
         return this.count(queryWrapper);
     }
+
+    @Override
+    public void copyScene(String num,String newNum) throws IOException {
+        ScenePro scenePro = sceneProService.findBySceneNum(num);
+        if (ObjectUtils.isEmpty(scenePro)) {
+            return;
+        }
+
+        // 拷贝场景编辑资源
+        String oldEditPath = String.format(UploadFilePath.USER_EDIT_PATH, num);
+        String newEditPath = String.format(UploadFilePath.USER_EDIT_PATH, newNum);
+        uploadToOssUtil.copyFiles(oldEditPath,newEditPath);
+
+        // 拷贝场景展示资源
+        String oldViewPath = String.format(UploadFilePath.USER_VIEW_PATH, num);
+        String newViewPath = String.format(UploadFilePath.USER_VIEW_PATH, newNum);
+        uploadToOssUtil.copyFiles(oldViewPath,newViewPath);
+
+        // 拷贝本地资源
+        String oldPath = String.format("/mnt/4Dkankan/scene/%s/caches/images/", num);
+        String newPath = String.format("/mnt/4Dkankan/scene/%s/caches/images/", newNum);
+        FileUtils.copyDirectiory(oldPath,newPath);
+
+        // 拷贝数据
+        Long proId = scenePro.getId();
+        scenePro.setId(null);
+        scenePro.setWebSite(scenePro.getWebSite().replace(num,newNum));
+        scenePro.setSceneName(scenePro.getSceneName().concat("(copy)"));
+        scenePro.setThumb(scenePro.getThumb().replace(num,newNum));
+        scenePro.setVideos(scenePro.getVideos().replaceAll(num,newNum));
+        scenePro.setNum(newNum);
+        sceneProService.save(scenePro);
+
+        SceneProExt proExt = sceneProExtService.findBySceneProId(proId);
+        proExt.setDataSource(proExt.getDataSource().concat("_cp"));
+        proExt.setId(null);
+        proExt.setSceneProId(scenePro.getId());
+        sceneProExtService.save(proExt);
+
+        ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
+        Long plusId = scenePlus.getId();
+        scenePlus.setNum(newNum);
+        scenePlus.setId(null);
+        scenePlus.setTitle(scenePro.getSceneName());
+        scenePlusService.save(scenePlus);
+
+        ScenePlusExt plusExt = scenePlusExtService.getScenePlusExtByPlusId(plusId);
+        plusExt.setId(null);
+        plusExt.setPlusId(scenePlus.getId());
+        plusExt.setDataSource(plusExt.getDataSource().concat("_cp"));
+        plusExt.setWebSite(plusExt.getWebSite().replace(num,newNum));
+        plusExt.setThumb(plusExt.getThumb().replace(num,newNum));
+        plusExt.setVideos(plusExt.getVideos().replace(num,newNum));
+        scenePlusExtService.save(plusExt);
+
+        SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(plusId);
+        Long sceneEditInfoId = sceneEditInfo.getId();
+
+        sceneEditInfo.setId(null);
+        sceneEditInfo.setScenePlusId(scenePlus.getId());
+        sceneEditInfo.setSceneProId(scenePro.getId());
+        sceneEditInfo.setTitle(sceneEditInfo.getTitle().concat("(copy)"));
+        sceneEditInfoService.save(sceneEditInfo);
+
+        SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfoId);
+        sceneEditInfoExt.setId(null);
+        sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
+        sceneEditInfoExt.setScenePlusId(scenePlus.getId());
+        sceneEditInfoExt.setSceneProId(scenePro.getId());
+        sceneEditInfoExtService.save(sceneEditInfoExt);
+
+        SceneEditControls sceneEditControls = sceneEditControlsService.getBySceneEditId(sceneEditInfoId);
+        sceneEditControls.setId(null);
+        sceneEditControls.setEditInfoId(sceneEditInfo.getId());
+        sceneEditControlsService.save(sceneEditControls);
+
+    }
 }