DownSceneServiceImpl.java 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package com.fdkankan.openApi.service.www.impl;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.baomidou.dynamic.datasource.annotation.DS;
  4. import com.fdkankan.common.constant.ErrorCode;
  5. import com.fdkankan.common.exception.BusinessException;
  6. import com.fdkankan.openApi.constant.JmgaConstant;
  7. import com.fdkankan.openApi.dto.www.DownSceneDto;
  8. import com.fdkankan.openApi.httpclient.client.FdKKClient;
  9. import com.fdkankan.openApi.httpclient.client.JmgaClient;
  10. import com.fdkankan.openApi.service.www.IDownSceneService;
  11. import com.fdkankan.web.response.ResultData;
  12. import org.apache.commons.lang3.StringUtils;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.stereotype.Service;
  15. import java.util.HashMap;
  16. @Service
  17. public class DownSceneServiceImpl implements IDownSceneService {
  18. @Autowired
  19. JmgaClient jmgaClient;
  20. @Override
  21. public DownSceneDto getSceneOfflinePage(String num) {
  22. if(StringUtils.isBlank(num)){
  23. throw new BusinessException(ErrorCode.PARAM_ERROR);
  24. }
  25. ResultData checkResult = jmgaClient.get(JmgaConstant.API_GET_CHECK_DOWNLOAD + "?num=" + num);
  26. if(checkResult.getCode() != 0 || checkResult.getData() == null){
  27. throw new BusinessException(checkResult.getCode(),checkResult.getMessage());
  28. }
  29. JSONObject checkObject = JSONObject.parseObject(JSONObject.toJSONString(checkResult.getData()));
  30. Integer checkStatus = checkObject.getInteger("downloadStatus");
  31. String checkUrl = checkObject.getString("downloadUrl");
  32. if(StringUtils.isNotBlank(checkUrl)){
  33. return new DownSceneDto(checkUrl);
  34. }
  35. if(checkStatus !=1){
  36. ResultData downResult = jmgaClient.get(JmgaConstant.API_GET_DOWN_SCENE + "?num=" + num);
  37. if(downResult.getCode() != 0 || downResult.getData() == null){
  38. throw new BusinessException(downResult.getCode(),downResult.getMessage());
  39. }
  40. }
  41. ResultData processResult = jmgaClient.get(JmgaConstant.API_GET_DOWNLOAD_PROCESS + "?num=" + num);
  42. if(processResult.getCode() != 0 || processResult.getData() == null){
  43. throw new BusinessException(processResult.getCode(),processResult.getMessage());
  44. }
  45. JSONObject processObj = JSONObject.parseObject(JSONObject.toJSONString(processResult.getData()));
  46. String processUrl = processObj.getString("url");
  47. Integer percent = processObj.getInteger("percent");
  48. return new DownSceneDto(processUrl,percent);
  49. }
  50. }