123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- package com.chinacreator.videoalliance.order.service;
- import com.chinacreator.videoalliance.order.bean.SPInfo;
- import com.chinacreator.videoalliance.order.dao.SPDao;
- import org.apache.commons.lang.StringUtils;
- import org.apache.log4j.Logger;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Component;
- import com.chinacreator.common.exception.BusinessException;
- import com.chinacreator.common.util.URLUtil;
- import com.chinacreator.videoalliance.common.dao.DictionaryDao;
- import net.sf.json.JSONObject;
- @Component
- public class ShareOrderService {
- private static Logger logger = Logger.getLogger(ShareOrderService.class);
-
- @Autowired
- private DictionaryDao dictionaryDao;
- @Autowired
- private SPDao spDao;
- //private static final String orderUrl = "http://10.199.99.158:8091/shareorder/order";
-
- //private static final String cancelUrl = "http://10.199.99.158:8091/shareorder/cancel";
-
- /**
- * 订购
- * @param userid
- * @param cpid
- * @param spid
- * @throws BusinessException
- */
- public void order(String userid,String cpid,String spid) throws BusinessException{
- //String result ="";
- SPInfo spInfo = null;
- try {
- spInfo = getSPInfo(spid);
- } catch (Exception e) {
- }
- if(spInfo == null){
- throw new BusinessException("7003", "产品配置错误");
- }
- String result ="";
- if("0".equals(spInfo.getHaslocal())){ //不调CAP接口
- result = "0";
- return ;
- }
- try{
- String url = dictionaryDao.getValue("shareOrderUrl");
- result = URLUtil.get(url+"?cpid="+cpid+"&spid="+spid+"&userid="+userid,60000); //2022022由15秒改为30秒,因为有重试机制,所以调整到了60秒
- if(result.indexOf("不可以重复订购")!= -1){ //包含不可以重复订购即落订购关系
- result = "{\"resultCode\":0,\"resultInfo\":\"成功!\",\"data\":null}";
- }
- }catch (Exception e) {
- throw new BusinessException("9170", "调用能力共享平台订购接口异常");
- }
- JSONObject obj = JSONObject.fromObject(result);
- if(!obj.getString("resultCode").equals("0")){
- throw new BusinessException(obj.getString("resultCode"), obj.getString("resultInfo"));
- }
- }
- /**
- * 退订
- * @param userid
- * @param cpid
- * @param spid
- * @throws BusinessException
- */
- public void cancel(String userid,String cpid,String spid) throws BusinessException{
- //String result ="";
- SPInfo spInfo = null;
- try {
- spInfo = getSPInfo(spid);
- } catch (Exception e) {
- }
- if(spInfo == null){
- throw new BusinessException("7003", "产品配置错误");
- }
- String result ="";
- if("0".equals(spInfo.getHaslocal())){ //不调CAP接口
- result = "0";
- return ;
- }
- try{
- String url = dictionaryDao.getValue("shareCancelUrl");
- result = URLUtil.get(url+"?cpid="+cpid+"&spid="+spid+"&userid="+userid,30000);
- }catch (Exception e) {
- throw new BusinessException("9170", "调用能力共享平台退订接口异常");
- }
- JSONObject obj = JSONObject.fromObject(result);
- if(!obj.getString("resultCode").equals("0")){
- throw new BusinessException(obj.getString("resultCode"), obj.getString("resultInfo"));
- }
- }
- /**
- * 鉴权平台退订
- * @param userid
- * @param cpid
- * @param spid
- * @throws BusinessException
- */
- public void cancel(String userid,String cpid,String spid,String channel) throws BusinessException{
- //String result ="";
- SPInfo spInfo = null;
- try {
- spInfo = getSPInfo(spid);
- } catch (Exception e) {
- }
- if(spInfo == null){
- throw new BusinessException("7003", "产品配置错误");
- }
- String result ="";
- if("0".equals(spInfo.getHaslocal())){ //不调CAP接口
- result = "0";
- return ;
- }
- logger.info("进入鉴权平台退订逻辑");
- System.out.println("进入鉴权平台退订逻辑");
- channel = "jianquanpingtai";
- try{
- String url = dictionaryDao.getValue("shareCancelUrl");
- result = URLUtil.get(url+"/kf?cpid="+cpid+"&spid="+spid+"&userid="+userid+"&channel="+channel,30000);
- logger.info(url);
- }catch (Exception e) {
- throw new BusinessException("9170", "调用能力共享平台退订接口异常");
- }
- JSONObject obj = JSONObject.fromObject(result);
- if(!obj.getString("resultCode").equals("0")){
- throw new BusinessException(obj.getString("resultCode"), obj.getString("resultInfo"));
- }
- }
- private SPInfo getSPInfo(String spid) throws Exception {
- return this.spDao.findById(spid);
- }
- }
|