ソースを参照

激光场景复制等待锁

lyhzzz 1 年間 前
コミット
d93073c544

+ 1 - 1
src/main/java/com/fdkankan/ucenter/common/RedisKeyUtil.java

@@ -15,5 +15,5 @@ public class RedisKeyUtil {
 
     public static final String SCENE_COOPERATION_NUM_USERID = "scene:cooperation:num:userId";
 
-
+    public static final String laserCopyLock = "ucenter:laser:copy:lock:";
 }

+ 1 - 5
src/main/java/com/fdkankan/ucenter/httpClient/service/LaserService.java

@@ -226,12 +226,8 @@ public class LaserService {
         }
         if(isObj == 1){
             params.put("buildObjStatus",isObj);
-
-        }
-        Result result = laserClient.saveOrEdit(newNum, params);
-        if( result.getCode() != HttpStatus.OK.value()){
-            log.error("激光场景状态同步失败!");
         }
+        rabbitMqProducer.sendByWorkQueue("laser-update-scene",params);
     }
 
     public List<SceneBySnCodeVo> getScenesBySnCode(String snCode, String token) {

+ 56 - 0
src/main/java/com/fdkankan/ucenter/mq/consumer/LaserSceneStatusConsumer.java

@@ -0,0 +1,56 @@
+package com.fdkankan.ucenter.mq.consumer;
+
+import com.alibaba.fastjson.JSONObject;
+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.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;
+
+/**
+ * 场景封存解封 mq
+ */
+@Slf4j
+@Component
+public class LaserSceneStatusConsumer {
+
+
+    @Autowired
+    RedisUtil redisUtil;
+
+    @RabbitListener(
+            queuesToDeclare = @Queue("${queue.scene.laser.status:update-scene-status-ucent}")
+    )
+    public void consumerQueue(Channel channel, Message message)  {
+        try {
+            String messageId = message.getMessageProperties().getMessageId();
+            String msg = new String(message.getBody(), StandardCharsets.UTF_8);
+            log.info("update-scene-status-ucent--messageId:{},msg:{}",messageId,msg);
+
+            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
+
+            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);
+            }
+
+        }catch (Exception e){
+            log.info("update-scene-status-ucent----消费失败",e);
+        }finally {
+
+        }
+
+    }
+
+}

+ 2 - 1
src/main/java/com/fdkankan/ucenter/service/IScenePlusService.java

@@ -3,6 +3,7 @@ package com.fdkankan.ucenter.service;
 import com.fdkankan.ucenter.common.PageInfo;
 import com.fdkankan.ucenter.common.Result;
 import com.fdkankan.ucenter.entity.CameraDetail;
+import com.fdkankan.ucenter.entity.CameraType;
 import com.fdkankan.ucenter.entity.ScenePlus;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.fdkankan.ucenter.vo.ResponseScene;
@@ -39,7 +40,7 @@ public interface IScenePlusService extends IService<ScenePlus> {
 
     ScenePlus getByNum(String sceneNum);
 
-    Long copyV4Scene(ScenePlus scenePlus,String newNum, CameraDetail cameraDetail) ;
+    Long copyV4Scene(ScenePlus scenePlus, String newNum, CameraDetail cameraDetail, CameraType cameraType) ;
 
     List<ScenePlus> getByIds(List<Long> plusIds);
 

+ 2 - 1
src/main/java/com/fdkankan/ucenter/service/ISceneProService.java

@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.fdkankan.ucenter.common.PageInfo;
 import com.fdkankan.ucenter.common.Result;
 import com.fdkankan.ucenter.entity.CameraDetail;
+import com.fdkankan.ucenter.entity.CameraType;
 import com.fdkankan.ucenter.entity.ScenePlus;
 import com.fdkankan.ucenter.entity.ScenePro;
 import com.baomidou.mybatisplus.extension.service.IService;
@@ -57,7 +58,7 @@ public interface ISceneProService extends IService<ScenePro> {
 
     ScenePro getByNum(String sceneNum);
 
-    Long copyV3Scene(ScenePro scenePro, String newNum, CameraDetail cameraDetail) throws Exception;
+    Long copyV3Scene(ScenePro scenePro, String newNum, CameraDetail cameraDetail, CameraType cameraType) throws Exception;
 
 
     void delete(String sceneNum,Long userId);

+ 13 - 2
src/main/java/com/fdkankan/ucenter/service/impl/ScenePlusServiceImpl.java

@@ -19,6 +19,7 @@ import com.fdkankan.image.MatrixToImageWriterUtil;
 import com.fdkankan.model.utils.CreateObjUtil;
 import com.fdkankan.ucenter.common.OssPath;
 import com.fdkankan.ucenter.common.PageInfo;
+import com.fdkankan.ucenter.common.RedisKeyUtil;
 import com.fdkankan.ucenter.common.Result;
 import com.fdkankan.ucenter.common.constants.ConstantFilePath;
 import com.fdkankan.ucenter.common.constants.NacosProperty;
@@ -174,11 +175,10 @@ public class ScenePlusServiceImpl extends ServiceImpl<IScenePlusMapper, ScenePlu
     }
 
     @Override
-    public Long copyV4Scene(ScenePlus scenePlus,String newNum ,CameraDetail cameraDetail)  {
+    public Long copyV4Scene(ScenePlus scenePlus,String newNum ,CameraDetail cameraDetail,CameraType cameraType)  {
         String oldNum = scenePlus.getNum();
 
         Long plusId = scenePlus.getId();
-        CameraType cameraType = cameraTypeService.getByCameraType(cameraDetail.getType());
 
         ScenePlusExt plusExt = scenePlusExtService.getByPlusId(plusId);
         if(plusExt == null){
@@ -268,6 +268,17 @@ public class ScenePlusServiceImpl extends ServiceImpl<IScenePlusMapper, ScenePlu
                     laserService.copy(oldNum,scenePlus.getCameraId(),scenePlus.getCreateTime(),newNum,2,laserPath,
                             sceneEditInfo.getScenePassword(),plusExt.getLocation(),scenePlus.getUserId(),"V4",plusExt.getIsObj(),scenePlus.getSceneSource(),plusExt.getAlgorithmTime(),plusExt.getShootCount());
                 }
+                String redisKey = RedisKeyUtil.laserCopyLock + newNum;
+                long startTime = new Date().getTime();
+                long startTime2 = new Date().getTime();
+                while (redisUtil.hasKey(redisKey) ){     //深时场景复制同步锁
+                    long waitTime = new Date().getTime();
+                    if(waitTime - startTime2 >1000){
+                        startTime2  = new Date().getTime();
+                        log.info("等待激光复制业务结束----:{}",(waitTime - startTime) /1000);
+                    }
+                }
+
                 scenePlus.setSceneStatus(-2);
                 this.updateById(scenePlus);
                 sceneCopyLogService.saveByNum(oldNum,newNum,scenePlus.getUserId());

+ 11 - 7
src/main/java/com/fdkankan/ucenter/service/impl/SceneProServiceImpl.java

@@ -23,6 +23,7 @@ import com.fdkankan.ucenter.common.OssPath;
 import com.fdkankan.ucenter.common.PageInfo;
 import com.fdkankan.fyun.face.FYunFileServiceInterface;
 import com.fdkankan.image.MatrixToImageWriterUtil;
+import com.fdkankan.ucenter.common.RedisKeyUtil;
 import com.fdkankan.ucenter.common.constants.ConstantFilePath;
 import com.fdkankan.redis.util.RedisUtil;
 import com.fdkankan.ucenter.common.constants.NacosProperty;
@@ -691,7 +692,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);
+        copyScene(detailEntity,scenePro,scenePlus,cameraType);
 
     }
 
@@ -725,25 +726,29 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
             throw new BusinessException(CameraConstant.FAILURE_CODE_6008, CameraConstant.FAILURE_MSG_6008);
         }
 
-        copyScene(detailEntity,scenePro,scenePlus);
+        copyScene(detailEntity,scenePro,scenePlus,cameraType);
     }
 
-    private  void copyScene(CameraDetail detailEntity,ScenePro scenePro,ScenePlus scenePlus) throws Exception {
+    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);
+            newSceneId = this.copyV3Scene(scenePro, newNum, detailEntity,cameraType);
         }
         if(scenePlus != null){      //v4场景复制
             log.info("场景复制--V4--OldNum:{},oldTitle:{},newNum:{}", scenePlus.getNum(),scenePlus.getTitle(),newNum);
 
-            newSceneId =  scenePlusService.copyV4Scene(scenePlus,newNum,detailEntity);
+            newSceneId =  scenePlusService.copyV4Scene(scenePlus,newNum,detailEntity,cameraType);
         }
         log.info("场景复制--完成--sceneId:{}",newSceneId);
 
@@ -768,7 +773,7 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
 
 
     @Override
-    public Long copyV3Scene(ScenePro scenePro,String newNum,CameraDetail cameraDetail) throws Exception {
+    public Long copyV3Scene(ScenePro scenePro,String newNum,CameraDetail cameraDetail,CameraType cameraType) throws Exception {
 
         String oldNum = scenePro.getNum();
         Long sceneProId = scenePro.getId();
@@ -782,7 +787,6 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
         scenePro.setStatus(0);
         this.save(scenePro);
 
-        CameraType cameraType = cameraTypeService.getByCameraType(cameraDetail.getType());
 
         ExecutorService executor = ThreadUtil.newSingleExecutor();
         try {