Bläddra i källkod

复制激光场景等待锁

lyhzzz 1 år sedan
förälder
incheckning
8dee9e6647

+ 3 - 0
src/main/java/com/fdkankan/manage_jp/common/RedisKeyUtil.java

@@ -9,4 +9,7 @@ public class RedisKeyUtil {
 
     public static final String loginToken= "manage:login:token:%s";
 
+    public static final String laserCopyLock = "manage:laser:copy:lock:";
+
+
 }

+ 1 - 0
src/main/java/com/fdkankan/manage_jp/common/ResultCode.java

@@ -44,6 +44,7 @@ public enum ResultCode  {
     GENERATE_OBJ_EXITS(5025, "场景已生成obj"),
     CAMERA_NOT_MOVE(5026, "场景已在改相机,无需迁移"),
     CAMERA_TYPE_NOT_ERROR(5027, "相机类型不同,不能迁移"),
+    SCENE_MODELING(5028, "正在计算中,请耐心等待"),
 
 
     ;

+ 53 - 0
src/main/java/com/fdkankan/manage_jp/mq/consumer/LaserSceneStatusConsumer.java

@@ -0,0 +1,53 @@
+package com.fdkankan.manage_jp.mq.consumer;
+
+import com.alibaba.fastjson.JSONObject;
+import com.fdkankan.manage_jp.common.RedisKeyUtil;
+import com.fdkankan.redis.util.RedisUtil;
+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");
+            String redisKey = RedisKeyUtil.laserCopyLock + num;
+            if(redisUtil.hasKey(redisKey)){
+                redisUtil.del(redisKey);
+            }
+
+        }catch (Exception e){
+            log.info("update-scene-status-ucent----消费失败",e);
+        }finally {
+
+        }
+
+    }
+
+}

+ 15 - 2
src/main/java/com/fdkankan/manage_jp/service/impl/SceneCommonService.java

@@ -12,6 +12,7 @@ import com.fdkankan.common.constant.SceneVersionType;
 import com.fdkankan.common.util.FileUtils;
 import com.fdkankan.fyun.face.FYunFileServiceInterface;
 import com.fdkankan.image.MatrixToImageWriterUtil;
+import com.fdkankan.manage_jp.common.RedisKeyUtil;
 import com.fdkankan.manage_jp.common.ResultCode;
 import com.fdkankan.manage_jp.entity.*;
 import com.fdkankan.manage_jp.exception.BusinessException;
@@ -19,6 +20,7 @@ import com.fdkankan.manage_jp.httpClient.service.LaserService;
 import com.fdkankan.manage_jp.service.*;
 import com.fdkankan.manage_jp.util.SceneResourcePath;
 import com.fdkankan.manage_jp.util.SnowflakeIdGenerator;
+import com.fdkankan.redis.util.RedisUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
@@ -58,6 +60,8 @@ public class SceneCommonService {
     ISceneProService sceneProService;
     @Autowired
     ISceneProEditService sceneProEditService;
+    @Autowired
+    RedisUtil redisUtil;
 
     public String getNewNum(String oldNum ){
         String newNum = scene3dNumService.generateNum();
@@ -222,8 +226,6 @@ public class SceneCommonService {
             log.info("sceneCopy-V4-oldNum:{},oldDataSource:{},newNum:{},newDataSource:{}",
                     oldNum,oldDataSource,newNum,newDataSource);
 
-
-
             String newVideos = plusExt.getVideos();
             if(StrUtil.isNotEmpty(newVideos)){
                 newVideos = plusExt.getVideos().replaceAll("/data/data" + oldNum, "/scene_view_data/" + newNum + "/data").replaceAll(oldNum, newNum);
@@ -294,6 +296,17 @@ public class SceneCommonService {
                         sceneEditInfo.getScenePassword(),scenePlus.getUserId(),"V4",
                         oldNum,plusExt.getAlgorithmTime(),scenePlus.getSceneSource(),plusExt.getShootCount(),plusExt.getLocation(),plusExt.getIsObj());
             }
+            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);
             scenePlusService.updateById(scenePlus);
         }catch (Exception e){

+ 8 - 0
src/main/java/com/fdkankan/manage_jp/service/impl/ScenePlusServiceImpl.java

@@ -11,6 +11,7 @@ import com.fdkankan.common.constant.SceneVersionType;
 import com.fdkankan.common.util.FileUtils;
 import com.fdkankan.fyun.face.FYunFileServiceInterface;
 import com.fdkankan.manage_jp.common.OssPath;
+import com.fdkankan.manage_jp.common.RedisKeyUtil;
 import com.fdkankan.manage_jp.common.Result;
 import com.fdkankan.manage_jp.common.ResultCode;
 import com.fdkankan.manage_jp.entity.*;
@@ -20,6 +21,7 @@ import com.fdkankan.manage_jp.mapper.IScenePlusMapper;
 import com.fdkankan.manage_jp.service.*;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fdkankan.manage_jp.util.SceneResourcePath;
+import com.fdkankan.redis.util.RedisUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.bytedeco.javacpp.presets.opencv_core;
@@ -66,6 +68,8 @@ public class ScenePlusServiceImpl extends ServiceImpl<IScenePlusMapper, ScenePlu
     LaserService laserService;
     @Autowired
     ISceneProService sceneProService;
+    @Autowired
+    RedisUtil redisUtil;
 
     @Override
     public ScenePlus getByNum(String sceneNum) {
@@ -120,6 +124,10 @@ public class ScenePlusServiceImpl extends ServiceImpl<IScenePlusMapper, ScenePlu
         scenePlus.setId(null);
         this.save(scenePlus);
 
+        if(scenePlus.getSceneSource() == 4 || scenePlus.getSceneSource() == 5){
+            String redisKey = RedisKeyUtil.laserCopyLock + newNum;
+            redisUtil.set(redisKey,"1",60*60);
+        }
         try {
             sceneCommonService.v4Async(plusExt,oldNum,newNum,scenePlus,plusId,oldSceneName);
         }catch (Exception e){

+ 2 - 2
src/main/java/com/fdkankan/manage_jp/service/impl/SceneProServiceImpl.java

@@ -368,7 +368,7 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
         ScenePlusExt scenePlusExt = null;
         if(scenePlusEntity != null){
             if(scenePlusEntity.getSceneStatus() !=-2){
-                throw new BusinessException(ResultCode.SCENE_ERROR);
+                throw new BusinessException(ResultCode.SCENE_MODELING);
             }
              scenePlusExt = scenePlusExtService.getByPlusId(scenePlusEntity.getId());
             if(scenePlusExt == null){
@@ -378,7 +378,7 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
         }else {
             path = sceneProEntity.getDataSource();
             if(sceneProEntity.getStatus() !=-2){
-                throw new BusinessException(ResultCode.SCENE_ERROR);
+                throw new BusinessException(ResultCode.SCENE_MODELING);
             }
         }