271de0244850409f6100780f735e8e77905871c0.svn-base 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. package com.chinacreator.videoalliance.order.service;
  2. import com.chinacreator.videoalliance.order.bean.SPInfo;
  3. import com.chinacreator.videoalliance.order.dao.SPDao;
  4. import org.apache.commons.lang.StringUtils;
  5. import org.apache.log4j.Logger;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.stereotype.Component;
  8. import com.chinacreator.common.exception.BusinessException;
  9. import com.chinacreator.common.util.URLUtil;
  10. import com.chinacreator.videoalliance.common.dao.DictionaryDao;
  11. import net.sf.json.JSONObject;
  12. @Component
  13. public class ShareOrderService {
  14. private static Logger logger = Logger.getLogger(ShareOrderService.class);
  15. @Autowired
  16. private DictionaryDao dictionaryDao;
  17. @Autowired
  18. private SPDao spDao;
  19. //private static final String orderUrl = "http://10.199.99.158:8091/shareorder/order";
  20. //private static final String cancelUrl = "http://10.199.99.158:8091/shareorder/cancel";
  21. /**
  22. * 订购
  23. * @param userid
  24. * @param cpid
  25. * @param spid
  26. * @throws BusinessException
  27. */
  28. public void order(String userid,String cpid,String spid) throws BusinessException{
  29. //String result ="";
  30. SPInfo spInfo = null;
  31. try {
  32. spInfo = getSPInfo(spid);
  33. } catch (Exception e) {
  34. }
  35. if(spInfo == null){
  36. throw new BusinessException("7003", "产品配置错误");
  37. }
  38. String result ="";
  39. if("0".equals(spInfo.getHaslocal())){ //不调CAP接口
  40. result = "0";
  41. return ;
  42. }
  43. try{
  44. String url = dictionaryDao.getValue("shareOrderUrl");
  45. result = URLUtil.get(url+"?cpid="+cpid+"&spid="+spid+"&userid="+userid,60000); //2022022由15秒改为30秒,因为有重试机制,所以调整到了60秒
  46. if(result.indexOf("不可以重复订购")!= -1){ //包含不可以重复订购即落订购关系
  47. result = "{\"resultCode\":0,\"resultInfo\":\"成功!\",\"data\":null}";
  48. }
  49. }catch (Exception e) {
  50. throw new BusinessException("9170", "调用能力共享平台订购接口异常");
  51. }
  52. JSONObject obj = JSONObject.fromObject(result);
  53. if(!obj.getString("resultCode").equals("0")){
  54. throw new BusinessException(obj.getString("resultCode"), obj.getString("resultInfo"));
  55. }
  56. }
  57. /**
  58. * 退订
  59. * @param userid
  60. * @param cpid
  61. * @param spid
  62. * @throws BusinessException
  63. */
  64. public void cancel(String userid,String cpid,String spid) throws BusinessException{
  65. //String result ="";
  66. SPInfo spInfo = null;
  67. try {
  68. spInfo = getSPInfo(spid);
  69. } catch (Exception e) {
  70. }
  71. if(spInfo == null){
  72. throw new BusinessException("7003", "产品配置错误");
  73. }
  74. String result ="";
  75. if("0".equals(spInfo.getHaslocal())){ //不调CAP接口
  76. result = "0";
  77. return ;
  78. }
  79. try{
  80. String url = dictionaryDao.getValue("shareCancelUrl");
  81. result = URLUtil.get(url+"?cpid="+cpid+"&spid="+spid+"&userid="+userid,30000);
  82. }catch (Exception e) {
  83. throw new BusinessException("9170", "调用能力共享平台退订接口异常");
  84. }
  85. JSONObject obj = JSONObject.fromObject(result);
  86. if(!obj.getString("resultCode").equals("0")){
  87. throw new BusinessException(obj.getString("resultCode"), obj.getString("resultInfo"));
  88. }
  89. }
  90. /**
  91. * 鉴权平台退订
  92. * @param userid
  93. * @param cpid
  94. * @param spid
  95. * @throws BusinessException
  96. */
  97. public void cancel(String userid,String cpid,String spid,String channel) throws BusinessException{
  98. //String result ="";
  99. SPInfo spInfo = null;
  100. try {
  101. spInfo = getSPInfo(spid);
  102. } catch (Exception e) {
  103. }
  104. if(spInfo == null){
  105. throw new BusinessException("7003", "产品配置错误");
  106. }
  107. String result ="";
  108. if("0".equals(spInfo.getHaslocal())){ //不调CAP接口
  109. result = "0";
  110. return ;
  111. }
  112. logger.info("进入鉴权平台退订逻辑");
  113. System.out.println("进入鉴权平台退订逻辑");
  114. channel = "jianquanpingtai";
  115. try{
  116. String url = dictionaryDao.getValue("shareCancelUrl");
  117. result = URLUtil.get(url+"/kf?cpid="+cpid+"&spid="+spid+"&userid="+userid+"&channel="+channel,30000);
  118. logger.info(url);
  119. }catch (Exception e) {
  120. throw new BusinessException("9170", "调用能力共享平台退订接口异常");
  121. }
  122. JSONObject obj = JSONObject.fromObject(result);
  123. if(!obj.getString("resultCode").equals("0")){
  124. throw new BusinessException(obj.getString("resultCode"), obj.getString("resultInfo"));
  125. }
  126. }
  127. private SPInfo getSPInfo(String spid) throws Exception {
  128. return this.spDao.findById(spid);
  129. }
  130. }