dengsixing vor 3 Jahren
Ursprung
Commit
2212133f16
21 geänderte Dateien mit 2050 neuen und 1059 gelöschten Zeilen
  1. 6 0
      4dkankan-center-modeling/pom.xml
  2. 41 0
      4dkankan-center-modeling/src/main/java/com/fdkankan/modeling/receiver/RabbitMqListener.java
  3. 4 0
      4dkankan-center-modeling/src/main/resources/bootstrap-dev.yml
  4. 4 0
      4dkankan-center-modeling/src/main/resources/bootstrap-pro.yml
  5. 4 0
      4dkankan-center-modeling/src/main/resources/bootstrap-test.yml
  6. 9 4
      4dkankan-center-scene/pom.xml
  7. 0 30
      4dkankan-center-scene/src/main/java/com/fdkankan/scene/config/RabbitMqConfig.java
  8. 17 32
      4dkankan-center-scene/src/main/java/com/fdkankan/scene/controller/TestController.java
  9. 94 94
      4dkankan-center-scene/src/main/java/com/fdkankan/scene/listener/BuildSceneFailDTMQListener.java
  10. 144 144
      4dkankan-center-scene/src/main/java/com/fdkankan/scene/listener/BuildScenePreMQListener.java
  11. 443 443
      4dkankan-center-scene/src/main/java/com/fdkankan/scene/listener/BuildSceneResultMQListener.java
  12. 101 7
      4dkankan-center-scene/src/main/java/com/fdkankan/scene/listener/RabbitMqListener.java
  13. 17 0
      4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/IBuildSceneDTService.java
  14. 25 0
      4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/IBuildScenePostService.java
  15. 11 9
      4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/IBuildScenePreService.java
  16. 56 0
      4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/impl/BuildSceneDTServiceImpl.java
  17. 709 0
      4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/impl/BuildScenePostServiceImpl.java
  18. 340 283
      4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/impl/BuildScenePreServiceImpl.java
  19. 17 13
      4dkankan-center-scene/src/main/resources/bootstrap-dev.yml
  20. 4 0
      4dkankan-center-scene/src/main/resources/bootstrap-pro.yml
  21. 4 0
      4dkankan-center-scene/src/main/resources/bootstrap-test.yml

+ 6 - 0
4dkankan-center-modeling/pom.xml

@@ -40,6 +40,12 @@
 
 		<dependency>
 			<groupId>com.fdkankan</groupId>
+			<artifactId>4dkankan-utils-rabbitmq</artifactId>
+			<version>2.0.0-SNAPSHOT</version>
+		</dependency>
+
+		<dependency>
+			<groupId>com.fdkankan</groupId>
 			<artifactId>4dkankan-utils-redis</artifactId>
 			<version>2.0.0-SNAPSHOT</version>
 		</dependency>

+ 41 - 0
4dkankan-center-modeling/src/main/java/com/fdkankan/modeling/receiver/RabbitMqListener.java

@@ -0,0 +1,41 @@
+package com.fdkankan.modeling.receiver;
+
+import com.alibaba.fastjson.JSONObject;
+import com.fdkankan.mq.message.BuildSceneMqMessage;
+import java.nio.charset.StandardCharsets;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+/**
+ * <p>
+ * TODO
+ * </p>
+ *
+ * @author dengsixing
+ * @since 2022/4/20
+ **/
+@Slf4j
+@Component
+public class RabbitMqListener {
+
+    /**
+     * 场景计算前置资源准备处理
+     * @param channel
+     * @param message
+     * @throws Exception
+     */
+    @RabbitListener(
+        queuesToDeclare = @Queue("${queue.modeling.modeling-pre}"),
+        concurrency = "${maxThread.modeling.modeling-pre}"
+    )
+    public void buildScenePreHandler(Channel channel, Message message) throws Exception {
+        String correlationId = message.getMessageProperties().getCorrelationId();
+        String msg = new String(message.getBody(), StandardCharsets.UTF_8);
+        BuildSceneMqMessage buildSceneMessage = JSONObject.parseObject(msg, BuildSceneMqMessage.class);
+        log.info("场景计算资源准备开始,队列名:{},id:{}", queueModelingPre, correlationId);
+        Thread.sleep(2000L);
+        buildScenePreService.buildScenePre(buildSceneMessage);
+        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
+    }
+
+}

+ 4 - 0
4dkankan-center-modeling/src/main/resources/bootstrap-dev.yml

@@ -24,6 +24,10 @@ spring:
             group: DEFAULT_GROUP
             refresh: true
 
+          - data-id: common-rabbitmq-config.yaml
+            group: DEFAULT_GROUP
+            refresh: true
+
           - data-id: other-config.yaml
             group: DEFAULT_GROUP
             refresh: true

+ 4 - 0
4dkankan-center-modeling/src/main/resources/bootstrap-pro.yml

@@ -20,6 +20,10 @@ spring:
             group: DEFAULT_GROUP
             refresh: true
 
+          - data-id: common-rabbitmq-config.yaml
+            group: DEFAULT_GROUP
+            refresh: true
+
           - data-id: other-config.yaml
             group: DEFAULT_GROUP
             refresh: true

+ 4 - 0
4dkankan-center-modeling/src/main/resources/bootstrap-test.yml

@@ -20,6 +20,10 @@ spring:
             group: DEFAULT_GROUP
             refresh: true
 
+          - data-id: common-rabbitmq-config.yaml
+            group: DEFAULT_GROUP
+            refresh: true
+
           - data-id: other-config.yaml
             group: DEFAULT_GROUP
             refresh: true

+ 9 - 4
4dkankan-center-scene/pom.xml

@@ -42,6 +42,11 @@
         </dependency>
         <dependency>
             <groupId>com.fdkankan</groupId>
+            <artifactId>4dkankan-utils-rabbitmq</artifactId>
+            <version>2.0.0-SNAPSHOT</version>
+        </dependency>
+        <dependency>
+            <groupId>com.fdkankan</groupId>
             <artifactId>4dkankan-utils-redis</artifactId>
             <version>2.0.0-SNAPSHOT</version>
         </dependency>
@@ -109,10 +114,10 @@
             <version>2.3.1</version>
         </dependency>
 
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-amqp</artifactId>
-        </dependency>
+<!--        <dependency>-->
+<!--            <groupId>org.springframework.boot</groupId>-->
+<!--            <artifactId>spring-boot-starter-amqp</artifactId>-->
+<!--        </dependency>-->
 
 
     </dependencies>

+ 0 - 30
4dkankan-center-scene/src/main/java/com/fdkankan/scene/config/RabbitMqConfig.java

@@ -1,30 +0,0 @@
-package com.fdkankan.scene.config;
-
-import org.springframework.amqp.core.Queue;
-import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
-import org.springframework.boot.SpringBootConfiguration;
-import org.springframework.context.annotation.Bean;
-
-/**
- * <p>
- * TODO
- * </p>
- *
- * @author dengsixing
- * @since 2022/4/19
- **/
-@SpringBootConfiguration
-public class RabbitMqConfig {
-
-    // 配置一个工作模型队列
-    @Bean
-    public Queue queueWork() {
-        return new Queue("queue_work_dsx");
-    }
-
-    @Bean
-    public Jackson2JsonMessageConverter messageConverter(){
-        return new Jackson2JsonMessageConverter();
-    }
-
-}

+ 17 - 32
4dkankan-center-scene/src/main/java/com/fdkankan/scene/controller/TestController.java

@@ -1,45 +1,34 @@
 package com.fdkankan.scene.controller;
 
-import cn.hutool.core.date.DateUtil;
 import com.alibaba.druid.pool.DruidDataSource;
 import com.alibaba.fastjson.JSONObject;
-import com.fdkankan.common.constant.ErrorCode;
 import com.fdkankan.common.controller.BaseController;
-import com.fdkankan.common.exception.BusinessException;
 import com.fdkankan.common.response.ResultData;
-import com.fdkankan.common.util.DateExtUtil;
 import com.fdkankan.common.util.SpringUtil;
 import com.fdkankan.mq.message.BuildSceneMqMessage;
 import com.fdkankan.mq.util.RocketMQProducer;
-import com.fdkankan.platform.api.feign.PlatformGoodsClient;
-import com.fdkankan.platform.api.feign.PlatformUserClient;
 import com.fdkankan.platform.api.dto.Camera;
 import com.fdkankan.platform.api.dto.Company;
 import com.fdkankan.platform.api.dto.User;
+import com.fdkankan.platform.api.feign.PlatformGoodsClient;
+import com.fdkankan.platform.api.feign.PlatformUserClient;
+import com.fdkankan.rabbitmq.config.ModelingQueueConfig;
+import com.fdkankan.rabbitmq.util.RabbitMqProducer;
 import com.fdkankan.redis.util.RedisLockUtil;
 import com.fdkankan.redis.util.RedisUtil;
 import com.fdkankan.scene.service.IFolderService;
 import com.fdkankan.scene.service.IScene3dNumService;
 import com.fdkankan.scene.service.ISceneService;
-import com.fdkankan.scene.service.impl.IFdkkLaserServiceImpl.Result;
-import com.fdkankan.scene.vo.SceneEditInfoVO;
 import com.fdkankan.scene.vo.SceneVO;
-import com.fdkankan.scene.vo.UploadPanoramaVO;
 import com.google.common.collect.Lists;
-import com.sun.org.apache.bcel.internal.generic.RETURN;
-import com.yomahub.tlog.core.mq.TLogMqWrapBean;
-import com.yomahub.tlog.id.TLogIdGenerator;
 import com.yomahub.tlog.task.spring.SpringScheduledTaskAop;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Enumeration;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import javax.swing.Spring;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import javax.sql.DataSource;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.rocketmq.client.producer.MQProducer;
 import org.springframework.amqp.rabbit.core.RabbitTemplate;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -48,17 +37,8 @@ import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
-import javax.sql.DataSource;
-import java.sql.SQLException;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import org.springframework.web.multipart.MultipartFile;
-
 @RefreshScope
 @RestController
 @RequestMapping("/service/scene/test")
@@ -99,6 +79,11 @@ public class TestController extends BaseController {
     @Autowired
     private RabbitTemplate rabbitTemplate;
 
+    @Autowired
+    ModelingQueueConfig modelingQueueConfig;
+    @Autowired
+    private RabbitMqProducer rabbitMqProducer;
+
 
 
     @PostMapping("/test")
@@ -150,10 +135,10 @@ public class TestController extends BaseController {
 //        TLogIdGenerator bean = SpringUtil.getBean(TLogIdGenerator.class);
 //        log.info(bean.generateTraceId());
 
-        for(int i=0; i<1; i++){
+        for(int i=0; i<5; i++){
             BuildSceneMqMessage message = new BuildSceneMqMessage();
             message.setFileId("hhjjS鬼地方个" + "-" + i);
-            rabbitTemplate.convertAndSend("queue_work_dsx", message);
+            rabbitMqProducer.sendByWorkQueue(modelingQueueConfig.modelingPre, message);
         }
 
         return ResultData.ok();

+ 94 - 94
4dkankan-center-scene/src/main/java/com/fdkankan/scene/listener/BuildSceneFailDTMQListener.java

@@ -1,94 +1,94 @@
-package com.fdkankan.scene.listener;
-
-import com.alibaba.fastjson.JSONObject;
-import com.fdkankan.common.util.ComputerUtil;
-import com.fdkankan.fyun.oss.UploadToOssUtil;
-import com.fdkankan.mq.message.BuildSceneFailDTMqMessage;
-import com.fdkankan.mq.message.BuildSceneMqMessage;
-import com.fdkankan.mq.util.RocketMQProducer;
-import com.fdkankan.platform.api.feign.PlatformGoodsClient;
-import com.fdkankan.platform.api.feign.PlatformUserClient;
-import com.fdkankan.scene.service.IBuildScenePreService;
-import com.fdkankan.scene.service.ISceneEditControlsService;
-import com.fdkankan.scene.service.ISceneEditInfoService;
-import com.fdkankan.scene.service.ISceneFileBuildService;
-import com.fdkankan.scene.service.ISceneProExtService;
-import com.fdkankan.scene.service.ISceneProService;
-import com.fdkankan.scene.service.ISceneService;
-import com.fdkankan.scene.service.impl.BuildScenePreServiceImpl;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.rocketmq.spring.annotation.MessageModel;
-import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
-import org.apache.rocketmq.spring.core.RocketMQListener;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Component;
-
-
-/**
- * <p>
-        场景计算前准备工作,如下载资源等
- * </p>
- * @author dengsixing
- * @date 2022/2/23
- **/
-@Slf4j
-@Component
-@RocketMQMessageListener(
-        consumerGroup = "${rocketmq.consumer.build-scene-dt-group}",
-        topic = "${rocketmq.build-scene.topicName.topic-modeling-a-dt}",
-        messageModel = MessageModel.CLUSTERING,//负载均衡模式
-        consumeThreadMax = 10
-)
-public class BuildSceneFailDTMQListener implements RocketMQListener<String> {
-
-
-    @Value("${main.url}")
-    private String mainUrl;
-
-    @Value("${scene.pro.url}")
-    private String sceneProUrl;
-
-    @Value("${scene.pro.new.url}")
-    private String sceneProNewUrl;
-
-    @Autowired
-    ISceneService sceneService;
-    @Autowired
-    ISceneFileBuildService sceneFileBuildService;
-    @Autowired
-    ISceneProService sceneProService;
-    @Autowired
-    ISceneProExtService sceneProExtService;
-    @Autowired
-    PlatformGoodsClient platformGoodsClient;
-    @Autowired
-    PlatformUserClient platformUserClient;
-    @Autowired
-    ISceneEditInfoService sceneEditInfoService;
-    @Autowired
-    ISceneEditControlsService sceneEditControlsService;
-    @Autowired
-    UploadToOssUtil uploadToOssUtil;
-    @Autowired
-    IBuildScenePreService buildScenePreService;
-    @Autowired
-    private RocketMQProducer producer;
-    @Value("${rocketmq.build-scene.topicName.topic-modeling-a}")
-    private String topicName;
-
-
-    @Override
-    public void onMessage(String message) {
-
-        BuildSceneFailDTMqMessage buildSceneMqMessage = JSONObject.parseObject(message, BuildSceneFailDTMqMessage.class);
-        log.info("开始处理消息,消费者组:{},主题名:{}, 消息内容:{}", "build-scene-dt-group", "topic-modeling-a-dt", message);
-        process(buildSceneMqMessage);
-    }
-
-    private void process(BuildSceneFailDTMqMessage message){
-//        buildScenePreService.handFail(message.getReason(), message.getServerPath(), message.getNum(), message.getHostName(),
-//            BuildScenePreServiceImpl.contentExt);
-    }
-
-}
+//package com.fdkankan.scene.listener;
+//
+//import com.alibaba.fastjson.JSONObject;
+//import com.fdkankan.common.util.ComputerUtil;
+//import com.fdkankan.fyun.oss.UploadToOssUtil;
+//import com.fdkankan.mq.message.BuildSceneFailDTMqMessage;
+//import com.fdkankan.mq.message.BuildSceneMqMessage;
+//import com.fdkankan.mq.util.RocketMQProducer;
+//import com.fdkankan.platform.api.feign.PlatformGoodsClient;
+//import com.fdkankan.platform.api.feign.PlatformUserClient;
+//import com.fdkankan.scene.service.IBuildScenePreService;
+//import com.fdkankan.scene.service.ISceneEditControlsService;
+//import com.fdkankan.scene.service.ISceneEditInfoService;
+//import com.fdkankan.scene.service.ISceneFileBuildService;
+//import com.fdkankan.scene.service.ISceneProExtService;
+//import com.fdkankan.scene.service.ISceneProService;
+//import com.fdkankan.scene.service.ISceneService;
+//import com.fdkankan.scene.service.impl.BuildScenePreServiceImpl;
+//import lombok.extern.slf4j.Slf4j;
+//import org.apache.rocketmq.spring.annotation.MessageModel;
+//import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
+//import org.apache.rocketmq.spring.core.RocketMQListener;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.beans.factory.annotation.Value;
+//import org.springframework.stereotype.Component;
+//
+//
+///**
+// * <p>
+//        场景计算前准备工作,如下载资源等
+// * </p>
+// * @author dengsixing
+// * @date 2022/2/23
+// **/
+//@Slf4j
+//@Component
+//@RocketMQMessageListener(
+//        consumerGroup = "${rocketmq.consumer.build-scene-dt-group}",
+//        topic = "${rocketmq.build-scene.topicName.topic-modeling-a-dt}",
+//        messageModel = MessageModel.CLUSTERING,//负载均衡模式
+//        consumeThreadMax = 10
+//)
+//public class BuildSceneFailDTMQListener implements RocketMQListener<String> {
+//
+//
+//    @Value("${main.url}")
+//    private String mainUrl;
+//
+//    @Value("${scene.pro.url}")
+//    private String sceneProUrl;
+//
+//    @Value("${scene.pro.new.url}")
+//    private String sceneProNewUrl;
+//
+//    @Autowired
+//    ISceneService sceneService;
+//    @Autowired
+//    ISceneFileBuildService sceneFileBuildService;
+//    @Autowired
+//    ISceneProService sceneProService;
+//    @Autowired
+//    ISceneProExtService sceneProExtService;
+//    @Autowired
+//    PlatformGoodsClient platformGoodsClient;
+//    @Autowired
+//    PlatformUserClient platformUserClient;
+//    @Autowired
+//    ISceneEditInfoService sceneEditInfoService;
+//    @Autowired
+//    ISceneEditControlsService sceneEditControlsService;
+//    @Autowired
+//    UploadToOssUtil uploadToOssUtil;
+//    @Autowired
+//    IBuildScenePreService buildScenePreService;
+//    @Autowired
+//    private RocketMQProducer producer;
+//    @Value("${rocketmq.build-scene.topicName.topic-modeling-a}")
+//    private String topicName;
+//
+//
+//    @Override
+//    public void onMessage(String message) {
+//
+//        BuildSceneFailDTMqMessage buildSceneMqMessage = JSONObject.parseObject(message, BuildSceneFailDTMqMessage.class);
+//        log.info("开始处理消息,消费者组:{},主题名:{}, 消息内容:{}", "build-scene-dt-group", "topic-modeling-a-dt", message);
+//        process(buildSceneMqMessage);
+//    }
+//
+//    private void process(BuildSceneFailDTMqMessage message){
+////        buildScenePreService.handFail(message.getReason(), message.getServerPath(), message.getNum(), message.getHostName(),
+////            BuildScenePreServiceImpl.contentExt);
+//    }
+//
+//}

+ 144 - 144
4dkankan-center-scene/src/main/java/com/fdkankan/scene/listener/BuildScenePreMQListener.java

@@ -1,144 +1,144 @@
-package com.fdkankan.scene.listener;
-
-import com.alibaba.fastjson.JSONObject;
-import com.fdkankan.common.constant.ModelingBuildStatus;
-import com.fdkankan.common.util.SceneUtil;
-import com.fdkankan.fyun.oss.UploadToOssUtil;
-import com.fdkankan.mq.message.BuildSceneMqMessage;
-import com.fdkankan.mq.util.RocketMQProducer;
-import com.fdkankan.platform.api.feign.PlatformGoodsClient;
-import com.fdkankan.platform.api.feign.PlatformUserClient;
-import com.fdkankan.redis.constant.RedisKey;
-import com.fdkankan.redis.util.RedisUtil;
-import com.fdkankan.scene.service.IBuildScenePreService;
-import com.fdkankan.scene.service.ISceneEditControlsService;
-import com.fdkankan.scene.service.ISceneEditInfoService;
-import com.fdkankan.scene.service.ISceneFileBuildService;
-import com.fdkankan.scene.service.ISceneProExtService;
-import com.fdkankan.scene.service.ISceneProService;
-import com.fdkankan.scene.service.ISceneService;
-import java.time.Duration;
-import java.time.temporal.ChronoUnit;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.rocketmq.spring.annotation.MessageModel;
-import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
-import org.apache.rocketmq.spring.core.RocketMQListener;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Component;
-
-
-/**
- * <p>
-        场景计算前准备工作,如下载资源等
- * </p>
- * @author dengsixing
- * @date 2022/2/23
- **/
-@Slf4j
-@Component
-@RocketMQMessageListener(
-        consumerGroup = "${rocketmq.consumer.build-scene-pre-group}",
-        topic = "${rocketmq.build-scene.topicName.topic-modeling-a-pre}",
-        messageModel = MessageModel.CLUSTERING,//负载均衡模式
-        consumeThreadMax = 10,
-        consumeTimeout = 172801000L
-)
-public class BuildScenePreMQListener implements RocketMQListener<String> {
-
-
-    @Value("${main.url}")
-    private String mainUrl;
-
-    @Value("${scene.pro.url}")
-    private String sceneProUrl;
-
-    @Value("${scene.pro.new.url}")
-    private String sceneProNewUrl;
-
-    @Autowired
-    ISceneService sceneService;
-    @Autowired
-    ISceneFileBuildService sceneFileBuildService;
-    @Autowired
-    ISceneProService sceneProService;
-    @Autowired
-    ISceneProExtService sceneProExtService;
-    @Autowired
-    PlatformGoodsClient platformGoodsClient;
-    @Autowired
-    PlatformUserClient platformUserClient;
-    @Autowired
-    ISceneEditInfoService sceneEditInfoService;
-    @Autowired
-    ISceneEditControlsService sceneEditControlsService;
-    @Autowired
-    UploadToOssUtil uploadToOssUtil;
-    @Autowired
-    IBuildScenePreService buildScenePreService;
-    @Autowired
-    private RocketMQProducer producer;
-    @Value("${rocketmq.build-scene.topicName.topic-modeling-a}")
-    private String topicName;
-    @Autowired
-    RedisUtil redisUtil;
-
-    @Value("${model.timeOut:48}")
-    private int modelTimeOut;
-
-
-    @Override
-    public void onMessage(String message) {
-
-        try {
-            BuildSceneMqMessage buildSceneMqMessage = JSONObject.parseObject(message, BuildSceneMqMessage.class);
-            log.info("开始处理消息,消费者组:{},主题名:{}, 消息内容:{}", "build-scene-pre-group", "topic-modeling-a-pre", message);
-            process(buildSceneMqMessage);
-        }catch (Exception e){
-
-        }
-
-    }
-
-    private void process(BuildSceneMqMessage message){
-        boolean success = false;
-        String reason = null;
-        try {
-            String key = String.format(RedisKey.SCENE_BUILDING, message.getSceneNum());
-            Long building = redisUtil.incr(key, 1);
-            if (building.compareTo(1L) != 0) {
-                log.error("场景正在构建中,退出构建,参数:{}", JSONObject.toJSONString(message));
-                reason = "重复计算";
-                return;
-            } else {
-                redisUtil.expire(key, Duration.of(modelTimeOut, ChronoUnit.HOURS));
-            }
-
-            //根据相机类型,组装资源路径
-            String path = SceneUtil.getPath(message.getPath(), message.getCameraName(),
-                message.getFileId(), Integer.parseInt(message.getCameraType()), message.getUnicode());
-
-            //下载资源到本地
-            this.buildScenePreService.downLoadSource(message, path);
-
-            //发送mq,就进行计算
-            producer.syncSend(topicName, message);
-
-            success = true;
-
-            log.info("场景计算前置处理完成,场景码:{}", message.getSceneNum());
-
-        }catch (Exception e){
-            log.error("场景计算前置处理出错", e);
-            reason = "场景计算前置处理出错";
-        }finally {
-            //如果前置处理失败,发送钉钉消息
-            if(!success){
-                String serverPath = message.getPath().substring(0,message.getPath().lastIndexOf("/")+1).concat(message.getPrefix());
-//            buildScenePreService.handFail(reason, serverPath, message.getSceneNum(), BuildScenePreServiceImpl.hostName, null);
-            }
-
-        }
-    }
-
-}
+//package com.fdkankan.scene.listener;
+//
+//import com.alibaba.fastjson.JSONObject;
+//import com.fdkankan.common.constant.ModelingBuildStatus;
+//import com.fdkankan.common.util.SceneUtil;
+//import com.fdkankan.fyun.oss.UploadToOssUtil;
+//import com.fdkankan.mq.message.BuildSceneMqMessage;
+//import com.fdkankan.mq.util.RocketMQProducer;
+//import com.fdkankan.platform.api.feign.PlatformGoodsClient;
+//import com.fdkankan.platform.api.feign.PlatformUserClient;
+//import com.fdkankan.redis.constant.RedisKey;
+//import com.fdkankan.redis.util.RedisUtil;
+//import com.fdkankan.scene.service.IBuildScenePreService;
+//import com.fdkankan.scene.service.ISceneEditControlsService;
+//import com.fdkankan.scene.service.ISceneEditInfoService;
+//import com.fdkankan.scene.service.ISceneFileBuildService;
+//import com.fdkankan.scene.service.ISceneProExtService;
+//import com.fdkankan.scene.service.ISceneProService;
+//import com.fdkankan.scene.service.ISceneService;
+//import java.time.Duration;
+//import java.time.temporal.ChronoUnit;
+//import lombok.extern.slf4j.Slf4j;
+//import org.apache.rocketmq.spring.annotation.MessageModel;
+//import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
+//import org.apache.rocketmq.spring.core.RocketMQListener;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.beans.factory.annotation.Value;
+//import org.springframework.stereotype.Component;
+//
+//
+///**
+// * <p>
+//        场景计算前准备工作,如下载资源等
+// * </p>
+// * @author dengsixing
+// * @date 2022/2/23
+// **/
+//@Slf4j
+////@Component
+////@RocketMQMessageListener(
+////        consumerGroup = "${rocketmq.consumer.build-scene-pre-group}",
+////        topic = "${rocketmq.build-scene.topicName.topic-modeling-a-pre}",
+////        messageModel = MessageModel.CLUSTERING,//负载均衡模式
+////        consumeThreadMax = 10,
+////        consumeTimeout = 172801000L
+////)
+//public class BuildScenePreMQListener implements RocketMQListener<String> {
+//
+//
+//    @Value("${main.url}")
+//    private String mainUrl;
+//
+//    @Value("${scene.pro.url}")
+//    private String sceneProUrl;
+//
+//    @Value("${scene.pro.new.url}")
+//    private String sceneProNewUrl;
+//
+//    @Autowired
+//    ISceneService sceneService;
+//    @Autowired
+//    ISceneFileBuildService sceneFileBuildService;
+//    @Autowired
+//    ISceneProService sceneProService;
+//    @Autowired
+//    ISceneProExtService sceneProExtService;
+//    @Autowired
+//    PlatformGoodsClient platformGoodsClient;
+//    @Autowired
+//    PlatformUserClient platformUserClient;
+//    @Autowired
+//    ISceneEditInfoService sceneEditInfoService;
+//    @Autowired
+//    ISceneEditControlsService sceneEditControlsService;
+//    @Autowired
+//    UploadToOssUtil uploadToOssUtil;
+//    @Autowired
+//    IBuildScenePreService buildScenePreService;
+//    @Autowired
+//    private RocketMQProducer producer;
+//    @Value("${rocketmq.build-scene.topicName.topic-modeling-a}")
+//    private String topicName;
+//    @Autowired
+//    RedisUtil redisUtil;
+//
+//    @Value("${model.timeOut:48}")
+//    private int modelTimeOut;
+//
+//
+//    @Override
+//    public void onMessage(String message) {
+//
+//        try {
+//            BuildSceneMqMessage buildSceneMqMessage = JSONObject.parseObject(message, BuildSceneMqMessage.class);
+//            log.info("开始处理消息,消费者组:{},主题名:{}, 消息内容:{}", "build-scene-pre-group", "topic-modeling-a-pre", message);
+//            process(buildSceneMqMessage);
+//        }catch (Exception e){
+//
+//        }
+//
+//    }
+//
+//    private void process(BuildSceneMqMessage message){
+//        boolean success = false;
+//        String reason = null;
+//        try {
+//            String key = String.format(RedisKey.SCENE_BUILDING, message.getSceneNum());
+//            Long building = redisUtil.incr(key, 1);
+//            if (building.compareTo(1L) != 0) {
+//                log.error("场景正在构建中,退出构建,参数:{}", JSONObject.toJSONString(message));
+//                reason = "重复计算";
+//                return;
+//            } else {
+//                redisUtil.expire(key, Duration.of(modelTimeOut, ChronoUnit.HOURS));
+//            }
+//
+//            //根据相机类型,组装资源路径
+//            String path = SceneUtil.getPath(message.getPath(), message.getCameraName(),
+//                message.getFileId(), Integer.parseInt(message.getCameraType()), message.getUnicode());
+//
+//            //下载资源到本地
+//            this.buildScenePreService.downLoadSource(message, path);
+//
+//            //发送mq,就进行计算
+//            producer.syncSend(topicName, message);
+//
+//            success = true;
+//
+//            log.info("场景计算前置处理完成,场景码:{}", message.getSceneNum());
+//
+//        }catch (Exception e){
+//            log.error("场景计算前置处理出错", e);
+//            reason = "场景计算前置处理出错";
+//        }finally {
+//            //如果前置处理失败,发送钉钉消息
+//            if(!success){
+//                String serverPath = message.getPath().substring(0,message.getPath().lastIndexOf("/")+1).concat(message.getPrefix());
+////            buildScenePreService.handFail(reason, serverPath, message.getSceneNum(), BuildScenePreServiceImpl.hostName, null);
+//            }
+//
+//        }
+//    }
+//
+//}

+ 443 - 443
4dkankan-center-scene/src/main/java/com/fdkankan/scene/listener/BuildSceneResultMQListener.java

@@ -1,443 +1,443 @@
-package com.fdkankan.scene.listener;
-
-import cn.hutool.core.collection.CollUtil;
-import com.alibaba.fastjson.JSONObject;
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
-import com.fdkankan.common.constant.BuildStatus;
-import com.fdkankan.common.constant.ConstantFilePath;
-import com.fdkankan.common.constant.ExpiredStatus;
-import com.fdkankan.common.constant.PayStatus;
-import com.fdkankan.common.constant.SceneFrom;
-import com.fdkankan.common.constant.SceneResolution;
-import com.fdkankan.common.constant.SceneSource;
-import com.fdkankan.common.constant.SceneStatus;
-import com.fdkankan.common.constant.ServerCode;
-import com.fdkankan.common.constant.UploadFilePath;
-import com.fdkankan.common.response.ResultData;
-import com.fdkankan.common.util.MatrixToImageWriterUtil;
-import com.fdkankan.fyun.oss.UploadToOssUtil;
-import com.fdkankan.mq.message.BuildSceneResultMqMessage;
-import com.fdkankan.platform.api.feign.PlatformGoodsClient;
-import com.fdkankan.platform.api.feign.PlatformUserClient;
-import com.fdkankan.platform.api.dto.CameraDetail;
-import com.fdkankan.platform.api.dto.UserIncrement;
-import com.fdkankan.redis.constant.RedisKey;
-import com.fdkankan.redis.util.RedisUtil;
-import com.fdkankan.scene.entity.SceneEditControls;
-import com.fdkankan.scene.entity.SceneEditInfo;
-import com.fdkankan.scene.entity.SceneFileBuild;
-import com.fdkankan.scene.entity.ScenePlus;
-import com.fdkankan.scene.entity.ScenePlusExt;
-import com.fdkankan.scene.entity.ScenePro;
-import com.fdkankan.scene.entity.SceneProExt;
-import com.fdkankan.scene.service.IBuildScenePreService;
-import com.fdkankan.scene.service.ISceneEditControlsService;
-import com.fdkankan.scene.service.ISceneEditInfoService;
-import com.fdkankan.scene.service.ISceneFileBuildService;
-import com.fdkankan.scene.service.IScenePlusExtService;
-import com.fdkankan.scene.service.IScenePlusService;
-import com.fdkankan.scene.service.ISceneProExtService;
-import com.fdkankan.scene.service.ISceneProService;
-import com.fdkankan.scene.service.ISceneService;
-import java.io.File;
-import java.util.Calendar;
-import java.util.Map;
-import java.util.stream.Collectors;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.rocketmq.spring.annotation.MessageModel;
-import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
-import org.apache.rocketmq.spring.core.RocketMQListener;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-
-import java.util.List;
-import java.util.Objects;
-import org.springframework.stereotype.Component;
-import org.springframework.transaction.annotation.Transactional;
-
-
-/**
- * <p>
-        场景计算后 写库相关业务逻辑
- * </p>
- * @author dengsixing
- * @date 2022/2/23
- **/
-@Slf4j
-@Component
-@RocketMQMessageListener(
-        consumerGroup = "${rocketmq.consumer.build-scene-result-group}",
-        topic = "${rocketmq.build-scene-result.topicName.topic-modeling-a}",
-        messageModel = MessageModel.CLUSTERING//负载均衡模式
-)
-public class BuildSceneResultMQListener implements RocketMQListener<String> {
-
-    @Value("${rocketmq.consumer.build-scene-result-group}")
-    private String consumerGroup;
-
-    @Value("${rocketmq.build-scene-result.topicName.topic-modeling-a}")
-    private String buildSceneResultTopic;
-
-    @Value("${main.url}")
-    private String mainUrl;
-
-    @Value("${scene.pro.url}")
-    private String sceneProUrl;
-
-    @Value("${scene.pro.new.url}")
-    private String sceneProNewUrl;
-
-    @Autowired
-    ISceneService sceneService;
-    @Autowired
-    ISceneFileBuildService sceneFileBuildService;
-    @Autowired
-    ISceneProService sceneProService;
-    @Autowired
-    ISceneProExtService sceneProExtService;
-    @Autowired
-    PlatformGoodsClient platformGoodsClient;
-    @Autowired
-    PlatformUserClient platformUserClient;
-    @Autowired
-    ISceneEditInfoService sceneEditInfoService;
-    @Autowired
-    ISceneEditControlsService sceneEditControlsService;
-    @Autowired
-    UploadToOssUtil uploadToOssUtil;
-    @Autowired
-    IBuildScenePreService buildScenePreService;
-    @Autowired
-    RedisUtil redisUtil;
-    @Autowired
-    IScenePlusService scenePlusService;
-    @Autowired
-    IScenePlusExtService scenePlusExtService;
-
-
-    @Override
-    public void onMessage(String message) {
-
-        BuildSceneResultMqMessage resultMqMessage = JSONObject.parseObject(message, BuildSceneResultMqMessage.class);
-        log.info("开始处理消息,消费者组:{},主题名:{}, 消息内容:{}", consumerGroup, buildSceneResultTopic, message);
-        process(resultMqMessage);
-    }
-
-    @Transactional
-    public void process(BuildSceneResultMqMessage message){
-        Integer cameraType = Integer.parseInt(message.getCameraType());
-        String sceneCode = message.getSceneCode();
-        String fileId = message.getFileId();
-        Integer payStatus = message.getPayStatus();
-        Long computeTime = message.getComputeTime();
-        Boolean buildSuccess = message.getBuildSuccess();
-        Integer videoVersion = message.getVideoVersion();
-
-        Map<String, String> uploadFiles = message.getUploadFiles();
-        String path = message.getPath();
-        Integer pushChannel = message.getPushChannel();
-        String pushToken = message.getPushToken();
-        String prefix = message.getPrefix();
-        try {
-            if(!buildSuccess){//建模失败,修改状态为失败状态
-                log.info("建模失败,修改状态为失败状态");
-                // TODO: 2022/3/21 plus版本稳定后删除------------------------start
-                sceneService.updateStatus(sceneCode, SceneStatus.FAILD.code());
-                sceneProService.updateStatus(sceneCode, SceneStatus.FAILD.code());
-                // TODO: 2022/3/21 plus版本稳定后删除------------------------send
-
-                scenePlusService.update(
-                    new LambdaUpdateWrapper<ScenePlus>()
-                        .set(ScenePlus::getSceneStatus, SceneStatus.FAILD.code())
-                        .eq(ScenePlus::getNum, sceneCode));
-
-                SceneFileBuild sceneFileBuild = sceneFileBuildService.findByFileId(fileId);
-                if(Objects.nonNull(sceneFileBuild)){
-                    sceneFileBuild.setBuildStatus(BuildStatus.fail.code());
-                    sceneFileBuildService.updateById(sceneFileBuild);
-                }
-                return;
-            }
-
-            //建模成功
-            log.info("cameraType:{}",cameraType);
-
-            //计算场景消耗磁盘空间
-            long space = buildScenePreService.calUseSpace(uploadFiles);
-
-            if(cameraType < 3){
-                // TODO: 2022/3/21 plus版本稳定后删除------------------------start
-                sceneService.updateTime(sceneCode, space, payStatus);
-                // TODO: 2022/3/21 plus版本稳定后删除------------------------send
-
-                this.updateDb4Sm(sceneCode, space);
-
-                uploadToOssUtil.uploadMulFiles(uploadFiles);
-                return;
-            }
-
-            //读取计算结果文件生成videosJson
-            JSONObject videosJson = buildScenePreService.getVideosJson(path, videoVersion, sceneCode, cameraType);
-
-            //写入数据库
-            // TODO: 2022/3/21 plus版本稳定后删除------------------------start
-            ScenePro scenePro = this.updateDbPro(sceneCode, space, payStatus, videosJson.toJSONString(), computeTime, fileId);
-            SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
-            // TODO: 2022/3/21 plus版本稳定后删除------------------------send
-            ScenePlus scenePlus = this.updateDbPlus(sceneCode, space, payStatus, videosJson.toJSONString(), computeTime, fileId);
-            ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
-
-            //变更容量,arrearCap为true时,代表容量不足
-            boolean arrearCap = this.updateSpace(scenePlus.getCameraId(), space, scenePlus.getId(), scenePro.getId());
-
-            //如果相机容量不足,需要把场景的paystatus改为容量不足状态
-            this.sealScene(arrearCap, scenePlus.getId(), scenePro.getId());
-
-            Object[] editInfoArr = this.updateEditInfo(scenePro, scenePlus);
-            SceneEditInfo sceneEditInfo = (SceneEditInfo)editInfoArr[0];
-            SceneEditControls sceneEditControls = (SceneEditControls)editInfoArr[1];
-
-            String sceneUrl = mainUrl + "/" + sceneProNewUrl;
-            String outPathZh = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneCode+".png";
-            String outPathEn = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneCode+"_en.png";
-            //生成新的分享的二维码-中文版本
-            MatrixToImageWriterUtil.createQRCode(sceneUrl + sceneCode, outPathZh, false,null);
-            //生成新的分享的二维码-英文版本
-            MatrixToImageWriterUtil.createQRCode(sceneUrl + sceneCode + "&lang=en", outPathEn, false, null);
-            //上传二维码
-            uploadToOssUtil.upload(outPathZh, String.format(UploadFilePath.DOWNLOADS_QRCODE, sceneCode) + sceneCode + ".png");
-            uploadToOssUtil.upload(outPathEn, String.format(UploadFilePath.DOWNLOADS_QRCODE, sceneCode) + sceneCode + "_en.png");
-
-            Map<String, String> newUploadFiles = buildScenePreService
-                .uploadFileMapHandler(sceneCode, cameraType, uploadFiles);
-
-            //上传计算结果中的caches/images和caches/videos
-            buildScenePreService.uploadCaches(sceneCode, uploadFiles, path);
-
-            //上传文件
-            uploadToOssUtil.uploadMulFiles(newUploadFiles);
-            // TODO: 2022/3/11 同时上传一份到旧版本的目录,用于过渡期使用,待重构版本稳定后删除
-            uploadToOssUtil.uploadMulFiles(uploadFiles);
-
-            //拷贝部分文件到编辑目录,用于用户编辑
-            buildScenePreService.copyToEditDir(sceneCode);
-
-            //计算成功,发短信
-            buildScenePreService.sendSms(pushChannel,pushToken, cameraType, scenePro.getSceneName(), scenePro.getWebSite());
-
-//            //上传日志文件
-//            buildScenePreService.uploadLogFile(sceneCode, sceneProExt.getDataSource());
-
-            //写scene.json
-            String sceneJson = buildScenePreService.writeSceneJson(sceneCode, videosJson,
-                sceneEditInfo, sceneEditControls, scenePlus, scenePlusExt, arrearCap);
-
-            //上传sceneJson文件
-            String sceneJsonPath = String.format(UploadFilePath.DATA_VIEW_PATH+"scene.json", sceneCode);
-            uploadToOssUtil.upload(sceneJson.getBytes(), sceneJsonPath);
-
-            //scenejson写入缓存
-            redisUtil.set(String.format(RedisKey.SCENE_JSON, sceneCode), sceneJson);
-
-        }catch (Exception e){
-            log.error("场景计算后置处理出错", e);
-            //发送钉钉
-            String serverPath = message.getPath().substring(0,message.getPath().lastIndexOf("/")+1).concat(prefix);
-//            buildScenePreService.handFail("后置处理失败", serverPath, sceneCode, BuildScenePreServiceImpl.hostName, BuildScenePreServiceImpl.contentExt);
-        }
-    }
-
-    private void sealScene(boolean arrearCap, Long scenePlusId, Long sceneProId){
-        if(!arrearCap){
-            return;
-        }
-        scenePlusService.update(
-            new LambdaUpdateWrapper<ScenePlus>()
-                .set(ScenePlus::getPayStatus, PayStatus.NO_CAPACITY)
-                .eq(ScenePlus::getId, scenePlusId));
-
-
-        // TODO: 2022/3/22 plus版本稳定后删除---------------------------start
-        sceneProService.update(
-            new LambdaUpdateWrapper<ScenePro>()
-                .set(ScenePro::getPayStatus, PayStatus.NO_CAPACITY)
-                .eq(ScenePro::getId, sceneProId));
-        // TODO: 2022/3/22 plus版本稳定后删除---------------------------end
-    }
-
-    /**
-     * <p>
-            双目场景更新数据库
-     * </p>
-     * @author dengsixing
-     * @date 2022/3/21
-     * @param num
-     * @param space
-     **/
-    private void updateDb4Sm(String num, long space){
-        List<ScenePlus> ScenePlusList = scenePlusService.list(
-            new LambdaQueryWrapper<ScenePlus>()
-            .select(ScenePlus::getId)
-            .eq(ScenePlus::getNum, num));
-
-        if(CollUtil.isNotEmpty(ScenePlusList))
-            return ;
-        List<Long> sceneIds = ScenePlusList.stream().map(scene -> {
-            return scene.getId();
-        }).collect(Collectors.toList());
-
-        //更新场景创建时间
-        scenePlusService.update(new LambdaUpdateWrapper<ScenePlus>()
-            .in(ScenePlus::getId, sceneIds)
-            .set(ScenePlus::getCreateTime, Calendar.getInstance().getTime())
-            .set(ScenePlus::getSceneStatus, SceneStatus.NO_DISPLAY.code()));
-
-        //更新使用容量
-        scenePlusExtService.update(
-            new LambdaUpdateWrapper<ScenePlusExt>()
-                .in(ScenePlusExt::getPlusId, sceneIds)
-                .set(ScenePlusExt::getSpace, space));
-    }
-
-    private ScenePro updateDbPro(String sceneCode, Long space, Integer payStatus, String videosJson, Long computeTime, String fileId) throws Exception{
-        ScenePro scenePro = sceneProService.findBySceneNum(sceneCode);
-
-        sceneProService.updateTime(sceneCode, space, payStatus, videosJson, computeTime);
-        SceneFileBuild sceneFileBuild = sceneFileBuildService.findByFileId(fileId);
-        if(sceneFileBuild != null){
-            sceneFileBuild.setBuildStatus(BuildStatus.success.code());
-            sceneFileBuildService.updateById(sceneFileBuild);
-        }
-
-        if(Objects.nonNull(scenePro)){
-            SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
-            SceneSource sceneSource = SceneSource.get(sceneProExt.getSceneSource());
-            switch (sceneSource){
-                case BM:
-                    sceneProExt.setSceneResolution(SceneResolution.TILES_2K.code());
-                    sceneProExt.setSceneFrom(SceneFrom.PRO.code());
-                    break;
-                case SM:
-                    sceneProExt.setSceneResolution(SceneResolution.TILES_1K.code());
-                    sceneProExt.setSceneFrom(SceneFrom.LITE.code());
-                    break;
-                case ZT:
-                    sceneProExt.setSceneResolution(SceneResolution.TILES_4K.code());
-                    sceneProExt.setSceneFrom(SceneFrom.MINION.code());
-                    break;
-                case JG:
-                    sceneProExt.setSceneResolution(SceneResolution.TILES_4K.code());
-                    sceneProExt.setSceneFrom(SceneFrom.LASER.code());
-                    break;
-            }
-            sceneProExtService.updateById(sceneProExt);
-
-        }
-
-        return scenePro;
-    }
-
-    private ScenePlus updateDbPlus(String num, Long space, Integer payStatus, String videosJson, Long computeTime, String fileId) throws Exception{
-        ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
-        ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
-        List<ScenePlus> list = scenePlusService.list(
-            new LambdaQueryWrapper<ScenePlus>()
-                .select(ScenePlus::getId)
-                .eq(ScenePlus::getNum, num));
-        if(scenePlus == null || CollUtil.isEmpty(list))
-            return null;
-
-        //修改场景状态 空间 支付状态 计算时间
-        List<Long> scenePlusIds = list.stream().map(plus -> {
-            return plus.getId();
-        }).collect(Collectors.toList());
-
-        scenePlusService.update(new LambdaUpdateWrapper<ScenePlus>()
-            .in(ScenePlus::getId, scenePlusIds)
-            .set(ScenePlus::getSceneStatus, SceneStatus.NO_DISPLAY.code())
-            .set(ScenePlus::getCreateTime, Calendar.getInstance().getTime())
-            .set(ScenePlus::getPayStatus, payStatus));
-
-        scenePlusExtService.update(new LambdaUpdateWrapper<ScenePlusExt>()
-            .in(ScenePlusExt::getPlusId, scenePlusIds)
-            .set(ScenePlusExt::getSpace, space)
-            .set(ScenePlusExt::getComputeTime, computeTime)
-            .set(ScenePlusExt::getVideos, videosJson));
-
-        SceneFileBuild sceneFileBuild = sceneFileBuildService.findByFileId(fileId);
-        if(sceneFileBuild != null){
-            sceneFileBuild.setBuildStatus(BuildStatus.success.code());
-            sceneFileBuildService.updateById(sceneFileBuild);
-        }
-
-        SceneSource sceneSource = SceneSource.get(scenePlus.getSceneSource());
-        switch (sceneSource){
-            case BM:
-                scenePlusExt.setSceneResolution(SceneResolution.TILES_2K.code());
-                scenePlusExt.setSceneFrom(SceneFrom.PRO.code());
-                break;
-            case SM:
-                scenePlusExt.setSceneResolution(SceneResolution.TILES_1K.code());
-                scenePlusExt.setSceneFrom(SceneFrom.LITE.code());
-                break;
-            case ZT:
-                scenePlusExt.setSceneResolution(SceneResolution.TILES_4K.code());
-                scenePlusExt.setSceneFrom(SceneFrom.MINION.code());
-                break;
-            case JG:
-                scenePlusExt.setSceneResolution(SceneResolution.TILES_4K.code());
-                scenePlusExt.setSceneFrom(SceneFrom.LASER.code());
-                break;
-        }
-        scenePlusExtService.updateById(scenePlusExt);
-
-
-        return scenePlus;
-    }
-
-    private boolean updateSpace(Long cameraId, Long space, Long scenePlusId, Long sceneProId) throws Exception{
-        //更新相机使用用量
-        ResultData<CameraDetail> resultData = platformGoodsClient.updateCameraDetailByCameraIdAndSpace(cameraId, space);
-        if(resultData.getCode() != ServerCode.SUCCESS.code()){
-            log.error("调用platform服务updateCameraDetailByCameraIdAndSpace失败,参数{},{}" ,cameraId, space);
-            throw new Exception(ServerCode.FEIGN_REQUEST_FAILD.message());
-        }
-        CameraDetail cameraDetail = JSONObject.parseObject(JSONObject.toJSONString(resultData.getData()), CameraDetail.class);
-
-        ResultData<UserIncrement> resultData1 = platformUserClient.getUserIncrementByCameraId(cameraId);
-        if(resultData1.getCode() != ServerCode.SUCCESS.code()){
-            log.error("调用platform服务getUserIncrementByCameraId失败,参数{}" ,cameraId);
-            throw new Exception(ServerCode.FEIGN_REQUEST_FAILD.message());
-        }
-        if( resultData1.getData() == null || resultData1.getData().getIsExpired() == ExpiredStatus.Expired.code()) {
-            // 新上传的场景,如果总容量小于使用容量,则该大场景保留在临时存储空间30天
-            if (cameraDetail.getTotalSpace().compareTo(cameraDetail.getUsedSpace()) == -1){
-                return true;
-            }
-        }
-        return false;
-    }
-
-    private Object[] updateEditInfo(ScenePro scenePro, ScenePlus scenePlus){
-        SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
-        SceneEditControls sceneEditControls = null;
-        if(sceneEditInfo == null){
-            sceneEditInfo = new SceneEditInfo();
-            sceneEditInfo.setScenePlusId(scenePlus.getId());
-            sceneEditInfo.setSceneProId(scenePro.getId());
-            sceneEditInfo.setDescription(scenePlus.getDescription());
-            sceneEditInfo.setTitle(scenePlus.getTitle());
-            sceneEditInfoService.save(sceneEditInfo);
-        }else{
-            sceneEditControls = sceneEditControlsService.getBySceneEditId(sceneEditInfo.getId());
-        }
-        if(sceneEditControls == null){
-            sceneEditControls = new SceneEditControls();
-            sceneEditControls.setEditInfoId(sceneEditInfo.getId());
-            sceneEditControlsService.save(sceneEditControls);
-        }
-        return new Object[]{sceneEditInfo, sceneEditControls};
-    }
-
-}
+//package com.fdkankan.scene.listener;
+//
+//import cn.hutool.core.collection.CollUtil;
+//import com.alibaba.fastjson.JSONObject;
+//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+//import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+//import com.fdkankan.common.constant.BuildStatus;
+//import com.fdkankan.common.constant.ConstantFilePath;
+//import com.fdkankan.common.constant.ExpiredStatus;
+//import com.fdkankan.common.constant.PayStatus;
+//import com.fdkankan.common.constant.SceneFrom;
+//import com.fdkankan.common.constant.SceneResolution;
+//import com.fdkankan.common.constant.SceneSource;
+//import com.fdkankan.common.constant.SceneStatus;
+//import com.fdkankan.common.constant.ServerCode;
+//import com.fdkankan.common.constant.UploadFilePath;
+//import com.fdkankan.common.response.ResultData;
+//import com.fdkankan.common.util.MatrixToImageWriterUtil;
+//import com.fdkankan.fyun.oss.UploadToOssUtil;
+//import com.fdkankan.mq.message.BuildSceneResultMqMessage;
+//import com.fdkankan.platform.api.feign.PlatformGoodsClient;
+//import com.fdkankan.platform.api.feign.PlatformUserClient;
+//import com.fdkankan.platform.api.dto.CameraDetail;
+//import com.fdkankan.platform.api.dto.UserIncrement;
+//import com.fdkankan.redis.constant.RedisKey;
+//import com.fdkankan.redis.util.RedisUtil;
+//import com.fdkankan.scene.entity.SceneEditControls;
+//import com.fdkankan.scene.entity.SceneEditInfo;
+//import com.fdkankan.scene.entity.SceneFileBuild;
+//import com.fdkankan.scene.entity.ScenePlus;
+//import com.fdkankan.scene.entity.ScenePlusExt;
+//import com.fdkankan.scene.entity.ScenePro;
+//import com.fdkankan.scene.entity.SceneProExt;
+//import com.fdkankan.scene.service.IBuildScenePreService;
+//import com.fdkankan.scene.service.ISceneEditControlsService;
+//import com.fdkankan.scene.service.ISceneEditInfoService;
+//import com.fdkankan.scene.service.ISceneFileBuildService;
+//import com.fdkankan.scene.service.IScenePlusExtService;
+//import com.fdkankan.scene.service.IScenePlusService;
+//import com.fdkankan.scene.service.ISceneProExtService;
+//import com.fdkankan.scene.service.ISceneProService;
+//import com.fdkankan.scene.service.ISceneService;
+//import java.io.File;
+//import java.util.Calendar;
+//import java.util.Map;
+//import java.util.stream.Collectors;
+//import lombok.extern.slf4j.Slf4j;
+//import org.apache.rocketmq.spring.annotation.MessageModel;
+//import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
+//import org.apache.rocketmq.spring.core.RocketMQListener;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.beans.factory.annotation.Value;
+//
+//import java.util.List;
+//import java.util.Objects;
+//import org.springframework.stereotype.Component;
+//import org.springframework.transaction.annotation.Transactional;
+//
+//
+///**
+// * <p>
+//        场景计算后 写库相关业务逻辑
+// * </p>
+// * @author dengsixing
+// * @date 2022/2/23
+// **/
+//@Slf4j
+////@Component
+////@RocketMQMessageListener(
+////        consumerGroup = "${rocketmq.consumer.build-scene-result-group}",
+////        topic = "${rocketmq.build-scene-result.topicName.topic-modeling-a}",
+////        messageModel = MessageModel.CLUSTERING//负载均衡模式
+////)
+//public class BuildSceneResultMQListener implements RocketMQListener<String> {
+//
+//    @Value("${rocketmq.consumer.build-scene-result-group}")
+//    private String consumerGroup;
+//
+//    @Value("${rocketmq.build-scene-result.topicName.topic-modeling-a}")
+//    private String buildSceneResultTopic;
+//
+//    @Value("${main.url}")
+//    private String mainUrl;
+//
+//    @Value("${scene.pro.url}")
+//    private String sceneProUrl;
+//
+//    @Value("${scene.pro.new.url}")
+//    private String sceneProNewUrl;
+//
+//    @Autowired
+//    ISceneService sceneService;
+//    @Autowired
+//    ISceneFileBuildService sceneFileBuildService;
+//    @Autowired
+//    ISceneProService sceneProService;
+//    @Autowired
+//    ISceneProExtService sceneProExtService;
+//    @Autowired
+//    PlatformGoodsClient platformGoodsClient;
+//    @Autowired
+//    PlatformUserClient platformUserClient;
+//    @Autowired
+//    ISceneEditInfoService sceneEditInfoService;
+//    @Autowired
+//    ISceneEditControlsService sceneEditControlsService;
+//    @Autowired
+//    UploadToOssUtil uploadToOssUtil;
+//    @Autowired
+//    IBuildScenePreService buildScenePreService;
+//    @Autowired
+//    RedisUtil redisUtil;
+//    @Autowired
+//    IScenePlusService scenePlusService;
+//    @Autowired
+//    IScenePlusExtService scenePlusExtService;
+//
+//
+//    @Override
+//    public void onMessage(String message) {
+//
+//        BuildSceneResultMqMessage resultMqMessage = JSONObject.parseObject(message, BuildSceneResultMqMessage.class);
+//        log.info("开始处理消息,消费者组:{},主题名:{}, 消息内容:{}", consumerGroup, buildSceneResultTopic, message);
+//        process(resultMqMessage);
+//    }
+//
+//    @Transactional
+//    public void process(BuildSceneResultMqMessage message){
+//        Integer cameraType = Integer.parseInt(message.getCameraType());
+//        String sceneCode = message.getSceneCode();
+//        String fileId = message.getFileId();
+//        Integer payStatus = message.getPayStatus();
+//        Long computeTime = message.getComputeTime();
+//        Boolean buildSuccess = message.getBuildSuccess();
+//        Integer videoVersion = message.getVideoVersion();
+//
+//        Map<String, String> uploadFiles = message.getUploadFiles();
+//        String path = message.getPath();
+//        Integer pushChannel = message.getPushChannel();
+//        String pushToken = message.getPushToken();
+//        String prefix = message.getPrefix();
+//        try {
+//            if(!buildSuccess){//建模失败,修改状态为失败状态
+//                log.info("建模失败,修改状态为失败状态");
+//                // TODO: 2022/3/21 plus版本稳定后删除------------------------start
+//                sceneService.updateStatus(sceneCode, SceneStatus.FAILD.code());
+//                sceneProService.updateStatus(sceneCode, SceneStatus.FAILD.code());
+//                // TODO: 2022/3/21 plus版本稳定后删除------------------------send
+//
+//                scenePlusService.update(
+//                    new LambdaUpdateWrapper<ScenePlus>()
+//                        .set(ScenePlus::getSceneStatus, SceneStatus.FAILD.code())
+//                        .eq(ScenePlus::getNum, sceneCode));
+//
+//                SceneFileBuild sceneFileBuild = sceneFileBuildService.findByFileId(fileId);
+//                if(Objects.nonNull(sceneFileBuild)){
+//                    sceneFileBuild.setBuildStatus(BuildStatus.fail.code());
+//                    sceneFileBuildService.updateById(sceneFileBuild);
+//                }
+//                return;
+//            }
+//
+//            //建模成功
+//            log.info("cameraType:{}",cameraType);
+//
+//            //计算场景消耗磁盘空间
+//            long space = buildScenePreService.calUseSpace(uploadFiles);
+//
+//            if(cameraType < 3){
+//                // TODO: 2022/3/21 plus版本稳定后删除------------------------start
+//                sceneService.updateTime(sceneCode, space, payStatus);
+//                // TODO: 2022/3/21 plus版本稳定后删除------------------------send
+//
+//                this.updateDb4Sm(sceneCode, space);
+//
+//                uploadToOssUtil.uploadMulFiles(uploadFiles);
+//                return;
+//            }
+//
+//            //读取计算结果文件生成videosJson
+//            JSONObject videosJson = buildScenePreService.getVideosJson(path, videoVersion, sceneCode, cameraType);
+//
+//            //写入数据库
+//            // TODO: 2022/3/21 plus版本稳定后删除------------------------start
+//            ScenePro scenePro = this.updateDbPro(sceneCode, space, payStatus, videosJson.toJSONString(), computeTime, fileId);
+//            SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
+//            // TODO: 2022/3/21 plus版本稳定后删除------------------------send
+//            ScenePlus scenePlus = this.updateDbPlus(sceneCode, space, payStatus, videosJson.toJSONString(), computeTime, fileId);
+//            ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
+//
+//            //变更容量,arrearCap为true时,代表容量不足
+//            boolean arrearCap = this.updateSpace(scenePlus.getCameraId(), space, scenePlus.getId(), scenePro.getId());
+//
+//            //如果相机容量不足,需要把场景的paystatus改为容量不足状态
+//            this.sealScene(arrearCap, scenePlus.getId(), scenePro.getId());
+//
+//            Object[] editInfoArr = this.updateEditInfo(scenePro, scenePlus);
+//            SceneEditInfo sceneEditInfo = (SceneEditInfo)editInfoArr[0];
+//            SceneEditControls sceneEditControls = (SceneEditControls)editInfoArr[1];
+//
+//            String sceneUrl = mainUrl + "/" + sceneProNewUrl;
+//            String outPathZh = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneCode+".png";
+//            String outPathEn = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneCode+"_en.png";
+//            //生成新的分享的二维码-中文版本
+//            MatrixToImageWriterUtil.createQRCode(sceneUrl + sceneCode, outPathZh, false,null);
+//            //生成新的分享的二维码-英文版本
+//            MatrixToImageWriterUtil.createQRCode(sceneUrl + sceneCode + "&lang=en", outPathEn, false, null);
+//            //上传二维码
+//            uploadToOssUtil.upload(outPathZh, String.format(UploadFilePath.DOWNLOADS_QRCODE, sceneCode) + sceneCode + ".png");
+//            uploadToOssUtil.upload(outPathEn, String.format(UploadFilePath.DOWNLOADS_QRCODE, sceneCode) + sceneCode + "_en.png");
+//
+//            Map<String, String> newUploadFiles = buildScenePreService
+//                .uploadFileMapHandler(sceneCode, cameraType, uploadFiles);
+//
+//            //上传计算结果中的caches/images和caches/videos
+//            buildScenePreService.uploadCaches(sceneCode, uploadFiles, path);
+//
+//            //上传文件
+//            uploadToOssUtil.uploadMulFiles(newUploadFiles);
+//            // TODO: 2022/3/11 同时上传一份到旧版本的目录,用于过渡期使用,待重构版本稳定后删除
+//            uploadToOssUtil.uploadMulFiles(uploadFiles);
+//
+//            //拷贝部分文件到编辑目录,用于用户编辑
+//            buildScenePreService.copyToEditDir(sceneCode);
+//
+//            //计算成功,发短信
+//            buildScenePreService.sendSms(pushChannel,pushToken, cameraType, scenePro.getSceneName(), scenePro.getWebSite());
+//
+////            //上传日志文件
+////            buildScenePreService.uploadLogFile(sceneCode, sceneProExt.getDataSource());
+//
+//            //写scene.json
+//            String sceneJson = buildScenePreService.writeSceneJson(sceneCode, videosJson,
+//                sceneEditInfo, sceneEditControls, scenePlus, scenePlusExt, arrearCap);
+//
+//            //上传sceneJson文件
+//            String sceneJsonPath = String.format(UploadFilePath.DATA_VIEW_PATH+"scene.json", sceneCode);
+//            uploadToOssUtil.upload(sceneJson.getBytes(), sceneJsonPath);
+//
+//            //scenejson写入缓存
+//            redisUtil.set(String.format(RedisKey.SCENE_JSON, sceneCode), sceneJson);
+//
+//        }catch (Exception e){
+//            log.error("场景计算后置处理出错", e);
+//            //发送钉钉
+//            String serverPath = message.getPath().substring(0,message.getPath().lastIndexOf("/")+1).concat(prefix);
+////            buildScenePreService.handFail("后置处理失败", serverPath, sceneCode, BuildScenePreServiceImpl.hostName, BuildScenePreServiceImpl.contentExt);
+//        }
+//    }
+//
+//    private void sealScene(boolean arrearCap, Long scenePlusId, Long sceneProId){
+//        if(!arrearCap){
+//            return;
+//        }
+//        scenePlusService.update(
+//            new LambdaUpdateWrapper<ScenePlus>()
+//                .set(ScenePlus::getPayStatus, PayStatus.NO_CAPACITY)
+//                .eq(ScenePlus::getId, scenePlusId));
+//
+//
+//        // TODO: 2022/3/22 plus版本稳定后删除---------------------------start
+//        sceneProService.update(
+//            new LambdaUpdateWrapper<ScenePro>()
+//                .set(ScenePro::getPayStatus, PayStatus.NO_CAPACITY)
+//                .eq(ScenePro::getId, sceneProId));
+//        // TODO: 2022/3/22 plus版本稳定后删除---------------------------end
+//    }
+//
+//    /**
+//     * <p>
+//            双目场景更新数据库
+//     * </p>
+//     * @author dengsixing
+//     * @date 2022/3/21
+//     * @param num
+//     * @param space
+//     **/
+//    private void updateDb4Sm(String num, long space){
+//        List<ScenePlus> ScenePlusList = scenePlusService.list(
+//            new LambdaQueryWrapper<ScenePlus>()
+//            .select(ScenePlus::getId)
+//            .eq(ScenePlus::getNum, num));
+//
+//        if(CollUtil.isNotEmpty(ScenePlusList))
+//            return ;
+//        List<Long> sceneIds = ScenePlusList.stream().map(scene -> {
+//            return scene.getId();
+//        }).collect(Collectors.toList());
+//
+//        //更新场景创建时间
+//        scenePlusService.update(new LambdaUpdateWrapper<ScenePlus>()
+//            .in(ScenePlus::getId, sceneIds)
+//            .set(ScenePlus::getCreateTime, Calendar.getInstance().getTime())
+//            .set(ScenePlus::getSceneStatus, SceneStatus.NO_DISPLAY.code()));
+//
+//        //更新使用容量
+//        scenePlusExtService.update(
+//            new LambdaUpdateWrapper<ScenePlusExt>()
+//                .in(ScenePlusExt::getPlusId, sceneIds)
+//                .set(ScenePlusExt::getSpace, space));
+//    }
+//
+//    private ScenePro updateDbPro(String sceneCode, Long space, Integer payStatus, String videosJson, Long computeTime, String fileId) throws Exception{
+//        ScenePro scenePro = sceneProService.findBySceneNum(sceneCode);
+//
+//        sceneProService.updateTime(sceneCode, space, payStatus, videosJson, computeTime);
+//        SceneFileBuild sceneFileBuild = sceneFileBuildService.findByFileId(fileId);
+//        if(sceneFileBuild != null){
+//            sceneFileBuild.setBuildStatus(BuildStatus.success.code());
+//            sceneFileBuildService.updateById(sceneFileBuild);
+//        }
+//
+//        if(Objects.nonNull(scenePro)){
+//            SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
+//            SceneSource sceneSource = SceneSource.get(sceneProExt.getSceneSource());
+//            switch (sceneSource){
+//                case BM:
+//                    sceneProExt.setSceneResolution(SceneResolution.TILES_2K.code());
+//                    sceneProExt.setSceneFrom(SceneFrom.PRO.code());
+//                    break;
+//                case SM:
+//                    sceneProExt.setSceneResolution(SceneResolution.TILES_1K.code());
+//                    sceneProExt.setSceneFrom(SceneFrom.LITE.code());
+//                    break;
+//                case ZT:
+//                    sceneProExt.setSceneResolution(SceneResolution.TILES_4K.code());
+//                    sceneProExt.setSceneFrom(SceneFrom.MINION.code());
+//                    break;
+//                case JG:
+//                    sceneProExt.setSceneResolution(SceneResolution.TILES_4K.code());
+//                    sceneProExt.setSceneFrom(SceneFrom.LASER.code());
+//                    break;
+//            }
+//            sceneProExtService.updateById(sceneProExt);
+//
+//        }
+//
+//        return scenePro;
+//    }
+//
+//    private ScenePlus updateDbPlus(String num, Long space, Integer payStatus, String videosJson, Long computeTime, String fileId) throws Exception{
+//        ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
+//        ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
+//        List<ScenePlus> list = scenePlusService.list(
+//            new LambdaQueryWrapper<ScenePlus>()
+//                .select(ScenePlus::getId)
+//                .eq(ScenePlus::getNum, num));
+//        if(scenePlus == null || CollUtil.isEmpty(list))
+//            return null;
+//
+//        //修改场景状态 空间 支付状态 计算时间
+//        List<Long> scenePlusIds = list.stream().map(plus -> {
+//            return plus.getId();
+//        }).collect(Collectors.toList());
+//
+//        scenePlusService.update(new LambdaUpdateWrapper<ScenePlus>()
+//            .in(ScenePlus::getId, scenePlusIds)
+//            .set(ScenePlus::getSceneStatus, SceneStatus.NO_DISPLAY.code())
+//            .set(ScenePlus::getCreateTime, Calendar.getInstance().getTime())
+//            .set(ScenePlus::getPayStatus, payStatus));
+//
+//        scenePlusExtService.update(new LambdaUpdateWrapper<ScenePlusExt>()
+//            .in(ScenePlusExt::getPlusId, scenePlusIds)
+//            .set(ScenePlusExt::getSpace, space)
+//            .set(ScenePlusExt::getComputeTime, computeTime)
+//            .set(ScenePlusExt::getVideos, videosJson));
+//
+//        SceneFileBuild sceneFileBuild = sceneFileBuildService.findByFileId(fileId);
+//        if(sceneFileBuild != null){
+//            sceneFileBuild.setBuildStatus(BuildStatus.success.code());
+//            sceneFileBuildService.updateById(sceneFileBuild);
+//        }
+//
+//        SceneSource sceneSource = SceneSource.get(scenePlus.getSceneSource());
+//        switch (sceneSource){
+//            case BM:
+//                scenePlusExt.setSceneResolution(SceneResolution.TILES_2K.code());
+//                scenePlusExt.setSceneFrom(SceneFrom.PRO.code());
+//                break;
+//            case SM:
+//                scenePlusExt.setSceneResolution(SceneResolution.TILES_1K.code());
+//                scenePlusExt.setSceneFrom(SceneFrom.LITE.code());
+//                break;
+//            case ZT:
+//                scenePlusExt.setSceneResolution(SceneResolution.TILES_4K.code());
+//                scenePlusExt.setSceneFrom(SceneFrom.MINION.code());
+//                break;
+//            case JG:
+//                scenePlusExt.setSceneResolution(SceneResolution.TILES_4K.code());
+//                scenePlusExt.setSceneFrom(SceneFrom.LASER.code());
+//                break;
+//        }
+//        scenePlusExtService.updateById(scenePlusExt);
+//
+//
+//        return scenePlus;
+//    }
+//
+//    private boolean updateSpace(Long cameraId, Long space, Long scenePlusId, Long sceneProId) throws Exception{
+//        //更新相机使用用量
+//        ResultData<CameraDetail> resultData = platformGoodsClient.updateCameraDetailByCameraIdAndSpace(cameraId, space);
+//        if(resultData.getCode() != ServerCode.SUCCESS.code()){
+//            log.error("调用platform服务updateCameraDetailByCameraIdAndSpace失败,参数{},{}" ,cameraId, space);
+//            throw new Exception(ServerCode.FEIGN_REQUEST_FAILD.message());
+//        }
+//        CameraDetail cameraDetail = JSONObject.parseObject(JSONObject.toJSONString(resultData.getData()), CameraDetail.class);
+//
+//        ResultData<UserIncrement> resultData1 = platformUserClient.getUserIncrementByCameraId(cameraId);
+//        if(resultData1.getCode() != ServerCode.SUCCESS.code()){
+//            log.error("调用platform服务getUserIncrementByCameraId失败,参数{}" ,cameraId);
+//            throw new Exception(ServerCode.FEIGN_REQUEST_FAILD.message());
+//        }
+//        if( resultData1.getData() == null || resultData1.getData().getIsExpired() == ExpiredStatus.Expired.code()) {
+//            // 新上传的场景,如果总容量小于使用容量,则该大场景保留在临时存储空间30天
+//            if (cameraDetail.getTotalSpace().compareTo(cameraDetail.getUsedSpace()) == -1){
+//                return true;
+//            }
+//        }
+//        return false;
+//    }
+//
+//    private Object[] updateEditInfo(ScenePro scenePro, ScenePlus scenePlus){
+//        SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
+//        SceneEditControls sceneEditControls = null;
+//        if(sceneEditInfo == null){
+//            sceneEditInfo = new SceneEditInfo();
+//            sceneEditInfo.setScenePlusId(scenePlus.getId());
+//            sceneEditInfo.setSceneProId(scenePro.getId());
+//            sceneEditInfo.setDescription(scenePlus.getDescription());
+//            sceneEditInfo.setTitle(scenePlus.getTitle());
+//            sceneEditInfoService.save(sceneEditInfo);
+//        }else{
+//            sceneEditControls = sceneEditControlsService.getBySceneEditId(sceneEditInfo.getId());
+//        }
+//        if(sceneEditControls == null){
+//            sceneEditControls = new SceneEditControls();
+//            sceneEditControls.setEditInfoId(sceneEditInfo.getId());
+//            sceneEditControlsService.save(sceneEditControls);
+//        }
+//        return new Object[]{sceneEditInfo, sceneEditControls};
+//    }
+//
+//}

+ 101 - 7
4dkankan-center-scene/src/main/java/com/fdkankan/scene/listener/RabbitMqListener.java

@@ -1,11 +1,21 @@
 package com.fdkankan.scene.listener;
 
+import com.alibaba.fastjson.JSONObject;
+import com.fdkankan.mq.message.BuildSceneFailDTMqMessage;
+import com.fdkankan.mq.message.BuildSceneMqMessage;
+import com.fdkankan.mq.message.BuildSceneResultMqMessage;
+import com.fdkankan.scene.service.IBuildSceneDTService;
+import com.fdkankan.scene.service.IBuildScenePostService;
+import com.fdkankan.scene.service.IBuildScenePreService;
+import com.fdkankan.scene.service.impl.BuildSceneDTServiceImpl;
 import com.rabbitmq.client.Channel;
-import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 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.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
 /**
@@ -19,15 +29,99 @@ import org.springframework.stereotype.Component;
 @Slf4j
 @Component
 public class RabbitMqListener {
+    @Value("${queue.modeling.modeling-pre}")
+    private String queueModelingPre;
+    @Value("${queue.modeling.modeling-post}")
+    private String queueModelingPost;
+    @Value("${queue.modeling.modeling-dt}")
+    private String queueModelingDt;
 
-    @RabbitListener(queues = "queue_work_dsx",)
-    public void receiveMessageDsx(Channel channel, Message message) throws IOException {
+    @Autowired
+    IBuildScenePreService buildScenePreService;
+    @Autowired
+    IBuildScenePostService buildScenePostService;
+    @Autowired
+    IBuildSceneDTService buildSceneDTService;
+
+
+
+    /**
+     * 开启了手动确认模式,如果没有手动确认,消费者不会重试,当服务重启时会再次消费,因为rabbitmq认为你还没有处理完你的业务
+     * queuesToDeclare = @Queue("${queue.modeling.modeling-test}"),  如果队列补不存在会自动创建队列
+     * concurrency = "3"    设置消费线程数,每个线程每次只拉取一条消息消费
+     */
+//    @RabbitListener(
+//        queuesToDeclare = @Queue("${queue.modeling.modeling-test}"),
+//        concurrency = "1"
+//    )
+//    public void receiveMessageDsx(Channel channel, Message message) throws Exception {
+//        channel.queueDeclare();
+//        String msg = new String(message.getBody(), StandardCharsets.UTF_8);
+//        log.info("开始消费消息-" + msg + "-" + Thread.currentThread().getId());
+//        Thread.sleep(5000L);
+//        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
+//        log.info("结束消息-" + Thread.currentThread().getId());
+//    }
+
+
+    /**
+     * 场景计算前置资源准备处理
+     * @param channel
+     * @param message
+     * @throws Exception
+     */
+    @RabbitListener(
+        queuesToDeclare = @Queue("${queue.modeling.modeling-pre}"),
+        concurrency = "${maxThread.modeling.modeling-pre}"
+    )
+    public void buildScenePreHandler(Channel channel, Message message) throws Exception {
+        String correlationId = message.getMessageProperties().getCorrelationId();
+        String msg = new String(message.getBody(), StandardCharsets.UTF_8);
+        BuildSceneMqMessage buildSceneMessage = JSONObject.parseObject(msg, BuildSceneMqMessage.class);
+        log.info("场景计算资源准备开始,队列名:{},id:{}", queueModelingPre, correlationId);
+        Thread.sleep(2000L);
+        buildScenePreService.buildScenePre(buildSceneMessage);
+        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
+    }
+
+    /**
+     * 场景计算后置结果处理
+     * @param channel
+     * @param message
+     * @throws Exception
+     */
+    @RabbitListener(
+        queuesToDeclare = @Queue("${queue.modeling.modeling-post}"),
+        concurrency = "${maxThread.modeling.modeling-post}"
+    )
+    public void buildScenePostHandler(Channel channel, Message message) throws Exception {
+        String correlationId = message.getMessageProperties().getCorrelationId();
+        String msg = new String(message.getBody(), StandardCharsets.UTF_8);
+        BuildSceneResultMqMessage resultMessage = JSONObject.parseObject(msg, BuildSceneResultMqMessage.class);
+        log.info("场景计算结果处理开始,队列名:{},id:{}", queueModelingPost, correlationId);
+        Thread.sleep(2000L);
+        buildScenePostService.buildScenePost(resultMessage);
+        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
+    }
+
+    /**
+     * 场景计算发送钉钉消息
+     * @param channel
+     * @param message
+     * @throws Exception
+     */
+    @RabbitListener(
+        queuesToDeclare = @Queue("${queue.modeling.modeling-dt}"),
+        concurrency = "${maxThread.modeling.modeling-dt}"
+    )
+    public void buildSceneDTHandler(Channel channel, Message message) throws Exception {
+        String correlationId = message.getMessageProperties().getCorrelationId();
         String msg = new String(message.getBody(), StandardCharsets.UTF_8);
-        log.info("消费消息--------" + msg);
-        String test = null;
-        test.equals("123");
+        BuildSceneFailDTMqMessage dtMessage = JSONObject.parseObject(msg, BuildSceneFailDTMqMessage.class);
+        log.info("发送钉钉消息处理,队列名:{},id:{}", queueModelingDt, correlationId);
+        buildSceneDTService.handFail(dtMessage.getReason(), dtMessage.getServerPath(),
+            dtMessage.getNum(), dtMessage.getHostName(), BuildSceneDTServiceImpl.contentExt);
         channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
-        log.info("接收消息");
     }
 
 

+ 17 - 0
4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/IBuildSceneDTService.java

@@ -0,0 +1,17 @@
+package com.fdkankan.scene.service;
+
+import com.fdkankan.mq.message.BuildSceneResultMqMessage;
+
+/**
+ * <p>
+ * TODO
+ * </p>
+ *
+ * @author dengsixing
+ * @since 2022/3/1
+ **/
+public interface IBuildSceneDTService {
+
+    void handFail(String reason, String serverPath, String num, String hostName, String contentExt);
+
+}

+ 25 - 0
4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/IBuildScenePostService.java

@@ -0,0 +1,25 @@
+package com.fdkankan.scene.service;
+
+import com.alibaba.fastjson.JSONObject;
+import com.fdkankan.mq.message.BuildSceneMqMessage;
+import com.fdkankan.mq.message.BuildSceneResultMqMessage;
+import com.fdkankan.scene.entity.SceneEditControls;
+import com.fdkankan.scene.entity.SceneEditInfo;
+import com.fdkankan.scene.entity.ScenePlus;
+import com.fdkankan.scene.entity.ScenePlusExt;
+import java.io.IOException;
+import java.util.Map;
+
+/**
+ * <p>
+ * TODO
+ * </p>
+ *
+ * @author dengsixing
+ * @since 2022/3/1
+ **/
+public interface IBuildScenePostService {
+
+    void buildScenePost(BuildSceneResultMqMessage message);
+
+}

+ 11 - 9
4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/IBuildScenePreService.java

@@ -22,30 +22,32 @@ import java.util.Map;
  **/
 public interface IBuildScenePreService {
 
+    void buildScenePre(BuildSceneMqMessage message);
+
     Map<String, String> getTypeString(String cameraType, String algorithm, String resolution, JSONObject dataJson);
 
     String getPath(BuildSceneMqMessage buildSceneMqMessage) throws Exception;
 
     void downLoadSource(BuildSceneMqMessage buildSceneMqMessage, String path) throws Exception;
 
-    Map<String, String> uploadFileMapHandler(String num, int cameraType, Map<String, String> map);
+//    Map<String, String> uploadFileMapHandler(String num, int cameraType, Map<String, String> map);
 
-    void uploadCaches(String num, Map<String,String> map, String path);
+//    void uploadCaches(String num, Map<String,String> map, String path);
 
-    void copyToEditDir(String num) throws IOException;
+//    void copyToEditDir(String num) throws IOException;
 
-    void sendSms(Integer pushChannel, String pushToken, int cameraType, String sceneName, String webSite);
+//    void sendSms(Integer pushChannel, String pushToken, int cameraType, String sceneName, String webSite);
 
-    void handFail(String reason, String serverPath, String num, String hostName, String contentExt);
+//    void handFail(String reason, String serverPath, String num, String hostName, String contentExt);
 
-    Long calUseSpace(Map<String, String> uploadFile);
+//    Long calUseSpace(Map<String, String> uploadFile);
 
     void uploadLogFile(String num, String dataSource);
 
-    JSONObject getVideosJson(String path, Integer videoVersion, String projectNum, int cameraType) throws Exception ;
+//    JSONObject getVideosJson(String path, Integer videoVersion, String projectNum, int cameraType) throws Exception ;
 
-    String writeSceneJson(String num, JSONObject videoJson, SceneEditInfo sceneEditInfo, SceneEditControls sceneEditControls,
-        ScenePlus scenePlus, ScenePlusExt scenePlusExt, boolean arrearCap) throws Exception;
+//    String writeSceneJson(String num, JSONObject videoJson, SceneEditInfo sceneEditInfo, SceneEditControls sceneEditControls,
+//        ScenePlus scenePlus, ScenePlusExt scenePlusExt, boolean arrearCap) throws Exception;
 
 
 

+ 56 - 0
4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/impl/BuildSceneDTServiceImpl.java

@@ -0,0 +1,56 @@
+package com.fdkankan.scene.service.impl;
+
+import cn.hutool.core.util.StrUtil;
+import com.fdkankan.dingtalk.DingTalkSendUtils;
+import com.fdkankan.scene.service.IBuildSceneDTService;
+import com.taobao.api.ApiException;
+import java.io.UnsupportedEncodingException;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.util.concurrent.CompletableFuture;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ * TODO
+ * </p>
+ *
+ * @author dengsixing
+ * @since 2022/4/20
+ **/
+@Slf4j
+@Service
+public class BuildSceneDTServiceImpl implements IBuildSceneDTService {
+
+    public static final String DINGTALK_MSG_PATTERN = "**环境**: %s\n\n" +
+        "**服务器名称**: %s\n\n" +
+        "**失败原因**: %s\n\n" +
+        "**num**: %s\n\n" +
+        "**server-path**: %s\n\n";
+//        "**algorithm-log**: [https://4dkk.4dage.com/build_log/%s/console.log](https://4dkk.4dage.com/build_log/%s/console.log)";
+
+    public static final String contentExt = "**algorithm-log**: [https://4dkk.4dage.com/build_log/%s/console.log](https://4dkk.4dage.com/build_log/%s/console.log)";
+
+    @Autowired
+    private DingTalkSendUtils dingTalkSendUtils;
+    @Value("${spring.profiles.active}")
+    private String environment;
+
+    @Override
+    public void handFail(String reason, String serverPath, String num, String hostName, String contentExt) {
+        CompletableFuture.runAsync(() -> {
+            try {
+                String contentFormat = StrUtil.isBlank(contentExt) ? this.DINGTALK_MSG_PATTERN : this.DINGTALK_MSG_PATTERN +  contentExt;
+                String content = String.format(contentFormat, this.environment, hostName, reason, num, serverPath, num, num);
+                log.info("发送钉钉消息,content:{}", content);
+                dingTalkSendUtils.sendActioncardMsgToDingRobot(content,"场景计算失败");
+            } catch (ApiException | UnsupportedEncodingException | NoSuchAlgorithmException | InvalidKeyException apiException) {
+                log.error("发送钉钉消息失败", apiException);
+            }
+        });
+    }
+
+}

+ 709 - 0
4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/impl/BuildScenePostServiceImpl.java

@@ -0,0 +1,709 @@
+package com.fdkankan.scene.service.impl;
+
+import static com.fdkankan.push.PushMessageConfig.ANDROID_KEY;
+import static com.fdkankan.push.PushMessageConfig.ANDROID_KEY_Z;
+import static com.fdkankan.push.PushMessageConfig.ANDROID_SECRET;
+import static com.fdkankan.push.PushMessageConfig.ANDROID_SECRET_Z;
+import static com.fdkankan.push.PushMessageConfig.IOS_KEY;
+import static com.fdkankan.push.PushMessageConfig.IOS_KEY_Z;
+import static com.fdkankan.push.PushMessageConfig.IOS_SECRET;
+import static com.fdkankan.push.PushMessageConfig.IOS_SECRET_Z;
+
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.fdkankan.common.constant.BuildStatus;
+import com.fdkankan.common.constant.ConstantFilePath;
+import com.fdkankan.common.constant.ConstantUrl;
+import com.fdkankan.common.constant.ExpiredStatus;
+import com.fdkankan.common.constant.PayStatus;
+import com.fdkankan.common.constant.SceneFrom;
+import com.fdkankan.common.constant.SceneResolution;
+import com.fdkankan.common.constant.SceneSource;
+import com.fdkankan.common.constant.SceneStatus;
+import com.fdkankan.common.constant.ServerCode;
+import com.fdkankan.common.constant.UploadFilePath;
+import com.fdkankan.common.response.ResultData;
+import com.fdkankan.common.util.FileUtil;
+import com.fdkankan.common.util.FileUtils;
+import com.fdkankan.common.util.MatrixToImageWriterUtil;
+import com.fdkankan.fyun.constant.StorageType;
+import com.fdkankan.fyun.oss.UploadToOssUtil;
+import com.fdkankan.mq.message.BuildSceneMqMessage;
+import com.fdkankan.mq.message.BuildSceneResultMqMessage;
+import com.fdkankan.platform.api.dto.CameraDetail;
+import com.fdkankan.platform.api.dto.UserIncrement;
+import com.fdkankan.platform.api.feign.PlatformGoodsClient;
+import com.fdkankan.platform.api.feign.PlatformUserClient;
+import com.fdkankan.push.PushMessageConfig;
+import com.fdkankan.push.PushMsgUtil;
+import com.fdkankan.redis.constant.RedisKey;
+import com.fdkankan.redis.util.RedisUtil;
+import com.fdkankan.scene.bean.SceneJsonBean;
+import com.fdkankan.scene.entity.SceneEditControls;
+import com.fdkankan.scene.entity.SceneEditInfo;
+import com.fdkankan.scene.entity.SceneFileBuild;
+import com.fdkankan.scene.entity.ScenePlus;
+import com.fdkankan.scene.entity.ScenePlusExt;
+import com.fdkankan.scene.entity.ScenePro;
+import com.fdkankan.scene.entity.SceneProExt;
+import com.fdkankan.scene.service.IBuildSceneDTService;
+import com.fdkankan.scene.service.IBuildScenePostService;
+import com.fdkankan.scene.service.IBuildScenePreService;
+import com.fdkankan.scene.service.ISceneEditControlsService;
+import com.fdkankan.scene.service.ISceneEditInfoService;
+import com.fdkankan.scene.service.ISceneFileBuildService;
+import com.fdkankan.scene.service.IScenePlusExtService;
+import com.fdkankan.scene.service.IScenePlusService;
+import com.fdkankan.scene.service.ISceneProExtService;
+import com.fdkankan.scene.service.ISceneProService;
+import com.fdkankan.scene.service.ISceneService;
+import com.fdkankan.scene.vo.SceneEditControlsVO;
+import java.io.File;
+import java.io.IOException;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Objects;
+import java.util.stream.Collectors;
+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;
+
+/**
+ * <p>
+ * TODO
+ * </p>
+ *
+ * @author dengsixing
+ * @since 2022/4/20
+ **/
+@Slf4j
+@Service
+public class BuildScenePostServiceImpl implements IBuildScenePostService {
+
+    @Value("${main.url}")
+    private String mainUrl;
+    @Value("${scene.pro.url}")
+    private String sceneProUrl;
+    @Value("${scene.pro.new.url}")
+    private String sceneProNewUrl;
+    @Value("${upload.type}")
+    private String ossType;
+    @Value("${oss.prefix.ali}")
+    private String prefixAli;
+
+    @Autowired
+    ISceneService sceneService;
+    @Autowired
+    ISceneFileBuildService sceneFileBuildService;
+    @Autowired
+    ISceneProService sceneProService;
+    @Autowired
+    ISceneProExtService sceneProExtService;
+    @Autowired
+    PlatformGoodsClient platformGoodsClient;
+    @Autowired
+    PlatformUserClient platformUserClient;
+    @Autowired
+    ISceneEditInfoService sceneEditInfoService;
+    @Autowired
+    ISceneEditControlsService sceneEditControlsService;
+    @Autowired
+    UploadToOssUtil uploadToOssUtil;
+//    @Autowired
+//    IBuildScenePreService buildScenePreService;
+    @Autowired
+    RedisUtil redisUtil;
+    @Autowired
+    IScenePlusService scenePlusService;
+    @Autowired
+    IScenePlusExtService scenePlusExtService;
+    @Autowired
+    IBuildSceneDTService buildSceneDTService;
+
+    @Override
+    public void buildScenePost(BuildSceneResultMqMessage message) {
+        Integer cameraType = Integer.parseInt(message.getCameraType());
+        String sceneCode = message.getSceneCode();
+        String fileId = message.getFileId();
+        Integer payStatus = message.getPayStatus();
+        Long computeTime = message.getComputeTime();
+        Boolean buildSuccess = message.getBuildSuccess();
+        Integer videoVersion = message.getVideoVersion();
+
+        Map<String, String> uploadFiles = message.getUploadFiles();
+        String path = message.getPath();
+        Integer pushChannel = message.getPushChannel();
+        String pushToken = message.getPushToken();
+        String prefix = message.getPrefix();
+        try {
+            if(!buildSuccess){//建模失败,修改状态为失败状态
+                log.info("建模失败,修改状态为失败状态");
+                // TODO: 2022/3/21 plus版本稳定后删除------------------------start
+                sceneService.updateStatus(sceneCode, SceneStatus.FAILD.code());
+                sceneProService.updateStatus(sceneCode, SceneStatus.FAILD.code());
+                // TODO: 2022/3/21 plus版本稳定后删除------------------------send
+
+                scenePlusService.update(
+                    new LambdaUpdateWrapper<ScenePlus>()
+                        .set(ScenePlus::getSceneStatus, SceneStatus.FAILD.code())
+                        .eq(ScenePlus::getNum, sceneCode));
+
+                SceneFileBuild sceneFileBuild = sceneFileBuildService.findByFileId(fileId);
+                if(Objects.nonNull(sceneFileBuild)){
+                    sceneFileBuild.setBuildStatus(BuildStatus.fail.code());
+                    sceneFileBuildService.updateById(sceneFileBuild);
+                }
+                return;
+            }
+
+            //建模成功走以下逻辑
+            log.info("cameraType:{}",cameraType);
+
+            //计算场景消耗磁盘空间
+            long space = this.calUseSpace(uploadFiles);
+
+            if(cameraType < 3){
+                // TODO: 2022/3/21 plus版本稳定后删除------------------------start
+                sceneService.updateTime(sceneCode, space, payStatus);
+                // TODO: 2022/3/21 plus版本稳定后删除------------------------send
+
+                this.updateDb4Sm(sceneCode, space);
+
+                uploadToOssUtil.uploadMulFiles(uploadFiles);
+                return;
+            }
+
+            //读取计算结果文件生成videosJson
+            JSONObject videosJson = this.getVideosJson(path, videoVersion, sceneCode, cameraType);
+
+            //写入数据库
+            // TODO: 2022/3/21 plus版本稳定后删除------------------------start
+            ScenePro scenePro = this.updateDbPro(sceneCode, space, payStatus, videosJson.toJSONString(), computeTime, fileId);
+            SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
+            // TODO: 2022/3/21 plus版本稳定后删除------------------------send
+            ScenePlus scenePlus = this.updateDbPlus(sceneCode, space, payStatus, videosJson.toJSONString(), computeTime, fileId);
+            ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
+
+            //变更容量,arrearCap为true时,代表容量不足
+            boolean arrearCap = this.updateSpace(scenePlus.getCameraId(), space, scenePlus.getId(), scenePro.getId());
+
+            //如果相机容量不足,需要把场景的paystatus改为容量不足状态
+            this.sealScene(arrearCap, scenePlus.getId(), scenePro.getId());
+
+            Object[] editInfoArr = this.updateEditInfo(scenePro, scenePlus);
+            SceneEditInfo sceneEditInfo = (SceneEditInfo)editInfoArr[0];
+            SceneEditControls sceneEditControls = (SceneEditControls)editInfoArr[1];
+
+            String sceneUrl = mainUrl + "/" + sceneProNewUrl;
+            String outPathZh = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneCode+".png";
+            String outPathEn = ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneCode+"_en.png";
+            //生成新的分享的二维码-中文版本
+            MatrixToImageWriterUtil.createQRCode(sceneUrl + sceneCode, outPathZh, false,null);
+            //生成新的分享的二维码-英文版本
+            MatrixToImageWriterUtil.createQRCode(sceneUrl + sceneCode + "&lang=en", outPathEn, false, null);
+            //上传二维码
+            uploadToOssUtil.upload(outPathZh, String.format(UploadFilePath.DOWNLOADS_QRCODE, sceneCode) + sceneCode + ".png");
+            uploadToOssUtil.upload(outPathEn, String.format(UploadFilePath.DOWNLOADS_QRCODE, sceneCode) + sceneCode + "_en.png");
+
+            Map<String, String> newUploadFiles = this.uploadFileMapHandler(sceneCode, cameraType, uploadFiles);
+
+            //上传计算结果中的caches/images和caches/videos
+            this.uploadCaches(sceneCode, uploadFiles, path);
+
+            //上传文件
+            uploadToOssUtil.uploadMulFiles(newUploadFiles);
+            // TODO: 2022/3/11 同时上传一份到旧版本的目录,用于过渡期使用,待重构版本稳定后删除
+            uploadToOssUtil.uploadMulFiles(uploadFiles);
+
+            //拷贝部分文件到编辑目录,用于用户编辑
+            this.copyToEditDir(sceneCode);
+
+            //计算成功,发短信
+            this.sendSms(pushChannel,pushToken, cameraType, scenePro.getSceneName(), scenePro.getWebSite());
+
+//            //上传日志文件
+//            buildScenePreService.uploadLogFile(sceneCode, sceneProExt.getDataSource());
+
+            //写scene.json
+            String sceneJson = this.writeSceneJson(sceneCode, videosJson,
+                sceneEditInfo, sceneEditControls, scenePlus, scenePlusExt, arrearCap);
+
+            //上传sceneJson文件
+            String sceneJsonPath = String.format(UploadFilePath.DATA_VIEW_PATH+"scene.json", sceneCode);
+            uploadToOssUtil.upload(sceneJson.getBytes(), sceneJsonPath);
+
+            //scenejson写入缓存
+            redisUtil.set(String.format(RedisKey.SCENE_JSON, sceneCode), sceneJson);
+
+            log.info("场景计算结果处理结束,场景码:{}", message.getSceneCode());
+
+        }catch (Exception e){
+            log.error("场景计算结果处理出错", e);
+            //发送钉钉
+            String serverPath = message.getPath().substring(0,message.getPath().lastIndexOf("/")+1).concat(prefix);
+//            buildSceneDTService.handFail("场景计算结果处理出错", serverPath, sceneCode, BuildScenePreServiceImpl.hostName, BuildScenePreServiceImpl.contentExt);
+        }
+    }
+
+    private String writeSceneJson(String num, JSONObject videosJson, SceneEditInfo sceneEditInfo,
+        SceneEditControls sceneEditControls, ScenePlus scenePlus, ScenePlusExt scenePlusExt, boolean arrearCap)  throws Exception{
+        String sceneJsonPath = String.format(ConstantFilePath.SCENE_PATH_FORMAT, num);
+        String strsceneInfos = FileUtils.readFile(sceneJsonPath);
+        SceneJsonBean sceneJson = null;
+        if(strsceneInfos!=null){
+            sceneJson = JSON.parseObject(strsceneInfos, SceneJsonBean.class);
+        }else{
+            sceneJson = BeanUtil.copyProperties(sceneEditInfo, SceneJsonBean.class);
+            SceneEditControlsVO sceneEditControlsVO = BeanUtil.copyProperties(sceneEditControls, SceneEditControlsVO.class);
+            sceneJson.setControls(sceneEditControlsVO);
+            sceneJson.setNum(num);
+            sceneJson.setCreateTime(scenePlus.getCreateTime());
+            sceneJson.setSceneResolution(scenePlusExt.getSceneResolution());
+            sceneJson.setSceneFrom(scenePlusExt.getSceneFrom());
+            sceneJson.setVideos(videosJson);
+        }
+        sceneJson.setVideos(videosJson);
+
+        if(arrearCap) {
+            sceneJson.setPayStatus(PayStatus.NO_CAPACITY.code());
+        }
+
+        String sceneJsonStr = JSON.toJSONString(sceneJson);
+        FileUtils.writeFile(sceneJsonPath, sceneJsonStr);
+        return sceneJsonStr;
+    }
+
+    private void sendSms(Integer pushChannel, String pushToken, int cameraType, String sceneName, String webSite){
+        log.info("推送消息,渠道是 {}, 手机token是 {}", pushChannel, pushToken);
+        if(Objects.isNull(pushChannel) && StrUtil.isBlank(pushToken))
+            return;
+
+        try{
+            if(StorageType.AWS.code().equals(ossType)){
+                PushMsgUtil
+                    .googlePushMsg(ConstantFilePath.BASE_PATH + "/refreshToken.json", pushToken,
+                        sceneName + "计算完成", "您上传的" + sceneName + "计算完成,点击查看", webSite);
+                return;
+            }
+
+            PushMessageConfig demo = null;
+            if(pushChannel == 0){
+                if(cameraType == 10 || cameraType == 13){
+                    //ios
+                    log.info("IOS_KEY:{}, IOS_SECRET:{}", IOS_KEY_Z, IOS_SECRET_Z);
+                    demo = new PushMessageConfig(IOS_KEY_Z, IOS_SECRET_Z);
+                    demo.sendIOSUnicast(pushToken,  "四维看看Minion",
+                        sceneName + "计算完成", "您上传的" + sceneName + "计算完成,点击查看", webSite);
+                }else {
+                    //ios
+                    log.info("IOS_KEY:{}, IOS_SECRET:{}", IOS_KEY, IOS_SECRET);
+                    demo = new PushMessageConfig(IOS_KEY, IOS_SECRET);
+                    demo.sendIOSUnicast(pushToken, "四维看看Pro",
+                        sceneName + "计算完成", "您上传的" + sceneName + "计算完成,点击查看", webSite);
+                }
+            }else {
+                if(cameraType == 10 || cameraType == 13){
+                    //ios
+                    //安卓
+                    log.info("ANDROID_KEY:{}, ANDROID_SECRET:{}", ANDROID_KEY_Z, ANDROID_SECRET_Z);
+                    demo = new PushMessageConfig(ANDROID_KEY_Z, ANDROID_SECRET_Z);
+                    demo.sendAndroidUnicast2(pushToken, "四维看看Minion",
+                        sceneName + "计算完成", "您上传的" + sceneName + "计算完成,点击查看", webSite);
+                }else {
+                    //安卓
+                    log.info("ANDROID_KEY:{}, ANDROID_SECRET:{}", ANDROID_KEY, ANDROID_SECRET);
+                    demo = new PushMessageConfig(ANDROID_KEY, ANDROID_SECRET);
+                    demo.sendAndroidUnicast(pushToken, "四维看看Pro",
+                        sceneName + "计算完成", "您上传的" + sceneName + "计算完成,点击查看", webSite);
+                }
+            }
+            log.info("消息推送结束!");
+        }catch (Exception e){
+            log.error("推送消息失败:", e);
+        }
+    }
+
+    private void copyToEditDir(String num) throws IOException {
+
+        String editImagesPath = String.format(UploadFilePath.IMG_EDIT_PATH, num);
+        String viewImagesPath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
+
+        String editDataPath = String.format(UploadFilePath.DATA_EDIT_PATH, num);
+        String viewDataPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
+
+        Map<String, String> map = new HashMap<>();
+        map.put(editImagesPath + "vision.modeldata", viewImagesPath + "vision.modeldata");
+        map.put(editImagesPath + "vision2.modeldata", viewImagesPath + "vision2.modeldata");
+        map.put(editDataPath + "floorplan_cad.json", viewDataPath + "floorplan_cad.json");
+
+        for (Entry<String, String> entry : map.entrySet()) {
+            uploadToOssUtil.copyFiles(entry.getValue(), entry.getKey());
+        }
+    }
+
+
+    private void uploadCaches(String num, Map<String,String> map, String path){
+
+        String sceneNumPAth = String.format("scene/%s", num);
+
+        List<String> imagesList = FileUtil.getFileList(path + "/caches/images");
+        log.info("caches/images_path:{}", path + "/caches/images");
+        if(CollUtil.isNotEmpty(imagesList)){
+            log.info("上传的caches/images文件列表:{}", imagesList.toString());
+            imagesList.stream().forEach(str -> {
+                if(str.endsWith(".jpg")){
+                    map.put(str, str.replace(path, sceneNumPAth));
+                }
+            });
+        }
+
+        List<String> videosList = FileUtil.getFileList(path + "/caches/videos");
+        if(CollUtil.isNotEmpty(videosList)){
+            log.info("上传的caches/videos文件列表:{}", videosList.toString());
+            videosList.stream().forEach(str -> map.put(str, str.replace(path, sceneNumPAth)));
+        }
+    }
+
+    private Map<String, String> uploadFileMapHandler(String num, int cameraType, Map<String, String> map) {
+        if(CollUtil.isEmpty(map)){
+            return null;
+        }
+
+        String dataPath = String.format("data/data%s/", num);
+        String imagePath = String.format("images/images%s/", num);
+        String videoPath = String.format("video/video%s/", num);
+
+        String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
+        String imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
+        String videosViewPath = String.format(UploadFilePath.VIDEOS_VIEW_PATH, num);
+
+        Map<String, String> newMap = new HashMap<>();
+        for (String key : map.keySet()) {
+            String value = map.get(key);
+            if(value.contains(dataPath)){
+                newMap.put(key, value.replace(dataPath, dataViewPath));
+            }
+            if(value.contains(imagePath)){
+                newMap.put(key, value.replace(imagePath, imgViewPath));
+            }
+            if(value.contains(videoPath)){
+                newMap.put(key, value.replace(videoPath, videosViewPath));
+            }
+        }
+        return newMap;
+    }
+
+    private JSONObject getVideosJson(String path, Integer videoVersion, String projectNum, int cameraType) throws Exception {
+        //读取videos_hdr_param.json, 保存点位视频的value
+        Map<String, Object> videoMap = new HashMap<>();
+        String videosHdr = FileUtils.readFile(path + File.separator + "results/videos/videos_hdr_param.json");
+        JSONArray videoArray = null;
+        if(StringUtils.isNotEmpty(videosHdr)){
+            videoArray = JSONObject.parseObject(videosHdr).getJSONArray("hdr_param");
+        }
+        if(videoArray != null){
+            for(int i = 0, len = videoArray.size(); i < len; i++) {
+                videoMap.put(videoArray.getJSONObject(i).getString("name"), videoArray.getJSONObject(i).getString("value"));
+                if(videoArray.getJSONObject(i).containsKey("fov")){
+                    videoMap.put(videoArray.getJSONObject(i).getString("name") + "_fov", videoArray.getJSONObject(i).getString("fov"));
+                }
+            }
+        }
+
+        //获取upload中的video视频名称
+        String uploadData = FileUtils.readFile(path + File.separator + "results" +File.separator+"upload.json");
+        JSONObject uploadJson = null;
+        JSONArray array = null;
+        if(uploadData!=null) {
+            uploadJson = JSONObject.parseObject(uploadData);
+            array = uploadJson.getJSONArray("upload");
+        }
+        JSONObject fileJson = null;
+        String fileName = "";
+
+        //计算ts文件的大小,并拼接成json格式
+        JSONArray jsonArray = new JSONArray();
+        JSONObject videoJson = null;
+        JSONObject videosJson = new JSONObject();
+        long videoSize = 0L;
+        for(int i = 0, len = array.size(); i < len; i++) {
+            fileJson = array.getJSONObject(i);
+            fileName = fileJson.getString("file");
+            if(fileJson.getIntValue("clazz") == 11 && fileName.contains(".mp4") && !fileName.contains("-ios.mp4")){
+                videoJson = new JSONObject();
+                videoJson.put("id", fileName.substring(
+                    0, fileName.lastIndexOf(".")).replace("videos/", ""));
+
+                //如果ts文件存在,就计算ts大小
+                if(new File(path + File.separator + "results" +File.separator+ fileName.replace(".mp4", ".ts")).exists()){
+                    videoSize = new File(path + File.separator + "results" +File.separator+ fileName.replace(".mp4", ".ts")).length();
+                    videoJson.put("tsSize", videoSize);
+                }
+                if(videoMap.containsKey(videoJson.get("id"))){
+                    videoJson.put("value", videoMap.get(videoJson.get("id")));
+                }
+                if(videoMap.containsKey(videoJson.get("id") + "_fov")){
+                    videoJson.put("blend_fov", videoMap.get(videoJson.get("id") + "_fov"));
+                }else {
+                    videoJson.put("blend_fov", 7);
+                }
+                jsonArray.add(videoJson);
+            }
+        }
+
+        videosJson.put("data", jsonArray);
+        if(Objects.nonNull(videoVersion) && videoVersion >= 4){
+            videosJson.put("version", 3);
+            if(StorageType.OSS.code().equals(ossType)){
+                videosJson.put("upPath", prefixAli + "data/data" + projectNum + "/Up.xml");
+            }
+            if(StorageType.AWS.code().equals(ossType)){
+                videosJson.put("upPath", ConstantUrl.PREFIX_AWS + "data/data" + projectNum + "/Up.xml");
+            }
+            if(cameraType == 13){
+                //转台相机
+                videosJson.put("upPath", videosJson.getString("upPath").replace(".xml", ".txt"));
+            }
+        }else {
+            videosJson.put("version", 1);
+            if("oss".equals(ossType)){
+                videosJson.put("upPath", prefixAli + "data/data" + projectNum + "/Up2.xml");
+            }
+            if("aws".equals(ossType)){
+                videosJson.put("upPath", ConstantUrl.PREFIX_AWS + "data/data" + projectNum + "/Up2.xml");
+            }
+
+            if(cameraType == 13){
+                //转台相机
+                videosJson.put("upPath", videosJson.getString("upPath").replace(".xml", ".txt"));
+            }
+        }
+
+        if(cameraType == 5 || cameraType == 6){
+            videosJson.put("version", 1);
+            if("oss".equals(ossType)){
+                videosJson.put("upPath", prefixAli + "data/data" + projectNum + "/stitch_params.txt");
+            }
+            if("aws".equals(ossType)){
+                videosJson.put("upPath", ConstantUrl.PREFIX_AWS + "data/data" + projectNum + "/stitch_params.txt");
+            }
+        }
+
+        return videosJson;
+    }
+
+    private Long calUseSpace(Map<String, String> uploadFile) {
+        File spaceFile = null;
+        long space = 0L;
+        for (String key : uploadFile.keySet()) {
+            spaceFile = new File(key);
+            if(spaceFile.exists()){
+                space += spaceFile.length();
+            }
+        }
+        return space;
+    }
+
+    private void sealScene(boolean arrearCap, Long scenePlusId, Long sceneProId){
+        if(!arrearCap){
+            return;
+        }
+        scenePlusService.update(
+            new LambdaUpdateWrapper<ScenePlus>()
+                .set(ScenePlus::getPayStatus, PayStatus.NO_CAPACITY)
+                .eq(ScenePlus::getId, scenePlusId));
+
+
+        // TODO: 2022/3/22 plus版本稳定后删除---------------------------start
+        sceneProService.update(
+            new LambdaUpdateWrapper<ScenePro>()
+                .set(ScenePro::getPayStatus, PayStatus.NO_CAPACITY)
+                .eq(ScenePro::getId, sceneProId));
+        // TODO: 2022/3/22 plus版本稳定后删除---------------------------end
+    }
+
+    /**
+     * <p>
+     双目场景更新数据库
+     * </p>
+     * @author dengsixing
+     * @date 2022/3/21
+     * @param num
+     * @param space
+     **/
+    private void updateDb4Sm(String num, long space){
+        List<ScenePlus> ScenePlusList = scenePlusService.list(
+            new LambdaQueryWrapper<ScenePlus>()
+                .select(ScenePlus::getId)
+                .eq(ScenePlus::getNum, num));
+
+        if(CollUtil.isNotEmpty(ScenePlusList))
+            return ;
+        List<Long> sceneIds = ScenePlusList.stream().map(scene -> {
+            return scene.getId();
+        }).collect(Collectors.toList());
+
+        //更新场景创建时间
+        scenePlusService.update(new LambdaUpdateWrapper<ScenePlus>()
+            .in(ScenePlus::getId, sceneIds)
+            .set(ScenePlus::getCreateTime, Calendar.getInstance().getTime())
+            .set(ScenePlus::getSceneStatus, SceneStatus.NO_DISPLAY.code()));
+
+        //更新使用容量
+        scenePlusExtService.update(
+            new LambdaUpdateWrapper<ScenePlusExt>()
+                .in(ScenePlusExt::getPlusId, sceneIds)
+                .set(ScenePlusExt::getSpace, space));
+    }
+
+    private ScenePro updateDbPro(String sceneCode, Long space, Integer payStatus, String videosJson, Long computeTime, String fileId) throws Exception{
+        ScenePro scenePro = sceneProService.findBySceneNum(sceneCode);
+
+        sceneProService.updateTime(sceneCode, space, payStatus, videosJson, computeTime);
+        SceneFileBuild sceneFileBuild = sceneFileBuildService.findByFileId(fileId);
+        if(sceneFileBuild != null){
+            sceneFileBuild.setBuildStatus(BuildStatus.success.code());
+            sceneFileBuildService.updateById(sceneFileBuild);
+        }
+
+        if(Objects.nonNull(scenePro)){
+            SceneProExt sceneProExt = sceneProExtService.findBySceneProId(scenePro.getId());
+            SceneSource sceneSource = SceneSource.get(sceneProExt.getSceneSource());
+            switch (sceneSource){
+                case BM:
+                    sceneProExt.setSceneResolution(SceneResolution.TILES_2K.code());
+                    sceneProExt.setSceneFrom(SceneFrom.PRO.code());
+                    break;
+                case SM:
+                    sceneProExt.setSceneResolution(SceneResolution.TILES_1K.code());
+                    sceneProExt.setSceneFrom(SceneFrom.LITE.code());
+                    break;
+                case ZT:
+                    sceneProExt.setSceneResolution(SceneResolution.TILES_4K.code());
+                    sceneProExt.setSceneFrom(SceneFrom.MINION.code());
+                    break;
+                case JG:
+                    sceneProExt.setSceneResolution(SceneResolution.TILES_4K.code());
+                    sceneProExt.setSceneFrom(SceneFrom.LASER.code());
+                    break;
+            }
+            sceneProExtService.updateById(sceneProExt);
+
+        }
+
+        return scenePro;
+    }
+
+    private ScenePlus updateDbPlus(String num, Long space, Integer payStatus, String videosJson, Long computeTime, String fileId) throws Exception{
+        ScenePlus scenePlus = scenePlusService.getScenePlusByNum(num);
+        ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
+        List<ScenePlus> list = scenePlusService.list(
+            new LambdaQueryWrapper<ScenePlus>()
+                .select(ScenePlus::getId)
+                .eq(ScenePlus::getNum, num));
+        if(scenePlus == null || CollUtil.isEmpty(list))
+            return null;
+
+        //修改场景状态 空间 支付状态 计算时间
+        List<Long> scenePlusIds = list.stream().map(plus -> {
+            return plus.getId();
+        }).collect(Collectors.toList());
+
+        scenePlusService.update(new LambdaUpdateWrapper<ScenePlus>()
+            .in(ScenePlus::getId, scenePlusIds)
+            .set(ScenePlus::getSceneStatus, SceneStatus.NO_DISPLAY.code())
+            .set(ScenePlus::getCreateTime, Calendar.getInstance().getTime())
+            .set(ScenePlus::getPayStatus, payStatus));
+
+        scenePlusExtService.update(new LambdaUpdateWrapper<ScenePlusExt>()
+            .in(ScenePlusExt::getPlusId, scenePlusIds)
+            .set(ScenePlusExt::getSpace, space)
+            .set(ScenePlusExt::getComputeTime, computeTime)
+            .set(ScenePlusExt::getVideos, videosJson));
+
+        SceneFileBuild sceneFileBuild = sceneFileBuildService.findByFileId(fileId);
+        if(sceneFileBuild != null){
+            sceneFileBuild.setBuildStatus(BuildStatus.success.code());
+            sceneFileBuildService.updateById(sceneFileBuild);
+        }
+
+        SceneSource sceneSource = SceneSource.get(scenePlus.getSceneSource());
+        switch (sceneSource){
+            case BM:
+                scenePlusExt.setSceneResolution(SceneResolution.TILES_2K.code());
+                scenePlusExt.setSceneFrom(SceneFrom.PRO.code());
+                break;
+            case SM:
+                scenePlusExt.setSceneResolution(SceneResolution.TILES_1K.code());
+                scenePlusExt.setSceneFrom(SceneFrom.LITE.code());
+                break;
+            case ZT:
+                scenePlusExt.setSceneResolution(SceneResolution.TILES_4K.code());
+                scenePlusExt.setSceneFrom(SceneFrom.MINION.code());
+                break;
+            case JG:
+                scenePlusExt.setSceneResolution(SceneResolution.TILES_4K.code());
+                scenePlusExt.setSceneFrom(SceneFrom.LASER.code());
+                break;
+        }
+        scenePlusExtService.updateById(scenePlusExt);
+
+
+        return scenePlus;
+    }
+
+    private boolean updateSpace(Long cameraId, Long space, Long scenePlusId, Long sceneProId) throws Exception{
+        //更新相机使用用量
+        ResultData<CameraDetail> resultData = platformGoodsClient.updateCameraDetailByCameraIdAndSpace(cameraId, space);
+        if(resultData.getCode() != ServerCode.SUCCESS.code()){
+            log.error("调用platform服务updateCameraDetailByCameraIdAndSpace失败,参数{},{}" ,cameraId, space);
+            throw new Exception(ServerCode.FEIGN_REQUEST_FAILD.message());
+        }
+        CameraDetail cameraDetail = JSONObject.parseObject(JSONObject.toJSONString(resultData.getData()), CameraDetail.class);
+
+        ResultData<UserIncrement> resultData1 = platformUserClient.getUserIncrementByCameraId(cameraId);
+        if(resultData1.getCode() != ServerCode.SUCCESS.code()){
+            log.error("调用platform服务getUserIncrementByCameraId失败,参数{}" ,cameraId);
+            throw new Exception(ServerCode.FEIGN_REQUEST_FAILD.message());
+        }
+        if( resultData1.getData() == null || resultData1.getData().getIsExpired() == ExpiredStatus.Expired.code()) {
+            // 新上传的场景,如果总容量小于使用容量,则该大场景保留在临时存储空间30天
+            if (cameraDetail.getTotalSpace().compareTo(cameraDetail.getUsedSpace()) == -1){
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private Object[] updateEditInfo(ScenePro scenePro, ScenePlus scenePlus){
+        SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
+        SceneEditControls sceneEditControls = null;
+        if(sceneEditInfo == null){
+            sceneEditInfo = new SceneEditInfo();
+            sceneEditInfo.setScenePlusId(scenePlus.getId());
+            sceneEditInfo.setSceneProId(scenePro.getId());
+            sceneEditInfo.setDescription(scenePlus.getDescription());
+            sceneEditInfo.setTitle(scenePlus.getTitle());
+            sceneEditInfoService.save(sceneEditInfo);
+        }else{
+            sceneEditControls = sceneEditControlsService.getBySceneEditId(sceneEditInfo.getId());
+        }
+        if(sceneEditControls == null){
+            sceneEditControls = new SceneEditControls();
+            sceneEditControls.setEditInfoId(sceneEditInfo.getId());
+            sceneEditControlsService.save(sceneEditControls);
+        }
+        return new Object[]{sceneEditInfo, sceneEditControls};
+    }
+}

+ 340 - 283
4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/impl/BuildScenePreServiceImpl.java

@@ -22,6 +22,7 @@ import com.fdkankan.common.constant.UploadFilePath;
 import com.fdkankan.common.util.CreateObjUtil;
 import com.fdkankan.common.util.FileUtil;
 import com.fdkankan.common.util.FileUtils;
+import com.fdkankan.common.util.SceneUtil;
 import com.fdkankan.dingtalk.DingTalkSendUtils;
 import com.fdkankan.fyun.constant.StorageType;
 import com.fdkankan.fyun.oss.UploadToOssUtil;
@@ -30,11 +31,15 @@ import com.fdkankan.platform.api.feign.PlatformGoodsClient;
 import com.fdkankan.platform.api.feign.PlatformUserClient;
 import com.fdkankan.push.PushMessageConfig;
 import com.fdkankan.push.PushMsgUtil;
+import com.fdkankan.rabbitmq.util.RabbitMqProducer;
+import com.fdkankan.redis.constant.RedisKey;
+import com.fdkankan.redis.util.RedisUtil;
 import com.fdkankan.scene.bean.SceneJsonBean;
 import com.fdkankan.scene.entity.SceneEditControls;
 import com.fdkankan.scene.entity.SceneEditInfo;
 import com.fdkankan.scene.entity.ScenePlus;
 import com.fdkankan.scene.entity.ScenePlusExt;
+import com.fdkankan.scene.service.IBuildSceneDTService;
 import com.fdkankan.scene.service.IBuildScenePreService;
 import com.fdkankan.scene.service.IScenePlusService;
 import com.fdkankan.scene.vo.SceneEditControlsVO;
@@ -44,6 +49,8 @@ import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.security.InvalidKeyException;
 import java.security.NoSuchAlgorithmException;
+import java.time.Duration;
+import java.time.temporal.ChronoUnit;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
@@ -71,20 +78,31 @@ public class BuildScenePreServiceImpl implements IBuildScenePreService {
 
     @Value("${oss.prefix.ali}")
     private String prefixAli;
-    @Autowired
-    UploadToOssUtil uploadToOssUtil;
+    @Value("${model.timeOut:48}")
+    private int modelTimeOut;
     @Value("${upload.type}")
     private String ossType;
-    @Autowired
-    private DingTalkSendUtils dingTalkSendUtils;
     @Value("${environment:dev}")
     private String environment;
+    @Value("${queue.modeling.modeling-call}")
+    private String queueModelingCall;
+
+    @Autowired
+    UploadToOssUtil uploadToOssUtil;
+    @Autowired
+    private DingTalkSendUtils dingTalkSendUtils;
     @Autowired
     private IScenePlusService scenePlusService;
     @Autowired
     private PlatformUserClient platformUserClient;
     @Autowired
     private PlatformGoodsClient platformGoodsClient;
+    @Autowired
+    RedisUtil redisUtil;
+    @Autowired
+    private RabbitMqProducer mqProducer;
+    @Autowired
+    private IBuildSceneDTService buildSceneDTService;
 
     public static String hostName;
 
@@ -110,6 +128,45 @@ public class BuildScenePreServiceImpl implements IBuildScenePreService {
 
 
     @Override
+    public void buildScenePre(BuildSceneMqMessage message) {
+        boolean success = false;
+        try {
+            String key = String.format(RedisKey.SCENE_BUILDING, message.getSceneNum());
+            Long building = redisUtil.incr(key, 1);
+            if (building.compareTo(1L) != 0) {
+                log.error("场景正在构建中,退出构建,参数:{}", JSONObject.toJSONString(message));
+                return;
+            } else {
+                redisUtil.expire(key, Duration.of(modelTimeOut, ChronoUnit.HOURS));
+            }
+
+            //根据相机类型,组装资源路径
+            String path = SceneUtil.getPath(message.getPath(), message.getCameraName(),
+                message.getFileId(), Integer.parseInt(message.getCameraType()), message.getUnicode());
+
+            //下载资源到本地
+            this.downLoadSource(message, path);
+
+            //发送mq,就进行计算
+            mqProducer.sendByWorkQueue(queueModelingCall, message);
+
+            success = true;
+
+            log.info("场景计算资源准备结束,场景码:{}", message.getSceneNum());
+
+        }catch (Exception e){
+            log.error("场景计算前置处理出错", e);
+        }finally {
+            //如果前置处理失败,发送钉钉消息
+            if(!success){
+                String serverPath = message.getPath().substring(0,message.getPath().lastIndexOf("/")+1).concat(message.getPrefix());
+//            buildSceneDTService.handFail("场景计算前置处理出错", serverPath, message.getSceneNum(), BuildScenePreServiceImpl.hostName, null);
+            }
+
+        }
+    }
+
+    @Override
     public Map<String, String> getTypeString(String cameraType, String algorithm, String resolution,
         JSONObject dataJson) {
         return null;
@@ -187,36 +244,23 @@ public class BuildScenePreServiceImpl implements IBuildScenePreService {
         }
     }
 
-    @Override
-    public Map<String, String> uploadFileMapHandler(String num, int cameraType, Map<String, String> map) {
-        if(CollUtil.isEmpty(map)){
-            return null;
-        }
-
-        String dataPath = String.format("data/data%s/", num);
-        String imagePath = String.format("images/images%s/", num);
-        String videoPath = String.format("video/video%s/", num);
-
-        String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
-        String imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
-        String videosViewPath = String.format(UploadFilePath.VIDEOS_VIEW_PATH, num);
-
-        Map<String, String> newMap = new HashMap<>();
-        for (String key : map.keySet()) {
-            String value = map.get(key);
-            if(value.contains(dataPath)){
-                newMap.put(key, value.replace(dataPath, dataViewPath));
-            }
-            if(value.contains(imagePath)){
-                newMap.put(key, value.replace(imagePath, imgViewPath));
-            }
-            if(value.contains(videoPath)){
-                newMap.put(key, value.replace(videoPath, videosViewPath));
-            }
-        }
-//        map.entrySet().parallelStream().forEach(entry -> {
-//            String key = entry.getKey();
-//            String value = entry.getValue();
+//    @Override
+//    public Map<String, String> uploadFileMapHandler(String num, int cameraType, Map<String, String> map) {
+//        if(CollUtil.isEmpty(map)){
+//            return null;
+//        }
+//
+//        String dataPath = String.format("data/data%s/", num);
+//        String imagePath = String.format("images/images%s/", num);
+//        String videoPath = String.format("video/video%s/", num);
+//
+//        String dataViewPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
+//        String imgViewPath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
+//        String videosViewPath = String.format(UploadFilePath.VIDEOS_VIEW_PATH, num);
+//
+//        Map<String, String> newMap = new HashMap<>();
+//        for (String key : map.keySet()) {
+//            String value = map.get(key);
 //            if(value.contains(dataPath)){
 //                newMap.put(key, value.replace(dataPath, dataViewPath));
 //            }
@@ -226,128 +270,141 @@ public class BuildScenePreServiceImpl implements IBuildScenePreService {
 //            if(value.contains(videoPath)){
 //                newMap.put(key, value.replace(videoPath, videosViewPath));
 //            }
+//        }
+////        map.entrySet().parallelStream().forEach(entry -> {
+////            String key = entry.getKey();
+////            String value = entry.getValue();
+////            if(value.contains(dataPath)){
+////                newMap.put(key, value.replace(dataPath, dataViewPath));
+////            }
+////            if(value.contains(imagePath)){
+////                newMap.put(key, value.replace(imagePath, imgViewPath));
+////            }
+////            if(value.contains(videoPath)){
+////                newMap.put(key, value.replace(videoPath, videosViewPath));
+////            }
+////        });
+//        return newMap;
+//    }
+
+//    @Override
+//    public void uploadCaches(String num, Map<String,String> map, String path){
+//
+//        String sceneNumPAth = String.format("scene/%s", num);
+//
+//        List<String> imagesList = FileUtil.getFileList(path + "/caches/images");
+//        log.info("caches/images_path:{}", path + "/caches/images");
+//        if(CollUtil.isNotEmpty(imagesList)){
+//            log.info("上传的caches/images文件列表:{}", imagesList.toString());
+//            imagesList.stream().forEach(str -> {
+//                if(str.endsWith(".jpg")){
+//                    map.put(str, str.replace(path, sceneNumPAth));
+//                }
+//            });
+//        }
+//
+//        List<String> videosList = FileUtil.getFileList(path + "/caches/videos");
+//        if(CollUtil.isNotEmpty(videosList)){
+//            log.info("上传的caches/videos文件列表:{}", videosList.toString());
+//            videosList.stream().forEach(str -> map.put(str, str.replace(path, sceneNumPAth)));
+//        }
+//    }
+
+//    @Override
+//    public void copyToEditDir(String num) throws IOException {
+//
+//        String editImagesPath = String.format(UploadFilePath.IMG_EDIT_PATH, num);
+//        String viewImagesPath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
+//
+//        String editDataPath = String.format(UploadFilePath.DATA_EDIT_PATH, num);
+//        String viewDataPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
+//
+//        Map<String, String> map = new HashMap<>();
+//        map.put(editImagesPath + "vision.modeldata", viewImagesPath + "vision.modeldata");
+//        map.put(editImagesPath + "vision2.modeldata", viewImagesPath + "vision2.modeldata");
+//        map.put(editDataPath + "floorplan_cad.json", viewDataPath + "floorplan_cad.json");
+//
+//        for (Entry<String, String> entry : map.entrySet()) {
+//            uploadToOssUtil.copyFiles(entry.getValue(), entry.getKey());
+//        }
+//    }
+
+//    @Override
+//    public void sendSms(Integer pushChannel, String pushToken, int cameraType, String sceneName, String webSite){
+//        log.info("推送消息,渠道是 {}, 手机token是 {}", pushChannel, pushToken);
+//        if(Objects.isNull(pushChannel) && StrUtil.isBlank(pushToken))
+//            return;
+//
+//        try{
+//            if(StorageType.AWS.code().equals(ossType)){
+//                PushMsgUtil.googlePushMsg(ConstantFilePath.BASE_PATH + "/refreshToken.json", pushToken,
+//                    sceneName + "计算完成", "您上传的" + sceneName + "计算完成,点击查看", webSite);
+//                return;
+//            }
+//
+//            PushMessageConfig demo = null;
+//            if(pushChannel == 0){
+//                if(cameraType == 10 || cameraType == 13){
+//                    //ios
+//                    log.info("IOS_KEY:{}, IOS_SECRET:{}", IOS_KEY_Z, IOS_SECRET_Z);
+//                    demo = new PushMessageConfig(IOS_KEY_Z, IOS_SECRET_Z);
+//                    demo.sendIOSUnicast(pushToken,  "四维看看Minion",
+//                        sceneName + "计算完成", "您上传的" + sceneName + "计算完成,点击查看", webSite);
+//                }else {
+//                    //ios
+//                    log.info("IOS_KEY:{}, IOS_SECRET:{}", IOS_KEY, IOS_SECRET);
+//                    demo = new PushMessageConfig(IOS_KEY, IOS_SECRET);
+//                    demo.sendIOSUnicast(pushToken, "四维看看Pro",
+//                        sceneName + "计算完成", "您上传的" + sceneName + "计算完成,点击查看", webSite);
+//                }
+//            }else {
+//                if(cameraType == 10 || cameraType == 13){
+//                    //ios
+//                    //安卓
+//                    log.info("ANDROID_KEY:{}, ANDROID_SECRET:{}", ANDROID_KEY_Z, ANDROID_SECRET_Z);
+//                    demo = new PushMessageConfig(ANDROID_KEY_Z, ANDROID_SECRET_Z);
+//                    demo.sendAndroidUnicast2(pushToken, "四维看看Minion",
+//                        sceneName + "计算完成", "您上传的" + sceneName + "计算完成,点击查看", webSite);
+//                }else {
+//                    //安卓
+//                    log.info("ANDROID_KEY:{}, ANDROID_SECRET:{}", ANDROID_KEY, ANDROID_SECRET);
+//                    demo = new PushMessageConfig(ANDROID_KEY, ANDROID_SECRET);
+//                    demo.sendAndroidUnicast(pushToken, "四维看看Pro",
+//                        sceneName + "计算完成", "您上传的" + sceneName + "计算完成,点击查看", webSite);
+//                }
+//            }
+//            log.info("消息推送结束!");
+//        }catch (Exception e){
+//            log.error("推送消息失败:", e);
+//        }
+//    }
+
+//    @Override
+//    public void handFail(String reason, String serverPath, String num, String hostName, String contentExt) {
+//        CompletableFuture.runAsync(() -> {
+//            try {
+//                String contentFormat = StrUtil.isBlank(contentExt) ? this.DINGTALK_MSG_PATTERN : this.DINGTALK_MSG_PATTERN +  contentExt;
+//                String content = String.format(contentFormat, this.environment, hostName, reason, num, serverPath, num, num);
+//                log.error("发送钉钉消息,content:{}", content);
+//                dingTalkSendUtils.sendActioncardMsgToDingRobot(content,"场景计算失败");
+//            } catch (ApiException | UnsupportedEncodingException | NoSuchAlgorithmException | InvalidKeyException apiException) {
+//                log.error("发送钉钉消息失败", apiException);
+//            }
 //        });
-        return newMap;
-    }
-
-    @Override
-    public void uploadCaches(String num, Map<String,String> map, String path){
-
-        String sceneNumPAth = String.format("scene/%s", num);
-
-        List<String> imagesList = FileUtil.getFileList(path + "/caches/images");
-        log.info("caches/images_path:{}", path + "/caches/images");
-        if(CollUtil.isNotEmpty(imagesList)){
-            log.info("上传的caches/images文件列表:{}", imagesList.toString());
-            imagesList.stream().forEach(str -> {
-                if(str.endsWith(".jpg")){
-                    map.put(str, str.replace(path, sceneNumPAth));
-                }
-            });
-        }
-
-        List<String> videosList = FileUtil.getFileList(path + "/caches/videos");
-        if(CollUtil.isNotEmpty(videosList)){
-            log.info("上传的caches/videos文件列表:{}", videosList.toString());
-            videosList.stream().forEach(str -> map.put(str, str.replace(path, sceneNumPAth)));
-        }
-    }
-
-    @Override
-    public void copyToEditDir(String num) throws IOException {
-
-        String editImagesPath = String.format(UploadFilePath.IMG_EDIT_PATH, num);
-        String viewImagesPath = String.format(UploadFilePath.IMG_VIEW_PATH, num);
-
-        String editDataPath = String.format(UploadFilePath.DATA_EDIT_PATH, num);
-        String viewDataPath = String.format(UploadFilePath.DATA_VIEW_PATH, num);
-
-        Map<String, String> map = new HashMap<>();
-        map.put(editImagesPath + "vision.modeldata", viewImagesPath + "vision.modeldata");
-        map.put(editImagesPath + "vision2.modeldata", viewImagesPath + "vision2.modeldata");
-        map.put(editDataPath + "floorplan_cad.json", viewDataPath + "floorplan_cad.json");
-
-        for (Entry<String, String> entry : map.entrySet()) {
-            uploadToOssUtil.copyFiles(entry.getValue(), entry.getKey());
-        }
-    }
-
-    @Override
-    public void sendSms(Integer pushChannel, String pushToken, int cameraType, String sceneName, String webSite){
-        log.info("推送消息,渠道是 {}, 手机token是 {}", pushChannel, pushToken);
-        if(Objects.isNull(pushChannel) && StrUtil.isBlank(pushToken))
-            return;
-
-        try{
-            if(StorageType.AWS.code().equals(ossType)){
-                PushMsgUtil.googlePushMsg(ConstantFilePath.BASE_PATH + "/refreshToken.json", pushToken,
-                    sceneName + "计算完成", "您上传的" + sceneName + "计算完成,点击查看", webSite);
-                return;
-            }
-
-            PushMessageConfig demo = null;
-            if(pushChannel == 0){
-                if(cameraType == 10 || cameraType == 13){
-                    //ios
-                    log.info("IOS_KEY:{}, IOS_SECRET:{}", IOS_KEY_Z, IOS_SECRET_Z);
-                    demo = new PushMessageConfig(IOS_KEY_Z, IOS_SECRET_Z);
-                    demo.sendIOSUnicast(pushToken,  "四维看看Minion",
-                        sceneName + "计算完成", "您上传的" + sceneName + "计算完成,点击查看", webSite);
-                }else {
-                    //ios
-                    log.info("IOS_KEY:{}, IOS_SECRET:{}", IOS_KEY, IOS_SECRET);
-                    demo = new PushMessageConfig(IOS_KEY, IOS_SECRET);
-                    demo.sendIOSUnicast(pushToken, "四维看看Pro",
-                        sceneName + "计算完成", "您上传的" + sceneName + "计算完成,点击查看", webSite);
-                }
-            }else {
-                if(cameraType == 10 || cameraType == 13){
-                    //ios
-                    //安卓
-                    log.info("ANDROID_KEY:{}, ANDROID_SECRET:{}", ANDROID_KEY_Z, ANDROID_SECRET_Z);
-                    demo = new PushMessageConfig(ANDROID_KEY_Z, ANDROID_SECRET_Z);
-                    demo.sendAndroidUnicast2(pushToken, "四维看看Minion",
-                        sceneName + "计算完成", "您上传的" + sceneName + "计算完成,点击查看", webSite);
-                }else {
-                    //安卓
-                    log.info("ANDROID_KEY:{}, ANDROID_SECRET:{}", ANDROID_KEY, ANDROID_SECRET);
-                    demo = new PushMessageConfig(ANDROID_KEY, ANDROID_SECRET);
-                    demo.sendAndroidUnicast(pushToken, "四维看看Pro",
-                        sceneName + "计算完成", "您上传的" + sceneName + "计算完成,点击查看", webSite);
-                }
-            }
-            log.info("消息推送结束!");
-        }catch (Exception e){
-            log.error("推送消息失败:", e);
-        }
-    }
-
-    @Override
-    public void handFail(String reason, String serverPath, String num, String hostName, String contentExt) {
-        CompletableFuture.runAsync(() -> {
-            try {
-                String contentFormat = StrUtil.isBlank(contentExt) ? this.DINGTALK_MSG_PATTERN : this.DINGTALK_MSG_PATTERN +  contentExt;
-                String content = String.format(contentFormat, this.environment, hostName, reason, num, serverPath, num, num);
-                log.error("发送钉钉消息,content:{}", content);
-                dingTalkSendUtils.sendActioncardMsgToDingRobot(content,"场景计算失败");
-            } catch (ApiException | UnsupportedEncodingException | NoSuchAlgorithmException | InvalidKeyException apiException) {
-                log.error("发送钉钉消息失败", apiException);
-            }
-        });
-    }
-
-    @Override
-    public Long calUseSpace(Map<String, String> uploadFile) {
-        File spaceFile = null;
-        long space = 0L;
-        for (String key : uploadFile.keySet()) {
-            spaceFile = new File(key);
-            if(spaceFile.exists()){
-                space += spaceFile.length();
-            }
-        }
-        return space;
-    }
+//    }
+
+//    @Override
+//    public Long calUseSpace(Map<String, String> uploadFile) {
+//        File spaceFile = null;
+//        long space = 0L;
+//        for (String key : uploadFile.keySet()) {
+//            spaceFile = new File(key);
+//            if(spaceFile.exists()){
+//                space += spaceFile.length();
+//            }
+//        }
+//        return space;
+//    }
 
     @Override
     public void uploadLogFile(String num, String dataSource) {
@@ -368,132 +425,132 @@ public class BuildScenePreServiceImpl implements IBuildScenePreService {
 
     }
 
-    @Override
-    public JSONObject getVideosJson(String path, Integer videoVersion, String projectNum, int cameraType) throws Exception {
-        //读取videos_hdr_param.json, 保存点位视频的value
-        Map<String, Object> videoMap = new HashMap<>();
-        String videosHdr = FileUtils.readFile(path + File.separator + "results/videos/videos_hdr_param.json");
-        JSONArray videoArray = null;
-        if(StringUtils.isNotEmpty(videosHdr)){
-            videoArray = JSONObject.parseObject(videosHdr).getJSONArray("hdr_param");
-        }
-        if(videoArray != null){
-            for(int i = 0, len = videoArray.size(); i < len; i++) {
-                videoMap.put(videoArray.getJSONObject(i).getString("name"), videoArray.getJSONObject(i).getString("value"));
-                if(videoArray.getJSONObject(i).containsKey("fov")){
-                    videoMap.put(videoArray.getJSONObject(i).getString("name") + "_fov", videoArray.getJSONObject(i).getString("fov"));
-                }
-            }
-        }
-
-        //获取upload中的video视频名称
-        String uploadData = FileUtils.readFile(path + File.separator + "results" +File.separator+"upload.json");
-        JSONObject uploadJson = null;
-        JSONArray array = null;
-        if(uploadData!=null) {
-            uploadJson = JSONObject.parseObject(uploadData);
-            array = uploadJson.getJSONArray("upload");
-        }
-        JSONObject fileJson = null;
-        String fileName = "";
-
-        //计算ts文件的大小,并拼接成json格式
-        JSONArray jsonArray = new JSONArray();
-        JSONObject videoJson = null;
-        JSONObject videosJson = new JSONObject();
-        long videoSize = 0L;
-        for(int i = 0, len = array.size(); i < len; i++) {
-            fileJson = array.getJSONObject(i);
-            fileName = fileJson.getString("file");
-            if(fileJson.getIntValue("clazz") == 11 && fileName.contains(".mp4") && !fileName.contains("-ios.mp4")){
-                videoJson = new JSONObject();
-                videoJson.put("id", fileName.substring(
-                    0, fileName.lastIndexOf(".")).replace("videos/", ""));
-
-                //如果ts文件存在,就计算ts大小
-                if(new File(path + File.separator + "results" +File.separator+ fileName.replace(".mp4", ".ts")).exists()){
-                    videoSize = new File(path + File.separator + "results" +File.separator+ fileName.replace(".mp4", ".ts")).length();
-                    videoJson.put("tsSize", videoSize);
-                }
-                if(videoMap.containsKey(videoJson.get("id"))){
-                    videoJson.put("value", videoMap.get(videoJson.get("id")));
-                }
-                if(videoMap.containsKey(videoJson.get("id") + "_fov")){
-                    videoJson.put("blend_fov", videoMap.get(videoJson.get("id") + "_fov"));
-                }else {
-                    videoJson.put("blend_fov", 7);
-                }
-                jsonArray.add(videoJson);
-            }
-        }
-
-        videosJson.put("data", jsonArray);
-        if(Objects.nonNull(videoVersion) && videoVersion >= 4){
-            videosJson.put("version", 3);
-            if(StorageType.OSS.code().equals(ossType)){
-                videosJson.put("upPath", prefixAli + "data/data" + projectNum + "/Up.xml");
-            }
-            if(StorageType.AWS.code().equals(ossType)){
-                videosJson.put("upPath", ConstantUrl.PREFIX_AWS + "data/data" + projectNum + "/Up.xml");
-            }
-            if(cameraType == 13){
-                //转台相机
-                videosJson.put("upPath", videosJson.getString("upPath").replace(".xml", ".txt"));
-            }
-        }else {
-            videosJson.put("version", 1);
-            if("oss".equals(ossType)){
-                videosJson.put("upPath", prefixAli + "data/data" + projectNum + "/Up2.xml");
-            }
-            if("aws".equals(ossType)){
-                videosJson.put("upPath", ConstantUrl.PREFIX_AWS + "data/data" + projectNum + "/Up2.xml");
-            }
-
-            if(cameraType == 13){
-                //转台相机
-                videosJson.put("upPath", videosJson.getString("upPath").replace(".xml", ".txt"));
-            }
-        }
-
-        if(cameraType == 5 || cameraType == 6){
-            videosJson.put("version", 1);
-            if("oss".equals(ossType)){
-                videosJson.put("upPath", prefixAli + "data/data" + projectNum + "/stitch_params.txt");
-            }
-            if("aws".equals(ossType)){
-                videosJson.put("upPath", ConstantUrl.PREFIX_AWS + "data/data" + projectNum + "/stitch_params.txt");
-            }
-        }
-
-        return videosJson;
-    }
-
-    @Override
-    public String writeSceneJson(String num, JSONObject videosJson, SceneEditInfo sceneEditInfo,
-        SceneEditControls sceneEditControls, ScenePlus scenePlus, ScenePlusExt scenePlusExt, boolean arrearCap)  throws Exception{
-        String sceneJsonPath = String.format(ConstantFilePath.SCENE_PATH_FORMAT, num);
-        String strsceneInfos = FileUtils.readFile(sceneJsonPath);
-        SceneJsonBean sceneJson = null;
-        if(strsceneInfos!=null){
-            sceneJson = JSON.parseObject(strsceneInfos, SceneJsonBean.class);
-        }else{
-            sceneJson = BeanUtil.copyProperties(sceneEditInfo, SceneJsonBean.class);
-            SceneEditControlsVO sceneEditControlsVO = BeanUtil.copyProperties(sceneEditControls, SceneEditControlsVO.class);
-            sceneJson.setControls(sceneEditControlsVO);
-            sceneJson.setNum(num);
-            sceneJson.setCreateTime(scenePlus.getCreateTime());
-            sceneJson.setSceneResolution(scenePlusExt.getSceneResolution());
-            sceneJson.setSceneFrom(scenePlusExt.getSceneFrom());
-            sceneJson.setVideos(videosJson);
-        }
-        sceneJson.setVideos(videosJson);
-
-        if(arrearCap) {
-            sceneJson.setPayStatus(PayStatus.NO_CAPACITY.code());
-        }
-
-        String sceneJsonStr = JSON.toJSONString(sceneJson);
-        FileUtils.writeFile(sceneJsonPath, sceneJsonStr);
-        return sceneJsonStr;
-    }
+//    @Override
+//    public JSONObject getVideosJson(String path, Integer videoVersion, String projectNum, int cameraType) throws Exception {
+//        //读取videos_hdr_param.json, 保存点位视频的value
+//        Map<String, Object> videoMap = new HashMap<>();
+//        String videosHdr = FileUtils.readFile(path + File.separator + "results/videos/videos_hdr_param.json");
+//        JSONArray videoArray = null;
+//        if(StringUtils.isNotEmpty(videosHdr)){
+//            videoArray = JSONObject.parseObject(videosHdr).getJSONArray("hdr_param");
+//        }
+//        if(videoArray != null){
+//            for(int i = 0, len = videoArray.size(); i < len; i++) {
+//                videoMap.put(videoArray.getJSONObject(i).getString("name"), videoArray.getJSONObject(i).getString("value"));
+//                if(videoArray.getJSONObject(i).containsKey("fov")){
+//                    videoMap.put(videoArray.getJSONObject(i).getString("name") + "_fov", videoArray.getJSONObject(i).getString("fov"));
+//                }
+//            }
+//        }
+//
+//        //获取upload中的video视频名称
+//        String uploadData = FileUtils.readFile(path + File.separator + "results" +File.separator+"upload.json");
+//        JSONObject uploadJson = null;
+//        JSONArray array = null;
+//        if(uploadData!=null) {
+//            uploadJson = JSONObject.parseObject(uploadData);
+//            array = uploadJson.getJSONArray("upload");
+//        }
+//        JSONObject fileJson = null;
+//        String fileName = "";
+//
+//        //计算ts文件的大小,并拼接成json格式
+//        JSONArray jsonArray = new JSONArray();
+//        JSONObject videoJson = null;
+//        JSONObject videosJson = new JSONObject();
+//        long videoSize = 0L;
+//        for(int i = 0, len = array.size(); i < len; i++) {
+//            fileJson = array.getJSONObject(i);
+//            fileName = fileJson.getString("file");
+//            if(fileJson.getIntValue("clazz") == 11 && fileName.contains(".mp4") && !fileName.contains("-ios.mp4")){
+//                videoJson = new JSONObject();
+//                videoJson.put("id", fileName.substring(
+//                    0, fileName.lastIndexOf(".")).replace("videos/", ""));
+//
+//                //如果ts文件存在,就计算ts大小
+//                if(new File(path + File.separator + "results" +File.separator+ fileName.replace(".mp4", ".ts")).exists()){
+//                    videoSize = new File(path + File.separator + "results" +File.separator+ fileName.replace(".mp4", ".ts")).length();
+//                    videoJson.put("tsSize", videoSize);
+//                }
+//                if(videoMap.containsKey(videoJson.get("id"))){
+//                    videoJson.put("value", videoMap.get(videoJson.get("id")));
+//                }
+//                if(videoMap.containsKey(videoJson.get("id") + "_fov")){
+//                    videoJson.put("blend_fov", videoMap.get(videoJson.get("id") + "_fov"));
+//                }else {
+//                    videoJson.put("blend_fov", 7);
+//                }
+//                jsonArray.add(videoJson);
+//            }
+//        }
+//
+//        videosJson.put("data", jsonArray);
+//        if(Objects.nonNull(videoVersion) && videoVersion >= 4){
+//            videosJson.put("version", 3);
+//            if(StorageType.OSS.code().equals(ossType)){
+//                videosJson.put("upPath", prefixAli + "data/data" + projectNum + "/Up.xml");
+//            }
+//            if(StorageType.AWS.code().equals(ossType)){
+//                videosJson.put("upPath", ConstantUrl.PREFIX_AWS + "data/data" + projectNum + "/Up.xml");
+//            }
+//            if(cameraType == 13){
+//                //转台相机
+//                videosJson.put("upPath", videosJson.getString("upPath").replace(".xml", ".txt"));
+//            }
+//        }else {
+//            videosJson.put("version", 1);
+//            if("oss".equals(ossType)){
+//                videosJson.put("upPath", prefixAli + "data/data" + projectNum + "/Up2.xml");
+//            }
+//            if("aws".equals(ossType)){
+//                videosJson.put("upPath", ConstantUrl.PREFIX_AWS + "data/data" + projectNum + "/Up2.xml");
+//            }
+//
+//            if(cameraType == 13){
+//                //转台相机
+//                videosJson.put("upPath", videosJson.getString("upPath").replace(".xml", ".txt"));
+//            }
+//        }
+//
+//        if(cameraType == 5 || cameraType == 6){
+//            videosJson.put("version", 1);
+//            if("oss".equals(ossType)){
+//                videosJson.put("upPath", prefixAli + "data/data" + projectNum + "/stitch_params.txt");
+//            }
+//            if("aws".equals(ossType)){
+//                videosJson.put("upPath", ConstantUrl.PREFIX_AWS + "data/data" + projectNum + "/stitch_params.txt");
+//            }
+//        }
+//
+//        return videosJson;
+//    }
+
+//    @Override
+//    public String writeSceneJson(String num, JSONObject videosJson, SceneEditInfo sceneEditInfo,
+//        SceneEditControls sceneEditControls, ScenePlus scenePlus, ScenePlusExt scenePlusExt, boolean arrearCap)  throws Exception{
+//        String sceneJsonPath = String.format(ConstantFilePath.SCENE_PATH_FORMAT, num);
+//        String strsceneInfos = FileUtils.readFile(sceneJsonPath);
+//        SceneJsonBean sceneJson = null;
+//        if(strsceneInfos!=null){
+//            sceneJson = JSON.parseObject(strsceneInfos, SceneJsonBean.class);
+//        }else{
+//            sceneJson = BeanUtil.copyProperties(sceneEditInfo, SceneJsonBean.class);
+//            SceneEditControlsVO sceneEditControlsVO = BeanUtil.copyProperties(sceneEditControls, SceneEditControlsVO.class);
+//            sceneJson.setControls(sceneEditControlsVO);
+//            sceneJson.setNum(num);
+//            sceneJson.setCreateTime(scenePlus.getCreateTime());
+//            sceneJson.setSceneResolution(scenePlusExt.getSceneResolution());
+//            sceneJson.setSceneFrom(scenePlusExt.getSceneFrom());
+//            sceneJson.setVideos(videosJson);
+//        }
+//        sceneJson.setVideos(videosJson);
+//
+//        if(arrearCap) {
+//            sceneJson.setPayStatus(PayStatus.NO_CAPACITY.code());
+//        }
+//
+//        String sceneJsonStr = JSON.toJSONString(sceneJson);
+//        FileUtils.writeFile(sceneJsonPath, sceneJsonStr);
+//        return sceneJsonStr;
+//    }
 }

+ 17 - 13
4dkankan-center-scene/src/main/resources/bootstrap-dev.yml

@@ -38,6 +38,10 @@ spring:
             group: DEFAULT_GROUP
             refresh: true
 
+          - data-id: common-rabbitmq-config.yaml
+            group: DEFAULT_GROUP
+            refresh: true
+
           - data-id: other-config.yaml
             group: DEFAULT_GROUP
             refresh: true
@@ -73,19 +77,19 @@ spring:
             groupId: SENTINEL_GROUP
             namespace: 4dkankan-dev
             rule-type: degrade
-  rabbitmq:
-    host: 120.25.146.52
-    port: 5672
-    username: guest
-    password: 4dagecui2019$
-    virtual-host: /
-    listener:
-      direct:
-        acknowledge-mode: manual
-      simple:
-        retry:
-          max-attempts: 3
-          enabled: true
+#  rabbitmq:
+#    host: 120.25.146.52
+#    port: 5672
+#    username: guest
+#    password: 4dagecui2019$
+#    virtual-host: /
+#    listener:
+#      simple:
+#        acknowledge-mode: manual
+#        retry:
+#          max-attempts: 3
+#          enabled: true
+#    publisher-confirm-type: correlated
 #      log:
 #        dir: ./logs # 默认值${home}/logs/csp/
 #        switch-pid: true # 日志带上线程id

+ 4 - 0
4dkankan-center-scene/src/main/resources/bootstrap-pro.yml

@@ -38,6 +38,10 @@ spring:
             group: DEFAULT_GROUP
             refresh: true
 
+          - data-id: common-rabbitmq-config.yaml
+            group: DEFAULT_GROUP
+            refresh: true
+
           - data-id: other-config.yaml
             group: DEFAULT_GROUP
             refresh: true

+ 4 - 0
4dkankan-center-scene/src/main/resources/bootstrap-test.yml

@@ -38,6 +38,10 @@ spring:
             group: DEFAULT_GROUP
             refresh: true
 
+          - data-id: common-rabbitmq-config.yaml
+            group: DEFAULT_GROUP
+            refresh: true
+
           - data-id: other-config.yaml
             group: DEFAULT_GROUP
             refresh: true