65ebf359f5330847af0b8033f91a9393c21a68ca.svn-base 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. package com.chinacreator.videoalliance.order.service;
  2. import java.text.ParseException;
  3. import java.util.ArrayList;
  4. import java.util.Calendar;
  5. import java.util.Date;
  6. import java.util.List;
  7. import java.util.Map;
  8. import com.chinacreator.common.exception.BusinessException;
  9. import com.chinacreator.common.util.Base64;
  10. import com.chinacreator.common.util.MD5;
  11. import com.chinacreator.common.util.URLUtil;
  12. import com.chinacreator.common.util.UsermobUtil;
  13. import com.chinacreator.videoalliance.common.bean.AreaInfo;
  14. import com.chinacreator.videoalliance.common.bean.CPInfo;
  15. import com.chinacreator.videoalliance.common.dao.DictionaryDao;
  16. import com.chinacreator.videoalliance.common.dao.ProvinceControlDao;
  17. import com.chinacreator.videoalliance.common.util.AreaUtil;
  18. import com.chinacreator.videoalliance.common.util.ConfigUtil;
  19. import com.chinacreator.videoalliance.order.bean.EcbProductInfo;
  20. import com.chinacreator.videoalliance.order.bean.EcbResponseBean;
  21. import com.chinacreator.videoalliance.order.bean.OrderInfo;
  22. import com.chinacreator.videoalliance.order.bean.OrderLog;
  23. import com.chinacreator.videoalliance.order.bean.SPInfo;
  24. import com.chinacreator.videoalliance.order.dao.*;
  25. import com.chinacreator.videoalliance.order.util.JsonUtil;
  26. import org.apache.commons.lang.math.NumberUtils;
  27. import org.apache.commons.lang.time.DateUtils;
  28. import org.apache.log4j.Logger;
  29. import org.springframework.beans.factory.annotation.Autowired;
  30. import org.springframework.stereotype.Component;
  31. import org.springframework.util.StringUtils;
  32. @Component
  33. public class CSNewOrderService {
  34. private static Logger log = Logger.getLogger("orderError");
  35. @Autowired
  36. private OrderDao orderDao;
  37. @Autowired
  38. private BlackWhiteDao blackWhiteDao;
  39. @Autowired
  40. private SPDao spDao;
  41. @Autowired
  42. private DictionaryDao dictionaryDao;
  43. @Autowired
  44. private EcbDiscntNewDao ecbDiscntNewDao;
  45. @Autowired
  46. private ProvinceControlDao provinceControlDao;
  47. @Autowired
  48. private OrderLogDao orderLogDao;
  49. @Autowired
  50. private OrderSysDao sysDao;
  51. @Autowired
  52. private EcbService ecbService;
  53. @Autowired
  54. private BackBusiOrderDao backBusiOrderDao;
  55. /**
  56. * 验证手机号码
  57. * @param orderInfo
  58. * @throws Exception
  59. */
  60. private void checkUserid(OrderInfo orderInfo) throws Exception {
  61. String userid = orderInfo.getUserid();
  62. if ((StringUtils.isEmpty(userid)) || ("null".equals(userid)))
  63. throw new BusinessException("7002", "手机号码为空", new String[0]);
  64. orderInfo.setUserid(ConfigUtil.decrypt(userid, orderInfo.getCpid()));
  65. if ((orderInfo.getUserid() != null) && (orderInfo.getUserid().length() > 11)) {
  66. orderInfo.setUserid(ConfigUtil.getUserid(orderInfo.getUserid(), orderInfo.getCpid()));
  67. }
  68. if (!UsermobUtil.isValid(orderInfo.getUserid())) {
  69. throw new BusinessException("7002", "手机号码无效", new String[0]);
  70. }
  71. }
  72. /**
  73. * 验证CP
  74. * @param orderInfo
  75. * @throws Exception
  76. */
  77. private void checkCpInfo(OrderInfo orderInfo) throws Exception {
  78. CPInfo cpInfo = ConfigUtil.getCPInfo(orderInfo.getCpid(), null);
  79. if ((cpInfo.getStatus() != 0) && (cpInfo.getStatus() != 4)) {
  80. throw new BusinessException("9002", "该业务暂未开放,敬请期待。", new String[0]);
  81. }
  82. }
  83. /**
  84. * 验证SP
  85. * @param orderInfo
  86. * @throws Exception
  87. */
  88. private void checkSpInfo(OrderInfo orderInfo) throws Exception {
  89. SPInfo spInfo = getSPInfo(orderInfo);
  90. if (spInfo.getCanorder() == 1 && StringUtils.isEmpty(orderInfo.getOrderchannel())) {
  91. throw new BusinessException("9012", "该产品不支持订购操作", new String[0]);
  92. }
  93. if (orderInfo.getOrdertype() == 1) {
  94. if (spInfo.getType() != 0 && spInfo.getType() != 3) {
  95. throw new BusinessException("5305", "产品标识符无效", new String[0]);
  96. }
  97. if(spInfo.getType() == 0){
  98. if (StringUtils.isEmpty(orderInfo.getVideoid())) {
  99. throw new BusinessException("8002", "{0}参数无效", new String[] { "videoid" });
  100. }
  101. if (StringUtils.isEmpty(orderInfo.getVideoname()))
  102. throw new BusinessException("8002", "{0}参数无效", new String[] { "videoname" });
  103. try {
  104. String videoname = new String(Base64.decodeBase64(orderInfo.getVideoname()), "UTF-8");
  105. orderInfo.setVideoname(videoname);
  106. } catch (Exception e) {
  107. throw new BusinessException("8002", "{0}参数无效", new String[] { "videoname" });
  108. }
  109. orderInfo.setEndtime(this.sysDao.getLastDay());
  110. }else{
  111. orderInfo.setOrdertype(3);
  112. }
  113. } else if (orderInfo.getOrdertype() == 0) {
  114. if (spInfo.getType() == 0){
  115. throw new BusinessException("5305", "产品标识符无效", new String[0]);
  116. }
  117. } else if (orderInfo.getOrdertype() == 2) {
  118. if (spInfo.getType() != 0) {
  119. throw new BusinessException("5305", "产品标识符无效", new String[0]);
  120. }
  121. orderInfo.setCachesucceed(0);
  122. } else {
  123. throw new BusinessException("8002", "{0}参数无效", new String[] { "ordertype" });
  124. }
  125. orderInfo.setSpid(spInfo.getSpid());
  126. }
  127. /**
  128. * 订购验证
  129. * @param orderInfo
  130. * @throws Exception
  131. */
  132. public void checkOrder(OrderInfo orderInfo) throws Exception {
  133. checkSign(orderInfo);
  134. checkUserid(orderInfo);
  135. checkCpInfo(orderInfo);
  136. checkSpInfo(orderInfo);
  137. String userid = orderInfo.getUserid();
  138. if (this.blackWhiteDao.isBlackUser(userid, orderInfo.getCpid())) {
  139. throw new BusinessException("9002", "用户为黑名单用户", new String[0]);
  140. }
  141. AreaInfo areaInfo = getAreaInfo(userid);
  142. orderInfo.setProvince(areaInfo.getProvince());
  143. orderInfo.setArea(areaInfo.getArea());
  144. CPInfo cpInfo = ConfigUtil.getCPInfo(orderInfo.getCpid(), areaInfo.getProvince());
  145. if (cpInfo == null) {
  146. throw new BusinessException("7005", "CP标识无效", new String[0]);
  147. }
  148. String allowOrder = this.dictionaryDao.getValue("allowOrder");
  149. if (("1".equals(allowOrder)) || (areaInfo.getStatus() == 1)) {
  150. throw new BusinessException("9002", "该业务暂未开放,敬请期待。", new String[0]);
  151. }
  152. if ((areaInfo.getProvince() != null) && (this.provinceControlDao.isNotOpen(areaInfo.getProvince())))
  153. throw new BusinessException("9003", "您号码的归属地{0}暂未开放该业务,敬请期待。", new String[] { areaInfo.getProvince() });
  154. if(this.orderDao.isOpen(orderInfo.getSpid(),orderInfo.getCpid(),orderInfo.getProvince())){ // status 为2 表示省份尚未开通
  155. throw new BusinessException("9003", "省份尚未开通此业务,敬请期待!");
  156. }
  157. }
  158. /**
  159. * 验证签名是否有效
  160. * @param orderInfo
  161. * @param deuserid 加密的手机号码
  162. * @throws Exception
  163. */
  164. public void checkSign(OrderInfo orderInfo) throws Exception {
  165. String sign = orderInfo.getSignature();
  166. if (StringUtils.isEmpty(sign)) {
  167. throw new BusinessException("9054", "signature为空");
  168. }
  169. Map cpSpBean = backBusiOrderDao.getCpSp(orderInfo.getCpid(),orderInfo.getSpid());
  170. String pwd = cpSpBean.get("NETPWD").toString();
  171. //Md5(cpid + spid + userid + type + channel + timestamp + pwd)
  172. String channel = orderInfo.getOrderchannel();
  173. if(orderInfo.getType() == 1){
  174. channel = orderInfo.getCancelchannel();
  175. }
  176. String localSign = orderInfo.getCpid()
  177. + orderInfo.getSpid() + orderInfo.getUserid() + orderInfo.getType() + channel + orderInfo.getTimestamp() + pwd;
  178. System.out.println("localSign=>"+localSign);
  179. localSign = MD5.MD5Encode(localSign);
  180. if (!localSign.equals(orderInfo.getSignature())) {
  181. throw new BusinessException("9054", "signature校验失败");
  182. }
  183. }
  184. /**
  185. * 获取省份区域信息
  186. * @param userid
  187. * @return
  188. * @throws Exception
  189. */
  190. private AreaInfo getAreaInfo(String userid) throws Exception {
  191. AreaInfo areaInfo = AreaUtil.getAreaInfoByUserid(userid);
  192. if (areaInfo == null) {
  193. areaInfo = new AreaInfo();
  194. }
  195. return areaInfo;
  196. }
  197. /**
  198. * 获取SP信息
  199. * @param orderInfo
  200. * @return
  201. * @throws Exception
  202. */
  203. private SPInfo getSPInfo(OrderInfo orderInfo) throws Exception {
  204. SPInfo spInfo = null;
  205. if (StringUtils.isEmpty(orderInfo.getSpid()))
  206. spInfo = this.spDao.findDefaultByCP(orderInfo.getCpid());
  207. else {
  208. spInfo = this.spDao.findById(orderInfo.getSpid());
  209. }
  210. if (spInfo == null) {
  211. throw new BusinessException("5305", "产品标识符无效", new String[0]);
  212. }
  213. orderInfo.setSpid(spInfo.getSpid());
  214. orderInfo.setMutex(spInfo.getMutex());
  215. orderInfo.setRelationSp(spInfo.getRelationSp());
  216. orderInfo.setPaytype(spInfo.getPaytype());
  217. orderInfo.setErrorhandle(spInfo.getErrorhandle());
  218. return spInfo;
  219. }
  220. /**
  221. * 订购
  222. * @param orderInfo
  223. * @throws Exception
  224. */
  225. public void order(OrderInfo orderInfo) throws Exception {
  226. String errorcode = "0";
  227. String errorinfo = "";
  228. String result = "0";
  229. try {
  230. List<OrderInfo> listOrderInfo = orderDao.findByUser(orderInfo.getUserid());
  231. if (listOrderInfo != null && listOrderInfo.size() > 0) {
  232. if (!StringUtils.isEmpty(orderInfo.getMutex())) {
  233. String[] mutexSpids = orderInfo.getMutex().trim().split(",");
  234. for (String mutexSpid : mutexSpids) {
  235. for (OrderInfo oldOrderInfo : listOrderInfo) {
  236. if (oldOrderInfo.getSpid().equals(orderInfo.getSpid())
  237. && oldOrderInfo.getStatus() == 0) {
  238. throw new BusinessException("9010", "您已订购,请不要重复订购!", new String[0]);
  239. }
  240. if (oldOrderInfo.getSpid().equals(orderInfo.getSpid())
  241. && oldOrderInfo.getStatus() == 1) {
  242. throw new BusinessException("9010", "您本月已退订,请下月再订购!", new String[0]);
  243. }
  244. if (oldOrderInfo.getSpid().equals(mutexSpid)) {
  245. throw new BusinessException("9011", "您已订购同类产品!", new String[0]);
  246. }
  247. }
  248. }
  249. } else {
  250. if (listOrderInfo != null && listOrderInfo.size() != 0) {
  251. for (OrderInfo oldOrderInfo : listOrderInfo) {
  252. if (oldOrderInfo.getSpid().equals(orderInfo.getSpid())
  253. && oldOrderInfo.getStatus() == 0) {
  254. throw new BusinessException("9010", "您已订购,请不要重复订购!", new String[0]);
  255. }
  256. if (oldOrderInfo.getSpid().equals(orderInfo.getSpid())
  257. && oldOrderInfo.getStatus() == 1) {
  258. throw new BusinessException("9010", "您本月已退订,请下月再订购!", new String[0]);
  259. }
  260. }
  261. }
  262. }
  263. }
  264. //不是白名单
  265. if (!this.blackWhiteDao.isWhiteUser(orderInfo.getUserid(), orderInfo.getCpid())) { //不是白名单
  266. if(orderInfo.getPaytype() == 1){
  267. boolean hasinvoke = true;
  268. if("0".equals(dictionaryDao.getValue("csnewSwitch"))){
  269. hasinvoke = false;
  270. String whiteUserList = dictionaryDao.getValue("csnewList");
  271. if(whiteUserList != null && !"".equals(whiteUserList.trim())){
  272. String [] array = whiteUserList.trim().split("\\|");
  273. for(String tmpuser : array){
  274. if(orderInfo.getUserid().equals(tmpuser)){
  275. hasinvoke = true;
  276. break;
  277. }
  278. }
  279. }
  280. }
  281. if(!hasinvoke){
  282. throw new BusinessException("9013", "非畅视白名单", new String[0]);
  283. }
  284. EcbProductInfo ecbProductInfo = this.queryPorduct(orderInfo.getUserid(), orderInfo.getCpid(),orderInfo.getSpid());
  285. log.debug("HANDLEbean==>"+JsonUtil.objectToJson(ecbProductInfo));
  286. /**
  287. * 用户当前订购资费的状态:
  288. 0:用户当前无订购可订购(跟cBSS前台生成规则一致)
  289. 1:用户当前有订购可退订
  290. 2:用户当前有订购不可退订
  291. 3:用户当前有产品可订购
  292. */
  293. if(!"3".equals(ecbProductInfo.getDiscntOrderState()) && !"0".equals(ecbProductInfo.getDiscntOrderState())){
  294. throw new BusinessException("9013", "您不能订购此业务!", new String[0]);
  295. }
  296. result = ecbService.order(orderInfo.getUserid(), orderInfo.getCpid(),orderInfo.getSpid(),ecbProductInfo);
  297. ecbDiscntNewDao.order(ecbProductInfo,orderInfo);
  298. }else{
  299. throw new BusinessException("9012", "该产品不支持订购操作", new String[0]);
  300. }
  301. }
  302. String currentTime = this.sysDao.getCurrentTime();
  303. if (orderInfo.getOrdertime() == null) {
  304. orderInfo.setOrdertime(currentTime);
  305. }
  306. if (orderInfo.getEffecttime() == null) {
  307. orderInfo.setEffecttime(currentTime);
  308. }
  309. if (!result.equals("0") && orderInfo.getErrorhandle() == 0 ) {
  310. orderInfo.setOrderstatus(7);
  311. orderInfo.setIsexperience(1);
  312. orderInfo.setShowstatus("0");
  313. }
  314. //添加订购关系
  315. this.orderDao.order(orderInfo);
  316. } catch (Exception e) {
  317. log.error("userid:"+orderInfo.getUserid()+"订购出现异常,"+e);
  318. e.printStackTrace();
  319. if ((e instanceof BusinessException)) {
  320. errorcode = ((BusinessException) e).getCode();
  321. errorinfo = ((BusinessException) e).getMessage();
  322. if(errorinfo.length()>200){
  323. errorinfo = errorinfo.substring(0, 200);
  324. }
  325. }else{
  326. errorcode = "8000";
  327. errorinfo ="系统忙,"+e.getMessage();
  328. }
  329. if(!errorcode.equals("9999")){
  330. throw e;
  331. }
  332. } finally {
  333. saveLog(orderInfo, errorcode, errorinfo);
  334. }
  335. }
  336. /**
  337. * 退订验证
  338. * @param orderInfo
  339. * @throws Exception
  340. */
  341. public void checkCancel(OrderInfo orderInfo) throws Exception {
  342. checkSign(orderInfo);
  343. checkUserid(orderInfo);
  344. CPInfo cpInfo = ConfigUtil.getCPInfo(orderInfo.getCpid(), null);
  345. if (cpInfo == null) {
  346. throw new BusinessException("7005", "CP标识无效", new String[0]);
  347. }
  348. SPInfo spInfo = getSPInfo(orderInfo);
  349. if (spInfo.getCancancelorder() == 1 && StringUtils.isEmpty(orderInfo.getCancelchannel())) {
  350. throw new BusinessException("9011", "该产品不支持退订操作", new String[0]);
  351. }
  352. if (this.orderDao.hasTiyanValid(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid()))
  353. throw new BusinessException("9015", "该产品体验期未结束不支持退订操作", new String[0]);
  354. }
  355. /**
  356. * 退订
  357. * @param orderInfo
  358. * @throws Exception
  359. */
  360. public void cancel(OrderInfo orderInfo) throws Exception {
  361. String errorcode = "0";
  362. String errorinfo = "";
  363. try {
  364. List<OrderInfo> listOrderInfo = orderDao.findByUser(orderInfo.getUserid());
  365. if (listOrderInfo == null || listOrderInfo.size() == 0) {
  366. throw new BusinessException("9016", "退订失败,无该用户订购关系或者已失效", new String[0]);
  367. }
  368. boolean isHasOrder = false;
  369. for (OrderInfo oldOrderInfo : listOrderInfo) {
  370. if (orderInfo.getSpid().equals(oldOrderInfo.getSpid())) {
  371. orderInfo.setOrdertime(oldOrderInfo.getOrdertime());
  372. if(!StringUtils.isEmpty(oldOrderInfo.getEndtime())){
  373. orderInfo.setEndtime(oldOrderInfo.getEndtime());
  374. }
  375. if (oldOrderInfo.getStatus() != 0) {
  376. throw new BusinessException("9017", "退订失败,该用户已退订该产品", new String[0]);
  377. }
  378. isHasOrder = true;
  379. break;
  380. }
  381. }
  382. if (!isHasOrder) {
  383. throw new BusinessException("9018", "退订失败,该用户没有订购该产品或者已失效", new String[0]);
  384. }
  385. //不是白名单
  386. if (!this.blackWhiteDao.isWhiteUser(orderInfo.getUserid(), orderInfo.getCpid())) {
  387. if(orderInfo.getPaytype() == 1){
  388. EcbProductInfo ecbProductInfo = this.queryPorduct(orderInfo.getUserid(), orderInfo.getCpid(),orderInfo.getSpid());
  389. log.debug("HANDLEbean==>"+JsonUtil.objectToJson(ecbProductInfo));
  390. /**
  391. * 用户当前订购资费的状态:
  392. 0:用户当前无订购可订购(跟cBSS前台生成规则一致)
  393. 1:用户当前有订购可退订
  394. 2:用户当前有订购不可退订
  395. 3:用户当前有产品可订购
  396. */
  397. if(!"1".equals(ecbProductInfo.getDiscntOrderState())){
  398. throw new BusinessException("9013", "您不能退订此业务!", new String[0]);
  399. }
  400. errorcode = ecbService.cancelOrder(orderInfo.getUserid(), orderInfo.getCpid(),orderInfo.getSpid(),orderInfo.getOrdertime(),ecbProductInfo);
  401. ecbDiscntNewDao.cancel(ecbProductInfo,orderInfo);
  402. }else {
  403. throw new BusinessException("9012", "该产品不支持退订操作", new String[0]);
  404. }
  405. }
  406. String currentTime = this.sysDao.getCurrentTime();
  407. if (orderInfo.getCanceltime() != null) {
  408. orderInfo.setEndtime(getEndTime(orderInfo.getCanceltime()));
  409. } else {
  410. orderInfo.setCanceltime(currentTime);
  411. }
  412. if (orderInfo.getEffecttime() == null) {
  413. orderInfo.setEffecttime(currentTime);
  414. }
  415. if (orderInfo.getEndtime() == null) {
  416. orderInfo.setEndtime(this.sysDao.getEndDayOfCurrentMonth());
  417. }
  418. //退订
  419. this.orderDao.cancelOrder(orderInfo);
  420. } catch (Exception e) {
  421. e.printStackTrace();
  422. log.error("userid:"+orderInfo.getUserid()+"退订出现异常,"+e);
  423. if ((e instanceof BusinessException)) {
  424. errorcode = ((BusinessException) e).getCode();
  425. errorinfo = ((BusinessException) e).getMessage();
  426. if(errorinfo.length()>200){
  427. errorinfo = errorinfo.substring(0, 200);
  428. }
  429. }else{
  430. errorcode = "8000";
  431. errorinfo ="系统忙,"+e.getMessage();
  432. }
  433. if(!errorcode.equals("9999")){
  434. throw e;
  435. }
  436. } finally {
  437. saveLog(orderInfo, errorcode, errorinfo);
  438. }
  439. }
  440. public String getEndTime(String endTimeStr) throws ParseException {
  441. Calendar calendar = Calendar.getInstance();
  442. Date date = DateUtils.parseDate(endTimeStr.substring(0, 8), new String[] { "yyyyMMdd" });
  443. calendar.setTime(date);
  444. String day = calendar.getActualMaximum(Calendar.DAY_OF_MONTH) + "";
  445. String year = calendar.get(Calendar.YEAR) + "";
  446. String month = calendar.get(Calendar.MONTH) + 1 < 10 ? "0" + (calendar.get(Calendar.MONTH) + 1)
  447. : calendar.get(Calendar.MONTH) + 1 + "";
  448. return year + month + day + "235959";
  449. }
  450. /**
  451. * 写日志
  452. * @param orderInfo
  453. * @param errorcode
  454. * @param errorinfo
  455. */
  456. public void saveLog(OrderInfo orderInfo, String errorcode, String errorinfo) {
  457. OrderLog orderLog = new OrderLog();
  458. orderLog.setApptype(orderInfo.getApptype());
  459. orderLog.setArea(orderInfo.getArea());
  460. orderLog.setChannel(orderInfo.getOrderchannel());
  461. orderLog.setOrderstatus(orderInfo.getOrderstatus());
  462. orderLog.setStatus(orderInfo.getStatus());
  463. orderLog.setCpid(orderInfo.getCpid());
  464. orderLog.setIsexperience(orderInfo.getIsexperience());
  465. orderLog.setOrdertype(orderInfo.getOrdertype() + "");
  466. orderLog.setProvince(orderInfo.getProvince());
  467. orderLog.setArea(orderInfo.getArea());
  468. orderLog.setSpid(orderInfo.getSpid());
  469. orderLog.setUserid(orderInfo.getUserid());
  470. orderLog.setErrorcode(errorcode);
  471. orderLog.setErrorinfo(errorinfo);
  472. if(!orderInfo.getTimes().isEmpty()){
  473. orderLog.setTimes((System.currentTimeMillis()-NumberUtils.toLong(orderInfo.getTimes()))+"");
  474. }
  475. this.orderLogDao.addOrderLog(orderLog);
  476. }
  477. /**
  478. * 查询ECB产品信息
  479. * @param userid
  480. * @param cpid
  481. * @param spid
  482. * @return
  483. * @throws Exception
  484. */
  485. public EcbProductInfo queryPorduct(String userid, String cpid, String spid) throws Exception {
  486. EcbProductInfo resEcbProductInfo = null;
  487. String ecbProductUrl = dictionaryDao.getValue("ecbProductUrl");
  488. String result = URLUtil.get(ecbProductUrl+"?userid=" + userid + "&cpid=" +
  489. cpid + "&spid=" + spid, NumberUtils.toInt(this.dictionaryDao.getValue("ecbTimeout")));
  490. //String result = "{\"transIdo\":\"20190830120302278\",\"errorInfo\":\"成功\",\"requeststr\":\"\",\"resultCode\":\"0\",\"code\":\"0000\",\"userProductInfo\":{\"productInfos\":[{\"productId\":\"89016266\",\"productName\":\"4G套餐-30元套餐(苏湘川甘新)\",\"packageCode\":\"51947015\",\"packageName\":\"畅视产品资费包\",\"discntCode\":\"8244270\",\"discntName\":\"标清畅视包月套餐【每月30元】\",\"discntFee\":\"3000\",\"discntStartDate\":\"20190830120302\",\"discntEndDate\":\"20501231235959\",\"discntOrderState\":\"0\",\"discntValue\":\"0\"},{\"productId\":\"89016266\",\"productName\":\"4G套餐-30元套餐(苏湘川甘新)\",\"packageCode\":\"51947015\",\"packageName\":\"畅视产品资费包\",\"discntCode\":\"8302733\",\"discntName\":\"畅视20元包月套餐\",\"discntFee\":\"2000\",\"discntStartDate\":\"20190830120302\",\"discntEndDate\":\"20191231235959\",\"discntOrderState\":\"0\",\"discntValue\":\"1\"},{\"productId\":\"89016266\",\"productName\":\"4G套餐-30元套餐(苏湘川甘新)\",\"packageCode\":\"51947015\",\"packageName\":\"畅视产品资费包\",\"discntCode\":\"61125230\",\"discntName\":\"畅视业务60元40G定向流量包\",\"discntFee\":\"6000\",\"discntStartDate\":\"20190830120302\",\"discntEndDate\":\"20501231120000\",\"discntOrderState\":\"0\",\"discntValue\":\"1\"}],\"userProductId\":\"89016266\",\"userProductName\":\"4G套餐-30元套餐(苏湘川甘新)\"},\"responsestr\":\"\"}";
  491. log.info("result====" + userid + ":" + result);
  492. EcbResponseBean infos = (EcbResponseBean)JsonUtil.jsonToBean(result, EcbResponseBean.class);
  493. log.info("infos====" + userid + ":" + JsonUtil.objectToJson(infos));
  494. if (!infos.getResultCode().equals("0")) {
  495. throw new BusinessException(infos.getResultCode(), "查询产品信息未成功,"+infos.getErrorInfo(), new String[0]);
  496. }
  497. if (infos.getUserProductInfo() == null) {
  498. throw new BusinessException("9036", "无产品信息", new String[0]);
  499. }
  500. if ((infos.getUserProductInfo().getProductInfos() == null) ||
  501. (infos.getUserProductInfo().getProductInfos().size() == 0)) {
  502. throw new BusinessException("9034", "资费信息信息不全", new String[0]);
  503. }
  504. List<EcbProductInfo> infoList = new ArrayList<EcbProductInfo>();
  505. List<EcbProductInfo> proinfos = infos.getUserProductInfo().getProductInfos();
  506. for (EcbProductInfo ecbProductInfo : proinfos) {
  507. if ("51947015".equals(ecbProductInfo.getPackageCode()) && "61125230".equals(ecbProductInfo.getDiscntCode())){
  508. infoList.add(ecbProductInfo);
  509. }
  510. }
  511. log.info("infoList====" + userid + ":" + JsonUtil.objectToJson(infoList));
  512. if (infoList == null || infoList.size() == 0) {
  513. throw new BusinessException("9035", "未查询出用户资费信息", new String[0]);
  514. }else{
  515. resEcbProductInfo = infoList.get(0);
  516. }
  517. return resEcbProductInfo;
  518. }
  519. }