|
@@ -1,39 +1,71 @@
|
|
|
package com.fdkankan.scene.service.impl;
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fdkankan.common.constant.ConstantFilePath;
|
|
|
import com.fdkankan.common.constant.ErrorCode;
|
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
|
import com.fdkankan.common.model.SSOUser;
|
|
|
import com.fdkankan.common.response.ResultData;
|
|
|
import com.fdkankan.common.user.SSOLoginHelper;
|
|
|
+import com.fdkankan.common.util.CreateObjUtil;
|
|
|
import com.fdkankan.common.util.DateUtil;
|
|
|
+import com.fdkankan.common.util.FileUtils;
|
|
|
import com.fdkankan.common.util.JwtUtil;
|
|
|
+import com.fdkankan.fyun.oss.UploadToOssUtil;
|
|
|
+import com.fdkankan.rabbitmq.util.RabbitMqProducer;
|
|
|
+import com.fdkankan.redis.constant.RedisKey;
|
|
|
+import com.fdkankan.redis.constant.RedisLockKey;
|
|
|
+import com.fdkankan.redis.util.RedisLockUtil;
|
|
|
+import com.fdkankan.redis.util.RedisUtil;
|
|
|
+import com.fdkankan.scene.bean.RequestRebuildVedioScene;
|
|
|
import com.fdkankan.scene.bean.RequestSceneCooperation;
|
|
|
import com.fdkankan.scene.entity.Camera;
|
|
|
import com.fdkankan.scene.entity.CameraDetail;
|
|
|
+import com.fdkankan.scene.entity.PicSceneProgress;
|
|
|
+import com.fdkankan.scene.entity.Scene;
|
|
|
import com.fdkankan.scene.entity.SceneCooperation;
|
|
|
+import com.fdkankan.scene.entity.ScenePlus;
|
|
|
+import com.fdkankan.scene.entity.ScenePlusExt;
|
|
|
import com.fdkankan.scene.entity.ScenePro;
|
|
|
+import com.fdkankan.scene.entity.SceneProEdit;
|
|
|
import com.fdkankan.scene.entity.SceneResource;
|
|
|
import com.fdkankan.scene.entity.User;
|
|
|
import com.fdkankan.scene.entity.UserIncrement;
|
|
|
+import com.fdkankan.scene.entity.VideoSceneProgress;
|
|
|
+import com.fdkankan.scene.mapper.ISceneMapper;
|
|
|
+import com.fdkankan.scene.mapper.ISceneProMapper;
|
|
|
import com.fdkankan.scene.service.ICameraDetailService;
|
|
|
import com.fdkankan.scene.service.ICameraService;
|
|
|
+import com.fdkankan.scene.service.IPicSceneProgressService;
|
|
|
import com.fdkankan.scene.service.ISceneCooperationService;
|
|
|
+import com.fdkankan.scene.service.IScenePlusExtService;
|
|
|
+import com.fdkankan.scene.service.IScenePlusService;
|
|
|
+import com.fdkankan.scene.service.ISceneProEditService;
|
|
|
import com.fdkankan.scene.service.ISceneProService;
|
|
|
import com.fdkankan.scene.service.ISceneResourceService;
|
|
|
import com.fdkankan.scene.service.ISceneService;
|
|
|
import com.fdkankan.scene.service.IUserIncrementService;
|
|
|
import com.fdkankan.scene.service.IUserService;
|
|
|
+import com.fdkankan.scene.service.IVideoSceneProgressService;
|
|
|
+import java.io.File;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -45,7 +77,7 @@ import org.springframework.stereotype.Service;
|
|
|
**/
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
-public class SceneServiceImpl implements ISceneService {
|
|
|
+public class SceneServiceImpl extends ServiceImpl<ISceneMapper, Scene> implements ISceneService {
|
|
|
|
|
|
@Autowired
|
|
|
private ISceneProService sceneProService;
|
|
@@ -61,7 +93,29 @@ public class SceneServiceImpl implements ISceneService {
|
|
|
private ISceneCooperationService sceneCooperationService;
|
|
|
@Autowired
|
|
|
private ISceneResourceService sceneResourceService;
|
|
|
+ @Autowired
|
|
|
+ private ISceneProEditService sceneProEditService;
|
|
|
+ @Autowired
|
|
|
+ private RedisUtil redisUtil;
|
|
|
+ @Autowired
|
|
|
+ private RedisLockUtil redisLockUtil;
|
|
|
+ @Autowired
|
|
|
+ private IScenePlusService scenePlusService;
|
|
|
+ @Autowired
|
|
|
+ private IScenePlusExtService scenePlusExtService;
|
|
|
+ @Autowired
|
|
|
+ private UploadToOssUtil uploadToOssUtil;
|
|
|
+ @Autowired
|
|
|
+ private IVideoSceneProgressService videoSceneProgressService;
|
|
|
+ @Autowired
|
|
|
+ private IPicSceneProgressService picSceneProgressService;
|
|
|
+ @Autowired
|
|
|
+ private RabbitMqProducer rabbitMqProducer;
|
|
|
|
|
|
+ @Value("${queue.modeling.queue-video-a}")
|
|
|
+ private String queueVideoA;
|
|
|
+ @Value("${queue.modeling.queue_pic_a}")
|
|
|
+ private String queuePicA;
|
|
|
@Value("${expected-time}")
|
|
|
private String expectedTime;
|
|
|
|
|
@@ -231,4 +285,251 @@ public class SceneServiceImpl implements ISceneService {
|
|
|
|
|
|
return ResultData.ok(sceneResourceService.findByCooperationId(sceneCooperation.getId()));
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultData getVoiceSound(String sceneNum) throws Exception {
|
|
|
+ if(StringUtils.isEmpty(sceneNum)){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
|
|
|
+ }
|
|
|
+ ScenePro sceneProEntity = sceneProService.findBySceneNum(sceneNum);
|
|
|
+ if(sceneProEntity == null){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
|
+ }
|
|
|
+ SceneProEdit editEntity = sceneProEditService.findBySceneProId(sceneProEntity.getId());
|
|
|
+
|
|
|
+ return ResultData.ok(editEntity.getScreencapVoiceSoundsync());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultData updateViewCount(String sceneNum) {
|
|
|
+ String key = RedisKey.SCENE_VISIT_CNT;
|
|
|
+ if(!redisUtil.hHasKey(key, sceneNum)){
|
|
|
+ String lockKey = String.format(RedisLockKey.LOCK_SCENE_VISIT_CNT, sceneNum);
|
|
|
+ boolean lock = redisLockUtil.lock(lockKey, RedisKey.EXPIRE_TIME_10_MINUTE);
|
|
|
+ if(!lock){
|
|
|
+ return ResultData.ok();
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ String cnt = redisUtil.hget(key, sceneNum);
|
|
|
+ if(StrUtil.isEmpty(cnt)){
|
|
|
+ //标记是否找到了场景,如果找到就不往下找
|
|
|
+ boolean getScene = false;
|
|
|
+ Integer viewCount = null;
|
|
|
+ ScenePlus scenePlus = scenePlusService.getByNum(sceneNum);
|
|
|
+ if(Objects.nonNull(scenePlus)){
|
|
|
+ ScenePlusExt scenePlusExt = scenePlusExtService.getByScenePlusId(scenePlus.getId());
|
|
|
+ viewCount = scenePlusExt.getViewCount();
|
|
|
+ getScene = true;
|
|
|
+ }
|
|
|
+ if(!getScene){
|
|
|
+ ScenePro scenePro = sceneProService.findBySceneNum(sceneNum);
|
|
|
+ if(Objects.nonNull(scenePro)){
|
|
|
+ viewCount = scenePro.getViewCount();
|
|
|
+ getScene = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!getScene){
|
|
|
+ Scene scene = this.findByNum(sceneNum);
|
|
|
+ if(Objects.nonNull(scene)){
|
|
|
+ viewCount = scene.getViewCount();
|
|
|
+ getScene = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!getScene){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
|
+ }
|
|
|
+
|
|
|
+ redisUtil.hset(key, sceneNum, Objects.isNull(viewCount) ? "0" : String.valueOf(viewCount));
|
|
|
+ }
|
|
|
+ }finally {
|
|
|
+ redisLockUtil.unlockLua(lockKey);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ redisUtil.hincr(key, sceneNum, 1);
|
|
|
+ return ResultData.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Scene findByNum(String num) {
|
|
|
+ return this.getOne(new LambdaQueryWrapper<Scene>().eq(Scene::getNum, num));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultData rebuildVideoScene(RequestRebuildVedioScene requestRebuildVedioScene)
|
|
|
+ throws Exception {
|
|
|
+ if(StrUtil.isEmpty(requestRebuildVedioScene.getSceneNum()) || StrUtil.isEmpty(requestRebuildVedioScene.getPanoId())){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
|
|
|
+ }
|
|
|
+
|
|
|
+ String num = requestRebuildVedioScene.getSceneNum();
|
|
|
+
|
|
|
+ ScenePro sceneProEntity = sceneProService.findBySceneNum(num);
|
|
|
+ Scene scene = null;
|
|
|
+ String path = "";
|
|
|
+ if(sceneProEntity == null){
|
|
|
+ scene = this.findByNum(requestRebuildVedioScene.getSceneNum());
|
|
|
+ if(scene == null){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
|
+ }else {
|
|
|
+ path = ConstantFilePath.BUILD_MODEL_PATH + scene.getDataSource().split("/")[scene.getDataSource().split("/").length - 2];
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ path = sceneProEntity.getDataSource();
|
|
|
+ }
|
|
|
+
|
|
|
+ //先从备份文件下拉取
|
|
|
+ CreateObjUtil.ossUtilCp("video/video" +sceneProEntity.getNum() + File.separator + "back" + File.separator,
|
|
|
+ sceneProEntity.getDataSource() + "_rv" + File.separator + "videoback_temp");
|
|
|
+
|
|
|
+ String backpathtemp = sceneProEntity.getDataSource() + "_rv" + File.separator + "videoback_temp";
|
|
|
+ File fileback = new File(backpathtemp);
|
|
|
+ File[] filebackList = fileback.listFiles();
|
|
|
+
|
|
|
+ if(filebackList.length<=0){
|
|
|
+ String backpath = sceneProEntity.getDataSource() + "_rv" + File.separator + "videoback";
|
|
|
+ log.info("------------------" + backpath);
|
|
|
+
|
|
|
+ File file = new File(backpath);
|
|
|
+
|
|
|
+ //验证video 文件夹下是否有备份
|
|
|
+ CreateObjUtil.ossUtilCp("video/video" +sceneProEntity.getNum() + File.separator,
|
|
|
+ sceneProEntity.getDataSource() + "_rv" + File.separator + "videoback");
|
|
|
+
|
|
|
+ String name = "";
|
|
|
+ Map<String,String> map = new HashMap<String,String>();
|
|
|
+ file = new File(backpath);
|
|
|
+ File[] fileList = file.listFiles();
|
|
|
+ if(fileList.length>0){
|
|
|
+ for(File f:fileList){
|
|
|
+ name = f.getName();
|
|
|
+ log.info("file name :" + name);
|
|
|
+ map.put(sceneProEntity.getDataSource() + "_rv" + File.separator + "videoback" + File.separator + name,
|
|
|
+ "video/video" +sceneProEntity.getNum() + File.separator + "back" + File.separator + name);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //上传
|
|
|
+ log.info("上传内容 ===== + " + map);
|
|
|
+ uploadToOssUtil.uploadMulFiles(map);
|
|
|
+ FileUtils.deleteDirectory(backpathtemp);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //更新旧记录
|
|
|
+ videoSceneProgressService.updateProgressRec(requestRebuildVedioScene);
|
|
|
+
|
|
|
+ //往文件中写入值
|
|
|
+ JSONObject reObject = new JSONObject();
|
|
|
+ JSONObject Object = new JSONObject();
|
|
|
+ Object.put("name",requestRebuildVedioScene.getPanoId());
|
|
|
+ Object.put("x",requestRebuildVedioScene.getX());
|
|
|
+ Object.put("y",requestRebuildVedioScene.getY());
|
|
|
+ Object.put("width",requestRebuildVedioScene.getW());
|
|
|
+ Object.put("height",requestRebuildVedioScene.getH());
|
|
|
+ JSONArray arrayRe = new JSONArray();
|
|
|
+ arrayRe.add(Object);
|
|
|
+ reObject.put("required_videos",arrayRe);
|
|
|
+
|
|
|
+ JSONObject hdrObject = new JSONObject();
|
|
|
+ if(StringUtils.isNotEmpty(sceneProEntity.getVideos())){
|
|
|
+ JSONObject object = JSONObject.parseObject(sceneProEntity.getVideos());
|
|
|
+ if(object.containsKey("data")){
|
|
|
+ JSONArray array = new JSONArray();
|
|
|
+ array = (JSONArray) object.get("data");
|
|
|
+ arrayRe = new JSONArray();
|
|
|
+ if(array.size()>0){
|
|
|
+ for(int i = 0; i < array.size(); i++) {
|
|
|
+ JSONObject obj = (JSONObject) array.get(i);
|
|
|
+ Object = new JSONObject();
|
|
|
+ Object.put("name",(String) obj.get("id"));
|
|
|
+ Object.put("value",(String) obj.get("value"));
|
|
|
+ Object.put("fov",(String) obj.get("blend_fov"));
|
|
|
+ arrayRe.add(Object);
|
|
|
+ }
|
|
|
+ hdrObject.put("hdr_param",arrayRe);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ hdrObject.put("hdr_param","{}");
|
|
|
+ }
|
|
|
+
|
|
|
+ //重新计算时需要删除文件夹,否知使用缓存
|
|
|
+ log.info("开始清除result");
|
|
|
+ FileUtils.delAllFile(path + File.separator + "results");
|
|
|
+ log.info("清除result结束");
|
|
|
+
|
|
|
+ String fileId = path.split("/")[path.split("/").length - 2];
|
|
|
+ log.info("fileId:" + fileId);
|
|
|
+
|
|
|
+ String parametr = "";
|
|
|
+ parametr += sceneProEntity.getNum() + ":;" +
|
|
|
+ requestRebuildVedioScene.getPanoId();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+
|
|
|
+ VideoSceneProgress videoSceneProgressEntity = new VideoSceneProgress();
|
|
|
+ videoSceneProgressEntity.setSceneCode(sceneProEntity.getNum());
|
|
|
+ videoSceneProgressEntity.setVideoName(requestRebuildVedioScene.getPanoId());
|
|
|
+ videoSceneProgressEntity.setDataSource(sceneProEntity.getDataSource());
|
|
|
+ videoSceneProgressEntity.setRebuildResult(2);
|
|
|
+ videoSceneProgressEntity.setDataSource(sceneProEntity.getDataSource());
|
|
|
+ videoSceneProgressEntity.setRebuildQueueStartTime(new Date());
|
|
|
+ videoSceneProgressEntity.setHdrParam(hdrObject.toJSONString());
|
|
|
+ videoSceneProgressEntity.setRebuildParam(reObject.toJSONString());
|
|
|
+ videoSceneProgressService.save(videoSceneProgressEntity);
|
|
|
+
|
|
|
+ rabbitMqProducer.sendByWorkQueue(queueVideoA, parametr);
|
|
|
+
|
|
|
+ return ResultData.ok("视频场景计算中");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResultData rebuildPicScene(RequestRebuildVedioScene requestRebuildVedioScene) throws Exception {
|
|
|
+ if(StrUtil.isEmpty(requestRebuildVedioScene.getSceneNum())){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_3001);
|
|
|
+ }
|
|
|
+
|
|
|
+ String num = requestRebuildVedioScene.getSceneNum();
|
|
|
+
|
|
|
+ ScenePro sceneProEntity = sceneProService.findBySceneNum(num);
|
|
|
+ String path = "";
|
|
|
+ if(sceneProEntity == null){
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
|
+ }
|
|
|
+
|
|
|
+ path = sceneProEntity.getDataSource();
|
|
|
+
|
|
|
+ PicSceneProgress picSceneProgress = picSceneProgressService.findrebuildVideoProgressDetail(num,null);
|
|
|
+ if(!ObjectUtils.isEmpty(picSceneProgress) && (picSceneProgress.getRebuildResult() == 2 || picSceneProgress.getRebuildResult() == 3)){
|
|
|
+ return ResultData.error(ErrorCode.FAILURE_CODE_5035);
|
|
|
+ }
|
|
|
+
|
|
|
+ //更新旧记录
|
|
|
+ picSceneProgressService.updateProgressRec(requestRebuildVedioScene);
|
|
|
+
|
|
|
+ //重新计算时需要删除文件夹,否知使用缓存
|
|
|
+ log.info("开始清除result");
|
|
|
+ FileUtils.delAllFile(path + File.separator + "results");
|
|
|
+ log.info("清除result结束");
|
|
|
+
|
|
|
+ String fileId = path.split("/")[path.split("/").length - 2];
|
|
|
+ log.info("fileId:" + fileId);
|
|
|
+
|
|
|
+ PicSceneProgress picSceneProgressEntity = new PicSceneProgress();
|
|
|
+ picSceneProgressEntity.setSceneCode(sceneProEntity.getNum());
|
|
|
+ picSceneProgressEntity.setVideoName(requestRebuildVedioScene.getPanoId());
|
|
|
+ picSceneProgressEntity.setDataSource(sceneProEntity.getDataSource());
|
|
|
+ picSceneProgressEntity.setRebuildResult(2);
|
|
|
+ picSceneProgressEntity.setDataSource(sceneProEntity.getDataSource());
|
|
|
+ picSceneProgressEntity.setRebuildQueueStartTime(new Date());
|
|
|
+ picSceneProgressEntity.setRebuildParam(JSONObject.toJSONString(requestRebuildVedioScene));
|
|
|
+ picSceneProgressService.save(picSceneProgressEntity);
|
|
|
+
|
|
|
+ String parametr = picSceneProgressEntity.getId()+"";
|
|
|
+ rabbitMqProducer.sendByWorkQueue(queuePicA, parametr);
|
|
|
+
|
|
|
+ return ResultData.ok("图片场景计算中");
|
|
|
+ }
|
|
|
}
|