فهرست منبع

复制场景接口迁移编辑器

lyhzzz 1 سال پیش
والد
کامیت
0c25e6fe5d

+ 4 - 7
src/main/java/com/fdkankan/ucenter/mq/consumer/LaserSceneStatusConsumer.java

@@ -5,6 +5,7 @@ import com.fdkankan.redis.util.RedisUtil;
 import com.fdkankan.ucenter.common.RedisKeyUtil;
 import com.fdkankan.ucenter.mq.vo.ScenePayStatusVo;
 import com.fdkankan.ucenter.service.ISceneProService;
+import com.fdkankan.ucenter.service.impl.SceneCommonService;
 import com.rabbitmq.client.Channel;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.amqp.core.Message;
@@ -24,8 +25,7 @@ public class LaserSceneStatusConsumer {
 
 
     @Autowired
-    RedisUtil redisUtil;
-
+    SceneCommonService sceneCommonService;
     @RabbitListener(
             queuesToDeclare = @Queue("${queue.scene.laser.status:update-scene-status-ucent}")
             ,concurrency = "1"
@@ -41,15 +41,12 @@ public class LaserSceneStatusConsumer {
             JSONObject jsonObject = JSONObject.parseObject(msg);
             String num = jsonObject.getString("num");
             Integer status = jsonObject.getInteger("status");
-            String redisKey = RedisKeyUtil.laserCopyLock + num;
-            if(redisUtil.hasKey(redisKey)){
-                redisUtil.del(redisKey);
+            if(status == 1){
+                sceneCommonService.copyResult(num);
             }
 
         }catch (Exception e){
             log.info("update-scene-status-ucent----消费失败",e);
-        }finally {
-
         }
 
     }

+ 58 - 0
src/main/java/com/fdkankan/ucenter/mq/consumer/SceneCopyResultConsumer.java

@@ -0,0 +1,58 @@
+package com.fdkankan.ucenter.mq.consumer;
+
+import com.alibaba.fastjson.JSONObject;
+import com.fdkankan.ucenter.common.RedisKeyUtil;
+import com.fdkankan.ucenter.entity.*;
+import com.fdkankan.ucenter.mq.vo.ScenePayStatusVo;
+import com.fdkankan.ucenter.service.*;
+import com.fdkankan.ucenter.service.impl.SceneCommonService;
+import com.rabbitmq.client.Channel;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.amqp.core.Message;
+import org.springframework.amqp.rabbit.annotation.Queue;
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 场景封存解封 mq
+ */
+@Slf4j
+@Component
+public class SceneCopyResultConsumer {
+
+
+
+    @Autowired
+    SceneCommonService sceneCommonService;
+
+    @RabbitListener(
+            queuesToDeclare = @Queue("${queue.scene.copy.result:ucenter-copy-scene-result}")
+            ,concurrency = "1"
+    )
+    public void consumerQueue(Channel channel, Message message)  {
+        try {
+            String messageId = message.getMessageProperties().getMessageId();
+            String msg = new String(message.getBody(), StandardCharsets.UTF_8);
+            log.info("copy-scene-result--messageId:{},msg:{}",messageId,msg);
+            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
+
+            JSONObject jsonObject = JSONObject.parseObject(msg);
+            String oldNum = jsonObject.getString("oldNum");
+            String newNum = jsonObject.getString("newNum");
+
+            sceneCommonService.copyResult(newNum);
+
+        }catch (Exception e){
+            log.info("copy-scene-result----消费失败",e);
+        }
+
+    }
+
+}

+ 1 - 0
src/main/java/com/fdkankan/ucenter/service/ICameraDetailService.java

@@ -61,6 +61,7 @@ public interface ICameraDetailService extends IService<CameraDetail> {
     Boolean checkSpace(Long cameraId, Long space);
 
     Boolean checkSpace(Long cameraId,CameraType cameraType);
+    Boolean checkSpace(CameraDetail cameraId,CameraType cameraType);
 
     void initSpace(CameraDetail cameraDetail);
     void initSpace(Long cameraId);

+ 5 - 0
src/main/java/com/fdkankan/ucenter/service/impl/CameraDetailServiceImpl.java

@@ -306,6 +306,11 @@ public class CameraDetailServiceImpl extends ServiceImpl<ICameraDetailMapper, Ca
         if(detailEntity == null){
             return false;
         }
+        return checkSpace(detailEntity,cameraType);
+    }
+
+    @Override
+    public Boolean checkSpace(CameraDetail detailEntity, CameraType cameraType) {
         if (!"aws".equals(NacosProperty.uploadType) && cameraType.getIsLaser() == 1) {
             return true;
         }

+ 67 - 2
src/main/java/com/fdkankan/ucenter/service/impl/SceneCommonService.java

@@ -4,6 +4,7 @@ import cn.hutool.core.io.FileUtil;
 import cn.hutool.extra.qrcode.QrCodeUtil;
 import cn.hutool.extra.qrcode.QrConfig;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.fdkankan.common.constant.SceneVersionType;
 import com.fdkankan.common.exception.BusinessException;
 import com.fdkankan.common.util.FileUtils;
@@ -11,8 +12,8 @@ import com.fdkankan.common.util.SnowflakeIdGenerator;
 import com.fdkankan.fyun.face.FYunFileServiceInterface;
 import com.fdkankan.ucenter.common.RedisKeyUtil;
 import com.fdkankan.ucenter.common.constants.ResultCode;
-import com.fdkankan.ucenter.entity.SceneResource;
-import com.fdkankan.ucenter.service.IScene3dNumService;
+import com.fdkankan.ucenter.entity.*;
+import com.fdkankan.ucenter.service.*;
 import com.fdkankan.ucenter.util.SceneResourcePath;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.ObjectUtils;
@@ -21,6 +22,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
 import java.util.function.ObjDoubleConsumer;
@@ -246,4 +249,66 @@ public class SceneCommonService {
             }
         }
     }
+
+    @Autowired
+    ISceneProService sceneProService;
+    @Autowired
+    ICameraDetailService cameraDetailService;
+    @Autowired
+    ICameraTypeService cameraTypeService;
+    @Autowired
+    IScenePlusService scenePlusService;
+    @Autowired
+    IScenePlusExtService scenePlusExtService;
+
+    public void copyResult(String newNum) {
+        ScenePro scenePro = sceneProService.getByNum(newNum);
+        ScenePlus scenePlus = scenePlusService.getByNum(newNum);
+        if(scenePro == null && scenePlus == null){
+            log.info("复制失败:{}",newNum);
+            return;
+        }
+        Long cameraId = scenePro == null ? scenePlus.getCameraId() : scenePro.getCameraId();
+        Integer location = null;
+        Long space = 0L;
+        if(scenePlus != null){
+            ScenePlusExt plusExt = scenePlusExtService.getByPlusId(scenePlus.getId());
+            if(plusExt == null){
+                return;
+            }
+            location = plusExt.getLocation();
+            space = plusExt.getSpace();
+
+        }
+        if(scenePro != null){
+            space = scenePro.getSpace();
+        }
+        CameraDetail cameraDetail = cameraDetailService.getByCameraId(cameraId);
+        CameraType cameraType = cameraTypeService.getByCameraType(cameraDetail.getType());
+
+        Boolean checkSpace = cameraDetailService.checkSpace(cameraDetail,cameraType);
+        if(!checkSpace){
+            List<String> panoNumList = new ArrayList<>();
+            if(location != null && location == 7){
+                panoNumList.add(scenePlus.getNum());
+            }
+            sceneProService.lockOrUnLockScenes(new ArrayList<>(), Arrays.asList(newNum),-2,cameraType.getIsLaser(),panoNumList);
+        }
+        cameraDetailService.addUsedSpace(cameraDetail,space);
+
+
+        if(cameraType.getIsLaser() == 1 && scenePlus != null){
+            LambdaUpdateWrapper<ScenePlus> wrapper = new LambdaUpdateWrapper<>();
+            wrapper.eq(ScenePlus::getId,scenePlus.getId());
+            wrapper.set(ScenePlus::getSceneStatus,-2);
+            scenePlusService.update(wrapper);
+        }
+        if(cameraType.getIsLaser() == 1 && scenePro != null){
+            LambdaUpdateWrapper<ScenePro> wrapper = new LambdaUpdateWrapper<>();
+            wrapper.eq(ScenePro::getId,scenePro.getId());
+            wrapper.set(ScenePro::getStatus,-2);
+            sceneProService.update(wrapper);
+        }
+
+    }
 }

+ 14 - 28
src/main/java/com/fdkankan/ucenter/service/impl/SceneProServiceImpl.java

@@ -701,7 +701,7 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
         if(!canSpace){
             throw new BusinessException(CameraConstant.FAILURE_CODE_6008, CameraConstant.FAILURE_MSG_6008);
         }
-        copyScene(detailEntity,scenePro,scenePlus,cameraType);
+        copyScene(sceneNum,detailEntity,scenePro,scenePlus,cameraType);
 
     }
 
@@ -735,37 +735,23 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
             throw new BusinessException(CameraConstant.FAILURE_CODE_6008, CameraConstant.FAILURE_MSG_6008);
         }
 
-        copyScene(detailEntity,scenePro,scenePlus,cameraType);
+        copyScene(sceneNum,detailEntity,scenePro,scenePlus,cameraType);
     }
 
-    private  void copyScene(CameraDetail detailEntity,ScenePro scenePro,ScenePlus scenePlus,CameraType cameraType) throws Exception {
-        String newNum = scene3dNumService.generateSceneNum(detailEntity.getType());
-
-        Long sceneId = scenePro == null ? scenePlus.getId() :scenePro.getId();
-        Long newSceneId = null;
-        FolderScene folderScene = folderSceneService.getByType(sceneId, null);
-        if(cameraType.getIsLaser() == 1){
-            String redisKey = RedisKeyUtil.laserCopyLock + newNum;
-            redisUtil.set(redisKey,"1",60*60);
-        }
-
-        if(scenePro !=null){        //v3场景复制
-            log.info("场景复制--V3--OldNum:{},oldTitle:{},newNum:{},", scenePro.getNum(),scenePro.getSceneName(),newNum);
-
-            newSceneId = this.copyV3Scene(scenePro, newNum, detailEntity,cameraType);
-        }
-        if(scenePlus != null){      //v4场景复制
-            log.info("场景复制--V4--OldNum:{},oldTitle:{},newNum:{}", scenePlus.getNum(),scenePlus.getTitle(),newNum);
+    @Autowired
+    RabbitMqProducer rabbitMqProducer;
 
-            newSceneId =  scenePlusService.copyV4Scene(scenePlus,newNum,detailEntity,cameraType);
-        }
-        log.info("场景复制--完成--sceneId:{}",newSceneId);
+    @Value("${queue.scene.copy:ucenter-copy-scene}")
+    private String copySceneQueue;
 
-        if(newSceneId != null && folderScene!= null){
-            folderScene.setId(null);
-            folderScene.setSceneId(newSceneId);
-            folderSceneService.save(folderScene);
-        }
+    private void copyScene(String oldNum,CameraDetail detailEntity,ScenePro scenePro,ScenePlus scenePlus,CameraType cameraType) throws Exception {
+        String newNum = scene3dNumService.generateSceneNum(detailEntity.getType());
+        Long userId = scenePro == null ? scenePlus.getUserId() :scenePro.getUserId();
+        sceneCopyLogService.saveByNum(oldNum,newNum,userId);
+        HashMap<String,String > map = new HashMap<>();
+        map.put("oldNum",oldNum);
+        map.put("newNum",newNum);
+        rabbitMqProducer.sendByWorkQueue(copySceneQueue,map);
     }
 
     @Override