|
@@ -1,21 +1,37 @@
|
|
package com.fdkankan.ucenter.service.impl;
|
|
package com.fdkankan.ucenter.service.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
|
+import cn.hutool.core.thread.ThreadUtil;
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
|
+import com.fdkankan.common.constant.ConstantFilePath;
|
|
import com.fdkankan.common.constant.UploadFilePath;
|
|
import com.fdkankan.common.constant.UploadFilePath;
|
|
import com.fdkankan.common.util.FileUtils;
|
|
import com.fdkankan.common.util.FileUtils;
|
|
|
|
+import com.fdkankan.common.util.MatrixToImageWriterUtil;
|
|
import com.fdkankan.fyun.oss.UploadToOssUtil;
|
|
import com.fdkankan.fyun.oss.UploadToOssUtil;
|
|
|
|
+import com.fdkankan.redis.constant.RedisKey;
|
|
|
|
+import com.fdkankan.redis.util.RedisUtil;
|
|
|
|
+import com.fdkankan.ucenter.bean.SceneJsonBean;
|
|
import com.fdkankan.ucenter.entity.*;
|
|
import com.fdkankan.ucenter.entity.*;
|
|
import com.fdkankan.ucenter.mapper.IScenePlusMapper;
|
|
import com.fdkankan.ucenter.mapper.IScenePlusMapper;
|
|
import com.fdkankan.ucenter.service.*;
|
|
import com.fdkankan.ucenter.service.*;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.fdkankan.ucenter.vo.response.SceneEditControlsVO;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import java.io.File;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
+import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Objects;
|
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
@@ -25,6 +41,7 @@ import java.util.List;
|
|
* @author
|
|
* @author
|
|
* @since 2022-07-04
|
|
* @since 2022-07-04
|
|
*/
|
|
*/
|
|
|
|
+@Slf4j
|
|
@Service
|
|
@Service
|
|
public class ScenePlusServiceImpl extends ServiceImpl<IScenePlusMapper, ScenePlus> implements IScenePlusService {
|
|
public class ScenePlusServiceImpl extends ServiceImpl<IScenePlusMapper, ScenePlus> implements IScenePlusService {
|
|
|
|
|
|
@@ -44,6 +61,8 @@ public class ScenePlusServiceImpl extends ServiceImpl<IScenePlusMapper, ScenePlu
|
|
UploadToOssUtil uploadToOssUtil;
|
|
UploadToOssUtil uploadToOssUtil;
|
|
@Autowired
|
|
@Autowired
|
|
ISceneProService sceneProService;
|
|
ISceneProService sceneProService;
|
|
|
|
+ @Autowired
|
|
|
|
+ RedisUtil redisUtil;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Long getCountByUserId(Long userId, List<Integer> sceneSourceList) {
|
|
public Long getCountByUserId(Long userId, List<Integer> sceneSourceList) {
|
|
@@ -110,67 +129,132 @@ public class ScenePlusServiceImpl extends ServiceImpl<IScenePlusMapper, ScenePlu
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public void copyV4Scene(ScenePlus scenePlus,String newNum, CameraDetail cameraDetail) throws Exception {
|
|
|
|
|
|
+ public Long copyV4Scene(ScenePlus scenePlus,String newNum ,CameraDetail cameraDetail,String time) throws Exception {
|
|
String num = scenePlus.getNum();
|
|
String num = scenePlus.getNum();
|
|
Long plusId = scenePlus.getId();
|
|
Long plusId = scenePlus.getId();
|
|
- scenePlus.setSceneStatus(0);
|
|
|
|
|
|
+ ScenePlusExt plusExt = scenePlusExtService.getByPlusId(plusId);
|
|
|
|
+ String bucket = plusExt.getYunFileBucket();
|
|
|
|
+
|
|
|
|
+ // 拷贝数据
|
|
scenePlus.setNum(newNum);
|
|
scenePlus.setNum(newNum);
|
|
scenePlus.setId(null);
|
|
scenePlus.setId(null);
|
|
- scenePlus.setTitle(scenePlus.getTitle().concat("(copy)"));
|
|
|
|
|
|
+ scenePlus.setSceneStatus(0);
|
|
this.save(scenePlus);
|
|
this.save(scenePlus);
|
|
|
|
|
|
- ScenePlusExt plusExt = scenePlusExtService.getByPlusId(plusId);
|
|
|
|
- String videos ;
|
|
|
|
- if(plusExt.getVideos().contains("scene_view_data")){
|
|
|
|
- videos = plusExt.getVideos().replace(num,newNum);
|
|
|
|
- }else {
|
|
|
|
- videos = plusExt.getVideos().replaceAll("https://4dkk.4dage.com/data/data"+num, "https://4dkk.4dage.com/scene_view_data/"+newNum+"/data");
|
|
|
|
- }
|
|
|
|
|
|
+ ExecutorService executor = ThreadUtil.newSingleExecutor();
|
|
|
|
+ try {
|
|
|
|
+ CompletableFuture.runAsync(() -> {
|
|
|
|
+ try {
|
|
|
|
+ // 拷贝场景编辑资源
|
|
|
|
+ String oldEditPath = String.format(UploadFilePath.EDIT_PATH, num);
|
|
|
|
+ String newEditPath = String.format(UploadFilePath.EDIT_PATH, newNum);
|
|
|
|
+ uploadToOssUtil.copyFiles(bucket, oldEditPath, newEditPath);
|
|
|
|
+
|
|
|
|
+ // 拷贝场景展示资源
|
|
|
|
+ String oldViewPath = String.format(UploadFilePath.VIEW_PATH, num);
|
|
|
|
+ String newViewPath = String.format(UploadFilePath.VIEW_PATH, newNum);
|
|
|
|
+ uploadToOssUtil.copyFiles(bucket, oldViewPath, newViewPath);
|
|
|
|
|
|
- plusExt.setId(null);
|
|
|
|
- plusExt.setPlusId(scenePlus.getId());
|
|
|
|
- plusExt.setWebSite(plusExt.getWebSite().replace(num,newNum));
|
|
|
|
- plusExt.setThumb(plusExt.getThumb().replace(num,newNum));
|
|
|
|
- plusExt.setVideos(videos);
|
|
|
|
- plusExt.setViewCount(0);
|
|
|
|
|
|
+ // 拷贝本地资源
|
|
|
|
+ String oldPath = String.format("/mnt/4Dkankan/scene/%s/caches/images", num);
|
|
|
|
+ String newPath = String.format("/mnt/4Dkankan/scene/%s/caches/images", newNum);
|
|
|
|
+ if(new File(oldPath).exists()){
|
|
|
|
+ FileUtils.copyDirectiory(oldPath, newPath);
|
|
|
|
+ }
|
|
|
|
|
|
- String newDataSource = sceneProService.setDataSource(plusExt.getDataSource(), scenePlus.getSceneSource());
|
|
|
|
- plusExt.setDataSource(newDataSource);
|
|
|
|
- scenePlusExtService.save(plusExt);
|
|
|
|
|
|
+ String scenePath = ConstantFilePath.SCENE_V4_PATH + num;
|
|
|
|
+ File file = new File(scenePath);
|
|
|
|
+ if(file.exists()){
|
|
|
|
+ String newScenePath = ConstantFilePath.SCENE_V4_PATH + newNum;
|
|
|
|
+ FileUtils.copyDirectiory(scenePath, newScenePath);
|
|
|
|
+ }
|
|
|
|
+ String newVideos = plusExt.getVideos();
|
|
|
|
+ if(StrUtil.isNotEmpty(newVideos)){
|
|
|
|
+ newVideos = plusExt.getVideos().replaceAll("/data/data" + num, "/scene_view_data/" + newNum + "/data").replaceAll(num, newNum);
|
|
|
|
+ }
|
|
|
|
|
|
- //保存复制日志
|
|
|
|
- sceneCopyLogService.saveByNum(num,newNum,scenePlus.getUserId());
|
|
|
|
- //复制完成更新相机容量
|
|
|
|
- cameraDetail.setUsedSpace(cameraDetail.getUsedSpace() + plusExt.getSpace());
|
|
|
|
- cameraDetailService.updateById(cameraDetail);
|
|
|
|
|
|
+ plusExt.setId(null);
|
|
|
|
+ plusExt.setPlusId(scenePlus.getId());
|
|
|
|
+ plusExt.setWebSite(plusExt.getWebSite().replace(num, newNum));
|
|
|
|
+ plusExt.setThumb(plusExt.getThumb().replace(num, newNum));
|
|
|
|
+ plusExt.setVideos(newVideos);
|
|
|
|
+ plusExt.setViewCount(0);
|
|
|
|
+ scenePlusExtService.save(plusExt);
|
|
|
|
|
|
|
|
+ SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(plusId);
|
|
|
|
+ Long sceneEditInfoId = sceneEditInfo.getId();
|
|
|
|
|
|
- SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(plusId);
|
|
|
|
- Long sceneEditInfoId = sceneEditInfo.getId();
|
|
|
|
|
|
+ sceneEditInfo.setId(null);
|
|
|
|
+ sceneEditInfo.setScenePlusId(scenePlus.getId());
|
|
|
|
+ sceneEditInfo.setSceneProId(null);
|
|
|
|
+ sceneEditInfo.setTitle(scenePlus.getTitle());
|
|
|
|
+ sceneEditInfoService.save(sceneEditInfo);
|
|
|
|
|
|
- sceneEditInfo.setId(null);
|
|
|
|
- sceneEditInfo.setScenePlusId(scenePlus.getId());
|
|
|
|
- sceneEditInfo.setTitle(scenePlus.getTitle());
|
|
|
|
- sceneEditInfoService.save(sceneEditInfo);
|
|
|
|
|
|
+ SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfoId);
|
|
|
|
+ sceneEditInfoExt.setId(null);
|
|
|
|
+ sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
|
|
|
|
+ sceneEditInfoExt.setScenePlusId(scenePlus.getId());
|
|
|
|
+ sceneEditInfoExt.setSceneProId(null);
|
|
|
|
+ sceneEditInfoExtService.save(sceneEditInfoExt);
|
|
|
|
|
|
- SceneEditInfoExt sceneEditInfoExt = sceneEditInfoExtService.getByEditInfoId(sceneEditInfoId);
|
|
|
|
- sceneEditInfoExt.setId(null);
|
|
|
|
- sceneEditInfoExt.setEditInfoId(sceneEditInfo.getId());
|
|
|
|
- sceneEditInfoExt.setScenePlusId(scenePlus.getId());
|
|
|
|
- sceneEditInfoExtService.save(sceneEditInfoExt);
|
|
|
|
|
|
+ SceneEditControls sceneEditControls = sceneEditControlsService.getBySceneEditId(sceneEditInfoId);
|
|
|
|
+ sceneEditControls.setId(null);
|
|
|
|
+ sceneEditControls.setEditInfoId(sceneEditInfo.getId());
|
|
|
|
+ sceneEditControlsService.save(sceneEditControls);
|
|
|
|
|
|
- SceneEditControls sceneEditControls = sceneEditControlsService.getBySceneEditId(sceneEditInfoId);
|
|
|
|
- sceneEditControls.setId(null);
|
|
|
|
- sceneEditControls.setEditInfoId(sceneEditInfo.getId());
|
|
|
|
- sceneEditControlsService.save(sceneEditControls);
|
|
|
|
|
|
+ // 生成scene.json
|
|
|
|
+ SceneJsonBean sceneJson = new SceneJsonBean();
|
|
|
|
+ BeanUtil.copyProperties(sceneEditInfoExt, sceneJson);
|
|
|
|
+ BeanUtil.copyProperties(sceneEditInfo, sceneJson);
|
|
|
|
+ SceneEditControlsVO sceneEditControlsVO = BeanUtil.copyProperties(sceneEditControls, SceneEditControlsVO.class);
|
|
|
|
+ sceneJson.setControls(sceneEditControlsVO);
|
|
|
|
+ sceneJson.setNum(newNum);
|
|
|
|
+ sceneJson.setCreateTime(scenePlus.getCreateTime());
|
|
|
|
|
|
- sceneProService.setQrCode("V3",newNum);
|
|
|
|
- sceneProService.copyOssSource("v4",num,newNum);
|
|
|
|
- sceneProService.copyLocalSource(num,newNum);
|
|
|
|
- sceneProService.updateSceneJson("v4",plusExt.getVideos(),newNum,scenePlus.getTitle(),plusExt.getWebSite(),plusExt.getThumb(),scenePlus.getId());
|
|
|
|
|
|
+ sceneJson.setSceneResolution(plusExt.getSceneResolution());
|
|
|
|
+ sceneJson.setSceneFrom(plusExt.getSceneFrom());
|
|
|
|
+ sceneJson.setSceneKind(plusExt.getSceneKind());
|
|
|
|
+ if(StrUtil.isNotEmpty(plusExt.getVideos())){
|
|
|
|
+ sceneJson.setVideos(plusExt.getVideos());
|
|
|
|
+ }
|
|
|
|
|
|
- scenePlus.setSceneStatus(-2);
|
|
|
|
- this.updateById(scenePlus);
|
|
|
|
|
|
+ String sceneJsonLocalPath = ConstantFilePath.SCENE_PATH + "data" + File.separator + "data" + newNum + File.separator + "scene.json";
|
|
|
|
+ FileUtils.writeFile(sceneJsonLocalPath, JSON.toJSONString(sceneJson));
|
|
|
|
+
|
|
|
|
+ String sceneJsonPath = String.format(UploadFilePath.DATA_VIEW_PATH+"scene.json", newNum);
|
|
|
|
+ uploadToOssUtil.upload(bucket, JSON.toJSONBytes(sceneJson), sceneJsonPath);
|
|
|
|
+
|
|
|
|
+ //删除scenejson缓存
|
|
|
|
+ redisUtil.del(String.format(RedisKey.SCENE_JSON, num));
|
|
|
|
+
|
|
|
|
+ // 生成二维码
|
|
|
|
+ String outPathZh = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/" + newNum + ".png";
|
|
|
|
+ String outPathEn = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/" + newNum + "_en.png";
|
|
|
|
+ MatrixToImageWriterUtil.createQRCode(plusExt.getWebSite(), outPathZh, false,null);
|
|
|
|
+ MatrixToImageWriterUtil.createQRCode(plusExt.getWebSite() + "&lang=en", outPathEn, false, null);
|
|
|
|
+ uploadToOssUtil.upload(bucket, outPathZh, String.format(UploadFilePath.DOWNLOADS_QRCODE, newNum) + newNum + ".png");
|
|
|
|
+ uploadToOssUtil.upload(bucket, outPathEn, String.format(UploadFilePath.DOWNLOADS_QRCODE, newNum) + newNum + "_en.png");
|
|
|
|
+ scenePlus.setSceneStatus(-2);
|
|
|
|
+ this.updateById(scenePlus);
|
|
|
|
+
|
|
|
|
+ cameraDetail.setUsedSpace(cameraDetail.getUsedSpace() + plusExt.getSpace());
|
|
|
|
+ cameraDetailService.updateById(cameraDetail);
|
|
|
|
+
|
|
|
|
+ sceneCopyLogService.saveByNum(num,newNum,scenePlus.getUserId());
|
|
|
|
+
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ this.removeById(scenePlus.getId());
|
|
|
|
+ log.error("复制场景异常", e);
|
|
|
|
+ }
|
|
|
|
+ }, executor).whenComplete((reslut, e) -> {
|
|
|
|
+ log.info("复制场景oldNum:{},newNum:{}结束-{}",num,newNum, new Date());
|
|
|
|
+ });
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ log.error("线程错误:{}",e);
|
|
|
|
+ }finally {
|
|
|
|
+ executor.shutdown();
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ return scenePlus.getId();
|
|
}
|
|
}
|
|
}
|
|
}
|