package com.fdkankan.openApi.service.www.impl; import com.alibaba.fastjson.JSONObject; import com.baomidou.dynamic.datasource.annotation.DS; import com.fdkankan.common.constant.ErrorCode; import com.fdkankan.common.exception.BusinessException; import com.fdkankan.openApi.constant.JmgaConstant; import com.fdkankan.openApi.dto.www.DownSceneDto; import com.fdkankan.openApi.httpclient.client.FdKKClient; import com.fdkankan.openApi.httpclient.client.JmgaClient; import com.fdkankan.openApi.service.www.IDownSceneService; import com.fdkankan.web.response.ResultData; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.HashMap; @Service public class DownSceneServiceImpl implements IDownSceneService { @Autowired JmgaClient jmgaClient; @Override public DownSceneDto getSceneOfflinePage(String num) { if(StringUtils.isBlank(num)){ throw new BusinessException(ErrorCode.PARAM_ERROR); } ResultData checkResult = jmgaClient.get(JmgaConstant.API_GET_CHECK_DOWNLOAD + "?num=" + num); if(checkResult.getCode() != 0 || checkResult.getData() == null){ throw new BusinessException(checkResult.getCode(),checkResult.getMessage()); } JSONObject checkObject = JSONObject.parseObject(JSONObject.toJSONString(checkResult.getData())); Integer checkStatus = checkObject.getInteger("downloadStatus"); String checkUrl = checkObject.getString("downloadUrl"); if(StringUtils.isNotBlank(checkUrl)){ return new DownSceneDto(checkUrl); } if(checkStatus !=1){ ResultData downResult = jmgaClient.get(JmgaConstant.API_GET_DOWN_SCENE + "?num=" + num); if(downResult.getCode() != 0 || downResult.getData() == null){ throw new BusinessException(downResult.getCode(),downResult.getMessage()); } } ResultData processResult = jmgaClient.get(JmgaConstant.API_GET_DOWNLOAD_PROCESS + "?num=" + num); if(processResult.getCode() != 0 || processResult.getData() == null){ throw new BusinessException(processResult.getCode(),processResult.getMessage()); } JSONObject processObj = JSONObject.parseObject(JSONObject.toJSONString(processResult.getData())); String processUrl = processObj.getString("url"); Integer percent = processObj.getInteger("percent"); return new DownSceneDto(processUrl,percent); } }