1a1b390db56f6ef4352b709198a7919dec238a08.svn-base 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. package com.chinacreator.videoalliance.order.service;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.chinacreator.common.exception.BusinessException;
  5. import com.chinacreator.common.util.URLUtil;
  6. import com.chinacreator.videoalliance.common.dao.DictionaryDao;
  7. import com.chinacreator.videoalliance.order.bean.OrderInfo;
  8. import com.chinacreator.videoalliance.order.bean.SPInfo;
  9. import com.chinacreator.videoalliance.order.dao.CapBusiConfDao;
  10. import com.chinacreator.videoalliance.order.dao.SPDao;
  11. import com.chinacreator.videoalliance.order.util.CapUtil;
  12. import com.chinacreator.videoalliance.order.util.JsonUtil;
  13. import org.apache.commons.lang.StringUtils;
  14. import org.apache.log4j.Logger;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.stereotype.Component;
  17. import java.text.SimpleDateFormat;
  18. import java.util.Date;
  19. import java.util.HashMap;
  20. import java.util.Map;
  21. /**
  22. * CAP接口服务
  23. * @author xu.zhou
  24. * @date 20190905
  25. */
  26. @Component
  27. public class CapOrderService {
  28. private static Logger log = Logger.getLogger(CapOrderService.class);
  29. @Autowired
  30. private SPDao spDao;
  31. @Autowired
  32. private CapBusiConfDao capBusiConfDao;
  33. @Autowired
  34. private DictionaryDao dictionaryDao;
  35. /**
  36. * cap订单同步
  37. * @param orderInfo 订购信息
  38. * @param accesstype //sp/cp的二次认证方式: 1:H5认证 2:SDK认证 3:短信认证 4:页面认证
  39. * @return
  40. * @throws Exception
  41. */
  42. public String orderSync(OrderInfo orderInfo, String accesstype) throws Exception{
  43. String result = "-1";
  44. String errorinfo = "cap订单同步失败";
  45. try {
  46. SPInfo spInfo = getSPInfo(orderInfo.getSpid());
  47. if(spInfo == null || (StringUtils.isEmpty(spInfo.getVacproductid()) && !"0".equals(spInfo.getHaslocal()))){
  48. throw new BusinessException("7003", "产品配置错误");
  49. }
  50. if (!"0".equals(spInfo.getHaslocal()) && spInfo.getFeetype() == 1) {
  51. String resJson = CapUtil.capSync(orderInfo.getCpid(),orderInfo.getSpid(),orderInfo.getUserid(), spInfo.getSpcode(), spInfo.getVacproductid(), "0",
  52. orderInfo.getSeqnumber(), accesstype, spInfo.getPrice(), orderInfo.getToken());
  53. log.info("调cap订单同步接口返回结果:"+resJson);
  54. if (resJson != null) {
  55. Map<?,?> map = JsonUtil.jsonToMap(resJson);
  56. result = map.get("resultcode") != null ? map.get("resultcode").toString() : "-1";
  57. errorinfo = map.get("errorinfo") != null ? map.get("errorinfo").toString() : "cap订单同步失败";
  58. }
  59. }
  60. } catch (Exception e) {
  61. e.printStackTrace();
  62. log.info("cap订单同步失败====userid"+orderInfo.getUserid()+"====spid"+orderInfo.getSpid()+"==="+e.getMessage());
  63. }
  64. return result;
  65. }
  66. /**
  67. * 订购
  68. * @param orderInfo 订购信息
  69. * @param accesstype //sp/cp的二次认证方式: 1:H5认证 2:SDK认证 3:短信认证 4:页面认证
  70. * @return
  71. * @throws Exception
  72. */
  73. public String order(OrderInfo orderInfo, String accesstype) throws Exception{
  74. SPInfo spInfo = getSPInfo(orderInfo.getSpid());
  75. String result = "-1";
  76. String errorinfo = "cap订购失败";
  77. if(spInfo == null || (StringUtils.isEmpty(spInfo.getVacproductid()) && !"0".equals(spInfo.getHaslocal()))){
  78. throw new BusinessException("7003", "产品配置错误");
  79. }
  80. //该短代码已放开20220302
  81. if("0".equals(spInfo.getHaslocal())){ //不调CAP接口 只在本地生成订购关系
  82. result = "0";
  83. return result;
  84. }
  85. if (!"0".equals(spInfo.getHaslocal()) && spInfo.getFeetype() == 1) {
  86. String resJson = CapUtil.cap(orderInfo.getCpid(),orderInfo.getSpid(),orderInfo.getUserid(), spInfo.getSpcode(), spInfo.getVacproductid(), "0",
  87. orderInfo.getSeqnumber(), accesstype, spInfo.getPrice(), orderInfo.getToken());
  88. log.info("调AP返回结果:"+resJson);
  89. if (resJson != null) {
  90. Map<?,?> map = JsonUtil.jsonToMap(resJson);
  91. result = map.get("resultcode") != null ? map.get("resultcode").toString() : "-1";
  92. errorinfo = map.get("errorinfo") != null ? map.get("errorinfo").toString() : "cap订购失败";
  93. }
  94. }
  95. /**
  96. 业务返回编码
  97. 0000 处理成功
  98. 0007 订单同步失败
  99. 0009 参数异常
  100. 0008 非4G用户,鉴权失败
  101. 0001 订购鉴权失败/退订鉴权失败
  102. 0004 话单缓存失败
  103. 0003 查询用户归属省编码失败
  104. 0002 cbss产品订购异常
  105. 0006 cbss产品退订异常
  106. */
  107. if (!result.equals("0")) {
  108. if(!"cardbus".equals(orderInfo.getOrderchannel())){
  109. insertPushTw(orderInfo.getUserid(),orderInfo.getCpid(),orderInfo.getSpid());
  110. }
  111. if(result.equals("-1")){
  112. throw new BusinessException(result, "cap订购失败:接口调用失败,服务暂不可用!", new String[0]);
  113. }else{
  114. errorinfo = handelErrorinfo(result,errorinfo);
  115. throw new BusinessException(result, "cap订购失败:"+errorinfo, new String[0]);
  116. }
  117. }
  118. return result;
  119. }
  120. /**
  121. * 正向订购
  122. * @param orderInfo 订购信息
  123. * @param accesstype //sp/cp的二次认证方式: 1:H5认证 2:SDK认证 3:短信认证 4:页面认证
  124. * @return
  125. * @throws Exception
  126. */
  127. public Map<String,String> orderCap(OrderInfo orderInfo, String accesstype) throws Exception{
  128. SPInfo spInfo = getSPInfo(orderInfo.getSpid());
  129. String result = "-1";
  130. String errorinfo = "cap订购失败";
  131. String time="";
  132. HashMap<String,String> resultMap = new HashMap<String,String>();
  133. if(spInfo == null || (StringUtils.isEmpty(spInfo.getVacproductid()) && !"0".equals(spInfo.getHaslocal()))){
  134. throw new BusinessException("7003", "产品配置错误");
  135. }
  136. if("0".equals(spInfo.getHaslocal())){ //不调CAP接口 只在本地生成订购关系
  137. result = "0";
  138. String times = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
  139. resultMap.put("result",result);
  140. resultMap.put("orderTime",times);
  141. return resultMap;
  142. }
  143. if (!"0".equals(spInfo.getHaslocal()) && spInfo.getFeetype() == 1) {
  144. String resJson = CapUtil.cap(orderInfo.getCpid(),orderInfo.getSpid(),orderInfo.getUserid(), spInfo.getSpcode(), spInfo.getVacproductid(), "0",
  145. orderInfo.getSeqnumber(), accesstype, spInfo.getPrice(), orderInfo.getToken());
  146. log.info("调CAP返回结果:"+resJson);
  147. if (resJson != null) {
  148. Map<?,?> map = JsonUtil.jsonToMap(resJson);
  149. result = map.get("resultcode") != null ? map.get("resultcode").toString() : "-1";
  150. errorinfo = map.get("errorinfo") != null ? map.get("errorinfo").toString() : "cap订购失败";
  151. time= map.get("time") != null ? map.get("time").toString() : "";
  152. }
  153. }
  154. /**
  155. 业务返回编码
  156. 0000 处理成功
  157. 0007 订单同步失败
  158. 0009 参数异常
  159. 0008 非4G用户,鉴权失败
  160. 0001 订购鉴权失败/退订鉴权失败
  161. 0004 话单缓存失败
  162. 0003 查询用户归属省编码失败
  163. 0002 cbss产品订购异常
  164. 0006 cbss产品退订异常
  165. */
  166. if (!result.equals("0")) {
  167. if(!"cardbus".equals(orderInfo.getOrderchannel())){
  168. insertPushTw(orderInfo.getUserid(),orderInfo.getCpid(),orderInfo.getSpid());
  169. }
  170. if(result.equals("-1")){
  171. throw new BusinessException(result, "cap订购失败:接口调用失败,服务暂不可用!", new String[0]);
  172. }else if ("9068".equals(result)){
  173. throw new BusinessException(result, errorinfo);
  174. }else {
  175. errorinfo = handelErrorinfo(result,errorinfo);
  176. throw new BusinessException(result, "cap订购失败:"+errorinfo, new String[0]);
  177. }
  178. }
  179. resultMap.put("result",result);
  180. resultMap.put("orderTime",time);
  181. return resultMap;
  182. }
  183. private String handelErrorinfo(String result,String errorinfo){
  184. if(result.equals("0001") || result.equals("0002") || result.equals("0006") || result.equals("0007")){
  185. // System.out.println("---符合---");
  186. // errorinfo = errorinfo.replace("\\","");
  187. JSONObject obj = JSON.parseObject(errorinfo);
  188. String CAP_MSG = obj.getString("CAP_MSG");
  189. String OTHER_MSG = obj.getString("OTHER_MSG");
  190. errorinfo = CAP_MSG +","+ OTHER_MSG;
  191. return errorinfo;
  192. }
  193. // System.out.println("---不符合---");
  194. return errorinfo;
  195. }
  196. /**
  197. * 退订
  198. * @param orderInfo
  199. * @return
  200. * @throws Exception
  201. */
  202. public String cancel(OrderInfo orderInfo) throws Exception{
  203. SPInfo spInfo = getSPInfo(orderInfo.getSpid());
  204. String result = "-1";
  205. String errorinfo = "cap退订失败";
  206. if(spInfo == null || (StringUtils.isEmpty(spInfo.getVacproductid()) && !"0".equals(spInfo.getHaslocal()))){
  207. throw new BusinessException("7003", "产品配置错误");
  208. }
  209. /****
  210. * 指定下线产品可以通过鉴权平台退订
  211. * TB_SP_INFO表的计费点如果配置为XXX_delorder,代表这个业务已下线,不能订购,可以通过鉴权平台退订
  212. * 验证通过后把计费点的“_delorder”去除,还原计费点,用于CAP接口订购,否则调CAP接口会报:"8005", "不在白名单产品列表不能订购"
  213. */
  214. /***
  215. if("kf".equals(orderInfo.getCancelchannel()) && spInfo.getVacproductid().indexOf("_delorder") != -1){
  216. //还原计费点标识
  217. spInfo.setVacproductid(spInfo.getVacproductid().replace("_delorder", ""));
  218. }
  219. ****/
  220. //该段代码已放开20220302
  221. if("0".equals(spInfo.getHaslocal())){ //不调CAP接口
  222. result = "0";
  223. return result;
  224. }
  225. if (!"0".equals(spInfo.getHaslocal()) && spInfo.getFeetype() == 1) {
  226. String resJson = CapUtil.cap(orderInfo.getCpid(),orderInfo.getSpid(),orderInfo.getUserid(), spInfo.getSpcode(), spInfo.getVacproductid(), "1",
  227. "", "", "", "");
  228. log.info("调AP返回结果:"+resJson);
  229. if (resJson != null) {
  230. Map<?,?> map = JsonUtil.jsonToMap(resJson);
  231. result = map.get("resultcode") != null ? map.get("resultcode").toString() : "-1";
  232. errorinfo = map.get("errorinfo") != null ? map.get("errorinfo").toString() : "cap退订失败";
  233. }
  234. }
  235. /**
  236. 业务返回编码
  237. 0000 处理成功
  238. 0007 订单同步失败
  239. 0009 参数异常
  240. 0008 非4G用户,鉴权失败
  241. 0001 订购鉴权失败/退订鉴权失败
  242. 0004 话单缓存失败
  243. 0003 查询用户归属省编码失败
  244. 0002 cbss产品订购异常
  245. 0006 cbss产品退订异常
  246. */
  247. if (!result.equals("0")) {
  248. if(result.equals("-1")){
  249. throw new BusinessException(result, "cap退订失败:接口调用失败,服务暂不可用", new String[0]);
  250. }else{
  251. errorinfo = handelErrorinfo(result,errorinfo);
  252. throw new BusinessException(result, "cap退订失败:"+errorinfo, new String[0]);
  253. }
  254. }
  255. return result;
  256. }
  257. /**
  258. * 退订
  259. * @param orderInfo
  260. * @return
  261. * @throws Exception
  262. */
  263. public Map<String,String> cancelCap(OrderInfo orderInfo) throws Exception{
  264. SPInfo spInfo = getSPInfo(orderInfo.getSpid());
  265. String result = "-1";
  266. String errorinfo = "cap退订失败";
  267. String time="";
  268. HashMap<String,String> resultMap = new HashMap<String,String>();
  269. if(spInfo == null || (StringUtils.isEmpty(spInfo.getVacproductid()) && !"0".equals(spInfo.getHaslocal()))){
  270. throw new BusinessException("7003", "产品配置错误");
  271. }
  272. /****
  273. * 指定下线产品可以通过鉴权平台退订
  274. * TB_SP_INFO表的计费点如果配置为XXX_delorder,代表这个业务已下线,不能订购,可以通过鉴权平台退订
  275. * 验证通过后把计费点的“_delorder”去除,还原计费点,用于CAP接口订购,否则调CAP接口会报:"8005", "不在白名单产品列表不能订购"
  276. */
  277. /***
  278. if("kf".equals(orderInfo.getCancelchannel()) && spInfo.getVacproductid().indexOf("_delorder") != -1){
  279. //还原计费点标识
  280. spInfo.setVacproductid(spInfo.getVacproductid().replace("_delorder", ""));
  281. }
  282. ****/
  283. // if("0".equals(spInfo.getHaslocal())){ //不调CAP接口
  284. // result = "0";
  285. // return result;
  286. // }
  287. if("0".equals(spInfo.getHaslocal())){ //不调CAP接口
  288. result = "0";
  289. String times = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
  290. resultMap.put("result",result);
  291. resultMap.put("orderTime",times);
  292. return resultMap;
  293. }
  294. if (!"0".equals(spInfo.getHaslocal()) && spInfo.getFeetype() == 1) {
  295. String resJson = CapUtil.cap(orderInfo.getCpid(),orderInfo.getSpid(),orderInfo.getUserid(), spInfo.getSpcode(), spInfo.getVacproductid(), "1",
  296. "", "", "", "");
  297. log.info("调AP返回结果:"+resJson);
  298. if (resJson != null) {
  299. Map<?,?> map = JsonUtil.jsonToMap(resJson);
  300. result = map.get("resultcode") != null ? map.get("resultcode").toString() : "-1";
  301. errorinfo = map.get("errorinfo") != null ? map.get("errorinfo").toString() : "cap退订失败";
  302. time= map.get("time") != null ? map.get("time").toString() : "";
  303. }
  304. }
  305. /**
  306. 业务返回编码
  307. 0000 处理成功
  308. 0007 订单同步失败
  309. 0009 参数异常
  310. 0008 非4G用户,鉴权失败
  311. 0001 订购鉴权失败/退订鉴权失败
  312. 0004 话单缓存失败
  313. 0003 查询用户归属省编码失败
  314. 0002 cbss产品订购异常
  315. 0006 cbss产品退订异常
  316. */
  317. if (!result.equals("0")) {
  318. if(result.equals("-1")){
  319. throw new BusinessException(result, "cap退订失败:接口调用失败,服务暂不可用", new String[0]);
  320. }else{
  321. errorinfo = handelErrorinfo(result,errorinfo);
  322. throw new BusinessException(result, "cap退订失败:"+errorinfo, new String[0]);
  323. }
  324. }
  325. resultMap.put("result",result);
  326. resultMap.put("cancelTime",time);
  327. return resultMap;
  328. }
  329. /**
  330. * cap用户综合查询
  331. * @param userid
  332. * @return
  333. */
  334. public String capQuery(String userid) throws Exception {
  335. if(userid!=null && userid!=""){
  336. String resJson = CapUtil.capQuery(userid);
  337. log.info("调cap用户综合查询返回结果:"+resJson);
  338. JSONObject obj = JSON.parseObject(resJson);
  339. String data = obj.getString("data");
  340. return data;
  341. }
  342. return null;
  343. }
  344. /**
  345. * 卡部信控查询
  346. * @param userid
  347. * @return
  348. */
  349. public String kbxkQuery(String userid) throws Exception {
  350. if(userid!=null && userid!=""){
  351. String resJson = CapUtil.kbxkQuery(userid);
  352. log.info("调卡部信控查询返回结果:"+resJson);
  353. JSONObject obj = JSON.parseObject(resJson);
  354. String data = obj.getString("data");
  355. return data;
  356. }
  357. return null;
  358. }
  359. private SPInfo getSPInfo(String spid) throws Exception {
  360. return this.spDao.findById(spid);
  361. }
  362. public boolean hasCap(OrderInfo orderInfo) throws Exception{
  363. return capBusiConfDao.hasCap(orderInfo.getCpid(), orderInfo.getSpid());
  364. }
  365. /**
  366. * CAP订购失败推送拓维后向订购
  367. * @param userid
  368. * @param cpid
  369. * @param spid
  370. */
  371. public void insertPushTw(String userid,String cpid,String spid){
  372. try {
  373. Map<String, String> map = new HashMap<String, String>();
  374. map.put("userid",userid);
  375. map.put("kcSpid",spid);
  376. map.put("kcCpid",cpid);
  377. map.put("type", "twhx");
  378. String mqReciveUrl = dictionaryDao.getValue("mqReciveUrl");
  379. URLUtil.post(mqReciveUrl, JsonUtil.objectToJson(map));
  380. //测试环境
  381. //URLUtil.post("http://10.199.99.158:8030/mq-service/recive.do", JsonUtil.objectToJson(map));
  382. //生产环境
  383. //URLUtil.post("http://10.199.99.144:8090/mq-service/recive.do", JsonUtil.objectToJson(map));
  384. } catch (Exception e) {
  385. e.printStackTrace();
  386. }
  387. }
  388. // public static void main(String args[]){
  389. // CapOrderService c = new CapOrderService();
  390. // String result = "0006";
  391. // 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$$$\"}";
  392. //
  393. //
  394. // String re = c.handelErrorinfo(result,errorinfo);
  395. // System.out.println(re);
  396. // String ssss = "cbss产品退订异常,TCS_SPTradeOrder_VAC执行异常:\n" +
  397. // "[INDETERMINATE]TradeCheckTradeSuperLimit.cpp:1476,12CRMException-300263: 特殊限制判断:用户当前为5G主套餐不能订购sp定向流量包!$$$20106$$$";
  398. // System.out.println(ssss.length());
  399. // }
  400. }