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.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 ThreadBussService { @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(),sceneCode); }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(),sceneCode); } } } } 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,String sceneCode) { if(downloadUrl.contains("?")){ downloadUrl = downloadUrl.split("[?]")[0]; } ShellUtil.yunDownload(downloadUrl.replace(fyunConfig.getFyunHost(), ""),path +"/mesh/"+sceneCode +".zip"); } }