lyhzzz пре 3 месеци
родитељ
комит
45e29acdfd

+ 2 - 0
src/main/java/com/fdkankan/manage/ManageApplication.java

@@ -8,6 +8,7 @@ import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
 import org.springframework.context.annotation.ComponentScan;
+import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.transaction.annotation.EnableTransactionManagement;
 
@@ -15,6 +16,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
 @EnableTransactionManagement//开启事务
 @EnableDiscoveryClient
 @EnableScheduling
+@EnableAsync
 @ComponentScan(basePackages = {"com.fdkankan.*"})
 @MapperScan("com.fdkankan.**.mapper")
 public class ManageApplication implements CommandLineRunner {

+ 1 - 2
src/main/java/com/fdkankan/manage/controller/OverallController.java

@@ -180,8 +180,7 @@ public class OverallController {
 
     @GetMapping("/downOfflinePage/{workId}")
     public ResultData downOfflinePage(@PathVariable String workId){
-        overallService.downOfflinePage(workId);
-        return ResultData.ok();
+        return ResultData.ok(overallService.downOfflinePage(workId));
     }
 
 

+ 6 - 42
src/main/java/com/fdkankan/manage/httpClient/service/OverallService.java

@@ -16,6 +16,7 @@ import com.fdkankan.manage.httpClient.param.WorkOfflineDTO;
 import com.fdkankan.manage.httpClient.vo.OverallParam;
 import com.fdkankan.manage.httpClient.vo.OverallVo;
 import com.fdkankan.manage.service.IDownService;
+import com.fdkankan.manage.task.ThreadService;
 import com.fdkankan.manage.vo.response.DownVo;
 import com.fdkankan.manage.vo.response.DownloadProcessVo;
 import com.fdkankan.rabbitmq.util.RabbitMqProducer;
@@ -31,20 +32,18 @@ import org.springframework.stereotype.Service;
 @Slf4j
 public class OverallService {
     @Autowired
-    @Lazy
     OverallClient overallClient;
     @Autowired
-    @Lazy
     RabbitMqProducer rabbitMqProducer;
     @Autowired
-    @Lazy
     IDownService downService;
     @Autowired
-    @Lazy
     FyunConfig fyunConfig;
     @Autowired
-    @Lazy
     RedisUtil redisUtil;
+    @Autowired
+    @Lazy
+    ThreadService threadService;
 
     private static String appId ="BDA385EC848C1A425F746869011C8D23";
     private static String key ="appId";
@@ -75,7 +74,7 @@ public class OverallService {
             String jsonString = JSONObject.toJSONString(data);
             WorkOfflineDTO dto = JSONObject.parseObject(jsonString,WorkOfflineDTO.class);
             redisUtil.set(redisKey,jsonString,RedisKeyUtil.overallDownOfflineProgressKeyTime);
-            run(dto,redisKey);
+            threadService.overallDownScene(dto,redisKey);
             return dto;
         }catch (Exception e){
             log.info("全景看看访问失败:{}",e);
@@ -84,42 +83,7 @@ public class OverallService {
 
     }
 
-    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);
-                    DownVo downVo = downService.checkDownLoad(sceneCode, 1);
-                    if(downVo.getDownloadStatus() == 3 && StringUtils.isNotBlank(downVo.getDownloadUrl())){
-                        downScene(downVo.getDownloadUrl(),dto.getPath());
-                    }else {
-                        DownVo down = downService.down(sceneCode, 1);
-                        if(down.getDownloadStatus() == 1){
-                            DownloadProcessVo downloadProcessVo = downService.downloadProcess(sceneCode, 1);
-                            if(downloadProcessVo.getStatus() == 1003){
-                                log.info("下载场景失败:{}",sceneCode);
-                                throw new BusinessException(ResultCode.DOWN_SCENE_ERROR);
-                            }
-                            while (downloadProcessVo.getStatus() != 1002 ){
-                                downloadProcessVo =  downService.downloadProcess(sceneCode, 1);
-                                Thread.sleep(2000L);
-                            }
-                            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);
-        }
 
-    }
+
 }

+ 79 - 0
src/main/java/com/fdkankan/manage/task/ThreadService.java

@@ -0,0 +1,79 @@
+package com.fdkankan.manage.task;
+
+import cn.hutool.core.bean.BeanUtil;
+import com.alibaba.fastjson.JSONObject;
+import com.fdkankan.manage.common.RedisKeyUtil;
+import com.fdkankan.manage.common.ResultCode;
+import com.fdkankan.manage.common.ShellUtil;
+import com.fdkankan.manage.config.FyunConfig;
+import com.fdkankan.manage.exception.BusinessException;
+import com.fdkankan.manage.httpClient.client.OverallClient;
+import com.fdkankan.manage.httpClient.param.WorkOfflineDTO;
+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.context.annotation.Lazy;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Service;
+
+@Service
+@Slf4j
+public class ThreadService {
+
+    @Autowired
+    @Lazy
+    RabbitMqProducer rabbitMqProducer;
+    @Autowired
+    @Lazy
+    IDownService downService;
+    @Autowired
+    @Lazy
+    FyunConfig fyunConfig;
+    @Autowired
+    @Lazy
+    RedisUtil redisUtil;
+
+    @Async
+    public void overallDownScene(WorkOfflineDTO dto, String redisKey){
+        try {
+            if(dto.getSceneCodes() != null && !dto.getSceneCodes().isEmpty()){  //下载场景mesh离线包
+                for (String sceneCode : dto.getSceneCodes()) {
+                    log.info("下载mesh场景:{}",sceneCode);
+                    DownVo downVo = downService.checkDownLoad(sceneCode, 1);
+                    if(downVo.getDownloadStatus() == 3 && StringUtils.isNotBlank(downVo.getDownloadUrl())){
+                        downScene(downVo.getDownloadUrl(),dto.getPath());
+                    }else {
+                        DownVo down = downService.down(sceneCode, 1);
+                        if(down.getDownloadStatus() == 1){
+                            DownloadProcessVo downloadProcessVo = downService.downloadProcess(sceneCode, 1);
+                            if(downloadProcessVo.getStatus() == 1003){
+                                log.info("下载场景失败:{}",sceneCode);
+                                throw new BusinessException(ResultCode.DOWN_SCENE_ERROR);
+                            }
+                            while (downloadProcessVo.getStatus() != 1002 ){
+                                downloadProcessVo =  downService.downloadProcess(sceneCode, 1);
+                                Thread.sleep(2000L);
+                            }
+                            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);
+        }
+
+    }
+
+    private void downScene(String downloadUrl, String path) {
+        ShellUtil.yunDownload(downloadUrl.replace(fyunConfig.getFyunHost(), ""),path +"/mesh");
+    }
+}