7cf0d80faaff55eb205a558a09556c18b5643277.svn-base 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. package com.chinacreator.videoalliance.order.service;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.chinacreator.common.exception.BusinessException;
  4. import com.chinacreator.common.util.MD5;
  5. import com.chinacreator.videoalliance.common.bean.AreaInfo;
  6. import com.chinacreator.videoalliance.common.dao.DictionaryDao;
  7. import com.chinacreator.videoalliance.common.util.AreaUtil;
  8. import com.chinacreator.videoalliance.common.util.ConfigUtil;
  9. import com.chinacreator.videoalliance.order.bean.*;
  10. import com.chinacreator.videoalliance.order.dao.*;
  11. import com.chinacreator.videoalliance.order.util.BackAESUtil;
  12. import com.chinacreator.videoalliance.order.util.URLUtil;
  13. import org.apache.commons.lang.math.NumberUtils;
  14. import org.apache.commons.lang.time.DateUtils;
  15. import org.apache.log4j.Logger;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.stereotype.Component;
  18. import org.springframework.util.StringUtils;
  19. import java.sql.SQLException;
  20. import java.text.ParseException;
  21. import java.text.SimpleDateFormat;
  22. import java.util.*;
  23. /**
  24. * 后向产品异步处理
  25. * @author xu.zhou
  26. * @date 20200817
  27. */
  28. @Component
  29. public class BackBusiOrderAsynService_copy {
  30. private static Logger busilog = Logger.getLogger("youtuorder");
  31. private static Logger log = Logger.getLogger("orderpush");
  32. @Autowired
  33. private BlackWhiteDao blackWhiteDao;
  34. @Autowired
  35. private SPDao spDao;
  36. @Autowired
  37. private BackBusiOrderDao backBusiOrderDao;
  38. @Autowired
  39. private ShareOrderService shareOrderService;
  40. @Autowired
  41. private BackShareOrderDao backShareOrderDao;
  42. @Autowired
  43. private OrderDao orderDao;
  44. @Autowired
  45. private DictionaryDao dictionaryDao;
  46. /**
  47. * 验证及解密手机号码
  48. * @param orderInfo
  49. * @throws Exception
  50. */
  51. private void checkUserid(OrderInfo orderInfo) throws Exception {
  52. String userid = orderInfo.getUserid();
  53. if ((StringUtils.isEmpty(userid)) || ("null".equals(userid)))
  54. throw new BusinessException("9051", "手机号码无效", new String[0]);
  55. if (!isValid(userid)) {
  56. if(userid.length() >10){
  57. userid = ConfigUtil.decrypt(userid, orderInfo.getCpid());
  58. userid = ConfigUtil.getUserid(userid, orderInfo.getCpid());
  59. }
  60. }
  61. if (isValid(userid)) {
  62. if(userid.length() < 11){//QQ号
  63. //非指定渠道传入qq号码
  64. if(!"TX20_twback_old".equals(orderInfo.getChannel()) && !"TX20_twback".equals(orderInfo.getChannel())){
  65. throw new BusinessException("9051", "手机号码无效", new String[0]);
  66. }
  67. }
  68. }else{
  69. throw new BusinessException("9051", "手机号码无效", new String[0]);
  70. }
  71. orderInfo.setUserid(userid);
  72. }
  73. /**
  74. * 支持QQ号与手机号
  75. * zzb 2020/02/18
  76. * @throws BusinessException
  77. */
  78. private boolean isValid(String usermob) throws BusinessException{
  79. if (usermob == null) {
  80. return false;
  81. }
  82. usermob = usermob.replaceAll("[\\s-]", "");
  83. if(!usermob.matches("^[0-9]*$")){
  84. return false;
  85. }
  86. return true;
  87. }
  88. /**
  89. * 验证签名是否有效
  90. * @param orderInfo
  91. * @param deuserid 加密的手机号码
  92. * @throws Exception
  93. */
  94. public void checkSignChannel(OrderInfo orderInfo, String deuserid) throws Exception {
  95. String sign = orderInfo.getSignature();
  96. if (StringUtils.isEmpty(sign)) {
  97. throw new BusinessException("9054", "signature校验失败");
  98. }
  99. Map cpSpBean = backBusiOrderDao.getCpSp(orderInfo.getCpid(),orderInfo.getSpid());
  100. String pwd = cpSpBean.get("NETPWD").toString();
  101. //Md5(orderid+cpid+spid+userid+type+timestamp+pwd)
  102. String localSign = MD5.MD5Encode(orderInfo.getOrderid() + orderInfo.getCpid()
  103. + orderInfo.getSpid() + deuserid + orderInfo.getTimestamp() + pwd);
  104. if (!localSign.equals(orderInfo.getSignature())) {
  105. throw new BusinessException("9054", "signature校验失败");
  106. }
  107. }
  108. /**
  109. * 订购前验证
  110. * @param orderInfo
  111. * @throws Exception
  112. */
  113. public void checkOrder(OrderInfo orderInfo, String deuserid) throws Exception {
  114. checkCpSpInfo(orderInfo);
  115. checkSignChannel(orderInfo,deuserid);
  116. checkUserid(orderInfo);
  117. String userid = orderInfo.getUserid();
  118. //判断用户黑名单
  119. if (this.blackWhiteDao.isBlackUser(userid, orderInfo.getCpid())) {
  120. throw new BusinessException("9010", "用户为黑名单用户", new String[0]);
  121. }
  122. //获取地市信息
  123. AreaInfo areaInfo = getAreaInfo(userid);
  124. orderInfo.setProvince(areaInfo.getProvince());
  125. orderInfo.setArea(areaInfo.getArea());
  126. if(orderInfo.getProvince() != null && orderDao.isOpen(orderInfo.getSpid(),orderInfo.getCpid(),orderInfo.getProvince())){ // status 为2 表示省份尚未开通
  127. if(!this.blackWhiteDao.isWhiteUserBySpid(userid, orderInfo.getCpid(), orderInfo.getSpid())){//判断用户是否白名单,是则流程继续
  128. throw new BusinessException("9011", "省份尚未开通此业务,敬请期待!");
  129. }
  130. }
  131. }
  132. /**
  133. * 验证业务参数是否合法
  134. * @param orderInfo
  135. * @throws Exception
  136. */
  137. private void checkCpSpInfo(OrderInfo orderInfo)throws Exception {
  138. List<HashMap> confList = backBusiOrderDao.getBackBusiConf(orderInfo.getCpid(), orderInfo.getSpid());
  139. if(confList == null || confList.size() == 0){
  140. throw new BusinessException("9058", "无业务配置信息", new String[0]);
  141. }
  142. HashMap confHm = confList.get(0);
  143. //判断是否配置netdays参数
  144. if(("2".equals(confHm.get("BUSITYPE")) || "3".equals(confHm.get("BUSITYPE")))
  145. && (confHm.get("NETDAYS") == null || "".equals(confHm.get("NETDAYS")))){
  146. throw new BusinessException("9058", "无业务配置信息,NETDAYS", new String[0]);
  147. }
  148. if(!"1".equals(confHm.get("BUSITYPE")) && orderInfo.getUserid().length() != 11){
  149. throw new BusinessException("9051", "非纯免流产品只支持11位手机号码,USERID:"+orderInfo.getUserid()+", SPID:"+orderInfo.getSpid(), new String[0]);
  150. }
  151. getSPInfo(orderInfo); //设置SP其他信息
  152. }
  153. /**
  154. * 获取手机号码的地市信息
  155. * @param userid
  156. * @return
  157. * @throws Exception
  158. */
  159. private AreaInfo getAreaInfo(String userid) throws Exception {
  160. AreaInfo areaInfo = AreaUtil.getAreaInfoByUserid(userid);
  161. if (areaInfo == null) {
  162. areaInfo = new AreaInfo();
  163. }
  164. return areaInfo;
  165. }
  166. /**
  167. * 设置SP相关信息
  168. * @param orderInfo
  169. * @throws Exception
  170. */
  171. private void getSPInfo(OrderInfo orderInfo) throws Exception {
  172. SPInfo spInfo = this.spDao.findById(orderInfo.getSpid());
  173. if (spInfo != null) {
  174. orderInfo.setSpid(spInfo.getSpid());
  175. orderInfo.setMutex(spInfo.getMutex());
  176. orderInfo.setRelationSp(spInfo.getRelationSp());
  177. orderInfo.setPaytype(spInfo.getPaytype());
  178. orderInfo.setErrorhandle(spInfo.getErrorhandle());
  179. }
  180. }
  181. /**
  182. * 填充BackBusiOrderRec
  183. * @param orderInfo
  184. * @return
  185. * @throws Exception
  186. */
  187. private BackBusiOrderRec getOrderRecBean(OrderInfo orderInfo) throws Exception{
  188. BackBusiOrderRec bean = new BackBusiOrderRec();
  189. bean.setLogid(orderInfo.getReorderid());
  190. bean.setId(backBusiOrderDao.generateID());
  191. bean.setArea(orderInfo.getArea());
  192. bean.setCpid(orderInfo.getCpid());
  193. bean.setSpid(orderInfo.getSpid());
  194. bean.setOrderid(orderInfo.getOrderid());
  195. bean.setProvince(orderInfo.getProvince());
  196. bean.setUserid(orderInfo.getUserid());
  197. bean.setChannel(orderInfo.getOrderchannel());
  198. bean.setSubchannel((orderInfo.getSubchannel() != null && !"null".equals(orderInfo.getSubchannel())) ? orderInfo.getSubchannel() : "");
  199. bean.setVipstatus("4"); //默认设置为不赠送
  200. bean.setType(orderInfo.getType()+"");
  201. if("1".equals(bean.getType())){//退订
  202. bean.setVipstatus(""); //设置为空
  203. }
  204. return bean;
  205. }
  206. /**
  207. * 获取endtime
  208. * @param orderInfo
  209. * @return
  210. */
  211. private String getEndTime(OrderInfo orderInfo)throws Exception{
  212. String endtime = "";
  213. String currEndtime = "";
  214. Map reMap = this.hasEffect(orderInfo);
  215. if((Boolean)reMap.get("hasEffect")){ //存在有效订购关系
  216. Map currOrderInfo = (Map)reMap.get("currOrderInfo");
  217. currEndtime = (String)currOrderInfo.get("ENDTIME");
  218. }
  219. //[{PWD=kijkfds, NETDAYS=31, CHANNEL=test_01, NETDAYS=2, SPID=1168, BUSITYPE=3, CPID=youtu}]
  220. HashMap confHm = backBusiOrderDao.getBackBusiConf(orderInfo.getCpid(), orderInfo.getSpid()).get(0);
  221. //String busiType = confHm.get("BUSITYPE")+"";
  222. //免流或免流+会员两种产品要以netdays参数来确定endtime
  223. if("2".equals(confHm.get("BUSITYPE")) || "3".equals(confHm.get("BUSITYPE"))){
  224. if(currEndtime != null && !"".equals(currEndtime)){
  225. endtime = backBusiOrderDao.endtimeParamDay(confHm.get("NETDAYS")+"", currEndtime);
  226. }else{
  227. endtime = backBusiOrderDao.currParamDay(confHm.get("NETDAYS")+"");
  228. }
  229. }
  230. return endtime;
  231. }
  232. /**
  233. * 业务办理
  234. * @param orderInfo
  235. * @return
  236. * @throws Exception
  237. */
  238. public String orderBusi(OrderInfo orderInfo)throws Exception{
  239. if( 0 == orderInfo.getType()){//订购
  240. orderInfo.setType(0); ////设置为订购
  241. return this.order(orderInfo);
  242. }else{
  243. throw new BusinessException("8000", "不支持操作类型,"+orderInfo.getType(), new String[0]);
  244. }
  245. }
  246. /**
  247. * 判断结束时间是否大于当前时间
  248. * @param endTime
  249. * @param currTime
  250. * @return
  251. * @throws Exception
  252. */
  253. private boolean compareDate(String endTime, String currTime)throws Exception{
  254. boolean result = false;
  255. SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
  256. Date dateCurrTime = sdf.parse(currTime);
  257. Date dateEndTime = sdf.parse(endTime);
  258. //dateEndTime小于dateCurrTime返回-1,dateEndTime大于dateCurrTime返回1,相等返回0
  259. if(dateEndTime.compareTo(dateCurrTime)>0){
  260. result = true;
  261. }
  262. return result;
  263. }
  264. /**
  265. * 订购业务
  266. * @param orderInfo
  267. * @return
  268. */
  269. public String order(OrderInfo orderInfo)throws Exception{
  270. String errorcode = "-1";
  271. String errorinfo = "";
  272. String result = "-1";
  273. BackBusiOrderRec bean = getOrderRecBean(orderInfo);
  274. try {
  275. orderInfo.setType(0); //设置为订购
  276. List<HashMap> confList = backBusiOrderDao.getBackBusiConf(orderInfo.getCpid(), orderInfo.getSpid());
  277. //[{PWD=kijkfds, CHANNEL=test_01, VIPTYPE=2, VIPPOOL=vip_yout, SPID=1168, BUSITYPE=3, CPID=youtu}]
  278. HashMap confHm = confList.get(0);
  279. String busiType = confHm.get("BUSITYPE")+"";
  280. //是否为复合产品,0是,为空或为1时不是
  281. String hasfh = confHm.get("HASFH") == null ? "": confHm.get("HASFH")+"";
  282. //调能力平台标识:0调能力平台并以结果落订购关系,1调能力平台其结果不影响订购关系,为空时不调能力平台
  283. String hasshare = confHm.get("HASSHARE") == null ? "": confHm.get("HASSHARE")+"";
  284. bean.setBusitype(busiType);
  285. this.hasDupliOrderid(orderInfo);//判断是否重复订单ID
  286. this.hasMutual(orderInfo); //已办理互斥业务
  287. String newEndtime = ""; //业务结束时间
  288. String starttime = ""; //业务开始时间
  289. Map<String, String> resMap = this.getBusiTime(orderInfo);
  290. newEndtime = resMap.get("endtime");
  291. starttime = resMap.get("starttime");
  292. //赠送会员状态,0成功,1待赠送,2赠送中,3失败
  293. //bean.setVipstatus("1");
  294. //办理结果编码,0成功,1待处理,2处理中,其他为异常
  295. bean.setResultcode("2");
  296. bean.setResultinfo("处理中");
  297. if("1".equals(busiType)){ //会员
  298. bean.setVipstatus("1");
  299. bean.setStarttime("");
  300. bean.setEndtime("");
  301. backBusiOrderDao.addOrderRec(bean); //添加订购记录
  302. }else if("2".equals(busiType)){ //免流
  303. //指定产品要先办理依赖业务才能受理
  304. /**
  305. if("200".equals(orderInfo.getSpid()) || "201".equals(orderInfo.getSpid())){
  306. List<OrderInfo> orderlist = orderDao.findByUser(orderInfo.getUserid(),orderInfo.getCpid());
  307. if(orderlist.size()>0 && orderInfo != null){
  308. List<String> spidlist = new ArrayList<String>();
  309. for(OrderInfo oi : orderlist){
  310. String spid = oi.getSpid();
  311. spidlist.add(spid);
  312. }
  313. //联通bilibili定向流量5GB包(后向),没办理979
  314. if("200".equals(orderInfo.getSpid()) && !spidlist.contains("979")){
  315. throw new BusinessException("8051","您未订购相应的产品,不能办理此加油包");
  316. }
  317. //联通爱奇艺定向流量5GB包(后向),没办理1018也没办理1017
  318. if("201".equals(orderInfo.getSpid()) && !spidlist.contains("1018") && !spidlist.contains("1017")){
  319. throw new BusinessException("8051","您未订购相应的产品,不能办理此加油包");
  320. }
  321. }else{
  322. throw new BusinessException("8051","您未订购相应的产品,不能办理此加油包");
  323. }
  324. }
  325. **/
  326. bean.setVipstatus("4"); //设置为不赠送
  327. bean.setStarttime(starttime);
  328. bean.setEndtime(newEndtime);
  329. backBusiOrderDao.addOrderRec(bean); //添加订购记录
  330. orderInfo.setEndtime(newEndtime);
  331. //设置订购时间
  332. this.setOrderTime(orderInfo);
  333. //调能力平台
  334. this.shareOrder(orderInfo, hasshare);
  335. backBusiOrderDao.order(orderInfo); //新增或更新订购关系
  336. }else if("3".equals(busiType)){ //会员+免流
  337. bean.setVipstatus("1");
  338. bean.setEndtime(newEndtime);
  339. bean.setStarttime(starttime);
  340. if("TX20_twback".equals(orderInfo.getOrderchannel())){//拓维订购会员+免流业务
  341. bean.setResultcode("0");
  342. bean.setResultinfo("拓维触发送会员");
  343. bean.setVipendtime(newEndtime); //设置领取会员的最后时间,默认为订单的endtime
  344. backBusiOrderDao.addOrderRec(bean); //添加订购记录
  345. orderInfo.setEndtime(newEndtime);
  346. //设置订购时间
  347. this.setOrderTime(orderInfo);
  348. bean.setVipstatus("4"); //设置为不赠送,由拓维发短信给用户,由用户自己去领取
  349. //调能力平台
  350. this.shareOrder(orderInfo, hasshare);
  351. backBusiOrderDao.order(orderInfo); //新增或更新订购关系
  352. //更新其他未领取会员的最后领取时间
  353. backBusiOrderDao.updVipEndtime(bean.getUserid(),newEndtime);
  354. }else{
  355. backBusiOrderDao.addOrderRec(bean); //添加订购记录
  356. orderInfo.setEndtime(newEndtime);
  357. //设置订购时间
  358. this.setOrderTime(orderInfo);
  359. //调能力平台
  360. this.shareOrder(orderInfo, hasshare);
  361. backBusiOrderDao.order(orderInfo); //新增或更新订购关系
  362. }
  363. }
  364. result = "0";
  365. errorcode = "0";
  366. errorinfo = "成功";
  367. } catch (Exception e) {
  368. e.printStackTrace();
  369. busilog.error("userid:"+orderInfo.getUserid()+"订购出现异常,"+e);
  370. if ((e instanceof BusinessException)) {
  371. errorcode = ((BusinessException) e).getCode();
  372. errorinfo = ((BusinessException) e).getMessage();
  373. }else{
  374. errorcode = "8000";
  375. errorinfo ="系统忙,"+e.getMessage();
  376. }
  377. if(errorinfo != null && errorinfo.length()>2000){
  378. errorinfo = errorinfo.substring(0, 2000);
  379. }
  380. throw e;
  381. } finally {
  382. bean.setResultcode(errorcode);
  383. bean.setResultinfo(errorinfo);
  384. if(bean.getResultinfo().indexOf("重复订单") == -1){
  385. try{
  386. backBusiOrderDao.addOrderRec(bean); //添加订购记录
  387. }catch(Exception e){
  388. busilog.info(orderInfo.getUserid()+",更新订购记录表出现异常,"+e.getMessage());
  389. }
  390. //如果是上海权益的订单,要更新到上海权益订购表
  391. if("shanghaiqy".equals(orderInfo.getOrderchannel())){
  392. backBusiOrderDao.updShInPaInfo(bean);
  393. }
  394. }
  395. saveLog(orderInfo, errorcode, errorinfo);
  396. //调9楼接口往省里推送订购关系
  397. try {
  398. if ("0".equals(errorcode)){
  399. if (backBusiOrderDao.orderPush(bean.getCpid(),bean.getSpid())){
  400. String serialid = bean.getId();
  401. if (serialid!=null&&serialid.length()>20){
  402. serialid=serialid.substring(0,20);
  403. }
  404. orderPush(serialid,bean.getUserid());
  405. }
  406. }
  407. } catch (SQLException e) {
  408. e.printStackTrace();
  409. log.error("调9楼接口往省里推送订购关系出现异常"+e.getMessage());
  410. }
  411. }
  412. return result;
  413. }
  414. /**
  415. *
  416. * @param serialid 流水号
  417. * @param usermob 手机号
  418. * @throws Exception
  419. */
  420. public void orderPush(String serialid,String usermob) throws Exception {
  421. String busiid="order";
  422. String url = dictionaryDao.getValue("orderPushUrl");
  423. if (org.apache.commons.lang.StringUtils.isEmpty(url)){
  424. throw new BusinessException("8005","url为空");
  425. }
  426. String parmas = dictionaryDao.getValue("orderPushParmas");
  427. busilog.info("9楼提供的数据=========="+parmas);
  428. if (StringUtils.isEmpty(parmas)){
  429. throw new BusinessException("8006","参数为空");
  430. }
  431. Map<String,String> paramsMap = JSONObject.parseObject(parmas, Map.class);
  432. String cpid=paramsMap.get("cpid");
  433. String productid=paramsMap.get("productid");//产品id
  434. String channel=paramsMap.get("channel");//渠道
  435. String key=paramsMap.get("key");//密钥
  436. Map<String,Object> dataMap=new HashMap<String,Object>();
  437. dataMap.put("busiid",busiid);
  438. dataMap.put("serialid",serialid);
  439. dataMap.put("usermob",usermob);
  440. dataMap.put("productid",productid);
  441. dataMap.put("channel",channel);
  442. String dataJson = JSONObject.toJSONString(dataMap);
  443. String data= BackAESUtil.encrypt(dataJson, key);
  444. Map<String,Object> paramMap=new HashMap<String,Object>();
  445. paramMap.put("cpid",cpid);
  446. paramMap.put("data",data);
  447. String params = JSONObject.toJSONString(paramMap);
  448. String response = URLUtil.postJson(url, params);
  449. if (StringUtils.isEmpty(response)){
  450. throw new BusinessException("9000","9楼接口调用失败"+usermob+"======"+serialid);
  451. }
  452. log.info("调9楼接口结果:"+response+"==userid"+usermob+"==serialid"+serialid);
  453. }
  454. /**
  455. * 设置当前时间
  456. * @param orderInfo
  457. * @throws Exception
  458. */
  459. private void setOrderTime(OrderInfo orderInfo) throws Exception{
  460. String currtime = this.backBusiOrderDao.getCurrentTime();
  461. orderInfo.setOrdertime(currtime);
  462. orderInfo.setEffecttime(currtime);
  463. }
  464. /**
  465. * 调能力平台
  466. * @param orderInfo
  467. * @param hasshare //调能力平台标识:0调能力平台并以结果落订购关系,1调能力平台其结果不影响订购关系,为空时不调能力平台,
  468. * @throws Exception
  469. */
  470. private void shareOrder(OrderInfo orderInfo, String hasshare) throws Exception{
  471. if("0".equals(hasshare) || "1".equals(hasshare)){
  472. String shareErcode = "0";
  473. String shareErnfo = "成功";
  474. if("0".equals(hasshare)){//以能力平台调用结果落订购关系的要设置渠道为SHARE,此渠道记录在订购关系表和订购日志表中
  475. orderInfo.setChannel("SHARE");
  476. }else{
  477. orderInfo.setChannel("");
  478. }
  479. try {
  480. shareOrderService.order(orderInfo.getUserid(),orderInfo.getCpid(),orderInfo.getSpid());
  481. } catch (BusinessException e) {
  482. e.printStackTrace();
  483. shareErcode = e.getCode();
  484. shareErnfo = e.getMessage();
  485. if("0".equals(hasshare)){
  486. throw new BusinessException("8888","调用能力共享平台订购接口失败");
  487. }
  488. } finally {
  489. saveBackShareLog(orderInfo,shareErcode,shareErnfo);
  490. }
  491. }
  492. }
  493. /**
  494. * 查询本地订购关系表当前是否有已生效的订购关系
  495. * @param orderInfo
  496. * @return
  497. * @throws Exception
  498. */
  499. private Map hasEffect(OrderInfo orderInfo) throws Exception{
  500. Map reMap = new HashMap();
  501. boolean hasEffect = false;
  502. Map currOrderInfo = null;
  503. String currentTime = backBusiOrderDao.getCurrentTime();
  504. //查询用户本地订购关系表未失效的订购数据
  505. currOrderInfo = backBusiOrderDao.findByUserAndSpid(orderInfo.getUserid(),orderInfo.getCpid(),orderInfo.getSpid());
  506. if(currOrderInfo != null){//本地有订购关系
  507. if(Long.parseLong(currOrderInfo.get("ENDTIME").toString()) >= Long.parseLong(currentTime)){ //结束时间大于或等于当前时间,订购关系有效
  508. hasEffect = true;
  509. }
  510. }
  511. reMap.put("hasEffect", hasEffect);
  512. reMap.put("currOrderInfo", currOrderInfo);
  513. return reMap;
  514. }
  515. /**
  516. * 判断业务是否互斥
  517. * @param orderInfo
  518. * @throws Exception
  519. */
  520. private void hasMutual(OrderInfo orderInfo) throws Exception{
  521. boolean result = false;
  522. List<OrderInfo> listOrderInfo = backBusiOrderDao.findByUser(orderInfo.getUserid());
  523. if (listOrderInfo != null && listOrderInfo.size() > 0
  524. && !StringUtils.isEmpty(orderInfo.getMutex())) {
  525. String[] mutexSpids = orderInfo.getMutex().trim().split(",");
  526. for (String mutexSpid : mutexSpids) {
  527. for (OrderInfo oldOrderInfo : listOrderInfo) {
  528. if (!oldOrderInfo.getSpid().equals(orderInfo.getSpid()) && oldOrderInfo.getSpid().equals(mutexSpid)) {
  529. result = true;
  530. break;
  531. }
  532. }
  533. }
  534. }
  535. if(result){
  536. throw new BusinessException("9003","已办理互斥业务", new String[0]);
  537. }
  538. }
  539. /**
  540. * 判断是否有相同订单
  541. * @param orderInfo
  542. * @return true是,false否
  543. */
  544. private void hasDupliOrderid(OrderInfo orderInfo) throws Exception{
  545. List<BackBusiOrderRec> list = backBusiOrderDao.findOrderRecByOrderid(orderInfo.getOrderid());
  546. if(list != null && list.size() > 0){
  547. throw new BusinessException("9001", "重复订单", new String[0]);
  548. }
  549. }
  550. public String getEndTime(String endTimeStr) throws ParseException {
  551. Calendar calendar = Calendar.getInstance();
  552. Date date = DateUtils.parseDate(endTimeStr.substring(0, 8), new String[] { "yyyyMMdd" });
  553. calendar.setTime(date);
  554. String day = calendar.getActualMaximum(Calendar.DAY_OF_MONTH) + "";
  555. String year = calendar.get(Calendar.YEAR) + "";
  556. String month = calendar.get(Calendar.MONTH) + 1 < 10 ? "0" + (calendar.get(Calendar.MONTH) + 1)
  557. : calendar.get(Calendar.MONTH) + 1 + "";
  558. return year + month + day + "235959";
  559. }
  560. /**
  561. * 写订购日志
  562. * @param orderInfo
  563. * @param errorcode
  564. * @param errorinfo
  565. */
  566. public void saveLog(OrderInfo orderInfo, String errorcode, String errorinfo) {
  567. try {
  568. OrderLog orderLog = new OrderLog();
  569. orderLog.setApptype(orderInfo.getApptype());
  570. orderLog.setArea(orderInfo.getArea());
  571. orderLog.setChannel(orderInfo.getOrderchannel());
  572. orderLog.setOrderstatus(orderInfo.getOrderstatus());
  573. orderLog.setStatus(orderInfo.getStatus());
  574. orderLog.setCpid(orderInfo.getCpid());
  575. orderLog.setIsexperience(orderInfo.getIsexperience());
  576. orderLog.setOrdertype(orderInfo.getOrdertype() + "");
  577. orderLog.setProvince(orderInfo.getProvince());
  578. orderLog.setArea(orderInfo.getArea());
  579. orderLog.setSpid(orderInfo.getSpid());
  580. orderLog.setUserid(orderInfo.getUserid());
  581. orderLog.setErrorcode(errorcode);
  582. orderLog.setErrorinfo(errorinfo);
  583. if(!orderInfo.getTimes().isEmpty()){
  584. orderLog.setTimes((System.currentTimeMillis()-NumberUtils.toLong(orderInfo.getTimes()))+"");
  585. }
  586. this.backBusiOrderDao.addOrderLog(orderLog);
  587. } catch (Exception e) {
  588. e.printStackTrace();
  589. busilog.error("userid:"+orderInfo.getUserid()+",写订购日志出现异常,"+e.getMessage());
  590. }
  591. }
  592. /**
  593. * 写后向订购能力平台日志
  594. * @param orderInfo
  595. * @param errorcode
  596. * @param errorinfo
  597. */
  598. private void saveBackShareLog(OrderInfo orderInfo,String errorcode,String errorinfo){
  599. BackShareOrderBean bso = new BackShareOrderBean();
  600. bso.setUserid(orderInfo.getUserid());
  601. bso.setErrorcode(errorcode);
  602. bso.setErrorinfo(errorinfo);
  603. bso.setCpid(orderInfo.getCpid());
  604. bso.setSpid(orderInfo.getSpid());
  605. try {
  606. backShareOrderDao.addShareOrderLog(bso);
  607. } catch (Exception e) {
  608. e.printStackTrace();
  609. busilog.error("userid:"+orderInfo.getUserid()+",写后向订购能力平台日志出现异常,"+e.getMessage());
  610. }
  611. }
  612. /**
  613. * 获取开始时间和结束时间
  614. * @param orderInfo
  615. * @return
  616. * @throws Exception
  617. */
  618. private Map<String, String> getBusiTime(OrderInfo orderInfo)throws Exception{
  619. Map<String, String> resMap = new HashMap<String, String>();
  620. String starttime = ""; //业务开始时间
  621. String endtime = ""; //业务结束时间
  622. String currEndtime = "";
  623. Map reMap = this.hasEffect(orderInfo);
  624. HashMap confHm = backBusiOrderDao.getBackBusiConf(orderInfo.getCpid(), orderInfo.getSpid()).get(0);
  625. if((Boolean)reMap.get("hasEffect")){ //存在有效订购关系
  626. if("1".equals(confHm.get("ENDTYPE"))){
  627. throw new BusinessException("9005","本月已订购,请勿重复订购");
  628. }
  629. Map currOrderInfo = (Map)reMap.get("currOrderInfo");
  630. currEndtime = (String)currOrderInfo.get("ENDTIME");
  631. }
  632. //[{PWD=kijkfds, NETDAYS=31, CHANNEL=test_01, NETDAYS=2, SPID=1168, BUSITYPE=3, CPID=youtu}]
  633. //String busiType = confHm.get("BUSITYPE")+"";
  634. //业务类型,1会员,2免流,3会员+免流
  635. //ENDTYPE: 1:结束时间到月底且不能重复订购,2:结束时间到月底且能重复订购,结束时间累加一个月,3:结束时间到月底,能重复订购,结束时间不累加。其余结束时间按netdays算且能重复订购
  636. //免流或免流+会员两种产品要以netdays参数来确定endtime
  637. if("2".equals(confHm.get("BUSITYPE")) || "3".equals(confHm.get("BUSITYPE"))){
  638. if(currEndtime != null && !"".equals(currEndtime)){
  639. if("3".equals(confHm.get("ENDTYPE"))){
  640. endtime = backBusiOrderDao.endtimeTheMonthLastDay();
  641. }else if("2".equals(confHm.get("ENDTYPE"))){
  642. endtime = backBusiOrderDao.endtimeNextMonthLastDay(currEndtime);
  643. }else{
  644. endtime = backBusiOrderDao.endtimeParamDay(confHm.get("NETDAYS")+"", currEndtime);
  645. }
  646. }else{
  647. if("1".equals(confHm.get("ENDTYPE")) || "2".equals(confHm.get("ENDTYPE"))|| "3".equals(confHm.get("ENDTYPE"))){
  648. endtime = backBusiOrderDao.endtimeTheMonthLastDay(); //特殊产品的结束时间只到本月底
  649. }else {
  650. endtime = backBusiOrderDao.currParamDay(confHm.get("NETDAYS")+"");
  651. }
  652. }
  653. if("1".equals(confHm.get("ENDTYPE")) || "2".equals(confHm.get("ENDTYPE")) || "3".equals(confHm.get("ENDTYPE"))){
  654. starttime = backBusiOrderDao.getKsStartTime(); //特殊产品开始时间就是当天
  655. }else{
  656. starttime = backBusiOrderDao.getStartTime(endtime,confHm.get("NETDAYS")+"");
  657. }
  658. }
  659. resMap.put("starttime", starttime);
  660. resMap.put("endtime", endtime);
  661. return resMap;
  662. }
  663. }