|
@@ -7,11 +7,16 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fdkankan.common.constant.ConstantFilePath;
|
|
|
import com.fdkankan.common.constant.ErrorCode;
|
|
|
+import com.fdkankan.common.constant.SceneConstant;
|
|
|
+import com.fdkankan.common.constant.UploadFilePath;
|
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
|
import com.fdkankan.common.response.PageInfo;
|
|
|
import com.fdkankan.common.util.CreateObjUtil;
|
|
|
import com.fdkankan.common.util.FileUtils;
|
|
|
+import com.fdkankan.common.util.MatrixToImageWriterUtil;
|
|
|
+import com.fdkankan.common.util.RandomUtil;
|
|
|
import com.fdkankan.fyun.oss.UploadToOssUtil;
|
|
|
+import com.fdkankan.manage.common.CameraConstant;
|
|
|
import com.fdkankan.manage.entity.*;
|
|
|
import com.fdkankan.manage.mapper.ISceneProMapper;
|
|
|
import com.fdkankan.manage.service.*;
|
|
@@ -23,11 +28,14 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -55,11 +63,29 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
ISceneProEditService sceneProEditService;
|
|
|
@Autowired
|
|
|
private UploadToOssUtil uploadToOssUtil;
|
|
|
+ @Autowired
|
|
|
+ IScenePlusService scenePlusService;
|
|
|
+ @Autowired
|
|
|
+ IScene3dNumService scene3dNumService;
|
|
|
+ @Autowired
|
|
|
+ ISceneCopyLogService sceneCopyLogService;
|
|
|
+ @Autowired
|
|
|
+ IScenePlusExtService scenePlusExtService;
|
|
|
+
|
|
|
+ @Value("${main.url}")
|
|
|
+ private String mainUrl;
|
|
|
+
|
|
|
+ @Value("${scene.pro.url}")
|
|
|
+ private String sceneProUrl;
|
|
|
+
|
|
|
+ @Value("${scene.pro.new.url}")
|
|
|
+ private String sceneProNewUrl;
|
|
|
|
|
|
@Override
|
|
|
public ScenePro getByNum(String num) {
|
|
|
LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.eq(ScenePro::getNum,num);
|
|
|
+ wrapper.eq(ScenePro::getIsUpgrade,0);
|
|
|
List<ScenePro> list = this.list(wrapper);
|
|
|
if(list == null || list.size() <=0){
|
|
|
return null;
|
|
@@ -88,6 +114,7 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
LambdaUpdateWrapper<ScenePro> wrapper = new LambdaUpdateWrapper<>();
|
|
|
wrapper.set(ScenePro::getUserId,null)
|
|
|
.eq(ScenePro::getCameraId,cameraId);
|
|
|
+ wrapper.eq(ScenePro::getIsUpgrade,0);
|
|
|
this.update(wrapper);
|
|
|
}
|
|
|
|
|
@@ -95,6 +122,7 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
public List<ScenePro> getListByCameraId(Long cameraId) {
|
|
|
LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.eq(ScenePro::getCameraId,cameraId);
|
|
|
+ wrapper.eq(ScenePro::getIsUpgrade,0);
|
|
|
return this.list(wrapper);
|
|
|
}
|
|
|
|
|
@@ -187,14 +215,22 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
throw new BusinessException(-1,"sn码不存在。");
|
|
|
}
|
|
|
ScenePro scenePro = this.getByNum(param.getNum());
|
|
|
- if(scenePro == null){
|
|
|
- throw new BusinessException(-1,"场景不存在");
|
|
|
+ ScenePlus scenePlus = scenePlusService.getByNum(param.getNum());
|
|
|
+ if((scenePro == null || scenePro.getCameraId() == null ) && (scenePlus== null || scenePlus.getCameraId() == null)){
|
|
|
+ throw new BusinessException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
|
|
|
}
|
|
|
- Long newUseSpace = scenePro.getSpace() + cameraDetail.getUsedSpace();
|
|
|
+
|
|
|
+ Long cameraId = scenePro == null ? scenePlus.getCameraId() : scenePro.getCameraId();
|
|
|
+ Long space = scenePro == null ? 0 :scenePro.getSpace();
|
|
|
+ if(scenePlus !=null){
|
|
|
+ ScenePlusExt scenePlusExt = scenePlusExtService.getByPlusId(scenePlus.getId());
|
|
|
+ space = scenePlusExt.getSpace();
|
|
|
+ }
|
|
|
+ Long newUseSpace = space + cameraDetail.getUsedSpace();
|
|
|
if(newUseSpace > cameraDetail.getTotalSpace()){
|
|
|
throw new BusinessException(-1,"相机容量不足,不能迁移");
|
|
|
}
|
|
|
- Camera oldCamera = cameraService.getById(scenePro.getCameraId());
|
|
|
+ Camera oldCamera = cameraService.getById(cameraId);
|
|
|
if(oldCamera == null){
|
|
|
throw new BusinessException(-1,"旧相机不存在");
|
|
|
}
|
|
@@ -205,7 +241,7 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
if(!oldCameraDetail.getType().equals(cameraDetail.getType())){
|
|
|
throw new BusinessException(-1,"必须迁移至相同的类型的相机下面!");
|
|
|
}
|
|
|
- Long oldUseSpace = oldCameraDetail.getUsedSpace() - scenePro.getSpace() < 0 ? 0 : oldCameraDetail.getUsedSpace() - scenePro.getSpace();
|
|
|
+ Long oldUseSpace = oldCameraDetail.getUsedSpace() - space < 0 ? 0 : oldCameraDetail.getUsedSpace() - space;
|
|
|
oldCameraDetail.setUsedSpace(oldUseSpace);
|
|
|
Long subSpace = oldCameraDetail.getTotalSpace() - oldUseSpace;
|
|
|
if(subSpace >0){ //有剩余容量解封容量内场景
|
|
@@ -217,102 +253,138 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
cameraDetail.setUsedSpace(newUseSpace);
|
|
|
cameraDetailService.updateById(cameraDetail);
|
|
|
|
|
|
- scenePro.setCameraId(camera.getId());
|
|
|
- scenePro.setUserId(cameraDetail.getUserId());
|
|
|
- this.updateById(scenePro);
|
|
|
+ if(scenePro!=null){
|
|
|
+ scenePro.setCameraId(camera.getId());
|
|
|
+ scenePro.setUserId(cameraDetail.getUserId());
|
|
|
+ this.updateById(scenePro);
|
|
|
+ }
|
|
|
+ if(scenePlus!=null){
|
|
|
+ scenePlus.setCameraId(camera.getId());
|
|
|
+ scenePlus.setUserId(cameraDetail.getUserId());
|
|
|
+ scenePlusService.updateById(scenePlus);
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void copy(String sceneNum) {
|
|
|
- ScenePro sourceScene = this.getByNum(sceneNum);
|
|
|
- if(sourceScene == null){
|
|
|
- throw new BusinessException(ErrorCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
- }
|
|
|
- Long count = copyLogService.getCountBySceneNum(sceneNum);
|
|
|
- String newNum = sourceScene.getNum() + "-cp-" + count + 1; //复制场景在原场景上添加标识
|
|
|
- ScenePro targetScene = new ScenePro();
|
|
|
- BeanUtils.copyProperties(sourceScene,targetScene);
|
|
|
- targetScene.setId(null);
|
|
|
- targetScene.setNum(newNum);
|
|
|
- targetScene.setWebSite(sourceScene.getWebSite().replace(sceneNum, newNum));
|
|
|
- targetScene.setThumb(sourceScene.getThumb().replace(sceneNum, newNum));
|
|
|
- //更新video
|
|
|
- HashMap<String,Object> map = new HashMap<>();
|
|
|
- JSONObject object = new JSONObject();
|
|
|
- if(StringUtils.isNotEmpty(sourceScene.getVideos())){
|
|
|
- object = JSONObject.parseObject(sourceScene.getVideos());
|
|
|
- if(object.containsKey("upPath")){
|
|
|
- String upPath = object.getString("upPath");
|
|
|
-
|
|
|
- upPath = upPath.replace(sceneNum,newNum);
|
|
|
- object.put("upPath",upPath);
|
|
|
- }
|
|
|
- targetScene.setVideos(object.toJSONString());
|
|
|
- map.put("videos",targetScene.getVideos());
|
|
|
- }
|
|
|
- this.save(targetScene);
|
|
|
- SceneProEdit oldEditScene = sceneProEditService.getByProId(sourceScene.getId());
|
|
|
- if(oldEditScene != null){
|
|
|
- oldEditScene.setId(null);
|
|
|
- oldEditScene.setProId(sourceScene.getId());
|
|
|
- oldEditScene.setScreencapVoiceSrc(oldEditScene.getScreencapVoiceSrc() == null ? null : oldEditScene.getScreencapVoiceSrc().replace(sceneNum, newNum));
|
|
|
- oldEditScene.setScreencapVoiceSound(oldEditScene.getScreencapVoiceSound() == null ? null : oldEditScene.getScreencapVoiceSound().replace(sceneNum, newNum));
|
|
|
- oldEditScene.setScreencapVoiceSoundsync(oldEditScene.getScreencapVoiceSoundsync() == null ? null : oldEditScene.getScreencapVoiceSoundsync().replace(sceneNum, newNum));
|
|
|
- oldEditScene.setPlayData(oldEditScene.getPlayData() == null ? null : oldEditScene.getPlayData().replace(sceneNum, newNum));
|
|
|
- oldEditScene.setScreencapThumb(oldEditScene.getScreencapThumb() == null ? null : oldEditScene.getScreencapThumb().replace(sceneNum, newNum));
|
|
|
- oldEditScene.setFloorPlanPng(oldEditScene.getFloorPlanPng() == null ? null : oldEditScene.getFloorPlanPng().replace(sceneNum, newNum));
|
|
|
- sceneProEditService.save(oldEditScene);
|
|
|
- }
|
|
|
- new Thread(){
|
|
|
- //重写run方法
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- try{
|
|
|
- log.info("开始复制场景-{}", new Date());
|
|
|
- //oss复制资源
|
|
|
- downloadFromOldNumFromOss(sceneNum, newNum);
|
|
|
- // 复制本地secen.json
|
|
|
- copyOldSceneLocalToNew(sceneNum, newNum);
|
|
|
-
|
|
|
- FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + newNum + File.separator + "scene.json", map);
|
|
|
-
|
|
|
- //上传资源到oss
|
|
|
- uploadNewSceneToOss(newNum);
|
|
|
-
|
|
|
- log.info("复制场景结束-{}", new Date());
|
|
|
-
|
|
|
- }catch (Exception e){
|
|
|
- log.error("复制场景异常", e);
|
|
|
- }
|
|
|
+ public void copy(String sceneNum) throws Exception {
|
|
|
+ ScenePro scenePro = this.getByNum(sceneNum);
|
|
|
+ ScenePlus scenePlus = scenePlusService.getByNum(sceneNum);
|
|
|
+ if((scenePro == null || scenePro.getCameraId() == null ) && (scenePlus== null || scenePlus.getCameraId() == null)){
|
|
|
+ throw new BusinessException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
|
|
|
+ }
|
|
|
+ Long cameraId = scenePro == null ? scenePlus.getCameraId() : scenePro.getCameraId();
|
|
|
|
|
|
- }
|
|
|
+ CameraDetail detailEntity = cameraDetailService.getByCameraId(cameraId);
|
|
|
+ if(detailEntity == null){
|
|
|
+ throw new BusinessException(CameraConstant.FAILURE_CODE_6029, CameraConstant.FAILURE_MSG_6029);
|
|
|
+ }
|
|
|
+ String newNum = scene3dNumService.generateSceneNum(detailEntity.getType());
|
|
|
|
|
|
- }.start();
|
|
|
+ if(scenePro !=null){ //v3场景复制
|
|
|
+ this.copyV3Scene(scenePro,newNum,detailEntity);
|
|
|
+ }
|
|
|
+ if(scenePlus != null){ //v4场景复制
|
|
|
+ scenePlusService.copyV4Scene(scenePlus,newNum,detailEntity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void deleteByNum(String num) {
|
|
|
+ ScenePro scenePro = this.getByNum(num);
|
|
|
+ if(scenePro!=null){
|
|
|
+ this.removeById(scenePro.getId());
|
|
|
+ }
|
|
|
+ Scene scene = sceneService.getByNum(num);
|
|
|
+ if(scene!=null){
|
|
|
+ sceneService.removeById(scene.getId());
|
|
|
+ }
|
|
|
+ ScenePlus scenePlus = scenePlusService.getByNum(num);
|
|
|
+ if(scenePlus!=null){
|
|
|
+ scenePlusService.removeById(scenePlus.getId());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 从旧场景下载资源
|
|
|
- * @param sceneNum
|
|
|
- * @param newNum
|
|
|
- * @throws Exception
|
|
|
- */
|
|
|
- private void downloadFromOldNumFromOss(String sceneNum, String newNum) throws Exception {
|
|
|
- CreateObjUtil.ossUtilCp("images/images" + sceneNum + "/",
|
|
|
- ConstantFilePath.SCENE_PATH + "images/images" + newNum);
|
|
|
- CreateObjUtil.ossUtilCp("data/data" + sceneNum + "/",
|
|
|
- ConstantFilePath.SCENE_PATH + "data/data" + newNum);
|
|
|
- CreateObjUtil.ossUtilCp("voice/voice" + sceneNum + "/",
|
|
|
- ConstantFilePath.SCENE_PATH + "voice/voice" + newNum);
|
|
|
- CreateObjUtil.ossUtilCp("video/video" + sceneNum + "/",
|
|
|
- ConstantFilePath.SCENE_PATH + "video/video" + newNum);
|
|
|
+ @Override
|
|
|
+ public void copyV3Scene(ScenePro oldScene,String newNum,CameraDetail cameraDetail) throws Exception {
|
|
|
+ SceneProEdit oldEditScene = sceneProEditService.getByProId(oldScene.getId());
|
|
|
+
|
|
|
+ String oldNum = oldScene.getNum();
|
|
|
+ //复制数据库数据
|
|
|
+ oldScene.setId(null);
|
|
|
+ oldScene.setStatus(0);
|
|
|
+ oldScene.setNum(newNum);
|
|
|
+ oldScene.setSceneName(oldScene.getSceneName().concat("(copy)"));
|
|
|
+ oldScene.setWebSite(oldScene.getWebSite().replace(oldScene.getNum(), newNum));
|
|
|
+ oldScene.setThumb(oldScene.getThumb().replace(oldScene.getNum(), newNum));
|
|
|
+ oldScene.setVideos(oldScene.getVideos().replace(oldNum,newNum));
|
|
|
+ oldScene.setViewCount(0);
|
|
|
+ String preDataSource = oldScene.getDataSource();
|
|
|
+ oldScene.setDataSource(this.setDataSource(preDataSource,oldScene.getSceneSource()));
|
|
|
+
|
|
|
+ this.save(oldScene);
|
|
|
+
|
|
|
+ sceneCopyLogService.saveByNum(oldNum,newNum,oldScene.getUserId());
|
|
|
+ //复制完成更新相机容量
|
|
|
+ cameraDetail.setUsedSpace(cameraDetail.getUsedSpace() + oldScene.getSpace());
|
|
|
+ cameraDetailService.updateById(cameraDetail);
|
|
|
+
|
|
|
+ oldEditScene.setId(null);
|
|
|
+ oldEditScene.setProId(oldScene.getId());
|
|
|
+ oldEditScene.setScreencapVoiceSrc(oldEditScene.getScreencapVoiceSrc() == null ? null : oldEditScene.getScreencapVoiceSrc().replace(oldNum, newNum));
|
|
|
+ oldEditScene.setScreencapVoiceSound(oldEditScene.getScreencapVoiceSound() == null ? null : oldEditScene.getScreencapVoiceSound().replace(oldNum, newNum));
|
|
|
+ oldEditScene.setScreencapVoiceSoundsync(oldEditScene.getScreencapVoiceSoundsync() == null ? null : oldEditScene.getScreencapVoiceSoundsync().replace(oldNum, newNum));
|
|
|
+ oldEditScene.setPlayData(oldEditScene.getPlayData() == null ? null : oldEditScene.getPlayData().replace(oldNum, newNum));
|
|
|
+ oldEditScene.setScreencapThumb(oldEditScene.getScreencapThumb() == null ? null : oldEditScene.getScreencapThumb().replace(oldNum, newNum));
|
|
|
+ oldEditScene.setFloorPlanPng(oldEditScene.getFloorPlanPng() == null ? null : oldEditScene.getFloorPlanPng().replace(oldNum, newNum));
|
|
|
+ sceneProEditService.save(oldEditScene);
|
|
|
+
|
|
|
+ this.setQrCode(oldScene.getBuildType(), oldScene.getNum());
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
+ try {
|
|
|
+ log.info("开始复制场景-{}", new Date());
|
|
|
+
|
|
|
+ //oss复制计算结果资源
|
|
|
+ this.copyOssSource("v3",oldNum,newNum);
|
|
|
+ this.copyLocalSource(oldNum,newNum);
|
|
|
+
|
|
|
+ this.updateSceneJson("v3",oldScene.getVideos(),newNum,oldScene.getSceneName(),oldScene.getWebSite(),oldScene.getThumb(),oldScene.getId());
|
|
|
+ //上传资源到oss
|
|
|
+ this.uploadNewSceneToOss(newNum);
|
|
|
+ oldScene.setStatus(-2);
|
|
|
+ this.updateById(oldScene);
|
|
|
+ log.info("复制场景结束-{}", new Date());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("复制场景异常", e);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 上传新场景资源到oss
|
|
|
- * @param newNum
|
|
|
- */
|
|
|
- private void uploadNewSceneToOss(String newNum) {
|
|
|
+ @Override
|
|
|
+ public void updateSceneJson(String type,String videos,String newNum,String sceneName,String webSite,String thumb,Long id) throws Exception {
|
|
|
+ //更新video
|
|
|
+ HashMap<String,Object> map = new HashMap<>();
|
|
|
+ map.put("videos",videos);
|
|
|
+ map.put("sceneName",sceneName);
|
|
|
+ map.put("webSite",webSite);
|
|
|
+ map.put("thumb",thumb);
|
|
|
+ map.put("num",newNum);
|
|
|
+ map.put("id",id);
|
|
|
+ String uploadPath ;
|
|
|
+ String localPath = ConstantFilePath.SCENE_PATH + "data/data" + newNum + File.separator + "scene.json";
|
|
|
+ if(type.equals("v3")){
|
|
|
+ uploadPath = localPath.replace(ConstantFilePath.SCENE_PATH, "");
|
|
|
+ }else {
|
|
|
+ uploadPath =localPath.replace(ConstantFilePath.SCENE_V4_PATH, "");
|
|
|
+ }
|
|
|
+ FileUtils.writeJsonFile(localPath, map);
|
|
|
+ if(type.equals("v4")){
|
|
|
+ uploadToOssUtil.upload(localPath,uploadPath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void uploadNewSceneToOss(String newNum) {
|
|
|
Map<String, String> map = new HashMap();
|
|
|
List<String> urlList = new ArrayList<>();
|
|
|
FileUtils.readfilePath(ConstantFilePath.SCENE_PATH + "images/images" + newNum, urlList);
|
|
@@ -325,51 +397,96 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
|
|
|
uploadToOssUtil.uploadMulFiles(map);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 从本地旧场景拷贝资源到新场景
|
|
|
- * @param sceneNum
|
|
|
- * @param newNum
|
|
|
- */
|
|
|
- private void copyOldSceneLocalToNew(String sceneNum, String newNum) throws IOException {
|
|
|
- FileUtils.copyFolderAllFiles(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + "/",
|
|
|
- ConstantFilePath.SCENE_PATH + "data/data" + newNum + "/", true);
|
|
|
-// log.info("成功拷贝完data文件夹-{}", sceneNum);
|
|
|
-
|
|
|
- // 复制本地视频
|
|
|
- FileUtils.copyFolderAllFiles(ConstantFilePath.SCENE_PATH + "video/video" + sceneNum + "/",
|
|
|
- ConstantFilePath.SCENE_PATH + "video/video" + newNum + "/", true);
|
|
|
-// log.info("成功拷贝完video文件夹-{}", sceneNum);
|
|
|
-
|
|
|
- // 复制本地二维码
|
|
|
- boolean copySucc = FileUtils.copyFile(ConstantFilePath.SCENE_QR_CODE_PATH + sceneNum + ".png",
|
|
|
- ConstantFilePath.SCENE_QR_CODE_PATH + newNum + ".png", true);
|
|
|
-// log.info("成功拷贝完二维码文件-{}", sceneNum);
|
|
|
-//
|
|
|
-// if (!copySucc) {
|
|
|
-// log.info("拷贝png失败,场景码-{}", sceneNum);
|
|
|
-// }
|
|
|
-
|
|
|
- // 复制本地二维码
|
|
|
- copySucc = FileUtils.copyFile(ConstantFilePath.SCENE_QR_CODE_PATH + sceneNum + "_en.png",
|
|
|
- ConstantFilePath.SCENE_QR_CODE_PATH + newNum + "_en.png", true);
|
|
|
-// log.info("成功拷贝完国际二维码文件-{}", sceneNum);
|
|
|
-
|
|
|
-// log.info("旧的场景码-{}", ConstantFilePath.SCENE_QR_CODE_PATH + sceneNum + "_en.png");
|
|
|
-// log.info("新的场景码-{}", ConstantFilePath.SCENE_QR_CODE_PATH + newNum + "_en.png");
|
|
|
-// if (!copySucc) {
|
|
|
-// log.info("拷贝png失败,场景码-{}", sceneNum);
|
|
|
-// }
|
|
|
+ @Override
|
|
|
+ public String setDataSource(String preDataSource,Integer sceneSource) throws Exception {
|
|
|
+ String datasourceFix;
|
|
|
+ String newDataSource;
|
|
|
+ // 判断场景是否拷贝过
|
|
|
+ ScenePro entity;
|
|
|
+ do{
|
|
|
+ datasourceFix = RandomUtil.generateShortUuid();
|
|
|
+ entity = this.findByFileId(preDataSource.concat(datasourceFix));
|
|
|
+ }while(!ObjectUtils.isEmpty(entity));
|
|
|
+ newDataSource = datasourceFix.concat(datasourceFix);
|
|
|
+
|
|
|
+ //oss复制源文件
|
|
|
+ String buildModelPath = ConstantFilePath.BUILD_MODEL_PATH;
|
|
|
+ if(sceneSource.equals(4)){
|
|
|
+ buildModelPath = ConstantFilePath.BUILD_MODEL_LASER_PATH;
|
|
|
+ }
|
|
|
+ CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX +newDataSource.replace(buildModelPath, "")+"/", newDataSource);
|
|
|
+
|
|
|
+ List<String> urlList = new ArrayList<>();
|
|
|
+ FileUtils.readfilePath(newDataSource, urlList);
|
|
|
+ Map<String,String> fileMap = new HashMap<>();
|
|
|
+ for(String url : urlList){
|
|
|
+ fileMap.put(url, ConstantFilePath.OSS_PREFIX + url.replace(buildModelPath, ""));
|
|
|
+ }
|
|
|
+ uploadToOssUtil.uploadMulFiles(fileMap);
|
|
|
+
|
|
|
+ FileUtils.delAllFile(newDataSource);
|
|
|
+
|
|
|
+ FileUtils.copyFolderAllFiles(preDataSource+"/",newDataSource+"/", true);
|
|
|
+ return datasourceFix.concat(datasourceFix);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void deleteByNum(String num) {
|
|
|
- ScenePro scenePro = this.getByNum(num);
|
|
|
- if(scenePro!=null){
|
|
|
- this.removeById(scenePro);
|
|
|
+ public ScenePro findByFileId(String fileId) {
|
|
|
+ LambdaQueryWrapper<ScenePro> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.like(ScenePro::getDataSource,fileId);
|
|
|
+ List<ScenePro> list = this.list(wrapper);
|
|
|
+ if(list !=null && list.size() >0){
|
|
|
+ return list.get(0);
|
|
|
}
|
|
|
- Scene scene = sceneService.getByNum(num);
|
|
|
- if(scene!=null){
|
|
|
- sceneService.removeById(scene);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public void setQrCode(String buildType,String num) throws Exception {
|
|
|
+ String basePath = mainUrl;
|
|
|
+ if("V2".equals(buildType)){
|
|
|
+ basePath += sceneProUrl;
|
|
|
+ }
|
|
|
+ if("V3".equals(buildType)){
|
|
|
+ basePath += sceneProNewUrl;
|
|
|
+ }
|
|
|
+ MatrixToImageWriterUtil.createQRCode(basePath + num, ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+num+".png", false,null);
|
|
|
+ MatrixToImageWriterUtil.createQRCode(basePath + num + "&lang=en", ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+num+"_en.png", false,null);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void copyOssSource(String type ,String sceneNum, String newNum) throws Exception {
|
|
|
+ List<String > copyList = new ArrayList<>();
|
|
|
+ if(type.equals("v3")){
|
|
|
+ copyList.add("images/images" + sceneNum);
|
|
|
+ copyList.add("data/data" + sceneNum);
|
|
|
+ copyList.add("voice/voice" + sceneNum);
|
|
|
+ copyList.add("video/video"+ sceneNum);
|
|
|
+ }else if(type.equals("v4")){
|
|
|
+ String oldEditPath = String.format(UploadFilePath.EDIT_PATH, sceneNum);
|
|
|
+ String oldViewPath = String.format(UploadFilePath.VIEW_PATH, sceneNum);
|
|
|
+ copyList.add(oldEditPath);
|
|
|
+ copyList.add(oldViewPath);
|
|
|
+ }
|
|
|
+ for (String sourcePath : copyList) {
|
|
|
+ uploadToOssUtil.copyFiles(sourcePath,sourcePath.replaceAll(sceneNum,newNum));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public void copyLocalSource(String sceneNum, String newNum) throws Exception {
|
|
|
+ FileUtils.copyDirectiory(ConstantFilePath.SCENE_PATH +"images/images" + sceneNum,ConstantFilePath.SCENE_PATH +"images/images" + newNum);
|
|
|
+ FileUtils.copyDirectiory(ConstantFilePath.SCENE_PATH +"data/data" + sceneNum,ConstantFilePath.SCENE_PATH +"data/data" + newNum);
|
|
|
+ reloadFile(ConstantFilePath.SCENE_PATH + "data/data" + newNum + "/link-scene.json",sceneNum, newNum);
|
|
|
+ reloadFile(ConstantFilePath.SCENE_PATH + "data/data" + newNum + "/hot.json",sceneNum, newNum);
|
|
|
+ FileUtils.copyDirectiory(ConstantFilePath.SCENE_PATH +"voice/voice" + sceneNum,ConstantFilePath.SCENE_PATH +"voice/voice" + newNum);
|
|
|
+ FileUtils.copyDirectiory(ConstantFilePath.SCENE_PATH +"video/video" + sceneNum,ConstantFilePath.SCENE_PATH +"video/video" + newNum);
|
|
|
+ }
|
|
|
+ private void reloadFile(String filePath,String sceneNum, String newNum) throws Exception {
|
|
|
+ // 修改link-scene.json
|
|
|
+ String content = FileUtils.readFile(filePath);
|
|
|
+ if (!ObjectUtils.isEmpty(content)) {
|
|
|
+ content = content.replaceAll(sceneNum, newNum);
|
|
|
+ FileUtils.writeFile(filePath,content);
|
|
|
}
|
|
|
}
|
|
|
}
|