0caf035259f38b68d66b5426c55164d653b803fe.svn-base 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134
  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) {
  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);
  397. if (spids.contains(spid)) {
  398. capOrderService.orderSync(orderInfo, accesstype);
  399. }
  400. } else if(orderInfo.getPaytype() == 5){
  401. /**
  402. * 增加9楼订购入口
  403. * czw 2020-02-21
  404. */
  405. orderInfo.setChannel("INTENSIVE");
  406. currencyService.order(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid(), orderInfo.getToken());
  407. }
  408. else {
  409. String brand = ecbService.query(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid(), orderInfo.getProvince());
  410. String accesstype = "1"; //sp/cp的二次认证方式: 1:H5认证 2:SDK认证 3:短信认证 4:页面认证
  411. if (!StringUtils.isEmpty(orderInfo.getSeqnumber())) {
  412. accesstype = "3";
  413. }
  414. //调cap综合用户查询接口和卡部信控接口
  415. String capqrydata = null;
  416. try {
  417. capqrydata = capOrderService.capQuery(orderInfo.getUserid());
  418. } catch (Exception e) {
  419. e.printStackTrace();
  420. }
  421. if (capqrydata != null) {
  422. JSONObject capqryJson = JSON.parseObject(capqrydata);
  423. BRAND_CODE = capqryJson.getString("BRAND_CODE");
  424. REMOVE_TAG = capqryJson.getString("REMOVE_TAG");
  425. ACT_TAG = capqryJson.getString("ACT_TAG");
  426. RSP_CODE = capqryJson.getString("RSP_CODE");
  427. CUST_STATUS = capqryJson.getString("CUST_STATUS");
  428. }
  429. /*
  430. String xkqrydata = null;
  431. try {
  432. xkqrydata = capOrderService.kbxkQuery(orderInfo.getUserid());
  433. } catch (Exception e) {
  434. e.printStackTrace();
  435. }
  436. if (xkqrydata != null) {
  437. JSONObject capqryJson = JSON.parseObject(xkqrydata);
  438. valiVal = capqryJson.getString("valiVal");
  439. level = capqryJson.getString("level");
  440. }
  441. */
  442. logflag = true;
  443. //if("0004".equals(RSP_CODE)){
  444. // throw new BusinessException("cap0004", "错误码cap0004", new String[0]);
  445. //}
  446. //if (unifiedAuthService.sycnOrder(orderInfo)) {CAP接口已包含统计认证,不用再验证
  447. //订购,选择走CAP接口或是VAC接口
  448. /* boolean hasvac = true; //是否调老vac接口
  449. if (capOrderService.hasCap(orderInfo)) {//产品配置是走CAP
  450. orderInfo.setChannel("CAP");
  451. hasvac = false;
  452. result = this.capOrderService.order(orderInfo, accesstype);
  453. if ("0008".equals(result)) { //不是4G用户,走原vac
  454. hasvac = true;
  455. }
  456. }
  457. log.info("userid=>" + orderInfo.getUserid() + ",brand=>" + brand + ",accesstype=>" + accesstype + ",hasvac=>" + hasvac);
  458. if (hasvac && unifiedAuthService.sycnOrder(orderInfo)) { //没有走CAP业务配置,或者不是4G用户,只有调vac才走统一认证验证
  459. orderInfo.setChannel("VAC");
  460. result = this.vacOrderService.order(orderInfo.getUserid(), orderInfo.getSpid(), orderInfo.getSeqnumber() == null ? "" : orderInfo.getSeqnumber(), orderInfo.getOrderchannel());
  461. }*/
  462. //取消走VAC接口,统一都走cap订购接口
  463. orderInfo.setChannel("CAP");
  464. //1为CAP短信接口,2为自有短信接口
  465. if ("1".equals(orderInfo.getSubtype())) {
  466. orderInfo.setChannel("SMSCAP"); //代表走的是CAP短信订购接口获取TOKEN再调CAP接口订购
  467. }
  468. Map<String, String> map = this.capOrderService.orderCap(orderInfo, accesstype);
  469. result = map.get("result");
  470. String orderTime = map.get("orderTime");
  471. if (!StringUtils.isEmpty(orderTime)) {
  472. orderInfo.setOrdertime(orderTime);
  473. }
  474. //}
  475. }
  476. } else if (orderInfo.getCpid().equals("changshi") && ecbProductInfo != null) {
  477. ecbDiscntDao.order(ecbProductInfo, orderInfo);
  478. }
  479. String currentTime = this.sysDao.getCurrentTime();
  480. if (orderInfo.getOrdertime() == null) {
  481. orderInfo.setOrdertime(currentTime);
  482. }
  483. if (orderInfo.getEffecttime() == null) {
  484. orderInfo.setEffecttime(currentTime);
  485. }
  486. if (!result.equals("0") && orderInfo.getErrorhandle() == 0) {
  487. orderInfo.setOrderstatus(7);
  488. orderInfo.setIsexperience(1);
  489. orderInfo.setShowstatus("0");
  490. }
  491. if (orderInfo.getOrdertype() != 2) {
  492. this.orderDao.order(orderInfo);
  493. } else {
  494. this.orderDao.countOrder(orderInfo);
  495. }
  496. //合约产品白名单限制处理
  497. heyueOrderService.heyueOrderAfter(orderInfo);
  498. try {
  499. //订购量计数
  500. setRides(orderInfo, 1);
  501. } catch (Exception e) {
  502. e.printStackTrace();
  503. }
  504. } catch (Exception e) {
  505. log.error("userid:" + orderInfo.getUserid() + "订购出现异常," + e);
  506. e.printStackTrace();
  507. errorcode = "8000";
  508. errorinfo = "系统处理失败";
  509. if ((e instanceof BusinessException)) {
  510. errorcode = ((BusinessException) e).getCode();
  511. errorinfo = ((BusinessException) e).getMessage();
  512. if (errorinfo.length() > 200) {
  513. errorinfo = errorinfo.substring(0, 200);
  514. }
  515. if (errorinfo.contains("cap订购失败")) {
  516. String errorinfo2 = "cap订购失败";
  517. throw new BusinessException(errorcode, errorinfo2);
  518. } else if ("9068".equals(errorcode)) {
  519. String errorinfo2 = "账户或业务服务异常,暂无法订购!";
  520. throw new BusinessException(errorcode, errorinfo2);
  521. }
  522. }
  523. if (!errorcode.equals("9999")) {
  524. log.error(errorcode + "==>" + errorinfo + "==>" + e.getMessage() + e);
  525. throw new BusinessException(errorcode, errorinfo);
  526. }
  527. } finally {
  528. //调CAP平台或能力平台返回了指定错误信息调CAP查询接口,如果有订购关系,则把数据添加到CAP反向通知表,使用反向通知流程落订购关系,此次流程不记录订购日志,以提高订购成功率
  529. if ("9666".equals(errorcode) && ("CAP".equals(orderInfo.getChannel()) || "SHARE".equals(orderInfo.getChannel()))) {
  530. log.info("调CAP或调能力平台接口返回指定错误信息查询CAP落订购关系,不记录订购日志,userid=>" + orderInfo.getUserid() + " : " + orderInfo.getSpid());
  531. } else {
  532. //20211115 实时订购落券码 yzr 伯源渠道号178916423536 发放979 券码
  533. if ("178916423536".equals(orderInfo.getSubchannel()) && "979".equals(orderInfo.getSpid()) && "0".equals(errorcode)) {
  534. //订购时间在20211117~20211121
  535. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  536. Date ordertime = new Date();
  537. Map map = orderDao.getActiveTime(orderInfo.getSpid(), orderInfo.getSubchannel());
  538. boolean hascoupon = orderDao.hasCoupon(orderInfo.getSpid(), orderInfo.getUserid());
  539. if (map != null && map.size() > 0) {
  540. Date startime = sdf.parse(map.get("STARTTIME").toString());
  541. Date endtime = sdf.parse(map.get("ENDTIME").toString());
  542. if (ordertime.getTime() >= startime.getTime() && ordertime.getTime() <= endtime.getTime() && !hascoupon) {
  543. String orderid = orderDao.getOrderid(orderInfo.getUserid(), orderInfo.getSpid());
  544. orderInfo.setOrderid(orderid);
  545. orderDao.addCoupon(orderInfo);
  546. }
  547. }
  548. }
  549. saveLog(orderInfo, errorcode, errorinfo);
  550. }
  551. CapKbxkQryBean capKbxkQryBean = new CapKbxkQryBean();
  552. capKbxkQryBean.setUserid(orderInfo.getUserid());
  553. capKbxkQryBean.setActtag(ACT_TAG);
  554. capKbxkQryBean.setBrandcode(BRAND_CODE);
  555. capKbxkQryBean.setCuststatus(CUST_STATUS);
  556. capKbxkQryBean.setRemovetag(REMOVE_TAG);
  557. capKbxkQryBean.setRspcode(RSP_CODE);
  558. capKbxkQryBean.setUserlevel(level);
  559. capKbxkQryBean.setValival(valiVal);
  560. capKbxkQryBean.setCpid(orderInfo.getCpid());
  561. capKbxkQryBean.setSpid(orderInfo.getSpid());
  562. if (logflag) {
  563. try {
  564. capKbxkQryDao.addCapKbxkQryLog(capKbxkQryBean);
  565. } catch (Exception e) {
  566. e.printStackTrace();
  567. }
  568. }
  569. }
  570. }
  571. public void checkCancelOrder(OrderInfo orderInfo) throws Exception {
  572. String userid = orderInfo.getUserid();
  573. checkUserid(orderInfo);
  574. AreaInfo areaInfo = getAreaInfo(userid);
  575. orderInfo.setProvince(areaInfo.getProvince());
  576. orderInfo.setArea(areaInfo.getArea());
  577. CPInfo cpInfo = ConfigUtil.getCPInfo(orderInfo.getCpid(), null);
  578. if (cpInfo == null) {
  579. throw new BusinessException("7005", "CP标识无效", new String[0]);
  580. }
  581. SPInfo spInfo = getSPInfo(orderInfo);
  582. if (spInfo.getCancancelorder() == 1 && StringUtils.isEmpty(orderInfo.getCancelchannel())) {
  583. throw new BusinessException("9011", "该产品不支持退订操作", new String[0]);
  584. }
  585. if (this.orderDao.hasTiyanValid(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid())) {
  586. throw new BusinessException("9015", "该产品体验期未结束不支持退订操作,如有疑问请咨询中国联通客服4000600611", new String[0]);
  587. }
  588. String spid = orderInfo.getSpid();
  589. /* if ("1009".equals(spid)){
  590. String activeTime = dictionaryDao.getValue("mangtv16ActiveTime");
  591. String[] split = activeTime.split("\\|");
  592. if(orderDao.isMangtvCancel(userid,spid,split[0],split[1])){
  593. throw new BusinessException("9016", "该产品体验期未结束不支持退订操作", new String[0]);
  594. }
  595. }*/
  596. if (orderDao.queryCancelConf(spid) && !"kf".equals(orderInfo.getChannel()) && !checkSpid(spid)) {
  597. Integer num = orderDao.getCancelMonth(spid);
  598. if (!orderDao.isCancel(userid, spid, num)) {
  599. throw new BusinessException("9016", "该产品合约期未结束不支持退订操作,如有疑问请咨询中国联通客服4000600611", new String[0]);
  600. }
  601. }
  602. }
  603. private boolean checkSpid(String spid) throws SQLException {
  604. boolean flag = false;
  605. String valueSpid = this.orderDao.getDictionryValue("hyCancelSpid");
  606. if (valueSpid != null && valueSpid.length() > 0) {
  607. for (String sp : valueSpid.split(",")) {
  608. if (spid.equals(sp)) {
  609. flag = true;
  610. }
  611. }
  612. }
  613. return flag;
  614. }
  615. public void cancelOrder(OrderInfo orderInfo) throws Exception {
  616. cancelOrder(orderInfo, null);
  617. }
  618. public void cancelOrder(OrderInfo orderInfo, EcbProductInfo ecbProductInfo) throws Exception {
  619. String errorcode = "0";
  620. String errorinfo = "";
  621. String oldSpid = "";
  622. try {
  623. OrderInfo relationOrder = null;
  624. boolean isHasOrder = false;
  625. boolean isHasOtherOrder = false;
  626. //20230103退订互斥产品
  627. String hcspid = orderDao.getDictionryValue("hcspid");
  628. if (!StringUtils.isEmpty(hcspid)){
  629. String[] splits = hcspid.split(",");
  630. for (String split:splits){
  631. if (orderInfo.getSpid().equals(split)){
  632. boolean flag = orderDao.hasOrder(orderInfo.getUserid(), orderInfo.getSpid());
  633. if (!flag){
  634. String mutex = orderInfo.getMutex();
  635. flag = orderDao.hasOrder(orderInfo.getUserid(), mutex);
  636. if (flag){
  637. oldSpid = orderInfo.getSpid();
  638. orderInfo.setSpid(mutex);
  639. getSPInfo(orderInfo);
  640. }
  641. }
  642. break;
  643. }
  644. }
  645. }
  646. //查询当前商品订购状态是否存在()
  647. List<OrderInfo> listOrderInfo = orderDao.findByUser(orderInfo.getUserid());
  648. if(!orderInfo.getChannel().equals("kf")) {
  649. log.info("======================进入不为kf分支========================" + orderInfo.getChannel());
  650. if (listOrderInfo == null || listOrderInfo.size() == 0) {
  651. throw new BusinessException("9016", "退订失败,无该用户订购关系或者已失效", new String[0]);
  652. }
  653. for (OrderInfo oldOrderInfo : listOrderInfo) {
  654. if (orderInfo.getSpid().equals(oldOrderInfo.getSpid())) {
  655. orderInfo.setOrdertime(oldOrderInfo.getOrdertime());
  656. //结束时间不为空就放进去
  657. if (!StringUtils.isEmpty(oldOrderInfo.getEndtime())) {
  658. orderInfo.setEndtime(oldOrderInfo.getEndtime());
  659. }
  660. //status不为零则已退订
  661. if (oldOrderInfo.getStatus() != 0) {
  662. throw new BusinessException("9017", "退订失败,该用户已退订该产品", new String[0]);
  663. }
  664. isHasOrder = true;
  665. break;
  666. }
  667. }
  668. }else{
  669. isHasOrder = true;
  670. }
  671. if (!StringUtils.isEmpty(orderInfo.getRelationSp())) {
  672. for (OrderInfo oldOrderInfo : listOrderInfo) {
  673. if (oldOrderInfo.getSpid().equals(orderInfo.getRelationSp()) && oldOrderInfo.getStatus() == 0) {
  674. relationOrder = orderInfo;
  675. relationOrder.setSpid(orderInfo.getRelationSp());
  676. isHasOtherOrder = true;
  677. break;
  678. }
  679. }
  680. }
  681. if (!isHasOrder && !isHasOtherOrder) {
  682. throw new BusinessException("9018", "退订失败,该用户没有订购该产品或者已失效", new String[0]);
  683. }
  684. if (!(orderInfo.getChannel().equals("kf") && !StringUtils.isEmpty(orderInfo.getIsvacorder()) && orderInfo.getIsvacorder().equals("0")) ) {
  685. if (!this.blackWhiteDao.isWhiteUser(orderInfo.getUserid(), orderInfo.getCpid())) {
  686. if (orderInfo.getPaytype() == 1) {
  687. if (ecbProductInfo == null || (ecbProductInfo != null && (!ecbProductInfo.getDiscntOrderState().equals("2") || !ecbProductInfo.getDiscntFee().equals("0")))) {
  688. errorcode = ecbService.cancelOrder(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid(), orderInfo.getOrdertime(), ecbProductInfo);
  689. if (ecbProductInfo != null) {
  690. ecbDiscntDao.cancel(ecbProductInfo, orderInfo);
  691. }
  692. }
  693. } else if (orderInfo.getPaytype() == 2) {
  694. } else if (orderInfo.getPaytype() == 3) {
  695. dingxiangOrderService.cancel(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid());
  696. } else if (orderInfo.getPaytype() == 4) {
  697. /**
  698. * 增加能力共享平台订购入口
  699. * zzb 2020-02-21
  700. */
  701. orderInfo.setChannel("SHARE");
  702. //1为CAP短信接口,2为自有短信接口
  703. if ("1".equals(orderInfo.getSubtype())) {
  704. orderInfo.setChannel("SMSCAPSHARE"); //代表走的是CAP短信订购接口获取TOKEN再调能力平台接口订购
  705. } else if ("2".equals(orderInfo.getSubtype())) {
  706. orderInfo.setChannel("SMSSHARE");//代表是自有短信订购接口获取TOKEN,再调能力平台接口订购
  707. }
  708. shareOrderService.cancel(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid());
  709. if (this.checkSpid(orderInfo.getSpid())) {
  710. try {
  711. Integer num = orderDao.getCancelMonth(orderInfo.getSpid());
  712. if (!orderDao.isCancel(orderInfo.getUserid(), orderInfo.getSpid(), num)) {
  713. String wyjSpid = orderDao.getWYJSpid(orderInfo.getSpid());
  714. WyjLogBean wyjLogBean = new WyjLogBean();
  715. wyjLogBean.setUserid(orderInfo.getUserid());
  716. wyjLogBean.setProvince(orderInfo.getProvince());
  717. wyjLogBean.setArea(orderInfo.getArea());
  718. wyjLogBean.setCpid("wyj");
  719. wyjLogBean.setChannel(orderInfo.getChannel());
  720. wyjLogBean.setSpid(wyjSpid);
  721. wyjLogBean.setExtend1(orderInfo.getSpid());
  722. log.info("合约包退订成功,违约包入库" + JSON.toJSONString(wyjLogBean));
  723. orderDao.addWYJLog(wyjLogBean);
  724. }
  725. } catch (Exception e) {
  726. log.info("w违约包入库失败" + orderInfo.getUserid());
  727. }
  728. }
  729. }else if(orderInfo.getPaytype() == 5){
  730. orderInfo.setChannel("INTENSIVE");
  731. currencyService.cancel(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid());
  732. } else {
  733. /* //退订,选择走CAP接口或是VAC接口
  734. boolean hasvac = true; //是否调老vac接口
  735. if (capOrderService.hasCap(orderInfo)) {//产品配置是走CAP
  736. orderInfo.setChannel("CAP");
  737. hasvac = false;
  738. String result = this.capOrderService.cancel(orderInfo);
  739. if ("0008".equals(result)) { //不是4G用户,走原vac
  740. hasvac = true;
  741. }
  742. }
  743. if (hasvac) { //没有走CAP业务配置,或者不是4G用户
  744. orderInfo.setChannel("VAC");
  745. this.vacOrderService.cancelOrder(orderInfo.getUserid(), orderInfo.getSpid());
  746. }*/
  747. //全部都走cap接口
  748. orderInfo.setChannel("CAP");
  749. //1为CAP短信接口,2为自有短信接口
  750. if ("1".equals(orderInfo.getSubtype())) {
  751. orderInfo.setChannel("SMSCAP"); //代表走的是CAP短信订购接口获取TOKEN再调CAP接口订购
  752. }
  753. //调用cap退订接口
  754. Map<String, String> map = this.capOrderService.cancelCap(orderInfo);
  755. String cancelTime = map.get("cancelTime");
  756. if (!StringUtils.isEmpty(cancelTime)) {
  757. orderInfo.setCanceltime(cancelTime);
  758. }
  759. if (this.checkSpid(orderInfo.getSpid())) {
  760. try {
  761. Integer num = orderDao.getCancelMonth(orderInfo.getSpid());
  762. if (!orderDao.isCancel(orderInfo.getUserid(), orderInfo.getSpid(), num)) {
  763. String wyjSpid = orderDao.getWYJSpid(orderInfo.getSpid());
  764. WyjLogBean wyjLogBean = new WyjLogBean();
  765. wyjLogBean.setUserid(orderInfo.getUserid());
  766. wyjLogBean.setProvince(orderInfo.getProvince());
  767. wyjLogBean.setArea(orderInfo.getArea());
  768. wyjLogBean.setCpid("wyj");
  769. wyjLogBean.setChannel(orderInfo.getChannel());
  770. wyjLogBean.setSpid(wyjSpid);
  771. wyjLogBean.setExtend1(orderInfo.getSpid());
  772. log.info("合约包退订成功,违约包入库" + JSON.toJSONString(wyjLogBean));
  773. orderDao.addWYJLog(wyjLogBean);
  774. }
  775. } catch (Exception e) {
  776. log.info("w违约包入库失败" + orderInfo.getUserid());
  777. }
  778. }
  779. }
  780. }
  781. }else{
  782. log.info("======================进入不走平台退订流程分支========================" + orderInfo.getChannel());
  783. }
  784. if (isHasOrder && isHasOtherOrder) {
  785. this.smCancelDao.cancelOrder(relationOrder);
  786. }
  787. if (!isHasOrder && isHasOtherOrder) {
  788. orderInfo.setSpid(orderInfo.getRelationSp());
  789. }
  790. String currentTime = this.sysDao.getCurrentTime();
  791. if (orderInfo.getCanceltime() != null) {
  792. orderInfo.setEndtime(getEndTime(orderInfo.getCanceltime()));
  793. } else {
  794. orderInfo.setCanceltime(currentTime);
  795. }
  796. if (orderInfo.getEffecttime() == null) {
  797. orderInfo.setEffecttime(currentTime);
  798. }
  799. if (orderInfo.getEndtime() == null) {
  800. orderInfo.setEndtime(this.sysDao.getEndDayOfCurrentMonth());
  801. }
  802. //更新操作
  803. this.orderDao.cancelOrder(orderInfo);
  804. } catch (Exception e) {
  805. log.error("userid:" + orderInfo.getUserid() + "退购出现异常," + e);
  806. errorcode = "8000";
  807. errorinfo = "系统忙";
  808. if ((e instanceof BusinessException)) {
  809. errorcode = ((BusinessException) e).getCode();
  810. errorinfo = ((BusinessException) e).getMessage();
  811. if (errorinfo.length() > 200) {
  812. errorinfo = errorinfo.substring(0, 200);
  813. }
  814. if (errorinfo.contains("cap退订失败")) {
  815. String errorinfo2 = "cap退订失败";
  816. throw new BusinessException(errorcode, errorinfo2);
  817. }
  818. }
  819. if (!errorcode.equals("9998")) {
  820. throw e;
  821. }
  822. } finally {
  823. if (!StringUtils.isEmpty(oldSpid)){
  824. errorinfo += "退订"+oldSpid+"实际退订"+orderInfo.getSpid();
  825. }
  826. saveLog(orderInfo, errorcode, errorinfo);
  827. }
  828. }
  829. /**
  830. * 鉴权平台用退订接口
  831. *
  832. * @param orderInfo
  833. * @param ecbProductInfo
  834. * @param channel
  835. * @throws Exception
  836. */
  837. public void cancelOrder(OrderInfo orderInfo, EcbProductInfo ecbProductInfo, String channel) throws Exception {
  838. String errorcode = "0";
  839. String errorinfo = "";
  840. try {
  841. List<OrderInfo> listOrderInfo = orderDao.findByUser(orderInfo.getUserid());
  842. OrderInfo relationOrder = null;
  843. boolean isHasOrder = false;
  844. boolean isHasOtherOrder = false;
  845. if (!orderInfo.getChannel().equals("kf")) {
  846. log.info("======================进入不为kf分支========================" + orderInfo.getChannel());
  847. if (listOrderInfo == null || listOrderInfo.size() == 0) {
  848. throw new BusinessException("9016", "退订失败,无该用户订购关系或者已失效", new String[0]);
  849. }
  850. for (OrderInfo oldOrderInfo : listOrderInfo) {
  851. if (orderInfo.getSpid().equals(oldOrderInfo.getSpid())) {
  852. orderInfo.setOrdertime(oldOrderInfo.getOrdertime());
  853. if (!StringUtils.isEmpty(oldOrderInfo.getEndtime())) {
  854. orderInfo.setEndtime(oldOrderInfo.getEndtime());
  855. }
  856. if (oldOrderInfo.getStatus() != 0) {
  857. throw new BusinessException("9017", "退订失败,该用户已退订该产品", new String[0]);
  858. }
  859. isHasOrder = true;
  860. break;
  861. }
  862. }
  863. } else {
  864. isHasOrder = true;
  865. }
  866. if (!StringUtils.isEmpty(orderInfo.getRelationSp())) {
  867. for (OrderInfo oldOrderInfo : listOrderInfo) {
  868. if (oldOrderInfo.getSpid().equals(orderInfo.getRelationSp()) && oldOrderInfo.getStatus() == 0) {
  869. relationOrder = orderInfo;
  870. relationOrder.setSpid(orderInfo.getRelationSp());
  871. isHasOtherOrder = true;
  872. break;
  873. }
  874. }
  875. }
  876. if (!isHasOrder && !isHasOtherOrder) {
  877. throw new BusinessException("9018", "退订失败,该用户没有订购该产品或者已失效", new String[0]);
  878. }
  879. if (!(orderInfo.getChannel().equals("kf") && !StringUtils.isEmpty(orderInfo.getIsvacorder()) && orderInfo.getIsvacorder().equals("0"))) {
  880. if (!this.blackWhiteDao.isWhiteUser(orderInfo.getUserid(), orderInfo.getCpid())) {
  881. if (orderInfo.getPaytype() == 1) {
  882. if (ecbProductInfo == null || (ecbProductInfo != null && (!ecbProductInfo.getDiscntOrderState().equals("2") || !ecbProductInfo.getDiscntFee().equals("0")))) {
  883. errorcode = ecbService.cancelOrder(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid(), orderInfo.getOrdertime(), ecbProductInfo);
  884. if (ecbProductInfo != null) {
  885. ecbDiscntDao.cancel(ecbProductInfo, orderInfo);
  886. }
  887. }
  888. } else if (orderInfo.getPaytype() == 2) {
  889. } else if (orderInfo.getPaytype() == 3) {
  890. dingxiangOrderService.cancel(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid());
  891. } else if (orderInfo.getPaytype() == 4) {
  892. /**
  893. * 增加能力共享平台订购入口
  894. * zzb 2020-02-21
  895. */
  896. orderInfo.setChannel("SHARE");
  897. shareOrderService.cancel(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid(), channel);
  898. if (this.checkSpid(orderInfo.getSpid())) {
  899. try {
  900. Integer num = orderDao.getCancelMonth(orderInfo.getSpid());
  901. if (!orderDao.isCancel(orderInfo.getUserid(), orderInfo.getSpid(), num)) {
  902. String wyjSpid = orderDao.getWYJSpid(orderInfo.getSpid());
  903. WyjLogBean wyjLogBean = new WyjLogBean();
  904. wyjLogBean.setUserid(orderInfo.getUserid());
  905. wyjLogBean.setProvince(orderInfo.getProvince());
  906. wyjLogBean.setArea(orderInfo.getArea());
  907. wyjLogBean.setCpid("wyj");
  908. wyjLogBean.setChannel(orderInfo.getChannel());
  909. wyjLogBean.setSpid(wyjSpid);
  910. wyjLogBean.setExtend1(orderInfo.getSpid());
  911. log.info("合约包退订成功,违约包入库" + JSON.toJSONString(wyjLogBean));
  912. orderDao.addWYJLog(wyjLogBean);
  913. }
  914. } catch (Exception e) {
  915. log.info("w违约包入库失败" + orderInfo.getUserid());
  916. }
  917. }
  918. }else if(orderInfo.getPaytype() == 5){
  919. orderInfo.setChannel("INTENSIVE");
  920. currencyService.cancel(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid());
  921. } else {
  922. /* //退订,选择走CAP接口或是VAC接口
  923. boolean hasvac = true; //是否调老vac接口
  924. if (capOrderService.hasCap(orderInfo)) {//产品配置是走CAP
  925. orderInfo.setChannel("CAP");
  926. hasvac = false;
  927. String result = this.capOrderService.cancel(orderInfo);
  928. if ("0008".equals(result)) { //不是4G用户,走原vac
  929. hasvac = true;
  930. }
  931. }
  932. if (hasvac) { //没有走CAP业务配置,或者不是4G用户
  933. orderInfo.setChannel("VAC");
  934. this.vacOrderService.cancelOrder(orderInfo.getUserid(), orderInfo.getSpid());
  935. }*/
  936. //全部都走cap接口
  937. orderInfo.setChannel("CAP");
  938. this.capOrderService.cancel(orderInfo);
  939. if (this.checkSpid(orderInfo.getSpid())) {
  940. try {
  941. Integer num = orderDao.getCancelMonth(orderInfo.getSpid());
  942. if (!orderDao.isCancel(orderInfo.getUserid(), orderInfo.getSpid(), num)) {
  943. String wyjSpid = orderDao.getWYJSpid(orderInfo.getSpid());
  944. WyjLogBean wyjLogBean = new WyjLogBean();
  945. wyjLogBean.setUserid(orderInfo.getUserid());
  946. wyjLogBean.setProvince(orderInfo.getProvince());
  947. wyjLogBean.setArea(orderInfo.getArea());
  948. wyjLogBean.setCpid("wyj");
  949. wyjLogBean.setChannel(orderInfo.getChannel());
  950. wyjLogBean.setSpid(wyjSpid);
  951. wyjLogBean.setExtend1(orderInfo.getSpid());
  952. log.info("合约包退订成功,违约包入库" + JSON.toJSONString(wyjLogBean));
  953. orderDao.addWYJLog(wyjLogBean);
  954. }
  955. } catch (Exception e) {
  956. log.info("w违约包入库失败" + orderInfo.getUserid());
  957. }
  958. }
  959. }
  960. }
  961. }else{
  962. log.info("======================进入不走平台退订流程分支========================" + orderInfo.getChannel());
  963. }
  964. if (isHasOrder && isHasOtherOrder) {
  965. this.smCancelDao.cancelOrder(relationOrder);
  966. }
  967. if (!isHasOrder && isHasOtherOrder) {
  968. orderInfo.setSpid(orderInfo.getRelationSp());
  969. }
  970. String currentTime = this.sysDao.getCurrentTime();
  971. if (orderInfo.getCanceltime() != null) {
  972. orderInfo.setEndtime(getEndTime(orderInfo.getCanceltime()));
  973. } else {
  974. orderInfo.setCanceltime(currentTime);
  975. }
  976. if (orderInfo.getEffecttime() == null) {
  977. orderInfo.setEffecttime(currentTime);
  978. }
  979. if (orderInfo.getEndtime() == null) {
  980. orderInfo.setEndtime(this.sysDao.getEndDayOfCurrentMonth());
  981. }
  982. this.orderDao.cancelOrder(orderInfo);
  983. } catch (Exception e) {
  984. log.error("userid:" + orderInfo.getUserid() + "退购出现异常," + e);
  985. errorcode = "8000";
  986. errorinfo = "系统忙";
  987. if ((e instanceof BusinessException)) {
  988. errorcode = ((BusinessException) e).getCode();
  989. errorinfo = ((BusinessException) e).getMessage();
  990. if (errorinfo.length() > 200) {
  991. errorinfo = errorinfo.substring(0, 200);
  992. }
  993. if (errorinfo.contains("cap退订失败")) {
  994. String errorinfo2 = "cap退订失败";
  995. throw new BusinessException(errorcode, errorinfo2);
  996. }
  997. }
  998. if (!errorcode.equals("9998")) {
  999. throw e;
  1000. }
  1001. } finally {
  1002. log.info("=========================================进入finally");
  1003. saveLog(orderInfo, errorcode, errorinfo);
  1004. }
  1005. }
  1006. public String getEndTime(String endTimeStr) throws ParseException {
  1007. Calendar calendar = Calendar.getInstance();
  1008. Date date = DateUtils.parseDate(endTimeStr.substring(0, 8), new String[]{"yyyyMMdd"});
  1009. calendar.setTime(date);
  1010. String day = calendar.getActualMaximum(Calendar.DAY_OF_MONTH) + "";
  1011. String year = calendar.get(Calendar.YEAR) + "";
  1012. String month = calendar.get(Calendar.MONTH) + 1 < 10 ? "0" + (calendar.get(Calendar.MONTH) + 1)
  1013. : calendar.get(Calendar.MONTH) + 1 + "";
  1014. return year + month + day + "235959";
  1015. }
  1016. public void saveLog(OrderInfo orderInfo, String errorcode, String errorinfo) {
  1017. OrderLog orderLog = new OrderLog();
  1018. orderLog.setApptype(orderInfo.getApptype());
  1019. orderLog.setArea(orderInfo.getArea());
  1020. if (orderInfo.getOrderchannel() != null) {
  1021. orderLog.setChannel(orderInfo.getOrderchannel());
  1022. } else {
  1023. orderLog.setChannel(orderInfo.getCancelchannel());
  1024. }
  1025. orderLog.setOrderstatus(orderInfo.getOrderstatus());
  1026. orderLog.setStatus(orderInfo.getStatus());
  1027. orderLog.setCpid(orderInfo.getCpid());
  1028. orderLog.setIsexperience(orderInfo.getIsexperience());
  1029. orderLog.setOrdertype(orderInfo.getOrdertype() + "");
  1030. orderLog.setProvince(orderInfo.getProvince());
  1031. orderLog.setArea(orderInfo.getArea());
  1032. orderLog.setSpid(orderInfo.getSpid());
  1033. orderLog.setUserid(orderInfo.getUserid());
  1034. orderLog.setErrorcode(errorcode);
  1035. orderLog.setErrorinfo(errorinfo);
  1036. if (!orderInfo.getTimes().isEmpty()) {
  1037. orderLog.setTimes((System.currentTimeMillis() - NumberUtils.toLong(orderInfo.getTimes())) + "");
  1038. }
  1039. this.orderLogDao.addOrderLog(orderLog);
  1040. }
  1041. public void inserArrearageData(OrderInfo orderInfo) throws SQLException {
  1042. ReflowBean reflowBean = new ReflowBean();
  1043. reflowBean.setUserid(orderInfo.getUserid());
  1044. reflowBean.setSpid(orderInfo.getSpid());
  1045. reflowBean.setActivitycode("reflowActivityLevel3");
  1046. reflowBean.setResultcode("1");
  1047. reflowBean.setResultinfo("待处理");
  1048. orderDao.inserArrearageData(reflowBean);
  1049. }
  1050. public static void main(String args[]) throws Exception {
  1051. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd");
  1052. System.out.println(simpleDateFormat.format(new Date()));
  1053. System.out.println((Integer.parseInt("09")) > 30);
  1054. System.out.println(Integer.parseInt("09"));
  1055. }
  1056. }