lyhzzz hai 3 meses
pai
achega
d53520e689

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

@@ -18,6 +18,7 @@ public class RedisKeyUtil {
 
     public static final String SCENE_VERSION = "scenejson:num:%s";
 
-
+    public static final String overallDownOfflineProgressKey= "manage:overall:down:offline:%s";
+    public static final Long overallDownOfflineProgressKeyTime= 60 * 60 * 24L;
 
 }

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

@@ -127,6 +127,7 @@ public enum ResultCode  {
 
     OVERALL_VIEW_ERROR(50098, "全景系统访问失败"),
     DOWN_SCENE_ERROR(50099, "下载场景失败"),
+    DOWN_OVERALL_ERROR(50100, "获取下载进度失败"),
 
     ;
 

+ 9 - 4
src/main/java/com/fdkankan/manage/controller/OverallController.java

@@ -16,10 +16,7 @@ import com.fdkankan.manage.util.SceneStatusUtil;
 import com.fdkankan.manage.vo.response.SceneVo;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 import java.util.ArrayList;
@@ -180,5 +177,13 @@ public class OverallController {
         return ResultData.ok(vo.getData());
     }
 
+
+    @GetMapping("/downOfflinePage/{workId}")
+    public ResultData downOfflinePage(@PathVariable String workId){
+        overallService.downOfflinePage(workId);
+        return ResultData.ok();
+    }
+
+
 }
 

+ 35 - 15
src/main/java/com/fdkankan/manage/httpClient/service/OverallService.java

@@ -1,9 +1,11 @@
 package com.fdkankan.manage.httpClient.service;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.thread.ThreadUtil;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.fdkankan.common.util.JwtUtil;
+import com.fdkankan.manage.common.RedisKeyUtil;
 import com.fdkankan.manage.common.Result;
 import com.fdkankan.manage.common.ResultCode;
 import com.fdkankan.manage.common.ShellUtil;
@@ -17,9 +19,11 @@ import com.fdkankan.manage.service.IDownService;
 import com.fdkankan.manage.vo.response.DownVo;
 import com.fdkankan.manage.vo.response.DownloadProcessVo;
 import com.fdkankan.rabbitmq.util.RabbitMqProducer;
+import com.fdkankan.redis.util.RedisUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
 @Service
@@ -33,6 +37,8 @@ public class OverallService {
     IDownService downService;
     @Autowired
     FyunConfig fyunConfig;
+    @Autowired
+    RedisUtil redisUtil;
 
     private static String appId ="BDA385EC848C1A425F746869011C8D23";
     private static String key ="appId";
@@ -45,17 +51,40 @@ public class OverallService {
     }
 
 
-    public void getSceneListByWorkId(String workId){
+
+
+    public synchronized Object downOfflinePage(String workId){
         try {
+            String redisKey = String.format(RedisKeyUtil.overallDownOfflineProgressKey,workId);
+
+            if(redisUtil.hasKey(redisKey)){
+                return redisUtil.get(redisKey);
+            }
 
             OverallVo offlineDetail = overallClient.getOfflineDetail(new WorkOfflineDTO(workId),appId,key);
             if(offlineDetail == null || offlineDetail.getCode() !=0){
                 throw new BusinessException(ResultCode.OVERALL_VIEW_ERROR);
             }
-
             Object data = offlineDetail.getData();
+            String jsonString = JSONObject.toJSONString(data);
+            WorkOfflineDTO dto = JSONObject.parseObject(jsonString,WorkOfflineDTO.class);
+            redisUtil.set(redisKey,jsonString,RedisKeyUtil.overallDownOfflineProgressKeyTime);
+            run(dto,redisKey);
+            return dto;
+        }catch (Exception e){
+            log.info("全景看看访问失败:{}",e);
+            throw new BusinessException(ResultCode.OVERALL_VIEW_ERROR);
+        }
+
+    }
 
-            WorkOfflineDTO dto = JSONObject.parseObject(JSONObject.toJSONString(data),WorkOfflineDTO.class);
+    private void downScene(String downloadUrl, String path) {
+        ShellUtil.yunDownload(downloadUrl.replace(fyunConfig.getFyunHost(), ""),path +"/mesh");
+    }
+
+    @Async
+    public void run(WorkOfflineDTO dto,String redisKey){
+        try {
             if(dto.getSceneCodes() != null && !dto.getSceneCodes().isEmpty()){  //下载场景mesh离线包
                 for (String sceneCode : dto.getSceneCodes()) {
                     log.info("下载mesh场景:{}",sceneCode);
@@ -76,24 +105,15 @@ public class OverallService {
                             }
                             downScene(downloadProcessVo.getUrl(),dto.getPath());
                         }
-
                     }
                 }
-
             }
-
+            dto.setProgress(50);
+            redisUtil.set(redisKey,JSONObject.toJSONString(dto),RedisKeyUtil.overallDownOfflineProgressKeyTime);
             rabbitMqProducer.sendByWorkQueue("qjkk-work-offline", BeanUtil.beanToMap(dto));
-
         }catch (Exception e){
-            log.info("全景看看访问失败:{}",e);
-            throw new BusinessException(ResultCode.OVERALL_VIEW_ERROR);
+            log.info("执行失败:{}",e);
         }
 
     }
-
-    private void downScene(String downloadUrl, String path) {
-        ShellUtil.yunDownload(downloadUrl.replace(fyunConfig.getFyunHost(), ""),path +"/mesh");
-    }
-
-
 }

+ 13 - 0
src/main/java/com/fdkankan/manage/mq/consumer/OverallConsumer.java

@@ -1,9 +1,12 @@
 package com.fdkankan.manage.mq.consumer;
 
 import com.alibaba.fastjson.JSONObject;
+import com.fdkankan.manage.common.RedisKeyUtil;
+import com.fdkankan.manage.httpClient.param.WorkOfflineDTO;
 import com.fdkankan.manage.mq.param.LaserSceneTitleVo;
 import com.fdkankan.manage.service.IScenePlusService;
 import com.fdkankan.manage.service.ISceneProService;
+import com.fdkankan.redis.util.RedisUtil;
 import com.rabbitmq.client.Channel;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
@@ -23,6 +26,10 @@ import java.nio.charset.StandardCharsets;
 public class OverallConsumer {
 
 
+    @Autowired
+    RedisUtil redisUtil;
+
+
     @RabbitListener(
             queuesToDeclare = @Queue("${queue.qjkk.offline-done:qjkk-work-offline-done}")
     )
@@ -34,6 +41,12 @@ public class OverallConsumer {
 
             channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
 
+            WorkOfflineDTO vo = JSONObject.parseObject(msg, WorkOfflineDTO.class);
+
+            String redisKey = String.format(RedisKeyUtil.overallDownOfflineProgressKey,vo.getWorkId());
+
+            vo.setProgress(100);
+            redisUtil.set(redisKey,JSONObject.toJSONString(vo), RedisKeyUtil.overallDownOfflineProgressKeyTime);
 
         }catch (Exception e){
             log.info("qjkk-work-offline-done-----消费失败",e);