ThreadBussService.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package com.fdkankan.manage.task;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.fdkankan.manage.common.RedisKeyUtil;
  5. import com.fdkankan.manage.common.ResultCode;
  6. import com.fdkankan.manage.common.ShellUtil;
  7. import com.fdkankan.manage.config.FyunConfig;
  8. import com.fdkankan.manage.exception.BusinessException;
  9. import com.fdkankan.manage.httpClient.param.WorkOfflineDTO;
  10. import com.fdkankan.manage.service.IDownService;
  11. import com.fdkankan.manage.vo.response.DownVo;
  12. import com.fdkankan.manage.vo.response.DownloadProcessVo;
  13. import com.fdkankan.rabbitmq.util.RabbitMqProducer;
  14. import com.fdkankan.redis.util.RedisUtil;
  15. import lombok.extern.slf4j.Slf4j;
  16. import org.apache.commons.lang3.StringUtils;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.context.annotation.Lazy;
  19. import org.springframework.scheduling.annotation.Async;
  20. import org.springframework.stereotype.Service;
  21. @Service
  22. @Slf4j
  23. public class ThreadBussService {
  24. @Autowired
  25. @Lazy
  26. RabbitMqProducer rabbitMqProducer;
  27. @Autowired
  28. @Lazy
  29. IDownService downService;
  30. @Autowired
  31. @Lazy
  32. FyunConfig fyunConfig;
  33. @Autowired
  34. @Lazy
  35. RedisUtil redisUtil;
  36. @Async
  37. public void overallDownScene(WorkOfflineDTO dto, String redisKey){
  38. try {
  39. if(dto.getSceneCodes() != null && !dto.getSceneCodes().isEmpty()){ //下载场景mesh离线包
  40. for (String sceneCode : dto.getSceneCodes()) {
  41. log.info("下载mesh场景:{}",sceneCode);
  42. DownVo downVo = downService.checkDownLoad(sceneCode, 1);
  43. if(downVo.getDownloadStatus() == 3 && StringUtils.isNotBlank(downVo.getDownloadUrl())){
  44. downScene(downVo.getDownloadUrl(),dto.getPath(),sceneCode);
  45. }else {
  46. DownVo down = downService.down(sceneCode, 1);
  47. if(down.getDownloadStatus() == 1){
  48. DownloadProcessVo downloadProcessVo = downService.downloadProcess(sceneCode, 1);
  49. if(downloadProcessVo.getStatus() == 1003){
  50. log.info("下载场景失败:{}",sceneCode);
  51. throw new BusinessException(ResultCode.DOWN_SCENE_ERROR);
  52. }
  53. while (downloadProcessVo.getStatus() != 1002 ){
  54. downloadProcessVo = downService.downloadProcess(sceneCode, 1);
  55. Thread.sleep(2000L);
  56. }
  57. downScene(downloadProcessVo.getUrl(),dto.getPath(),sceneCode);
  58. }
  59. }
  60. }
  61. }
  62. dto.setProgress(50);
  63. redisUtil.set(redisKey, JSONObject.toJSONString(dto), RedisKeyUtil.overallDownOfflineProgressKeyTime);
  64. rabbitMqProducer.sendByWorkQueue("qjkk-work-offline", BeanUtil.beanToMap(dto));
  65. }catch (Exception e){
  66. log.info("执行失败:{}",e);
  67. }
  68. }
  69. private void downScene(String downloadUrl, String path,String sceneCode) {
  70. if(downloadUrl.contains("?")){
  71. downloadUrl = downloadUrl.split("[?]")[0];
  72. }
  73. ShellUtil.yunDownload(downloadUrl.replace(fyunConfig.getFyunHost(), ""),path +"/mesh/"+sceneCode +".zip");
  74. }
  75. }