123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448 |
- package com.chinacreator.videoalliance.order.service;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONObject;
- import com.chinacreator.common.exception.BusinessException;
- import com.chinacreator.common.util.URLUtil;
- import com.chinacreator.videoalliance.common.dao.DictionaryDao;
- import com.chinacreator.videoalliance.order.bean.OrderInfo;
- import com.chinacreator.videoalliance.order.bean.SPInfo;
- import com.chinacreator.videoalliance.order.dao.CapBusiConfDao;
- import com.chinacreator.videoalliance.order.dao.SPDao;
- import com.chinacreator.videoalliance.order.util.CapUtil;
- import com.chinacreator.videoalliance.order.util.JsonUtil;
- import org.apache.commons.lang.StringUtils;
- import org.apache.log4j.Logger;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Component;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.Map;
- /**
- * CAP接口服务
- * @author xu.zhou
- * @date 20190905
- */
- @Component
- public class CapOrderService {
- private static Logger log = Logger.getLogger(CapOrderService.class);
- @Autowired
- private SPDao spDao;
- @Autowired
- private CapBusiConfDao capBusiConfDao;
- @Autowired
- private DictionaryDao dictionaryDao;
- /**
- * cap订单同步
- * @param orderInfo 订购信息
- * @param accesstype //sp/cp的二次认证方式: 1:H5认证 2:SDK认证 3:短信认证 4:页面认证
- * @return
- * @throws Exception
- */
- public String orderSync(OrderInfo orderInfo, String accesstype) throws Exception{
- String result = "-1";
- String errorinfo = "cap订单同步失败";
- try {
- SPInfo spInfo = getSPInfo(orderInfo.getSpid());
- if(spInfo == null || (StringUtils.isEmpty(spInfo.getVacproductid()) && !"0".equals(spInfo.getHaslocal()))){
- throw new BusinessException("7003", "产品配置错误");
- }
- if (!"0".equals(spInfo.getHaslocal()) && spInfo.getFeetype() == 1) {
- String resJson = CapUtil.capSync(orderInfo.getCpid(),orderInfo.getSpid(),orderInfo.getUserid(), spInfo.getSpcode(), spInfo.getVacproductid(), "0",
- orderInfo.getSeqnumber(), accesstype, spInfo.getPrice(), orderInfo.getToken());
- log.info("调cap订单同步接口返回结果:"+resJson);
- if (resJson != null) {
- Map<?,?> map = JsonUtil.jsonToMap(resJson);
- result = map.get("resultcode") != null ? map.get("resultcode").toString() : "-1";
- errorinfo = map.get("errorinfo") != null ? map.get("errorinfo").toString() : "cap订单同步失败";
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- log.info("cap订单同步失败====userid"+orderInfo.getUserid()+"====spid"+orderInfo.getSpid()+"==="+e.getMessage());
- }
- return result;
- }
- /**
- * 订购
- * @param orderInfo 订购信息
- * @param accesstype //sp/cp的二次认证方式: 1:H5认证 2:SDK认证 3:短信认证 4:页面认证
- * @return
- * @throws Exception
- */
- public String order(OrderInfo orderInfo, String accesstype) throws Exception{
- SPInfo spInfo = getSPInfo(orderInfo.getSpid());
- String result = "-1";
- String errorinfo = "cap订购失败";
- if(spInfo == null || (StringUtils.isEmpty(spInfo.getVacproductid()) && !"0".equals(spInfo.getHaslocal()))){
- throw new BusinessException("7003", "产品配置错误");
- }
- //该短代码已放开20220302
- if("0".equals(spInfo.getHaslocal())){ //不调CAP接口 只在本地生成订购关系
- result = "0";
- return result;
- }
- if (!"0".equals(spInfo.getHaslocal()) && spInfo.getFeetype() == 1) {
- String resJson = CapUtil.cap(orderInfo.getCpid(),orderInfo.getSpid(),orderInfo.getUserid(), spInfo.getSpcode(), spInfo.getVacproductid(), "0",
- orderInfo.getSeqnumber(), accesstype, spInfo.getPrice(), orderInfo.getToken());
- log.info("调AP返回结果:"+resJson);
- if (resJson != null) {
- Map<?,?> map = JsonUtil.jsonToMap(resJson);
- result = map.get("resultcode") != null ? map.get("resultcode").toString() : "-1";
- errorinfo = map.get("errorinfo") != null ? map.get("errorinfo").toString() : "cap订购失败";
- }
- }
- /**
- 业务返回编码
- 0000 处理成功
- 0007 订单同步失败
- 0009 参数异常
- 0008 非4G用户,鉴权失败
- 0001 订购鉴权失败/退订鉴权失败
- 0004 话单缓存失败
- 0003 查询用户归属省编码失败
- 0002 cbss产品订购异常
- 0006 cbss产品退订异常
- */
- if (!result.equals("0")) {
- if(!"cardbus".equals(orderInfo.getOrderchannel())){
- insertPushTw(orderInfo.getUserid(),orderInfo.getCpid(),orderInfo.getSpid());
- }
- if(result.equals("-1")){
- throw new BusinessException(result, "cap订购失败:接口调用失败,服务暂不可用!", new String[0]);
- }else{
- errorinfo = handelErrorinfo(result,errorinfo);
- throw new BusinessException(result, "cap订购失败:"+errorinfo, new String[0]);
- }
- }
- return result;
- }
- /**
- * 正向订购
- * @param orderInfo 订购信息
- * @param accesstype //sp/cp的二次认证方式: 1:H5认证 2:SDK认证 3:短信认证 4:页面认证
- * @return
- * @throws Exception
- */
- public Map<String,String> orderCap(OrderInfo orderInfo, String accesstype) throws Exception{
- SPInfo spInfo = getSPInfo(orderInfo.getSpid());
- String result = "-1";
- String errorinfo = "cap订购失败";
- String time="";
- HashMap<String,String> resultMap = new HashMap<String,String>();
- if(spInfo == null || (StringUtils.isEmpty(spInfo.getVacproductid()) && !"0".equals(spInfo.getHaslocal()))){
- throw new BusinessException("7003", "产品配置错误");
- }
- if("0".equals(spInfo.getHaslocal())){ //不调CAP接口 只在本地生成订购关系
- result = "0";
- String times = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
- resultMap.put("result",result);
- resultMap.put("orderTime",times);
- return resultMap;
- }
- if (!"0".equals(spInfo.getHaslocal()) && spInfo.getFeetype() == 1) {
- String resJson = CapUtil.cap(orderInfo.getCpid(),orderInfo.getSpid(),orderInfo.getUserid(), spInfo.getSpcode(), spInfo.getVacproductid(), "0",
- orderInfo.getSeqnumber(), accesstype, spInfo.getPrice(), orderInfo.getToken());
- log.info("调CAP返回结果:"+resJson);
- if (resJson != null) {
- Map<?,?> map = JsonUtil.jsonToMap(resJson);
- result = map.get("resultcode") != null ? map.get("resultcode").toString() : "-1";
- errorinfo = map.get("errorinfo") != null ? map.get("errorinfo").toString() : "cap订购失败";
- time= map.get("time") != null ? map.get("time").toString() : "";
- }
- }
- /**
- 业务返回编码
- 0000 处理成功
- 0007 订单同步失败
- 0009 参数异常
- 0008 非4G用户,鉴权失败
- 0001 订购鉴权失败/退订鉴权失败
- 0004 话单缓存失败
- 0003 查询用户归属省编码失败
- 0002 cbss产品订购异常
- 0006 cbss产品退订异常
- */
- if (!result.equals("0")) {
- if(!"cardbus".equals(orderInfo.getOrderchannel())){
- insertPushTw(orderInfo.getUserid(),orderInfo.getCpid(),orderInfo.getSpid());
- }
- if(result.equals("-1")){
- throw new BusinessException(result, "cap订购失败:接口调用失败,服务暂不可用!", new String[0]);
- }else if ("9068".equals(result)){
- throw new BusinessException(result, errorinfo);
- }else {
- errorinfo = handelErrorinfo(result,errorinfo);
- throw new BusinessException(result, "cap订购失败:"+errorinfo, new String[0]);
- }
- }
- resultMap.put("result",result);
- resultMap.put("orderTime",time);
- return resultMap;
- }
- private String handelErrorinfo(String result,String errorinfo){
- if(result.equals("0001") || result.equals("0002") || result.equals("0006") || result.equals("0007")){
- // System.out.println("---符合---");
- // errorinfo = errorinfo.replace("\\","");
- JSONObject obj = JSON.parseObject(errorinfo);
- String CAP_MSG = obj.getString("CAP_MSG");
- String OTHER_MSG = obj.getString("OTHER_MSG");
- errorinfo = CAP_MSG +","+ OTHER_MSG;
- return errorinfo;
- }
- // System.out.println("---不符合---");
- return errorinfo;
- }
- /**
- * 退订
- * @param orderInfo
- * @return
- * @throws Exception
- */
- public String cancel(OrderInfo orderInfo) throws Exception{
- SPInfo spInfo = getSPInfo(orderInfo.getSpid());
- String result = "-1";
- String errorinfo = "cap退订失败";
- if(spInfo == null || (StringUtils.isEmpty(spInfo.getVacproductid()) && !"0".equals(spInfo.getHaslocal()))){
- throw new BusinessException("7003", "产品配置错误");
- }
-
- /****
- * 指定下线产品可以通过鉴权平台退订
- * TB_SP_INFO表的计费点如果配置为XXX_delorder,代表这个业务已下线,不能订购,可以通过鉴权平台退订
- * 验证通过后把计费点的“_delorder”去除,还原计费点,用于CAP接口订购,否则调CAP接口会报:"8005", "不在白名单产品列表不能订购"
- */
- /***
- if("kf".equals(orderInfo.getCancelchannel()) && spInfo.getVacproductid().indexOf("_delorder") != -1){
- //还原计费点标识
- spInfo.setVacproductid(spInfo.getVacproductid().replace("_delorder", ""));
- }
- ****/
- //该段代码已放开20220302
- if("0".equals(spInfo.getHaslocal())){ //不调CAP接口
- result = "0";
- return result;
- }
- if (!"0".equals(spInfo.getHaslocal()) && spInfo.getFeetype() == 1) {
- String resJson = CapUtil.cap(orderInfo.getCpid(),orderInfo.getSpid(),orderInfo.getUserid(), spInfo.getSpcode(), spInfo.getVacproductid(), "1",
- "", "", "", "");
- log.info("调AP返回结果:"+resJson);
- if (resJson != null) {
- Map<?,?> map = JsonUtil.jsonToMap(resJson);
- result = map.get("resultcode") != null ? map.get("resultcode").toString() : "-1";
- errorinfo = map.get("errorinfo") != null ? map.get("errorinfo").toString() : "cap退订失败";
- }
- }
- /**
- 业务返回编码
- 0000 处理成功
- 0007 订单同步失败
- 0009 参数异常
- 0008 非4G用户,鉴权失败
- 0001 订购鉴权失败/退订鉴权失败
- 0004 话单缓存失败
- 0003 查询用户归属省编码失败
- 0002 cbss产品订购异常
- 0006 cbss产品退订异常
- */
- if (!result.equals("0")) {
- if(result.equals("-1")){
- throw new BusinessException(result, "cap退订失败:接口调用失败,服务暂不可用", new String[0]);
- }else{
- errorinfo = handelErrorinfo(result,errorinfo);
- throw new BusinessException(result, "cap退订失败:"+errorinfo, new String[0]);
- }
- }
- return result;
- }
- /**
- * 退订
- * @param orderInfo
- * @return
- * @throws Exception
- */
- public Map<String,String> cancelCap(OrderInfo orderInfo) throws Exception{
- SPInfo spInfo = getSPInfo(orderInfo.getSpid());
- String result = "-1";
- String errorinfo = "cap退订失败";
- String time="";
- HashMap<String,String> resultMap = new HashMap<String,String>();
- if(spInfo == null || (StringUtils.isEmpty(spInfo.getVacproductid()) && !"0".equals(spInfo.getHaslocal()))){
- throw new BusinessException("7003", "产品配置错误");
- }
- /****
- * 指定下线产品可以通过鉴权平台退订
- * TB_SP_INFO表的计费点如果配置为XXX_delorder,代表这个业务已下线,不能订购,可以通过鉴权平台退订
- * 验证通过后把计费点的“_delorder”去除,还原计费点,用于CAP接口订购,否则调CAP接口会报:"8005", "不在白名单产品列表不能订购"
- */
- /***
- if("kf".equals(orderInfo.getCancelchannel()) && spInfo.getVacproductid().indexOf("_delorder") != -1){
- //还原计费点标识
- spInfo.setVacproductid(spInfo.getVacproductid().replace("_delorder", ""));
- }
- ****/
- // if("0".equals(spInfo.getHaslocal())){ //不调CAP接口
- // result = "0";
- // return result;
- // }
- if("0".equals(spInfo.getHaslocal())){ //不调CAP接口
- result = "0";
- String times = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
- resultMap.put("result",result);
- resultMap.put("orderTime",times);
- return resultMap;
- }
- if (!"0".equals(spInfo.getHaslocal()) && spInfo.getFeetype() == 1) {
- String resJson = CapUtil.cap(orderInfo.getCpid(),orderInfo.getSpid(),orderInfo.getUserid(), spInfo.getSpcode(), spInfo.getVacproductid(), "1",
- "", "", "", "");
- log.info("调AP返回结果:"+resJson);
- if (resJson != null) {
- Map<?,?> map = JsonUtil.jsonToMap(resJson);
- result = map.get("resultcode") != null ? map.get("resultcode").toString() : "-1";
- errorinfo = map.get("errorinfo") != null ? map.get("errorinfo").toString() : "cap退订失败";
- time= map.get("time") != null ? map.get("time").toString() : "";
- }
- }
- /**
- 业务返回编码
- 0000 处理成功
- 0007 订单同步失败
- 0009 参数异常
- 0008 非4G用户,鉴权失败
- 0001 订购鉴权失败/退订鉴权失败
- 0004 话单缓存失败
- 0003 查询用户归属省编码失败
- 0002 cbss产品订购异常
- 0006 cbss产品退订异常
- */
- if (!result.equals("0")) {
- if(result.equals("-1")){
- throw new BusinessException(result, "cap退订失败:接口调用失败,服务暂不可用", new String[0]);
- }else{
- errorinfo = handelErrorinfo(result,errorinfo);
- throw new BusinessException(result, "cap退订失败:"+errorinfo, new String[0]);
- }
- }
- resultMap.put("result",result);
- resultMap.put("cancelTime",time);
- return resultMap;
- }
- /**
- * cap用户综合查询
- * @param userid
- * @return
- */
- public String capQuery(String userid) throws Exception {
- if(userid!=null && userid!=""){
- String resJson = CapUtil.capQuery(userid);
- log.info("调cap用户综合查询返回结果:"+resJson);
- JSONObject obj = JSON.parseObject(resJson);
- String data = obj.getString("data");
- return data;
- }
- return null;
- }
- /**
- * 卡部信控查询
- * @param userid
- * @return
- */
- public String kbxkQuery(String userid) throws Exception {
- if(userid!=null && userid!=""){
- String resJson = CapUtil.kbxkQuery(userid);
- log.info("调卡部信控查询返回结果:"+resJson);
- JSONObject obj = JSON.parseObject(resJson);
- String data = obj.getString("data");
- return data;
- }
- return null;
- }
- private SPInfo getSPInfo(String spid) throws Exception {
- return this.spDao.findById(spid);
- }
- public boolean hasCap(OrderInfo orderInfo) throws Exception{
- return capBusiConfDao.hasCap(orderInfo.getCpid(), orderInfo.getSpid());
- }
- /**
- * CAP订购失败推送拓维后向订购
- * @param userid
- * @param cpid
- * @param spid
- */
- public void insertPushTw(String userid,String cpid,String spid){
- try {
- Map<String, String> map = new HashMap<String, String>();
- map.put("userid",userid);
- map.put("kcSpid",spid);
- map.put("kcCpid",cpid);
- map.put("type", "twhx");
- String mqReciveUrl = dictionaryDao.getValue("mqReciveUrl");
- URLUtil.post(mqReciveUrl, JsonUtil.objectToJson(map));
- //测试环境
- //URLUtil.post("http://10.199.99.158:8030/mq-service/recive.do", JsonUtil.objectToJson(map));
- //生产环境
- //URLUtil.post("http://10.199.99.144:8090/mq-service/recive.do", JsonUtil.objectToJson(map));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- // public static void main(String args[]){
- // CapOrderService c = new CapOrderService();
- // String result = "0006";
- // String errorinfo = "{\"CAP_MSG\":\"cbss产品退订异常\",\"OTHER_CODE\":\"8888\",\"OTHER_INTER\":\"cbss退订接口\",\"OTHER_MSG\":\"TCS_SPTradeOrder_VAC执行异常:\\n[INDETERMINATE]TradeCheckTradeSuperLimit.cpp:1476,12CRMException-300263: 特殊限制判断:用户当前为5G主套餐不能订购sp定向流量包!$$$20106$$$\"}";
- //
- //
- // String re = c.handelErrorinfo(result,errorinfo);
- // System.out.println(re);
- // String ssss = "cbss产品退订异常,TCS_SPTradeOrder_VAC执行异常:\n" +
- // "[INDETERMINATE]TradeCheckTradeSuperLimit.cpp:1476,12CRMException-300263: 特殊限制判断:用户当前为5G主套餐不能订购sp定向流量包!$$$20106$$$";
- // System.out.println(ssss.length());
- // }
- }
|