6258aa152f0ea5731ff880c29da0cc8ff20ba662.svn-base 29 KB

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