0ef4c3806f3ebd00dd0b9e65239135429d2d9ca9.svn-base 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173
  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.MD5;
  7. import com.chinacreator.common.util.UsermobUtil;
  8. import com.chinacreator.videoalliance.common.bean.AreaInfo;
  9. import com.chinacreator.videoalliance.common.bean.CPInfo;
  10. import com.chinacreator.videoalliance.common.dao.DictionaryDao;
  11. import com.chinacreator.videoalliance.common.dao.ProvinceControlDao;
  12. import com.chinacreator.videoalliance.common.util.AreaUtil;
  13. import com.chinacreator.videoalliance.common.util.ConfigUtil;
  14. import com.chinacreator.videoalliance.order.bean.*;
  15. import com.chinacreator.videoalliance.order.dao.*;
  16. import com.chinacreator.videoalliance.order.util.*;
  17. import com.chinacreator.videoalliance.smc.util.SendSmsUtil;
  18. import org.apache.commons.lang.math.NumberUtils;
  19. import org.apache.commons.lang.time.DateFormatUtils;
  20. import org.apache.commons.lang.time.DateUtils;
  21. import org.apache.log4j.Logger;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.stereotype.Component;
  24. import org.springframework.util.StringUtils;
  25. import java.net.URLEncoder;
  26. import java.sql.SQLException;
  27. import java.text.ParseException;
  28. import java.text.SimpleDateFormat;
  29. import java.util.*;
  30. @Component
  31. public class OrderService {
  32. private static Logger log = Logger.getLogger("orderError");
  33. @Autowired
  34. private SmCancelDao smCancelDao;
  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 ProvinceControlDao provinceControlDao;
  45. @Autowired
  46. private VacOrderService vacOrderService;
  47. @Autowired
  48. private OrderLogDao orderLogDao;
  49. @Autowired
  50. private OrderSysDao sysDao;
  51. @Autowired
  52. private EcbService ecbService;
  53. @Autowired
  54. private EcbDiscntDao ecbDiscntDao;
  55. @Autowired
  56. private UnifiedAuthService unifiedAuthService;
  57. @Autowired
  58. private DingxiangOrderService dingxiangOrderService;
  59. @Autowired
  60. CapOrderService capOrderService;
  61. @Autowired
  62. CapKbxkQryDao capKbxkQryDao;
  63. @Autowired
  64. private ShareOrderService shareOrderService;
  65. @Autowired
  66. private HeyueOrderService heyueOrderService;
  67. @Autowired
  68. private CurrencyService currencyService;
  69. private String[] syncSpids = {"1011", "1012", "1013", "1014", "1016", "1047", "1048",
  70. "1049", "1051", "1052", "1221", "1222", "1223", "1224", "1225", "1226",
  71. "1009", "1027", "1028", "292", "293", "294", "295", "296", "297", "298", "299", "1022", "1023"};
  72. public void checkUserid(OrderInfo orderInfo) throws Exception {
  73. String userid = orderInfo.getUserid();
  74. if ((StringUtils.isEmpty(userid)) || ("null".equals(userid)))
  75. throw new BusinessException("7002", "手机号码无效", new String[0]);
  76. if (!UsermobUtil.isValid(userid)) {
  77. userid = ConfigUtil.decrypt(userid, orderInfo.getCpid());
  78. userid = ConfigUtil.getUserid(userid, orderInfo.getCpid());
  79. }
  80. if (!UsermobUtil.isValid(userid)) {
  81. throw new BusinessException("7002", "手机号码无效", new String[0]);
  82. }
  83. orderInfo.setUserid(userid);
  84. }
  85. public void checkCpInfo(OrderInfo orderInfo) throws Exception {
  86. CPInfo cpInfo = ConfigUtil.getCPInfo(orderInfo.getCpid(), null);
  87. if ((cpInfo.getStatus() != 0) && (cpInfo.getStatus() != 4)) {
  88. throw new BusinessException("9002", "该业务暂未开放,敬请期待。", new String[0]);
  89. }
  90. }
  91. private void checkSpInfo(OrderInfo orderInfo) throws Exception {
  92. SPInfo spInfo = getSPInfo(orderInfo);
  93. if (spInfo.getCanorder() == 1 && StringUtils.isEmpty(orderInfo.getOrderchannel())) {
  94. throw new BusinessException("9012", "该产品不支持订购操作", new String[0]);
  95. }
  96. if (orderInfo.getOrdertype() == 1) {
  97. if (spInfo.getType() != 0 && spInfo.getType() != 3) {
  98. throw new BusinessException("5305", "产品标识符无效", new String[0]);
  99. }
  100. if (spInfo.getType() == 0) {
  101. if (StringUtils.isEmpty(orderInfo.getVideoid())) {
  102. throw new BusinessException("8002", "{0}参数无效", new String[]{"videoid"});
  103. }
  104. if (StringUtils.isEmpty(orderInfo.getVideoname()))
  105. throw new BusinessException("8002", "{0}参数无效", new String[]{"videoname"});
  106. try {
  107. String videoname = new String(Base64.decodeBase64(orderInfo.getVideoname()), "UTF-8");
  108. orderInfo.setVideoname(videoname);
  109. } catch (Exception e) {
  110. throw new BusinessException("8002", "{0}参数无效", new String[]{"videoname"});
  111. }
  112. orderInfo.setEndtime(this.sysDao.getLastDay());
  113. } else {
  114. orderInfo.setOrdertype(3);
  115. }
  116. } else if (orderInfo.getOrdertype() == 0) {
  117. if (spInfo.getType() == 0) {
  118. throw new BusinessException("5305", "产品标识符无效", new String[0]);
  119. }
  120. } else if (orderInfo.getOrdertype() == 2) {
  121. if (spInfo.getType() != 0) {
  122. throw new BusinessException("5305", "产品标识符无效", new String[0]);
  123. }
  124. orderInfo.setCachesucceed(0);
  125. } else {
  126. throw new BusinessException("8002", "{0}参数无效", new String[]{"ordertype"});
  127. }
  128. orderInfo.setSpid(spInfo.getSpid());
  129. }
  130. public void checkOrder(OrderInfo orderInfo) throws Exception {
  131. checkUserid(orderInfo);
  132. checkCpInfo(orderInfo);
  133. checkSpInfo(orderInfo);
  134. checkToken(orderInfo);
  135. String userid = orderInfo.getUserid();
  136. String cpid = orderInfo.getCpid();
  137. String spid = orderInfo.getSpid();
  138. String province = orderInfo.getProvince();
  139. if (this.blackWhiteDao.isBlackUser(userid, orderInfo.getCpid())) {
  140. throw new BusinessException("9002", "用户为黑名单用户", new String[0]);
  141. }
  142. AreaInfo areaInfo = getAreaInfo(userid);
  143. orderInfo.setProvince(areaInfo.getProvince());
  144. orderInfo.setArea(areaInfo.getArea());
  145. CPInfo cpInfo = ConfigUtil.getCPInfo(orderInfo.getCpid(), areaInfo.getProvince());
  146. if (cpInfo == null) {
  147. throw new BusinessException("7005", "CP标识无效", new String[0]);
  148. }
  149. String allowOrder = this.dictionaryDao.getValue("allowOrder");
  150. if (("1".equals(allowOrder)) || (areaInfo.getStatus() == 1)) {
  151. throw new BusinessException("9002", "该业务暂未开放,敬请期待。", new String[0]);
  152. }
  153. if ((areaInfo.getProvince() != null) && (this.provinceControlDao.isNotOpen(areaInfo.getProvince())))
  154. throw new BusinessException("9003", "您号码的归属地{0}暂未开放该业务,敬请期待。", new String[]{areaInfo.getProvince()});
  155. if (this.orderDao.isOpen(orderInfo.getSpid(), orderInfo.getCpid(), orderInfo.getProvince())) { // status 为2 表示省份尚未开通
  156. // throw new BusinessException("9003", "省份尚未开通此业务,敬请期待!");
  157. if (!this.blackWhiteDao.isWhiteUserBySpid(userid, orderInfo.getCpid(), orderInfo.getSpid())) {//判断用户是否白名单,是则流程继续
  158. throw new BusinessException("9003", "省份尚未开通此业务,敬请期待!");
  159. }
  160. }
  161. if ("1009".equals(spid)) {
  162. if (orderDao.isMangtvOrder(userid, spid)) {
  163. throw new BusinessException("9014", "您已经参与过合约优惠活动,不能重复订购");
  164. }
  165. }
  166. //北京号码段订购限制,20210902李嘉涵
  167. String numberlimit = dictionaryDao.getValue("Numberlimit");
  168. if (numberlimit != null && numberlimit.indexOf(userid.substring(0, 7)) != -1) {
  169. throw new BusinessException("9010", "用户为黑名单用户!", new String[0]);
  170. }
  171. //合约产品验证
  172. heyueOrderService.heyueOrderBefore(orderInfo);
  173. //渠道方订购限制
  174. checkOrderNum(orderInfo);
  175. }
  176. public void checkOrderNum(OrderInfo orderInfo) throws BusinessException {
  177. try {
  178. Map map = orderDao.channelProvince(orderInfo);
  179. if (map != null && map.size() > 0) {
  180. String type = String.valueOf(map.get("TYPE"));
  181. String provinceCode = String.valueOf(map.get("PROVINCECODE"));
  182. int orderNum = Integer.parseInt(String.valueOf(map.get("ORDER_NUM")));
  183. orderInfo.setTimeType(type);
  184. orderInfo.setProvinceCode(provinceCode);
  185. Long count = setRides(orderInfo, 0);
  186. if (count >= orderNum) {
  187. throw new BusinessException("9066", "您所订购的产品今日额度已达到上限,请明日再尝试订购。");
  188. }
  189. }
  190. } catch (Exception e) {
  191. e.printStackTrace();
  192. if (e instanceof BusinessException) {
  193. String message = e.getMessage();
  194. String code = ((BusinessException) e).getCode();
  195. throw new BusinessException(code, message);
  196. }
  197. }
  198. }
  199. public Long setRides(OrderInfo orderInfo, int num) {
  200. String timeType = orderInfo.getTimeType();
  201. if (StringUtils.isEmpty(timeType)) {
  202. return null;
  203. }
  204. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
  205. String day = simpleDateFormat.format(new Date());
  206. String date;
  207. switch (Integer.parseInt(timeType)) {
  208. case 0:
  209. date = day;
  210. break;
  211. case 1:
  212. date = day.substring(0, 6);
  213. break;
  214. case 2:
  215. date = day.substring(0, 4);
  216. break;
  217. default:
  218. date = day;
  219. }
  220. String key = "order_" + date + "_" + orderInfo.getChannel() + "_" + orderInfo.getSpid() + "_" + orderInfo.getProvinceCode();
  221. Long count = RedisCluster.jedis.incrBy(key, num);
  222. if (count == 0) {
  223. switch (Integer.parseInt(timeType)) {
  224. case 0:
  225. RedisCluster.jedis.expire(key, 24 * 60 * 60);
  226. break;
  227. case 1:
  228. RedisCluster.jedis.expire(key, 30 * 24 * 60 * 60);
  229. break;
  230. case 2:
  231. RedisCluster.jedis.expire(key, 366 * 30 * 24 * 60 * 60);
  232. break;
  233. default:
  234. RedisCluster.jedis.expire(key, 24 * 60 * 60);
  235. }
  236. }
  237. return count;
  238. }
  239. public void checkToken(OrderInfo orderInfo) throws Exception {
  240. if (orderDao.isToken(orderInfo.getSpid(), orderInfo.getCpid(), orderInfo.getChannel())) {
  241. return;
  242. }
  243. if (StringUtils.isEmpty(orderInfo.getToken())) {
  244. throw new BusinessException("9001", "token不能为空");
  245. }
  246. /* if (orderInfo.getToken().length()!=32){
  247. throw new BusinessException("9003","token位数不对");
  248. }*/
  249. Long num = RedisCluster.jedis.incrBy(orderInfo.getToken(), 1);
  250. if (num == 1) {
  251. RedisCluster.jedis.del(orderInfo.getToken());
  252. throw new BusinessException("9001", "请求token不正确");
  253. }
  254. if (num > 2) {
  255. throw new BusinessException("9001", "请求token重复");
  256. }
  257. /* try {
  258. orderDao.insertToken(orderInfo.getToken());
  259. } catch (SQLException e) {
  260. e.printStackTrace();
  261. if(e.getMessage().contains("ORA-00001")){
  262. throw new BusinessException("9001","请求token重复");
  263. }
  264. }*/
  265. }
  266. private AreaInfo getAreaInfo(String userid) throws Exception {
  267. AreaInfo areaInfo = AreaUtil.getAreaInfoByUserid(userid);
  268. if (areaInfo == null) {
  269. areaInfo = new AreaInfo();
  270. }
  271. return areaInfo;
  272. }
  273. private SPInfo getSPInfo(OrderInfo orderInfo) throws Exception {
  274. SPInfo spInfo = null;
  275. if (StringUtils.isEmpty(orderInfo.getSpid()))
  276. spInfo = this.spDao.findDefaultByCP(orderInfo.getCpid());
  277. else {
  278. spInfo = this.spDao.findById(orderInfo.getSpid());
  279. }
  280. if (spInfo == null) {
  281. throw new BusinessException("5305", "产品标识符无效", new String[0]);
  282. }
  283. orderInfo.setSpid(spInfo.getSpid());
  284. orderInfo.setMutex(spInfo.getMutex());
  285. orderInfo.setRelationSp(spInfo.getRelationSp());
  286. orderInfo.setPaytype(spInfo.getPaytype());
  287. orderInfo.setErrorhandle(spInfo.getErrorhandle());
  288. orderInfo.setDirectype(spInfo.getDirectype());
  289. return spInfo;
  290. }
  291. public void order(OrderInfo orderInfo) throws Exception {
  292. order(orderInfo, null);
  293. }
  294. public void order(OrderInfo orderInfo, EcbProductInfo ecbProductInfo) throws Exception {
  295. String errorcode = "0";
  296. String errorinfo = "";
  297. String result = "0";
  298. String BRAND_CODE = "";
  299. String REMOVE_TAG = "";
  300. String ACT_TAG = "";
  301. String RSP_CODE = "";
  302. String CUST_STATUS = "";
  303. String valiVal = "";
  304. String level = "";
  305. boolean logflag = false;
  306. try {
  307. if (orderInfo.getOrdertype() != 2 && orderInfo.getOrdertype() != 3 && !isflag(orderInfo.getSpid())) {
  308. List<OrderInfo> listOrderInfo = orderDao.findByUser(orderInfo.getUserid());
  309. if (listOrderInfo != null && listOrderInfo.size() > 0) {
  310. if (!StringUtils.isEmpty(orderInfo.getMutex())) {
  311. String[] mutexSpids = orderInfo.getMutex().trim().split(",");
  312. for (String mutexSpid : mutexSpids) {
  313. for (OrderInfo oldOrderInfo : listOrderInfo) {
  314. if (oldOrderInfo.getSpid().equals(orderInfo.getSpid())
  315. && oldOrderInfo.getStatus() == 0) {
  316. if (!"1322".equals(orderInfo.getSpid())){
  317. throw new BusinessException("9010", "您已订购,请不要重复订购!", new String[0]);
  318. }
  319. }
  320. if (oldOrderInfo.getSpid().equals(mutexSpid)) {
  321. throw new BusinessException("9011", "您已订购同类产品!", new String[0]);
  322. }
  323. }
  324. }
  325. } else {
  326. if (listOrderInfo != null && listOrderInfo.size() != 0) {
  327. for (OrderInfo oldOrderInfo : listOrderInfo) {
  328. if (oldOrderInfo.getSpid().equals(orderInfo.getSpid())
  329. && oldOrderInfo.getStatus() == 0) {
  330. if (orderInfo.getCpid().equals("changshi") && ecbProductInfo != null && ecbProductInfo.getDiscntOrderState().equals("3") && orderInfo.getOrderchannel().equals("H5_ko")) {
  331. if (ecbDiscntDao.queryByUserid(orderInfo.getUserid(), ecbProductInfo.getDiscntValue(), 0) != null) {
  332. throw new BusinessException("9010", "用户续订,重复续订", new String[0]);
  333. } else {
  334. ecbService.order(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid(), ecbProductInfo);
  335. ecbDiscntDao.order(ecbProductInfo, orderInfo);
  336. this.orderDao.order(orderInfo);
  337. throw new BusinessException("9999", "用户续订", new String[0]);
  338. }
  339. } else if (orderInfo.getCpid().equals("changshi") && orderInfo.getSpid().equals("1040") && !orderInfo.getOrderchannel().equals("H5_ko")) {
  340. ecbService.order(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid(), ecbProductInfo);
  341. ecbDiscntDao.order(ecbProductInfo, orderInfo);
  342. this.orderDao.order(orderInfo);
  343. } else {
  344. if (!"1322".equals(orderInfo.getSpid())){
  345. throw new BusinessException("9010", "您已订购,请不要重复订购!", new String[0]);
  346. }
  347. }
  348. }
  349. }
  350. }
  351. }
  352. }
  353. } else if (orderInfo.getOrdertype() == 3) {
  354. OrderInfo oldOrderInfo = orderDao.findByUser(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid());
  355. if (oldOrderInfo != null && !StringUtils.isEmpty(oldOrderInfo.getEndtime())) {
  356. orderInfo.setEndtime(this.sysDao.getEndtimeForMonth(1, oldOrderInfo.getEndtime()));
  357. orderInfo.setOrdertime(oldOrderInfo.getOrdertime());
  358. } else {
  359. orderInfo.setEndtime(this.sysDao.getEndtimeForMonth(1, DateFormatUtils.format(new Date(), "yyyyMMdd") + "235959"));
  360. }
  361. }
  362. if (!this.blackWhiteDao.isWhiteUser(orderInfo.getUserid(), orderInfo.getCpid())) {
  363. if (orderInfo.getPaytype() == 1) {
  364. result = ecbService.order(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid(), ecbProductInfo);
  365. if (ecbProductInfo != null) {
  366. ecbDiscntDao.order(ecbProductInfo, orderInfo);
  367. }
  368. } else if (orderInfo.getPaytype() == 2) {
  369. } else if (orderInfo.getPaytype() == 3) {
  370. ecbService.query(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid(), orderInfo.getProvince());
  371. dingxiangOrderService.order(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid());
  372. } else if (orderInfo.getPaytype() == 4) {
  373. /**
  374. * 增加能力共享平台订购入口
  375. * zzb 2020-02-21
  376. */
  377. String accesstype = "1"; //sp/cp的二次认证方式: 1:H5认证 2:SDK认证 3:短信认证 4:页面认证
  378. if (!StringUtils.isEmpty(orderInfo.getSeqnumber())) {
  379. accesstype = "3";
  380. }
  381. orderInfo.setChannel("SHARE");
  382. //1为CAP短信接口,2为自有短信接口
  383. if ("1".equals(orderInfo.getSubtype())) {
  384. orderInfo.setChannel("SMSCAPSHARE"); //代表走的是CAP短信订购接口获取TOKEN再调能力平台接口订购
  385. } else if ("2".equals(orderInfo.getSubtype())) {
  386. orderInfo.setChannel("SMSSHARE");//代表是自有短信订购接口获取TOKEN,再调能力平台接口订购
  387. }
  388. shareOrderService.order(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid());
  389. String spid = orderInfo.getSpid();
  390. /****
  391. if ("1023".equals(spid)||"1022".equals(spid)||"1028".equals(spid)||"1027".equals(spid)) {
  392. capOrderService.orderSync(orderInfo, accesstype);
  393. }
  394. ****/
  395. //CAP订购同步,20210902严铮榕
  396. //List<String> spids = Arrays.asList(syncSpids);//20230220修改,直接走能力平台产品表
  397. List<String> spids = orderDao.queryAopProduct();
  398. if (spids.contains(spid)) {
  399. capOrderService.orderSync(orderInfo, accesstype);
  400. }
  401. } else if(orderInfo.getPaytype() == 5){
  402. /**
  403. * 增加9楼订购入口
  404. * czw 2020-02-21
  405. */
  406. orderInfo.setChannel("INTENSIVE");
  407. currencyService.order(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid(), orderInfo.getToken());
  408. }
  409. else {
  410. String brand = ecbService.query(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid(), orderInfo.getProvince());
  411. String accesstype = "1"; //sp/cp的二次认证方式: 1:H5认证 2:SDK认证 3:短信认证 4:页面认证
  412. if (!StringUtils.isEmpty(orderInfo.getSeqnumber())) {
  413. accesstype = "3";
  414. }
  415. //调cap综合用户查询接口和卡部信控接口
  416. String capqrydata = null;
  417. try {
  418. capqrydata = capOrderService.capQuery(orderInfo.getUserid());
  419. } catch (Exception e) {
  420. e.printStackTrace();
  421. }
  422. if (capqrydata != null) {
  423. JSONObject capqryJson = JSON.parseObject(capqrydata);
  424. BRAND_CODE = capqryJson.getString("BRAND_CODE");
  425. REMOVE_TAG = capqryJson.getString("REMOVE_TAG");
  426. ACT_TAG = capqryJson.getString("ACT_TAG");
  427. RSP_CODE = capqryJson.getString("RSP_CODE");
  428. CUST_STATUS = capqryJson.getString("CUST_STATUS");
  429. }
  430. /*
  431. String xkqrydata = null;
  432. try {
  433. xkqrydata = capOrderService.kbxkQuery(orderInfo.getUserid());
  434. } catch (Exception e) {
  435. e.printStackTrace();
  436. }
  437. if (xkqrydata != null) {
  438. JSONObject capqryJson = JSON.parseObject(xkqrydata);
  439. valiVal = capqryJson.getString("valiVal");
  440. level = capqryJson.getString("level");
  441. }
  442. */
  443. logflag = true;
  444. //if("0004".equals(RSP_CODE)){
  445. // throw new BusinessException("cap0004", "错误码cap0004", new String[0]);
  446. //}
  447. //if (unifiedAuthService.sycnOrder(orderInfo)) {CAP接口已包含统计认证,不用再验证
  448. //订购,选择走CAP接口或是VAC接口
  449. /* boolean hasvac = true; //是否调老vac接口
  450. if (capOrderService.hasCap(orderInfo)) {//产品配置是走CAP
  451. orderInfo.setChannel("CAP");
  452. hasvac = false;
  453. result = this.capOrderService.order(orderInfo, accesstype);
  454. if ("0008".equals(result)) { //不是4G用户,走原vac
  455. hasvac = true;
  456. }
  457. }
  458. log.info("userid=>" + orderInfo.getUserid() + ",brand=>" + brand + ",accesstype=>" + accesstype + ",hasvac=>" + hasvac);
  459. if (hasvac && unifiedAuthService.sycnOrder(orderInfo)) { //没有走CAP业务配置,或者不是4G用户,只有调vac才走统一认证验证
  460. orderInfo.setChannel("VAC");
  461. result = this.vacOrderService.order(orderInfo.getUserid(), orderInfo.getSpid(), orderInfo.getSeqnumber() == null ? "" : orderInfo.getSeqnumber(), orderInfo.getOrderchannel());
  462. }*/
  463. //取消走VAC接口,统一都走cap订购接口
  464. orderInfo.setChannel("CAP");
  465. //1为CAP短信接口,2为自有短信接口
  466. if ("1".equals(orderInfo.getSubtype())) {
  467. orderInfo.setChannel("SMSCAP"); //代表走的是CAP短信订购接口获取TOKEN再调CAP接口订购
  468. }
  469. Map<String, String> map = this.capOrderService.orderCap(orderInfo, accesstype);
  470. result = map.get("result");
  471. String orderTime = map.get("orderTime");
  472. if (!StringUtils.isEmpty(orderTime)) {
  473. orderInfo.setOrdertime(orderTime);
  474. }
  475. //}
  476. }
  477. } else if (orderInfo.getCpid().equals("changshi") && ecbProductInfo != null) {
  478. ecbDiscntDao.order(ecbProductInfo, orderInfo);
  479. }
  480. String currentTime = this.sysDao.getCurrentTime();
  481. if (orderInfo.getOrdertime() == null) {
  482. orderInfo.setOrdertime(currentTime);
  483. }
  484. if (orderInfo.getEffecttime() == null) {
  485. orderInfo.setEffecttime(currentTime);
  486. }
  487. if (!result.equals("0") && orderInfo.getErrorhandle() == 0) {
  488. orderInfo.setOrderstatus(7);
  489. orderInfo.setIsexperience(1);
  490. orderInfo.setShowstatus("0");
  491. }
  492. if (orderInfo.getOrdertype() != 2) {
  493. this.orderDao.order(orderInfo);
  494. } else {
  495. this.orderDao.countOrder(orderInfo);
  496. }
  497. //合约产品白名单限制处理
  498. heyueOrderService.heyueOrderAfter(orderInfo);
  499. try {
  500. //订购量计数
  501. setRides(orderInfo, 1);
  502. } catch (Exception e) {
  503. e.printStackTrace();
  504. }
  505. } catch (Exception e) {
  506. log.error("userid:" + orderInfo.getUserid() + "订购出现异常," + e);
  507. e.printStackTrace();
  508. errorcode = "8000";
  509. errorinfo = "系统处理失败";
  510. if ((e instanceof BusinessException)) {
  511. errorcode = ((BusinessException) e).getCode();
  512. errorinfo = ((BusinessException) e).getMessage();
  513. if (errorinfo.length() > 200) {
  514. errorinfo = errorinfo.substring(0, 200);
  515. }
  516. if (errorinfo.contains("cap订购失败")) {
  517. String errorinfo2 = "cap订购失败";
  518. throw new BusinessException(errorcode, errorinfo2);
  519. } else if ("9068".equals(errorcode)) {
  520. String errorinfo2 = "账户或业务服务异常,暂无法订购!";
  521. throw new BusinessException(errorcode, errorinfo2);
  522. }
  523. }
  524. if (!errorcode.equals("9999")) {
  525. log.error(errorcode + "==>" + errorinfo + "==>" + e.getMessage() + e);
  526. throw new BusinessException(errorcode, errorinfo);
  527. }
  528. } finally {
  529. //调CAP平台或能力平台返回了指定错误信息调CAP查询接口,如果有订购关系,则把数据添加到CAP反向通知表,使用反向通知流程落订购关系,此次流程不记录订购日志,以提高订购成功率
  530. if ("9666".equals(errorcode) && ("CAP".equals(orderInfo.getChannel()) || "SHARE".equals(orderInfo.getChannel()))) {
  531. log.info("调CAP或调能力平台接口返回指定错误信息查询CAP落订购关系,不记录订购日志,userid=>" + orderInfo.getUserid() + " : " + orderInfo.getSpid());
  532. } else {
  533. //20211115 实时订购落券码 yzr 伯源渠道号178916423536 发放979 券码
  534. if ("178916423536".equals(orderInfo.getSubchannel()) && "979".equals(orderInfo.getSpid()) && "0".equals(errorcode)) {
  535. //订购时间在20211117~20211121
  536. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  537. Date ordertime = new Date();
  538. Map map = orderDao.getActiveTime(orderInfo.getSpid(), orderInfo.getSubchannel());
  539. boolean hascoupon = orderDao.hasCoupon(orderInfo.getSpid(), orderInfo.getUserid());
  540. if (map != null && map.size() > 0) {
  541. Date startime = sdf.parse(map.get("STARTTIME").toString());
  542. Date endtime = sdf.parse(map.get("ENDTIME").toString());
  543. if (ordertime.getTime() >= startime.getTime() && ordertime.getTime() <= endtime.getTime() && !hascoupon) {
  544. String orderid = orderDao.getOrderid(orderInfo.getUserid(), orderInfo.getSpid());
  545. orderInfo.setOrderid(orderid);
  546. orderDao.addCoupon(orderInfo);
  547. }
  548. }
  549. }
  550. saveLog(orderInfo, errorcode, errorinfo);
  551. }
  552. CapKbxkQryBean capKbxkQryBean = new CapKbxkQryBean();
  553. capKbxkQryBean.setUserid(orderInfo.getUserid());
  554. capKbxkQryBean.setActtag(ACT_TAG);
  555. capKbxkQryBean.setBrandcode(BRAND_CODE);
  556. capKbxkQryBean.setCuststatus(CUST_STATUS);
  557. capKbxkQryBean.setRemovetag(REMOVE_TAG);
  558. capKbxkQryBean.setRspcode(RSP_CODE);
  559. capKbxkQryBean.setUserlevel(level);
  560. capKbxkQryBean.setValival(valiVal);
  561. capKbxkQryBean.setCpid(orderInfo.getCpid());
  562. capKbxkQryBean.setSpid(orderInfo.getSpid());
  563. if (logflag) {
  564. try {
  565. capKbxkQryDao.addCapKbxkQryLog(capKbxkQryBean);
  566. } catch (Exception e) {
  567. e.printStackTrace();
  568. }
  569. }
  570. }
  571. }
  572. public void checkCancelOrder(OrderInfo orderInfo) throws Exception {
  573. String userid = orderInfo.getUserid();
  574. checkUserid(orderInfo);
  575. AreaInfo areaInfo = getAreaInfo(userid);
  576. orderInfo.setProvince(areaInfo.getProvince());
  577. orderInfo.setArea(areaInfo.getArea());
  578. CPInfo cpInfo = ConfigUtil.getCPInfo(orderInfo.getCpid(), null);
  579. if (cpInfo == null) {
  580. throw new BusinessException("7005", "CP标识无效", new String[0]);
  581. }
  582. SPInfo spInfo = getSPInfo(orderInfo);
  583. if (spInfo.getCancancelorder() == 1 && StringUtils.isEmpty(orderInfo.getCancelchannel())) {
  584. throw new BusinessException("9011", "该产品不支持退订操作", new String[0]);
  585. }
  586. if (this.orderDao.hasTiyanValid(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid())) {
  587. throw new BusinessException("9015", "该产品体验期未结束不支持退订操作,如有疑问请咨询中国联通客服4000600611", new String[0]);
  588. }
  589. String spid = orderInfo.getSpid();
  590. /* if ("1009".equals(spid)){
  591. String activeTime = dictionaryDao.getValue("mangtv16ActiveTime");
  592. String[] split = activeTime.split("\\|");
  593. if(orderDao.isMangtvCancel(userid,spid,split[0],split[1])){
  594. throw new BusinessException("9016", "该产品体验期未结束不支持退订操作", new String[0]);
  595. }
  596. }*/
  597. if (orderDao.queryCancelConf(spid) && !"kf".equals(orderInfo.getChannel()) && !checkSpid(spid)) {
  598. Integer num = orderDao.getCancelMonth(spid);
  599. if (!orderDao.isCancel(userid, spid, num)) {
  600. throw new BusinessException("9016", "该产品合约期未结束不支持退订操作,如有疑问请咨询中国联通客服4000600611", new String[0]);
  601. }
  602. }
  603. }
  604. private boolean checkSpid(String spid) throws SQLException {
  605. boolean flag = false;
  606. String valueSpid = this.orderDao.getDictionryValue("hyCancelSpid");
  607. if (valueSpid != null && valueSpid.length() > 0) {
  608. for (String sp : valueSpid.split(",")) {
  609. if (spid.equals(sp)) {
  610. flag = true;
  611. }
  612. }
  613. }
  614. return flag;
  615. }
  616. public void cancelOrder(OrderInfo orderInfo) throws Exception {
  617. cancelOrder(orderInfo, null);
  618. }
  619. public void cancelOrder(OrderInfo orderInfo, EcbProductInfo ecbProductInfo) throws Exception {
  620. String errorcode = "0";
  621. String errorinfo = "";
  622. String oldSpid = "";
  623. try {
  624. OrderInfo relationOrder = null;
  625. boolean isHasOrder = false;
  626. boolean isHasOtherOrder = false;
  627. //20230103退订互斥产品
  628. String hcspid = orderDao.getDictionryValue("hcspid");
  629. if (!StringUtils.isEmpty(hcspid)){
  630. String[] splits = hcspid.split(",");
  631. for (String split:splits){
  632. if (orderInfo.getSpid().equals(split)){
  633. boolean flag = orderDao.hasOrder(orderInfo.getUserid(), orderInfo.getSpid());
  634. if (!flag){
  635. String mutex = orderInfo.getMutex();
  636. flag = orderDao.hasOrder(orderInfo.getUserid(), mutex);
  637. if (flag){
  638. oldSpid = orderInfo.getSpid();
  639. orderInfo.setSpid(mutex);
  640. getSPInfo(orderInfo);
  641. }
  642. }
  643. break;
  644. }
  645. }
  646. }
  647. //查询当前商品订购状态是否存在()
  648. List<OrderInfo> listOrderInfo = orderDao.findByUser(orderInfo.getUserid());
  649. if(!"kf".equals(orderInfo.getChannel())&&!isflag(orderInfo.getSpid())) {
  650. log.info("======================进入不为kf分支========================" + orderInfo.getChannel());
  651. if (listOrderInfo == null || listOrderInfo.size() == 0) {
  652. throw new BusinessException("9016", "退订失败,无该用户订购关系或者已失效", new String[0]);
  653. }
  654. for (OrderInfo oldOrderInfo : listOrderInfo) {
  655. if (orderInfo.getSpid().equals(oldOrderInfo.getSpid())) {
  656. orderInfo.setOrdertime(oldOrderInfo.getOrdertime());
  657. //结束时间不为空就放进去
  658. if (!StringUtils.isEmpty(oldOrderInfo.getEndtime())) {
  659. orderInfo.setEndtime(oldOrderInfo.getEndtime());
  660. }
  661. //status不为零则已退订
  662. if (oldOrderInfo.getStatus() != 0) {
  663. throw new BusinessException("9017", "退订失败,该用户已退订该产品", new String[0]);
  664. }
  665. isHasOrder = true;
  666. break;
  667. }
  668. }
  669. }else{
  670. isHasOrder = true;
  671. }
  672. if (!StringUtils.isEmpty(orderInfo.getRelationSp())) {
  673. for (OrderInfo oldOrderInfo : listOrderInfo) {
  674. if (oldOrderInfo.getSpid().equals(orderInfo.getRelationSp()) && oldOrderInfo.getStatus() == 0) {
  675. relationOrder = orderInfo;
  676. relationOrder.setSpid(orderInfo.getRelationSp());
  677. isHasOtherOrder = true;
  678. break;
  679. }
  680. }
  681. }
  682. if (!isHasOrder && !isHasOtherOrder) {
  683. throw new BusinessException("9018", "退订失败,该用户没有订购该产品或者已失效", new String[0]);
  684. }
  685. if (!("kf".equals(orderInfo.getChannel()) && !StringUtils.isEmpty(orderInfo.getIsvacorder()) && orderInfo.getIsvacorder().equals("0")) ) {
  686. if (!this.blackWhiteDao.isWhiteUser(orderInfo.getUserid(), orderInfo.getCpid())) {
  687. if (orderInfo.getPaytype() == 1) {
  688. if (ecbProductInfo == null || (ecbProductInfo != null && (!ecbProductInfo.getDiscntOrderState().equals("2") || !ecbProductInfo.getDiscntFee().equals("0")))) {
  689. errorcode = ecbService.cancelOrder(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid(), orderInfo.getOrdertime(), ecbProductInfo);
  690. if (ecbProductInfo != null) {
  691. ecbDiscntDao.cancel(ecbProductInfo, orderInfo);
  692. }
  693. }
  694. } else if (orderInfo.getPaytype() == 2) {
  695. } else if (orderInfo.getPaytype() == 3) {
  696. dingxiangOrderService.cancel(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid());
  697. } else if (orderInfo.getPaytype() == 4) {
  698. /**
  699. * 增加能力共享平台订购入口
  700. * zzb 2020-02-21
  701. */
  702. orderInfo.setChannel("SHARE");
  703. //1为CAP短信接口,2为自有短信接口
  704. if ("1".equals(orderInfo.getSubtype())) {
  705. orderInfo.setChannel("SMSCAPSHARE"); //代表走的是CAP短信订购接口获取TOKEN再调能力平台接口订购
  706. } else if ("2".equals(orderInfo.getSubtype())) {
  707. orderInfo.setChannel("SMSSHARE");//代表是自有短信订购接口获取TOKEN,再调能力平台接口订购
  708. }
  709. shareOrderService.cancel(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid());
  710. if (this.checkSpid(orderInfo.getSpid())) {
  711. try {
  712. Integer num = orderDao.getCancelMonth(orderInfo.getSpid());
  713. if (!orderDao.isCancel(orderInfo.getUserid(), orderInfo.getSpid(), num)) {
  714. String wyjSpid = orderDao.getWYJSpid(orderInfo.getSpid());
  715. WyjLogBean wyjLogBean = new WyjLogBean();
  716. wyjLogBean.setUserid(orderInfo.getUserid());
  717. wyjLogBean.setProvince(orderInfo.getProvince());
  718. wyjLogBean.setArea(orderInfo.getArea());
  719. wyjLogBean.setCpid("wyj");
  720. wyjLogBean.setChannel(orderInfo.getChannel());
  721. wyjLogBean.setSpid(wyjSpid);
  722. wyjLogBean.setExtend1(orderInfo.getSpid());
  723. log.info("合约包退订成功,违约包入库" + JSON.toJSONString(wyjLogBean));
  724. orderDao.addWYJLog(wyjLogBean);
  725. }
  726. } catch (Exception e) {
  727. log.info("w违约包入库失败" + orderInfo.getUserid());
  728. }
  729. }
  730. }else if(orderInfo.getPaytype() == 5){
  731. orderInfo.setChannel("INTENSIVE");
  732. currencyService.cancel(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid());
  733. } else {
  734. /* //退订,选择走CAP接口或是VAC接口
  735. boolean hasvac = true; //是否调老vac接口
  736. if (capOrderService.hasCap(orderInfo)) {//产品配置是走CAP
  737. orderInfo.setChannel("CAP");
  738. hasvac = false;
  739. String result = this.capOrderService.cancel(orderInfo);
  740. if ("0008".equals(result)) { //不是4G用户,走原vac
  741. hasvac = true;
  742. }
  743. }
  744. if (hasvac) { //没有走CAP业务配置,或者不是4G用户
  745. orderInfo.setChannel("VAC");
  746. this.vacOrderService.cancelOrder(orderInfo.getUserid(), orderInfo.getSpid());
  747. }*/
  748. //全部都走cap接口
  749. orderInfo.setChannel("CAP");
  750. //1为CAP短信接口,2为自有短信接口
  751. if ("1".equals(orderInfo.getSubtype())) {
  752. orderInfo.setChannel("SMSCAP"); //代表走的是CAP短信订购接口获取TOKEN再调CAP接口订购
  753. }
  754. //调用cap退订接口
  755. Map<String, String> map = this.capOrderService.cancelCap(orderInfo);
  756. String cancelTime = map.get("cancelTime");
  757. if (!StringUtils.isEmpty(cancelTime)) {
  758. orderInfo.setCanceltime(cancelTime);
  759. }
  760. if (this.checkSpid(orderInfo.getSpid())) {
  761. try {
  762. Integer num = orderDao.getCancelMonth(orderInfo.getSpid());
  763. if (!orderDao.isCancel(orderInfo.getUserid(), orderInfo.getSpid(), num)) {
  764. String wyjSpid = orderDao.getWYJSpid(orderInfo.getSpid());
  765. WyjLogBean wyjLogBean = new WyjLogBean();
  766. wyjLogBean.setUserid(orderInfo.getUserid());
  767. wyjLogBean.setProvince(orderInfo.getProvince());
  768. wyjLogBean.setArea(orderInfo.getArea());
  769. wyjLogBean.setCpid("wyj");
  770. wyjLogBean.setChannel(orderInfo.getChannel());
  771. wyjLogBean.setSpid(wyjSpid);
  772. wyjLogBean.setExtend1(orderInfo.getSpid());
  773. log.info("合约包退订成功,违约包入库" + JSON.toJSONString(wyjLogBean));
  774. orderDao.addWYJLog(wyjLogBean);
  775. }
  776. } catch (Exception e) {
  777. log.info("w违约包入库失败" + orderInfo.getUserid());
  778. }
  779. }
  780. }
  781. }
  782. }else{
  783. log.info("======================进入不走平台退订流程分支========================" + orderInfo.getChannel());
  784. }
  785. if (isHasOrder && isHasOtherOrder) {
  786. this.smCancelDao.cancelOrder(relationOrder);
  787. }
  788. if (!isHasOrder && isHasOtherOrder) {
  789. orderInfo.setSpid(orderInfo.getRelationSp());
  790. }
  791. String currentTime = this.sysDao.getCurrentTime();
  792. if (orderInfo.getCanceltime() != null) {
  793. orderInfo.setEndtime(getEndTime(orderInfo.getCanceltime()));
  794. } else {
  795. orderInfo.setCanceltime(currentTime);
  796. }
  797. if (orderInfo.getEffecttime() == null) {
  798. orderInfo.setEffecttime(currentTime);
  799. }
  800. if (orderInfo.getEndtime() == null) {
  801. orderInfo.setEndtime(this.sysDao.getEndDayOfCurrentMonth());
  802. }
  803. //更新操作
  804. this.orderDao.cancelOrder(orderInfo);
  805. } catch (Exception e) {
  806. log.error("userid:" + orderInfo.getUserid() + "退购出现异常," + e);
  807. errorcode = "8000";
  808. errorinfo = "系统忙";
  809. if ((e instanceof BusinessException)) {
  810. errorcode = ((BusinessException) e).getCode();
  811. errorinfo = ((BusinessException) e).getMessage();
  812. if (errorinfo.length() > 200) {
  813. errorinfo = errorinfo.substring(0, 200);
  814. }
  815. if (errorinfo.contains("cap退订失败")) {
  816. String errorinfo2 = "cap退订失败";
  817. throw new BusinessException(errorcode, errorinfo2);
  818. }
  819. }
  820. if (!errorcode.equals("9998")) {
  821. throw e;
  822. }
  823. } finally {
  824. if (!StringUtils.isEmpty(oldSpid)){
  825. errorinfo += "退订"+oldSpid+"实际退订"+orderInfo.getSpid();
  826. }
  827. saveLog(orderInfo, errorcode, errorinfo);
  828. }
  829. }
  830. /**
  831. * 鉴权平台用退订接口
  832. *
  833. * @param orderInfo
  834. * @param ecbProductInfo
  835. * @param channel
  836. * @throws Exception
  837. */
  838. public void cancelOrder(OrderInfo orderInfo, EcbProductInfo ecbProductInfo, String channel) throws Exception {
  839. String errorcode = "0";
  840. String errorinfo = "";
  841. String oldSpid = "";
  842. try {
  843. //20230201退订快手合约互斥产品
  844. String hcspid = orderDao.getDictionryValue("hcspid");
  845. if (!StringUtils.isEmpty(hcspid)){
  846. String[] splits = hcspid.split(",");
  847. for (String split:splits){
  848. if (orderInfo.getSpid().equals(split)){
  849. boolean flag = orderDao.hasOrder(orderInfo.getUserid(), orderInfo.getSpid());
  850. if (!flag){
  851. String mutex = orderInfo.getMutex();
  852. flag = orderDao.hasOrder(orderInfo.getUserid(), mutex);
  853. if (flag){
  854. oldSpid = orderInfo.getSpid();
  855. orderInfo.setSpid(mutex);
  856. getSPInfo(orderInfo);
  857. }
  858. }
  859. break;
  860. }
  861. }
  862. }
  863. List<OrderInfo> listOrderInfo = orderDao.findByUser(orderInfo.getUserid());
  864. OrderInfo relationOrder = null;
  865. boolean isHasOrder = false;
  866. boolean isHasOtherOrder = false;
  867. if (!"kf".equals(orderInfo.getChannel())) {
  868. log.info("======================进入不为kf分支========================" + orderInfo.getChannel());
  869. if (listOrderInfo == null || listOrderInfo.size() == 0) {
  870. throw new BusinessException("9016", "退订失败,无该用户订购关系或者已失效", new String[0]);
  871. }
  872. for (OrderInfo oldOrderInfo : listOrderInfo) {
  873. if (orderInfo.getSpid().equals(oldOrderInfo.getSpid())) {
  874. orderInfo.setOrdertime(oldOrderInfo.getOrdertime());
  875. if (!StringUtils.isEmpty(oldOrderInfo.getEndtime())) {
  876. orderInfo.setEndtime(oldOrderInfo.getEndtime());
  877. }
  878. if (oldOrderInfo.getStatus() != 0) {
  879. throw new BusinessException("9017", "退订失败,该用户已退订该产品", new String[0]);
  880. }
  881. isHasOrder = true;
  882. break;
  883. }
  884. }
  885. } else {
  886. isHasOrder = true;
  887. }
  888. if (!StringUtils.isEmpty(orderInfo.getRelationSp())) {
  889. for (OrderInfo oldOrderInfo : listOrderInfo) {
  890. if (oldOrderInfo.getSpid().equals(orderInfo.getRelationSp()) && oldOrderInfo.getStatus() == 0) {
  891. relationOrder = orderInfo;
  892. relationOrder.setSpid(orderInfo.getRelationSp());
  893. isHasOtherOrder = true;
  894. break;
  895. }
  896. }
  897. }
  898. if (!isHasOrder && !isHasOtherOrder) {
  899. throw new BusinessException("9018", "退订失败,该用户没有订购该产品或者已失效", new String[0]);
  900. }
  901. if (!("kf".equals(orderInfo.getChannel()) && !StringUtils.isEmpty(orderInfo.getIsvacorder()) && orderInfo.getIsvacorder().equals("0"))) {
  902. if (!this.blackWhiteDao.isWhiteUser(orderInfo.getUserid(), orderInfo.getCpid())) {
  903. if (orderInfo.getPaytype() == 1) {
  904. if (ecbProductInfo == null || (ecbProductInfo != null && (!ecbProductInfo.getDiscntOrderState().equals("2") || !ecbProductInfo.getDiscntFee().equals("0")))) {
  905. errorcode = ecbService.cancelOrder(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid(), orderInfo.getOrdertime(), ecbProductInfo);
  906. if (ecbProductInfo != null) {
  907. ecbDiscntDao.cancel(ecbProductInfo, orderInfo);
  908. }
  909. }
  910. } else if (orderInfo.getPaytype() == 2) {
  911. } else if (orderInfo.getPaytype() == 3) {
  912. dingxiangOrderService.cancel(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid());
  913. } else if (orderInfo.getPaytype() == 4) {
  914. /**
  915. * 增加能力共享平台订购入口
  916. * zzb 2020-02-21
  917. */
  918. orderInfo.setChannel("SHARE");
  919. shareOrderService.cancel(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid(), channel);
  920. if (this.checkSpid(orderInfo.getSpid())) {
  921. try {
  922. Integer num = orderDao.getCancelMonth(orderInfo.getSpid());
  923. if (!orderDao.isCancel(orderInfo.getUserid(), orderInfo.getSpid(), num)) {
  924. String wyjSpid = orderDao.getWYJSpid(orderInfo.getSpid());
  925. WyjLogBean wyjLogBean = new WyjLogBean();
  926. wyjLogBean.setUserid(orderInfo.getUserid());
  927. wyjLogBean.setProvince(orderInfo.getProvince());
  928. wyjLogBean.setArea(orderInfo.getArea());
  929. wyjLogBean.setCpid("wyj");
  930. wyjLogBean.setChannel(orderInfo.getChannel());
  931. wyjLogBean.setSpid(wyjSpid);
  932. wyjLogBean.setExtend1(orderInfo.getSpid());
  933. log.info("合约包退订成功,违约包入库" + JSON.toJSONString(wyjLogBean));
  934. orderDao.addWYJLog(wyjLogBean);
  935. }
  936. } catch (Exception e) {
  937. log.info("w违约包入库失败" + orderInfo.getUserid());
  938. }
  939. }
  940. }else if(orderInfo.getPaytype() == 5){
  941. orderInfo.setChannel("INTENSIVE");
  942. currencyService.cancel(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid());
  943. } else {
  944. /* //退订,选择走CAP接口或是VAC接口
  945. boolean hasvac = true; //是否调老vac接口
  946. if (capOrderService.hasCap(orderInfo)) {//产品配置是走CAP
  947. orderInfo.setChannel("CAP");
  948. hasvac = false;
  949. String result = this.capOrderService.cancel(orderInfo);
  950. if ("0008".equals(result)) { //不是4G用户,走原vac
  951. hasvac = true;
  952. }
  953. }
  954. if (hasvac) { //没有走CAP业务配置,或者不是4G用户
  955. orderInfo.setChannel("VAC");
  956. this.vacOrderService.cancelOrder(orderInfo.getUserid(), orderInfo.getSpid());
  957. }*/
  958. //全部都走cap接口
  959. orderInfo.setChannel("CAP");
  960. this.capOrderService.cancel(orderInfo);
  961. if (this.checkSpid(orderInfo.getSpid())) {
  962. try {
  963. Integer num = orderDao.getCancelMonth(orderInfo.getSpid());
  964. if (!orderDao.isCancel(orderInfo.getUserid(), orderInfo.getSpid(), num)) {
  965. String wyjSpid = orderDao.getWYJSpid(orderInfo.getSpid());
  966. WyjLogBean wyjLogBean = new WyjLogBean();
  967. wyjLogBean.setUserid(orderInfo.getUserid());
  968. wyjLogBean.setProvince(orderInfo.getProvince());
  969. wyjLogBean.setArea(orderInfo.getArea());
  970. wyjLogBean.setCpid("wyj");
  971. wyjLogBean.setChannel(orderInfo.getChannel());
  972. wyjLogBean.setSpid(wyjSpid);
  973. wyjLogBean.setExtend1(orderInfo.getSpid());
  974. log.info("合约包退订成功,违约包入库" + JSON.toJSONString(wyjLogBean));
  975. orderDao.addWYJLog(wyjLogBean);
  976. }
  977. } catch (Exception e) {
  978. log.info("w违约包入库失败" + orderInfo.getUserid());
  979. }
  980. }
  981. }
  982. }
  983. }else{
  984. log.info("======================进入不走平台退订流程分支========================" + orderInfo.getChannel());
  985. }
  986. if (isHasOrder && isHasOtherOrder) {
  987. this.smCancelDao.cancelOrder(relationOrder);
  988. }
  989. if (!isHasOrder && isHasOtherOrder) {
  990. orderInfo.setSpid(orderInfo.getRelationSp());
  991. }
  992. String currentTime = this.sysDao.getCurrentTime();
  993. if (orderInfo.getCanceltime() != null) {
  994. orderInfo.setEndtime(getEndTime(orderInfo.getCanceltime()));
  995. } else {
  996. orderInfo.setCanceltime(currentTime);
  997. }
  998. if (orderInfo.getEffecttime() == null) {
  999. orderInfo.setEffecttime(currentTime);
  1000. }
  1001. if (orderInfo.getEndtime() == null) {
  1002. orderInfo.setEndtime(this.sysDao.getEndDayOfCurrentMonth());
  1003. }
  1004. this.orderDao.cancelOrder(orderInfo);
  1005. } catch (Exception e) {
  1006. log.error("userid:" + orderInfo.getUserid() + "退购出现异常," + e);
  1007. errorcode = "8000";
  1008. errorinfo = "系统忙";
  1009. if ((e instanceof BusinessException)) {
  1010. errorcode = ((BusinessException) e).getCode();
  1011. errorinfo = ((BusinessException) e).getMessage();
  1012. if (errorinfo.length() > 200) {
  1013. errorinfo = errorinfo.substring(0, 200);
  1014. }
  1015. if (errorinfo.contains("cap退订失败")) {
  1016. String errorinfo2 = "cap退订失败";
  1017. throw new BusinessException(errorcode, errorinfo2);
  1018. }
  1019. }
  1020. if (!errorcode.equals("9998")) {
  1021. throw e;
  1022. }
  1023. } finally {
  1024. log.info("=========================================进入finally");
  1025. if (!StringUtils.isEmpty(oldSpid)) {
  1026. errorinfo = errorinfo + "退订" + oldSpid + "实际退订" + orderInfo.getSpid();
  1027. }
  1028. saveLog(orderInfo, errorcode, errorinfo);
  1029. }
  1030. }
  1031. public String getEndTime(String endTimeStr) throws ParseException {
  1032. Calendar calendar = Calendar.getInstance();
  1033. Date date = DateUtils.parseDate(endTimeStr.substring(0, 8), new String[]{"yyyyMMdd"});
  1034. calendar.setTime(date);
  1035. String day = calendar.getActualMaximum(Calendar.DAY_OF_MONTH) + "";
  1036. String year = calendar.get(Calendar.YEAR) + "";
  1037. String month = calendar.get(Calendar.MONTH) + 1 < 10 ? "0" + (calendar.get(Calendar.MONTH) + 1)
  1038. : calendar.get(Calendar.MONTH) + 1 + "";
  1039. return year + month + day + "235959";
  1040. }
  1041. public void saveLog(OrderInfo orderInfo, String errorcode, String errorinfo) {
  1042. OrderLog orderLog = new OrderLog();
  1043. orderLog.setApptype(orderInfo.getApptype());
  1044. orderLog.setArea(orderInfo.getArea());
  1045. if (orderInfo.getOrderchannel() != null) {
  1046. orderLog.setChannel(orderInfo.getOrderchannel());
  1047. } else {
  1048. orderLog.setChannel(orderInfo.getCancelchannel());
  1049. }
  1050. orderLog.setOrderstatus(orderInfo.getOrderstatus());
  1051. orderLog.setStatus(orderInfo.getStatus());
  1052. orderLog.setCpid(orderInfo.getCpid());
  1053. orderLog.setIsexperience(orderInfo.getIsexperience());
  1054. orderLog.setOrdertype(orderInfo.getOrdertype() + "");
  1055. orderLog.setProvince(orderInfo.getProvince());
  1056. orderLog.setArea(orderInfo.getArea());
  1057. orderLog.setSpid(orderInfo.getSpid());
  1058. orderLog.setUserid(orderInfo.getUserid());
  1059. orderLog.setErrorcode(errorcode);
  1060. orderLog.setErrorinfo(errorinfo);
  1061. if (!orderInfo.getTimes().isEmpty()) {
  1062. orderLog.setTimes((System.currentTimeMillis() - NumberUtils.toLong(orderInfo.getTimes())) + "");
  1063. }
  1064. this.orderLogDao.addOrderLog(orderLog);
  1065. }
  1066. public void inserArrearageData(OrderInfo orderInfo) throws SQLException {
  1067. ReflowBean reflowBean = new ReflowBean();
  1068. reflowBean.setUserid(orderInfo.getUserid());
  1069. reflowBean.setSpid(orderInfo.getSpid());
  1070. reflowBean.setActivitycode("reflowActivityLevel3");
  1071. reflowBean.setResultcode("1");
  1072. reflowBean.setResultinfo("待处理");
  1073. orderDao.inserArrearageData(reflowBean);
  1074. }
  1075. public boolean isflag(String spid) throws SQLException {
  1076. boolean flag = false;
  1077. String touTiaoSpid = dictionaryDao.getValue("touTiaoSpid");
  1078. String[] split = touTiaoSpid.split(",");
  1079. for (String str:split){
  1080. String[] s = str.split("_");
  1081. if (spid.equals(s[0])){
  1082. flag = true;
  1083. break;
  1084. }
  1085. }
  1086. return flag;
  1087. }
  1088. public static void main(String args[]) throws Exception {
  1089. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd");
  1090. System.out.println(simpleDateFormat.format(new Date()));
  1091. System.out.println((Integer.parseInt("09")) > 30);
  1092. System.out.println(Integer.parseInt("09"));
  1093. }
  1094. }