fb0266b6a7c054162be1bb40d70c66a450ac4c8e.svn-base 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  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.Base64;
  6. import com.chinacreator.common.util.UsermobUtil;
  7. import com.chinacreator.videoalliance.common.bean.AreaInfo;
  8. import com.chinacreator.videoalliance.common.bean.CPInfo;
  9. import com.chinacreator.videoalliance.common.dao.DictionaryDao;
  10. import com.chinacreator.videoalliance.common.dao.ProvinceControlDao;
  11. import com.chinacreator.videoalliance.common.util.AreaUtil;
  12. import com.chinacreator.videoalliance.common.util.ConfigUtil;
  13. import com.chinacreator.videoalliance.order.bean.*;
  14. import com.chinacreator.videoalliance.order.dao.*;
  15. import com.chinacreator.videoalliance.order.util.JsonUtil;
  16. import org.apache.commons.lang.math.NumberUtils;
  17. import org.apache.commons.lang.time.DateFormatUtils;
  18. import org.apache.commons.lang.time.DateUtils;
  19. import org.apache.log4j.Logger;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.stereotype.Component;
  22. import org.springframework.util.StringUtils;
  23. import java.sql.SQLException;
  24. import java.text.ParseException;
  25. import java.text.SimpleDateFormat;
  26. import java.util.*;
  27. @Component
  28. public class OrderKsPreService {
  29. private static Logger log = Logger.getLogger("orderError");
  30. @Autowired
  31. private SmCancelDao smCancelDao;
  32. @Autowired
  33. private OrderDao orderDao;
  34. @Autowired
  35. private BlackWhiteDao blackWhiteDao;
  36. @Autowired
  37. private SPDao spDao;
  38. @Autowired
  39. private DictionaryDao dictionaryDao;
  40. @Autowired
  41. private ProvinceControlDao provinceControlDao;
  42. @Autowired
  43. private VacOrderService vacOrderService;
  44. @Autowired
  45. private OrderLogDao orderLogDao;
  46. @Autowired
  47. private OrderSysDao sysDao;
  48. @Autowired
  49. private EcbService ecbService;
  50. @Autowired
  51. private EcbDiscntDao ecbDiscntDao;
  52. @Autowired
  53. private UnifiedAuthService unifiedAuthService;
  54. @Autowired
  55. private DingxiangOrderService dingxiangOrderService;
  56. @Autowired
  57. CapOrderService capOrderService;
  58. @Autowired
  59. CapKbxkQryDao capKbxkQryDao;
  60. @Autowired
  61. private ShareOrderService shareOrderService;
  62. @Autowired
  63. private OrderKsPreDao orderKsDao;
  64. private void checkUserid(OrderInfo orderInfo) throws Exception {
  65. String userid = orderInfo.getUserid();
  66. if ((StringUtils.isEmpty(userid)) || ("null".equals(userid)))
  67. throw new BusinessException("7002", "手机号码无效", new String[0]);
  68. if (!UsermobUtil.isValid(userid)) {
  69. userid = ConfigUtil.decrypt(userid, orderInfo.getCpid());
  70. userid = ConfigUtil.getUserid(userid, orderInfo.getCpid());
  71. }
  72. if (!UsermobUtil.isValid(userid)) {
  73. throw new BusinessException("7002", "手机号码无效", new String[0]);
  74. }
  75. orderInfo.setUserid(userid);
  76. }
  77. public 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. private void checkSpInfo(OrderInfo orderInfo) throws Exception {
  84. SPInfo spInfo = getSPInfo(orderInfo);
  85. if (spInfo.getCanorder() == 1 && StringUtils.isEmpty(orderInfo.getOrderchannel())) {
  86. throw new BusinessException("9012", "该产品不支持订购操作", new String[0]);
  87. }
  88. if (orderInfo.getOrdertype() == 1) {
  89. if (spInfo.getType() != 0 && spInfo.getType() != 3) {
  90. throw new BusinessException("5305", "产品标识符无效", new String[0]);
  91. }
  92. if (spInfo.getType() == 0) {
  93. if (StringUtils.isEmpty(orderInfo.getVideoid())) {
  94. throw new BusinessException("8002", "{0}参数无效", new String[]{"videoid"});
  95. }
  96. if (StringUtils.isEmpty(orderInfo.getVideoname()))
  97. throw new BusinessException("8002", "{0}参数无效", new String[]{"videoname"});
  98. try {
  99. String videoname = new String(Base64.decodeBase64(orderInfo.getVideoname()), "UTF-8");
  100. orderInfo.setVideoname(videoname);
  101. } catch (Exception e) {
  102. throw new BusinessException("8002", "{0}参数无效", new String[]{"videoname"});
  103. }
  104. orderInfo.setEndtime(this.sysDao.getLastDay());
  105. } else {
  106. orderInfo.setOrdertype(3);
  107. }
  108. } else if (orderInfo.getOrdertype() == 0) {
  109. if (spInfo.getType() == 0) {
  110. throw new BusinessException("5305", "产品标识符无效", new String[0]);
  111. }
  112. } else if (orderInfo.getOrdertype() == 2) {
  113. if (spInfo.getType() != 0) {
  114. throw new BusinessException("5305", "产品标识符无效", new String[0]);
  115. }
  116. orderInfo.setCachesucceed(0);
  117. } else {
  118. throw new BusinessException("8002", "{0}参数无效", new String[]{"ordertype"});
  119. }
  120. orderInfo.setSpid(spInfo.getSpid());
  121. }
  122. public void checkOrder(OrderInfo orderInfo) throws Exception {
  123. checkUserid(orderInfo);
  124. checkCpInfo(orderInfo);
  125. checkSpInfo(orderInfo);
  126. String userid = orderInfo.getUserid();
  127. String cpid = orderInfo.getCpid();
  128. String spid = orderInfo.getSpid();
  129. String province = orderInfo.getProvince();
  130. if (this.blackWhiteDao.isBlackUser(userid, orderInfo.getCpid())) {
  131. throw new BusinessException("9002", "用户为黑名单用户", new String[0]);
  132. }
  133. AreaInfo areaInfo = getAreaInfo(userid);
  134. orderInfo.setProvince(areaInfo.getProvince());
  135. orderInfo.setArea(areaInfo.getArea());
  136. CPInfo cpInfo = ConfigUtil.getCPInfo(orderInfo.getCpid(), areaInfo.getProvince());
  137. if (cpInfo == null) {
  138. throw new BusinessException("7005", "CP标识无效", new String[0]);
  139. }
  140. String allowOrder = this.dictionaryDao.getValue("allowOrder");
  141. if (("1".equals(allowOrder)) || (areaInfo.getStatus() == 1)) {
  142. throw new BusinessException("9002", "该业务暂未开放,敬请期待。", new String[0]);
  143. }
  144. if ((areaInfo.getProvince() != null) && (this.provinceControlDao.isNotOpen(areaInfo.getProvince())))
  145. throw new BusinessException("9003", "您号码的归属地{0}暂未开放该业务,敬请期待。", new String[]{areaInfo.getProvince()});
  146. if (this.orderDao.isOpen(orderInfo.getSpid(), orderInfo.getCpid(), orderInfo.getProvince())) { // status 为2 表示省份尚未开通
  147. // throw new BusinessException("9003", "省份尚未开通此业务,敬请期待!");
  148. if (!this.blackWhiteDao.isWhiteUserBySpid(userid, orderInfo.getCpid(), orderInfo.getSpid())) {//判断用户是否白名单,是则流程继续
  149. throw new BusinessException("9003", "省份尚未开通此业务,敬请期待!");
  150. }
  151. }
  152. }
  153. private AreaInfo getAreaInfo(String userid) throws Exception {
  154. AreaInfo areaInfo = AreaUtil.getAreaInfoByUserid(userid);
  155. if (areaInfo == null) {
  156. areaInfo = new AreaInfo();
  157. }
  158. return areaInfo;
  159. }
  160. private SPInfo getSPInfo(OrderInfo orderInfo) throws Exception {
  161. SPInfo spInfo = null;
  162. if (StringUtils.isEmpty(orderInfo.getSpid()))
  163. spInfo = this.spDao.findDefaultByCP(orderInfo.getCpid());
  164. else {
  165. spInfo = this.spDao.findById(orderInfo.getSpid());
  166. }
  167. if (spInfo == null) {
  168. throw new BusinessException("5305", "产品标识符无效", new String[0]);
  169. }
  170. orderInfo.setSpid(spInfo.getSpid());
  171. orderInfo.setMutex(spInfo.getMutex());
  172. orderInfo.setRelationSp(spInfo.getRelationSp());
  173. orderInfo.setPaytype(spInfo.getPaytype());
  174. orderInfo.setErrorhandle(spInfo.getErrorhandle());
  175. return spInfo;
  176. }
  177. public void order(OrderInfo orderInfo) throws Exception {
  178. order(orderInfo, null);
  179. }
  180. public boolean findKsPrs(OrderInfo orderInfo) throws SQLException {
  181. return orderKsDao.findKsPrs(orderInfo.getCpid(), orderInfo.getSpid(), orderInfo.getUserid());
  182. }
  183. public void order(OrderInfo orderInfo, EcbProductInfo ecbProductInfo) throws Exception {
  184. String errorcode = "0";
  185. String errorinfo = "";
  186. String result = "0";
  187. String BRAND_CODE = "";
  188. String REMOVE_TAG = "";
  189. String ACT_TAG = "";
  190. String RSP_CODE = "";
  191. String CUST_STATUS = "";
  192. String valiVal = "";
  193. String level = "";
  194. boolean logflag = false;
  195. try {
  196. if (orderInfo.getOrdertype() != 2 && orderInfo.getOrdertype() != 3) {
  197. List<OrderInfo> listOrderInfo = orderDao.findByUser(orderInfo.getUserid());
  198. if (listOrderInfo != null && listOrderInfo.size() > 0) {
  199. if (!StringUtils.isEmpty(orderInfo.getMutex())) {
  200. String[] mutexSpids = orderInfo.getMutex().trim().split(",");
  201. for (String mutexSpid : mutexSpids) {
  202. for (OrderInfo oldOrderInfo : listOrderInfo) {
  203. if (oldOrderInfo.getSpid().equals(orderInfo.getSpid())
  204. && oldOrderInfo.getStatus() == 0) {
  205. throw new BusinessException("9010", "您已订购,请不要重复订购!", new String[0]);
  206. }
  207. if (oldOrderInfo.getSpid().equals(mutexSpid)) {
  208. throw new BusinessException("9011", "您已订购同类产品!", new String[0]);
  209. }
  210. }
  211. }
  212. } else {
  213. if (listOrderInfo != null && listOrderInfo.size() != 0) {
  214. for (OrderInfo oldOrderInfo : listOrderInfo) {
  215. if (oldOrderInfo.getSpid().equals(orderInfo.getSpid())
  216. && oldOrderInfo.getStatus() == 0) {
  217. if (orderInfo.getCpid().equals("changshi") && ecbProductInfo != null && ecbProductInfo.getDiscntOrderState().equals("3") && orderInfo.getOrderchannel().equals("H5_ko")) {
  218. if (ecbDiscntDao.queryByUserid(orderInfo.getUserid(), ecbProductInfo.getDiscntValue(), 0) != null) {
  219. throw new BusinessException("9010", "用户续订,重复续订", new String[0]);
  220. } else {
  221. ecbService.order(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid(), ecbProductInfo);
  222. ecbDiscntDao.order(ecbProductInfo, orderInfo);
  223. this.orderDao.order(orderInfo);
  224. throw new BusinessException("9999", "用户续订", new String[0]);
  225. }
  226. } else if (orderInfo.getCpid().equals("changshi") && orderInfo.getSpid().equals("1040") && !orderInfo.getOrderchannel().equals("H5_ko")) {
  227. ecbService.order(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid(), ecbProductInfo);
  228. ecbDiscntDao.order(ecbProductInfo, orderInfo);
  229. this.orderDao.order(orderInfo);
  230. } else {
  231. throw new BusinessException("9010", "您已订购,请不要重复订购!", new String[0]);
  232. }
  233. }
  234. }
  235. }
  236. }
  237. }
  238. } else if (orderInfo.getOrdertype() == 3) {
  239. OrderInfo oldOrderInfo = orderDao.findByUser(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid());
  240. if (oldOrderInfo != null && !StringUtils.isEmpty(oldOrderInfo.getEndtime())) {
  241. orderInfo.setEndtime(this.sysDao.getEndtimeForMonth(1, oldOrderInfo.getEndtime()));
  242. orderInfo.setOrdertime(oldOrderInfo.getOrdertime());
  243. } else {
  244. orderInfo.setEndtime(this.sysDao.getEndtimeForMonth(1, DateFormatUtils.format(new Date(), "yyyyMMdd") + "235959"));
  245. }
  246. }
  247. if (!this.blackWhiteDao.isWhiteUser(orderInfo.getUserid(), orderInfo.getCpid())) {
  248. if (orderInfo.getPaytype() == 1) {
  249. result = ecbService.order(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid(), ecbProductInfo);
  250. if (ecbProductInfo != null) {
  251. ecbDiscntDao.order(ecbProductInfo, orderInfo);
  252. }
  253. } else if (orderInfo.getPaytype() == 2) {
  254. } else if (orderInfo.getPaytype() == 3) {
  255. ecbService.query(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid(), orderInfo.getProvince());
  256. dingxiangOrderService.order(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid());
  257. } else if (orderInfo.getPaytype() == 4) {
  258. /**
  259. * 增加能力共享平台订购入口
  260. * zzb 2020-02-21
  261. */
  262. String currentTime = this.sysDao.getCurrentTime();
  263. if (orderInfo.getOrdertime() == null) {
  264. orderInfo.setOrdertime(currentTime);
  265. }
  266. orderInfo.setChannel("SHARE");
  267. orderKsDao.updateKsPre("3", "0", "取消预退订成功", orderInfo);
  268. log.info(orderInfo.getUserid() + "取消预退订成功");
  269. errorinfo = "取消预退订成功";
  270. /* shareOrderService.order(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid());*/
  271. } else {
  272. String brand = ecbService.query(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid(), orderInfo.getProvince());
  273. String accesstype = "1"; //sp/cp的二次认证方式: 1:H5认证 2:SDK认证 3:短信认证 4:页面认证
  274. if (!StringUtils.isEmpty(orderInfo.getSeqnumber())) {
  275. accesstype = "3";
  276. }
  277. //调cap综合用户查询接口和卡部信控接口
  278. String capqrydata = null;
  279. try {
  280. capqrydata = capOrderService.capQuery(orderInfo.getUserid());
  281. } catch (Exception e) {
  282. e.printStackTrace();
  283. }
  284. if (capqrydata != null) {
  285. JSONObject capqryJson = JSON.parseObject(capqrydata);
  286. BRAND_CODE = capqryJson.getString("BRAND_CODE");
  287. REMOVE_TAG = capqryJson.getString("REMOVE_TAG");
  288. ACT_TAG = capqryJson.getString("ACT_TAG");
  289. RSP_CODE = capqryJson.getString("RSP_CODE");
  290. CUST_STATUS = capqryJson.getString("CUST_STATUS");
  291. }
  292. String xkqrydata = null;
  293. try {
  294. xkqrydata = capOrderService.kbxkQuery(orderInfo.getUserid());
  295. } catch (Exception e) {
  296. e.printStackTrace();
  297. }
  298. if (xkqrydata != null) {
  299. JSONObject capqryJson = JSON.parseObject(xkqrydata);
  300. valiVal = capqryJson.getString("valiVal");
  301. level = capqryJson.getString("level");
  302. }
  303. logflag = true;
  304. //if("0004".equals(RSP_CODE)){
  305. // throw new BusinessException("cap0004", "错误码cap0004", new String[0]);
  306. //}
  307. //if (unifiedAuthService.sycnOrder(orderInfo)) {CAP接口已包含统计认证,不用再验证
  308. //订购,选择走CAP接口或是VAC接口
  309. /* boolean hasvac = true; //是否调老vac接口
  310. if (capOrderService.hasCap(orderInfo)) {//产品配置是走CAP
  311. orderInfo.setChannel("CAP");
  312. hasvac = false;
  313. result = this.capOrderService.order(orderInfo, accesstype);
  314. if ("0008".equals(result)) { //不是4G用户,走原vac
  315. hasvac = true;
  316. }
  317. }
  318. log.info("userid=>" + orderInfo.getUserid() + ",brand=>" + brand + ",accesstype=>" + accesstype + ",hasvac=>" + hasvac);
  319. if (hasvac && unifiedAuthService.sycnOrder(orderInfo)) { //没有走CAP业务配置,或者不是4G用户,只有调vac才走统一认证验证
  320. orderInfo.setChannel("VAC");
  321. result = this.vacOrderService.order(orderInfo.getUserid(), orderInfo.getSpid(), orderInfo.getSeqnumber() == null ? "" : orderInfo.getSeqnumber(), orderInfo.getOrderchannel());
  322. }
  323. //}*/
  324. //全部走cap接口
  325. orderInfo.setChannel("CAP");
  326. this.capOrderService.order(orderInfo, accesstype);
  327. }
  328. } else if (orderInfo.getCpid().equals("changshi") && ecbProductInfo != null) {
  329. ecbDiscntDao.order(ecbProductInfo, orderInfo);
  330. }
  331. String currentTime = this.sysDao.getCurrentTime();
  332. if (orderInfo.getOrdertime() == null) {
  333. orderInfo.setOrdertime(currentTime);
  334. }
  335. if (orderInfo.getEffecttime() == null) {
  336. orderInfo.setEffecttime(currentTime);
  337. }
  338. if (!result.equals("0") && orderInfo.getErrorhandle() == 0) {
  339. orderInfo.setOrderstatus(7);
  340. orderInfo.setIsexperience(1);
  341. orderInfo.setShowstatus("0");
  342. }
  343. if (orderInfo.getOrdertype() != 2) {
  344. this.orderDao.order(orderInfo);
  345. } else {
  346. this.orderDao.countOrder(orderInfo);
  347. }
  348. } catch (Exception e) {
  349. log.error("userid:" + orderInfo.getUserid() + "订购出现异常," + e);
  350. e.printStackTrace();
  351. errorcode = "8000";
  352. errorinfo = "系统忙";
  353. if ((e instanceof BusinessException)) {
  354. errorcode = ((BusinessException) e).getCode();
  355. errorinfo = ((BusinessException) e).getMessage();
  356. if (errorinfo.length() > 200) {
  357. errorinfo = errorinfo.substring(0, 200);
  358. }
  359. if (errorinfo.contains("cap订购失败")) {
  360. String errorinfo2 = "cap订购失败";
  361. throw new BusinessException(errorcode, errorinfo2);
  362. }
  363. }
  364. if (!errorcode.equals("9999")) {
  365. throw e;
  366. }
  367. orderKsDao.updateKsPre("0", "8000", "取消预退订失败", orderInfo);
  368. } finally {
  369. saveLog(orderInfo, errorcode, errorinfo);
  370. CapKbxkQryBean capKbxkQryBean = new CapKbxkQryBean();
  371. capKbxkQryBean.setUserid(orderInfo.getUserid());
  372. capKbxkQryBean.setActtag(ACT_TAG);
  373. capKbxkQryBean.setBrandcode(BRAND_CODE);
  374. capKbxkQryBean.setCuststatus(CUST_STATUS);
  375. capKbxkQryBean.setRemovetag(REMOVE_TAG);
  376. capKbxkQryBean.setRspcode(RSP_CODE);
  377. capKbxkQryBean.setUserlevel(level);
  378. capKbxkQryBean.setValival(valiVal);
  379. capKbxkQryBean.setCpid(orderInfo.getCpid());
  380. capKbxkQryBean.setSpid(orderInfo.getSpid());
  381. if (logflag) {
  382. try {
  383. capKbxkQryDao.addCapKbxkQryLog(capKbxkQryBean);
  384. } catch (Exception e) {
  385. e.printStackTrace();
  386. }
  387. }
  388. }
  389. }
  390. public void checkCancelOrder(OrderInfo orderInfo) throws Exception {
  391. String userid = orderInfo.getUserid();
  392. checkUserid(orderInfo);
  393. AreaInfo areaInfo = getAreaInfo(userid);
  394. orderInfo.setProvince(areaInfo.getProvince());
  395. orderInfo.setArea(areaInfo.getArea());
  396. CPInfo cpInfo = ConfigUtil.getCPInfo(orderInfo.getCpid(), null);
  397. if (cpInfo == null) {
  398. throw new BusinessException("7005", "CP标识无效", new String[0]);
  399. }
  400. SPInfo spInfo = getSPInfo(orderInfo);
  401. if (spInfo.getCancancelorder() == 1 && StringUtils.isEmpty(orderInfo.getCancelchannel())) {
  402. throw new BusinessException("9011", "该产品不支持退订操作", new String[0]);
  403. }
  404. if (this.orderDao.hasTiyanValid(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid()))
  405. throw new BusinessException("9015", "该产品体验期未结束不支持退订操作", new String[0]);
  406. }
  407. public void cancelOrder(OrderInfo orderInfo) throws Exception {
  408. cancelOrder(orderInfo, null);
  409. }
  410. public void cancelOrder(OrderInfo orderInfo, EcbProductInfo ecbProductInfo) throws Exception {
  411. String errorcode = "0";
  412. String errorinfo = "";
  413. try {
  414. List<OrderInfo> listOrderInfo = orderDao.findByUser(orderInfo.getUserid());
  415. OrderInfo relationOrder = null;
  416. if (listOrderInfo == null || listOrderInfo.size() == 0) {
  417. throw new BusinessException("9016", "退订失败,无该用户订购关系或者已失效", new String[0]);
  418. }
  419. boolean isHasOrder = false;
  420. boolean isHasOtherOrder = false;
  421. for (OrderInfo oldOrderInfo : listOrderInfo) {
  422. if (orderInfo.getSpid().equals(oldOrderInfo.getSpid())) {
  423. orderInfo.setOrdertime(oldOrderInfo.getOrdertime());
  424. if (!StringUtils.isEmpty(oldOrderInfo.getEndtime())) {
  425. orderInfo.setEndtime(oldOrderInfo.getEndtime());
  426. }
  427. if (oldOrderInfo.getStatus() != 0) {
  428. throw new BusinessException("9017", "退订失败,该用户已退订该产品", new String[0]);
  429. }
  430. isHasOrder = true;
  431. break;
  432. }
  433. }
  434. if (!StringUtils.isEmpty(orderInfo.getRelationSp())) {
  435. for (OrderInfo oldOrderInfo : listOrderInfo) {
  436. if (oldOrderInfo.getSpid().equals(orderInfo.getRelationSp()) && oldOrderInfo.getStatus() == 0) {
  437. relationOrder = orderInfo;
  438. relationOrder.setSpid(orderInfo.getRelationSp());
  439. isHasOtherOrder = true;
  440. break;
  441. }
  442. }
  443. }
  444. if (!isHasOrder && !isHasOtherOrder) {
  445. throw new BusinessException("9018", "退订失败,该用户没有订购该产品或者已失效", new String[0]);
  446. }
  447. if (!this.blackWhiteDao.isWhiteUser(orderInfo.getUserid(), orderInfo.getCpid())) {
  448. if (orderInfo.getPaytype() == 1) {
  449. if (ecbProductInfo == null || (ecbProductInfo != null && (!ecbProductInfo.getDiscntOrderState().equals("2") || !ecbProductInfo.getDiscntFee().equals("0")))) {
  450. errorcode = ecbService.cancelOrder(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid(), orderInfo.getOrdertime(), ecbProductInfo);
  451. if (ecbProductInfo != null) {
  452. ecbDiscntDao.cancel(ecbProductInfo, orderInfo);
  453. }
  454. }
  455. } else if (orderInfo.getPaytype() == 2) {
  456. } else if (orderInfo.getPaytype() == 3) {
  457. dingxiangOrderService.cancel(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid());
  458. } else if (orderInfo.getPaytype() == 4) {
  459. /**
  460. * 增加能力共享平台订购入口
  461. * zzb 2020-02-21
  462. */
  463. orderInfo.setChannel("SHARE");
  464. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  465. Calendar cal = Calendar.getInstance();
  466. cal.set(Calendar.DATE, 1);
  467. cal.roll(Calendar.DATE, -1);
  468. String oldDay = sdf.format(cal.getTime());
  469. if (sdf.format(new Date()).equals(oldDay)) {
  470. //每月最后一天走能力平台
  471. shareOrderService.cancel(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid());
  472. } else {
  473. //添加到预处理表
  474. Map<String, Object> info = new HashMap<String, Object>();
  475. info.put("userid", orderInfo.getUserid());
  476. info.put("cpid", orderInfo.getCpid());
  477. info.put("spid", orderInfo.getSpid());
  478. info.put("status", "0");
  479. info.put("cancelTime", sdf.format(DateUtils.addDays(cal.getTime(), -1)));
  480. orderKsDao.insert(info);
  481. errorinfo = "快手预退订成功";
  482. log.info(orderInfo.getUserid() + "预退订成功");
  483. }
  484. } else {
  485. /* //退订,选择走CAP接口或是VAC接口
  486. boolean hasvac = true; //是否调老vac接口
  487. if (capOrderService.hasCap(orderInfo)) {//产品配置是走CAP
  488. orderInfo.setChannel("CAP");
  489. hasvac = false;
  490. String result = this.capOrderService.cancel(orderInfo);
  491. if ("0008".equals(result)) { //不是4G用户,走原vac
  492. hasvac = true;
  493. }
  494. }
  495. if (hasvac) { //没有走CAP业务配置,或者不是4G用户
  496. orderInfo.setChannel("VAC");
  497. this.vacOrderService.cancelOrder(orderInfo.getUserid(), orderInfo.getSpid());
  498. }*/
  499. //全部都走cap接口
  500. orderInfo.setChannel("CAP");
  501. this.capOrderService.cancel(orderInfo);
  502. }
  503. }
  504. if (isHasOrder && isHasOtherOrder) {
  505. this.smCancelDao.cancelOrder(relationOrder);
  506. }
  507. if (!isHasOrder && isHasOtherOrder) {
  508. orderInfo.setSpid(orderInfo.getRelationSp());
  509. }
  510. String currentTime = this.sysDao.getCurrentTime();
  511. if (orderInfo.getCanceltime() != null) {
  512. orderInfo.setEndtime(getEndTime(orderInfo.getCanceltime()));
  513. } else {
  514. orderInfo.setCanceltime(currentTime);
  515. }
  516. if (orderInfo.getEffecttime() == null) {
  517. orderInfo.setEffecttime(currentTime);
  518. }
  519. if (orderInfo.getEndtime() == null) {
  520. orderInfo.setEndtime(this.sysDao.getEndDayOfCurrentMonth());
  521. }
  522. this.orderDao.cancelOrder(orderInfo);
  523. } catch (Exception e) {
  524. log.error("userid:" + orderInfo.getUserid() + "退购出现异常," + e);
  525. errorcode = "8000";
  526. errorinfo = "系统忙";
  527. if ((e instanceof BusinessException)) {
  528. errorcode = ((BusinessException) e).getCode();
  529. errorinfo = ((BusinessException) e).getMessage();
  530. if (errorinfo.length() > 200) {
  531. errorinfo = errorinfo.substring(0, 200);
  532. }
  533. if (errorinfo.contains("cap退订失败")) {
  534. String errorinfo2 = "cap退订失败";
  535. throw new BusinessException(errorcode, errorinfo2);
  536. }
  537. }
  538. if (!errorcode.equals("9998")) {
  539. throw e;
  540. }
  541. } finally {
  542. saveLog(orderInfo, errorcode, errorinfo);
  543. }
  544. }
  545. public String getEndTime(String endTimeStr) throws ParseException {
  546. Calendar calendar = Calendar.getInstance();
  547. Date date = DateUtils.parseDate(endTimeStr.substring(0, 8), new String[]{"yyyyMMdd"});
  548. calendar.setTime(date);
  549. String day = calendar.getActualMaximum(Calendar.DAY_OF_MONTH) + "";
  550. String year = calendar.get(Calendar.YEAR) + "";
  551. String month = calendar.get(Calendar.MONTH) + 1 < 10 ? "0" + (calendar.get(Calendar.MONTH) + 1)
  552. : calendar.get(Calendar.MONTH) + 1 + "";
  553. return year + month + day + "235959";
  554. }
  555. public void saveLog(OrderInfo orderInfo, String errorcode, String errorinfo) {
  556. OrderLog orderLog = new OrderLog();
  557. orderLog.setApptype(orderInfo.getApptype());
  558. orderLog.setArea(orderInfo.getArea());
  559. if (orderInfo.getOrderchannel() != null) {
  560. orderLog.setChannel(orderInfo.getOrderchannel());
  561. } else {
  562. orderLog.setChannel(orderInfo.getCancelchannel());
  563. }
  564. orderLog.setOrderstatus(orderInfo.getOrderstatus());
  565. orderLog.setStatus(orderInfo.getStatus());
  566. orderLog.setCpid(orderInfo.getCpid());
  567. orderLog.setIsexperience(orderInfo.getIsexperience());
  568. orderLog.setOrdertype(orderInfo.getOrdertype() + "");
  569. orderLog.setProvince(orderInfo.getProvince());
  570. orderLog.setArea(orderInfo.getArea());
  571. orderLog.setSpid(orderInfo.getSpid());
  572. orderLog.setUserid(orderInfo.getUserid());
  573. orderLog.setErrorcode(errorcode);
  574. orderLog.setErrorinfo(errorinfo);
  575. if (!orderInfo.getTimes().isEmpty()) {
  576. orderLog.setTimes((System.currentTimeMillis() - NumberUtils.toLong(orderInfo.getTimes())) + "");
  577. }
  578. this.orderLogDao.addOrderLog(orderLog);
  579. }
  580. public static void main(String args[]) {
  581. Map<String, String> map = new HashMap<String, String>();
  582. map.put("userid", "18673197465");
  583. map.put("cpid", "tencent");
  584. map.put("spid", "101");
  585. String str = JsonUtil.objectToJson(map);
  586. String s = "5gLD5I2BeU+YKA8QQHD68AX13cto20yC0ilPkMG+fmI28Ey/hAWi3A==";
  587. String s2 = "N1GrAYM4evTnTaPLzci9Dg==";
  588. System.out.println(s2.length());
  589. System.out.println(str);
  590. }
  591. }