package com.chinacreator.videoalliance.order.service; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.chinacreator.common.exception.BusinessException; import com.chinacreator.common.util.Base64; import com.chinacreator.common.util.MD5; import com.chinacreator.common.util.UsermobUtil; import com.chinacreator.videoalliance.common.bean.AreaInfo; import com.chinacreator.videoalliance.common.bean.CPInfo; import com.chinacreator.videoalliance.common.dao.DictionaryDao; import com.chinacreator.videoalliance.common.dao.ProvinceControlDao; import com.chinacreator.videoalliance.common.util.AreaUtil; import com.chinacreator.videoalliance.common.util.ConfigUtil; import com.chinacreator.videoalliance.order.bean.*; import com.chinacreator.videoalliance.order.dao.*; import com.chinacreator.videoalliance.order.util.*; import com.chinacreator.videoalliance.smc.util.SendSmsUtil; import org.apache.commons.lang.math.NumberUtils; import org.apache.commons.lang.time.DateFormatUtils; import org.apache.commons.lang.time.DateUtils; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.util.StringUtils; import java.net.URLEncoder; import java.sql.SQLException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; @Component public class OrderService { private static Logger log = Logger.getLogger("orderError"); @Autowired private SmCancelDao smCancelDao; @Autowired private OrderDao orderDao; @Autowired private BlackWhiteDao blackWhiteDao; @Autowired private SPDao spDao; @Autowired private DictionaryDao dictionaryDao; @Autowired private ProvinceControlDao provinceControlDao; @Autowired private VacOrderService vacOrderService; @Autowired private OrderLogDao orderLogDao; @Autowired private OrderSysDao sysDao; @Autowired private EcbService ecbService; @Autowired private EcbDiscntDao ecbDiscntDao; @Autowired private UnifiedAuthService unifiedAuthService; @Autowired private DingxiangOrderService dingxiangOrderService; @Autowired CapOrderService capOrderService; @Autowired CapKbxkQryDao capKbxkQryDao; @Autowired private ShareOrderService shareOrderService; @Autowired private HeyueOrderService heyueOrderService; @Autowired private CurrencyService currencyService; private String[] syncSpids = {"1011", "1012", "1013", "1014", "1016", "1047", "1048", "1049", "1051", "1052", "1221", "1222", "1223", "1224", "1225", "1226", "1009", "1027", "1028", "292", "293", "294", "295", "296", "297", "298", "299", "1022", "1023"}; public void checkUserid(OrderInfo orderInfo) throws Exception { String userid = orderInfo.getUserid(); if ((StringUtils.isEmpty(userid)) || ("null".equals(userid))) throw new BusinessException("7002", "手机号码无效", new String[0]); if (!UsermobUtil.isValid(userid)) { userid = ConfigUtil.decrypt(userid, orderInfo.getCpid()); userid = ConfigUtil.getUserid(userid, orderInfo.getCpid()); } if (!UsermobUtil.isValid(userid)) { throw new BusinessException("7002", "手机号码无效", new String[0]); } orderInfo.setUserid(userid); } public void checkCpInfo(OrderInfo orderInfo) throws Exception { CPInfo cpInfo = ConfigUtil.getCPInfo(orderInfo.getCpid(), null); if ((cpInfo.getStatus() != 0) && (cpInfo.getStatus() != 4)) { throw new BusinessException("9002", "该业务暂未开放,敬请期待。", new String[0]); } } private void checkSpInfo(OrderInfo orderInfo) throws Exception { SPInfo spInfo = getSPInfo(orderInfo); if (spInfo.getCanorder() == 1 && StringUtils.isEmpty(orderInfo.getOrderchannel())) { throw new BusinessException("9012", "该产品不支持订购操作", new String[0]); } if (orderInfo.getOrdertype() == 1) { if (spInfo.getType() != 0 && spInfo.getType() != 3) { throw new BusinessException("5305", "产品标识符无效", new String[0]); } if (spInfo.getType() == 0) { if (StringUtils.isEmpty(orderInfo.getVideoid())) { throw new BusinessException("8002", "{0}参数无效", new String[]{"videoid"}); } if (StringUtils.isEmpty(orderInfo.getVideoname())) throw new BusinessException("8002", "{0}参数无效", new String[]{"videoname"}); try { String videoname = new String(Base64.decodeBase64(orderInfo.getVideoname()), "UTF-8"); orderInfo.setVideoname(videoname); } catch (Exception e) { throw new BusinessException("8002", "{0}参数无效", new String[]{"videoname"}); } orderInfo.setEndtime(this.sysDao.getLastDay()); } else { orderInfo.setOrdertype(3); } } else if (orderInfo.getOrdertype() == 0) { if (spInfo.getType() == 0) { throw new BusinessException("5305", "产品标识符无效", new String[0]); } } else if (orderInfo.getOrdertype() == 2) { if (spInfo.getType() != 0) { throw new BusinessException("5305", "产品标识符无效", new String[0]); } orderInfo.setCachesucceed(0); } else { throw new BusinessException("8002", "{0}参数无效", new String[]{"ordertype"}); } orderInfo.setSpid(spInfo.getSpid()); } public void checkOrder(OrderInfo orderInfo) throws Exception { checkUserid(orderInfo); checkCpInfo(orderInfo); checkSpInfo(orderInfo); checkToken(orderInfo); String userid = orderInfo.getUserid(); String cpid = orderInfo.getCpid(); String spid = orderInfo.getSpid(); String province = orderInfo.getProvince(); if (this.blackWhiteDao.isBlackUser(userid, orderInfo.getCpid())) { throw new BusinessException("9002", "用户为黑名单用户", new String[0]); } AreaInfo areaInfo = getAreaInfo(userid); orderInfo.setProvince(areaInfo.getProvince()); orderInfo.setArea(areaInfo.getArea()); CPInfo cpInfo = ConfigUtil.getCPInfo(orderInfo.getCpid(), areaInfo.getProvince()); if (cpInfo == null) { throw new BusinessException("7005", "CP标识无效", new String[0]); } String allowOrder = this.dictionaryDao.getValue("allowOrder"); if (("1".equals(allowOrder)) || (areaInfo.getStatus() == 1)) { throw new BusinessException("9002", "该业务暂未开放,敬请期待。", new String[0]); } if ((areaInfo.getProvince() != null) && (this.provinceControlDao.isNotOpen(areaInfo.getProvince()))) throw new BusinessException("9003", "您号码的归属地{0}暂未开放该业务,敬请期待。", new String[]{areaInfo.getProvince()}); if (this.orderDao.isOpen(orderInfo.getSpid(), orderInfo.getCpid(), orderInfo.getProvince())) { // status 为2 表示省份尚未开通 // throw new BusinessException("9003", "省份尚未开通此业务,敬请期待!"); if (!this.blackWhiteDao.isWhiteUserBySpid(userid, orderInfo.getCpid(), orderInfo.getSpid())) {//判断用户是否白名单,是则流程继续 throw new BusinessException("9003", "省份尚未开通此业务,敬请期待!"); } } if ("1009".equals(spid)) { if (orderDao.isMangtvOrder(userid, spid)) { throw new BusinessException("9014", "您已经参与过合约优惠活动,不能重复订购"); } } //北京号码段订购限制,20210902李嘉涵 String numberlimit = dictionaryDao.getValue("Numberlimit"); if (numberlimit != null && numberlimit.indexOf(userid.substring(0, 7)) != -1) { throw new BusinessException("9010", "用户为黑名单用户!", new String[0]); } //合约产品验证 heyueOrderService.heyueOrderBefore(orderInfo); //渠道方订购限制 checkOrderNum(orderInfo); } public void checkOrderNum(OrderInfo orderInfo) throws BusinessException { try { Map map = orderDao.channelProvince(orderInfo); if (map != null && map.size() > 0) { String type = String.valueOf(map.get("TYPE")); String provinceCode = String.valueOf(map.get("PROVINCECODE")); int orderNum = Integer.parseInt(String.valueOf(map.get("ORDER_NUM"))); orderInfo.setTimeType(type); orderInfo.setProvinceCode(provinceCode); Long count = setRides(orderInfo, 0); if (count >= orderNum) { throw new BusinessException("9066", "您所订购的产品今日额度已达到上限,请明日再尝试订购。"); } } } catch (Exception e) { e.printStackTrace(); if (e instanceof BusinessException) { String message = e.getMessage(); String code = ((BusinessException) e).getCode(); throw new BusinessException(code, message); } } } public Long setRides(OrderInfo orderInfo, int num) { String timeType = orderInfo.getTimeType(); if (StringUtils.isEmpty(timeType)) { return null; } SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd"); String day = simpleDateFormat.format(new Date()); String date; switch (Integer.parseInt(timeType)) { case 0: date = day; break; case 1: date = day.substring(0, 6); break; case 2: date = day.substring(0, 4); break; default: date = day; } String key = "order_" + date + "_" + orderInfo.getChannel() + "_" + orderInfo.getSpid() + "_" + orderInfo.getProvinceCode(); Long count = RedisCluster.jedis.incrBy(key, num); if (count == 0) { switch (Integer.parseInt(timeType)) { case 0: RedisCluster.jedis.expire(key, 24 * 60 * 60); break; case 1: RedisCluster.jedis.expire(key, 30 * 24 * 60 * 60); break; case 2: RedisCluster.jedis.expire(key, 366 * 30 * 24 * 60 * 60); break; default: RedisCluster.jedis.expire(key, 24 * 60 * 60); } } return count; } public void checkToken(OrderInfo orderInfo) throws Exception { if (orderDao.isToken(orderInfo.getSpid(), orderInfo.getCpid(), orderInfo.getChannel())) { return; } if (StringUtils.isEmpty(orderInfo.getToken())) { throw new BusinessException("9001", "token不能为空"); } /* if (orderInfo.getToken().length()!=32){ throw new BusinessException("9003","token位数不对"); }*/ Long num = RedisCluster.jedis.incrBy(orderInfo.getToken(), 1); if (num == 1) { RedisCluster.jedis.del(orderInfo.getToken()); throw new BusinessException("9001", "请求token不正确"); } if (num > 2) { throw new BusinessException("9001", "请求token重复"); } /* try { orderDao.insertToken(orderInfo.getToken()); } catch (SQLException e) { e.printStackTrace(); if(e.getMessage().contains("ORA-00001")){ throw new BusinessException("9001","请求token重复"); } }*/ } private AreaInfo getAreaInfo(String userid) throws Exception { AreaInfo areaInfo = AreaUtil.getAreaInfoByUserid(userid); if (areaInfo == null) { areaInfo = new AreaInfo(); } return areaInfo; } private SPInfo getSPInfo(OrderInfo orderInfo) throws Exception { SPInfo spInfo = null; if (StringUtils.isEmpty(orderInfo.getSpid())) spInfo = this.spDao.findDefaultByCP(orderInfo.getCpid()); else { spInfo = this.spDao.findById(orderInfo.getSpid()); } if (spInfo == null) { throw new BusinessException("5305", "产品标识符无效", new String[0]); } orderInfo.setSpid(spInfo.getSpid()); orderInfo.setMutex(spInfo.getMutex()); orderInfo.setRelationSp(spInfo.getRelationSp()); orderInfo.setPaytype(spInfo.getPaytype()); orderInfo.setErrorhandle(spInfo.getErrorhandle()); orderInfo.setDirectype(spInfo.getDirectype()); return spInfo; } public void order(OrderInfo orderInfo) throws Exception { order(orderInfo, null); } public void order(OrderInfo orderInfo, EcbProductInfo ecbProductInfo) throws Exception { String errorcode = "0"; String errorinfo = ""; String result = "0"; String BRAND_CODE = ""; String REMOVE_TAG = ""; String ACT_TAG = ""; String RSP_CODE = ""; String CUST_STATUS = ""; String valiVal = ""; String level = ""; boolean logflag = false; try { if (orderInfo.getOrdertype() != 2 && orderInfo.getOrdertype() != 3) { List listOrderInfo = orderDao.findByUser(orderInfo.getUserid()); if (listOrderInfo != null && listOrderInfo.size() > 0) { if (!StringUtils.isEmpty(orderInfo.getMutex())) { String[] mutexSpids = orderInfo.getMutex().trim().split(","); for (String mutexSpid : mutexSpids) { for (OrderInfo oldOrderInfo : listOrderInfo) { if (oldOrderInfo.getSpid().equals(orderInfo.getSpid()) && oldOrderInfo.getStatus() == 0) { if (!"1322".equals(orderInfo.getSpid())){ throw new BusinessException("9010", "您已订购,请不要重复订购!", new String[0]); } } if (oldOrderInfo.getSpid().equals(mutexSpid)) { throw new BusinessException("9011", "您已订购同类产品!", new String[0]); } } } } else { if (listOrderInfo != null && listOrderInfo.size() != 0) { for (OrderInfo oldOrderInfo : listOrderInfo) { if (oldOrderInfo.getSpid().equals(orderInfo.getSpid()) && oldOrderInfo.getStatus() == 0) { if (orderInfo.getCpid().equals("changshi") && ecbProductInfo != null && ecbProductInfo.getDiscntOrderState().equals("3") && orderInfo.getOrderchannel().equals("H5_ko")) { if (ecbDiscntDao.queryByUserid(orderInfo.getUserid(), ecbProductInfo.getDiscntValue(), 0) != null) { throw new BusinessException("9010", "用户续订,重复续订", new String[0]); } else { ecbService.order(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid(), ecbProductInfo); ecbDiscntDao.order(ecbProductInfo, orderInfo); this.orderDao.order(orderInfo); throw new BusinessException("9999", "用户续订", new String[0]); } } else if (orderInfo.getCpid().equals("changshi") && orderInfo.getSpid().equals("1040") && !orderInfo.getOrderchannel().equals("H5_ko")) { ecbService.order(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid(), ecbProductInfo); ecbDiscntDao.order(ecbProductInfo, orderInfo); this.orderDao.order(orderInfo); } else { if (!"1322".equals(orderInfo.getSpid())){ throw new BusinessException("9010", "您已订购,请不要重复订购!", new String[0]); } } } } } } } } else if (orderInfo.getOrdertype() == 3) { OrderInfo oldOrderInfo = orderDao.findByUser(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid()); if (oldOrderInfo != null && !StringUtils.isEmpty(oldOrderInfo.getEndtime())) { orderInfo.setEndtime(this.sysDao.getEndtimeForMonth(1, oldOrderInfo.getEndtime())); orderInfo.setOrdertime(oldOrderInfo.getOrdertime()); } else { orderInfo.setEndtime(this.sysDao.getEndtimeForMonth(1, DateFormatUtils.format(new Date(), "yyyyMMdd") + "235959")); } } if (!this.blackWhiteDao.isWhiteUser(orderInfo.getUserid(), orderInfo.getCpid())) { if (orderInfo.getPaytype() == 1) { result = ecbService.order(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid(), ecbProductInfo); if (ecbProductInfo != null) { ecbDiscntDao.order(ecbProductInfo, orderInfo); } } else if (orderInfo.getPaytype() == 2) { } else if (orderInfo.getPaytype() == 3) { ecbService.query(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid(), orderInfo.getProvince()); dingxiangOrderService.order(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid()); } else if (orderInfo.getPaytype() == 4) { /** * 增加能力共享平台订购入口 * zzb 2020-02-21 */ String accesstype = "1"; //sp/cp的二次认证方式: 1:H5认证 2:SDK认证 3:短信认证 4:页面认证 if (!StringUtils.isEmpty(orderInfo.getSeqnumber())) { accesstype = "3"; } orderInfo.setChannel("SHARE"); //1为CAP短信接口,2为自有短信接口 if ("1".equals(orderInfo.getSubtype())) { orderInfo.setChannel("SMSCAPSHARE"); //代表走的是CAP短信订购接口获取TOKEN再调能力平台接口订购 } else if ("2".equals(orderInfo.getSubtype())) { orderInfo.setChannel("SMSSHARE");//代表是自有短信订购接口获取TOKEN,再调能力平台接口订购 } shareOrderService.order(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid()); String spid = orderInfo.getSpid(); /**** if ("1023".equals(spid)||"1022".equals(spid)||"1028".equals(spid)||"1027".equals(spid)) { capOrderService.orderSync(orderInfo, accesstype); } ****/ //CAP订购同步,20210902严铮榕 List spids = Arrays.asList(syncSpids); if (spids.contains(spid)) { capOrderService.orderSync(orderInfo, accesstype); } } else if(orderInfo.getPaytype() == 5){ /** * 增加9楼订购入口 * czw 2020-02-21 */ orderInfo.setChannel("INTENSIVE"); currencyService.order(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid(), orderInfo.getToken()); } else { String brand = ecbService.query(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid(), orderInfo.getProvince()); String accesstype = "1"; //sp/cp的二次认证方式: 1:H5认证 2:SDK认证 3:短信认证 4:页面认证 if (!StringUtils.isEmpty(orderInfo.getSeqnumber())) { accesstype = "3"; } //调cap综合用户查询接口和卡部信控接口 String capqrydata = null; try { capqrydata = capOrderService.capQuery(orderInfo.getUserid()); } catch (Exception e) { e.printStackTrace(); } if (capqrydata != null) { JSONObject capqryJson = JSON.parseObject(capqrydata); BRAND_CODE = capqryJson.getString("BRAND_CODE"); REMOVE_TAG = capqryJson.getString("REMOVE_TAG"); ACT_TAG = capqryJson.getString("ACT_TAG"); RSP_CODE = capqryJson.getString("RSP_CODE"); CUST_STATUS = capqryJson.getString("CUST_STATUS"); } /* String xkqrydata = null; try { xkqrydata = capOrderService.kbxkQuery(orderInfo.getUserid()); } catch (Exception e) { e.printStackTrace(); } if (xkqrydata != null) { JSONObject capqryJson = JSON.parseObject(xkqrydata); valiVal = capqryJson.getString("valiVal"); level = capqryJson.getString("level"); } */ logflag = true; //if("0004".equals(RSP_CODE)){ // throw new BusinessException("cap0004", "错误码cap0004", new String[0]); //} //if (unifiedAuthService.sycnOrder(orderInfo)) {CAP接口已包含统计认证,不用再验证 //订购,选择走CAP接口或是VAC接口 /* boolean hasvac = true; //是否调老vac接口 if (capOrderService.hasCap(orderInfo)) {//产品配置是走CAP orderInfo.setChannel("CAP"); hasvac = false; result = this.capOrderService.order(orderInfo, accesstype); if ("0008".equals(result)) { //不是4G用户,走原vac hasvac = true; } } log.info("userid=>" + orderInfo.getUserid() + ",brand=>" + brand + ",accesstype=>" + accesstype + ",hasvac=>" + hasvac); if (hasvac && unifiedAuthService.sycnOrder(orderInfo)) { //没有走CAP业务配置,或者不是4G用户,只有调vac才走统一认证验证 orderInfo.setChannel("VAC"); result = this.vacOrderService.order(orderInfo.getUserid(), orderInfo.getSpid(), orderInfo.getSeqnumber() == null ? "" : orderInfo.getSeqnumber(), orderInfo.getOrderchannel()); }*/ //取消走VAC接口,统一都走cap订购接口 orderInfo.setChannel("CAP"); //1为CAP短信接口,2为自有短信接口 if ("1".equals(orderInfo.getSubtype())) { orderInfo.setChannel("SMSCAP"); //代表走的是CAP短信订购接口获取TOKEN再调CAP接口订购 } Map map = this.capOrderService.orderCap(orderInfo, accesstype); result = map.get("result"); String orderTime = map.get("orderTime"); if (!StringUtils.isEmpty(orderTime)) { orderInfo.setOrdertime(orderTime); } //} } } else if (orderInfo.getCpid().equals("changshi") && ecbProductInfo != null) { ecbDiscntDao.order(ecbProductInfo, orderInfo); } String currentTime = this.sysDao.getCurrentTime(); if (orderInfo.getOrdertime() == null) { orderInfo.setOrdertime(currentTime); } if (orderInfo.getEffecttime() == null) { orderInfo.setEffecttime(currentTime); } if (!result.equals("0") && orderInfo.getErrorhandle() == 0) { orderInfo.setOrderstatus(7); orderInfo.setIsexperience(1); orderInfo.setShowstatus("0"); } if (orderInfo.getOrdertype() != 2) { this.orderDao.order(orderInfo); } else { this.orderDao.countOrder(orderInfo); } //合约产品白名单限制处理 heyueOrderService.heyueOrderAfter(orderInfo); try { //订购量计数 setRides(orderInfo, 1); } catch (Exception e) { e.printStackTrace(); } } catch (Exception e) { log.error("userid:" + orderInfo.getUserid() + "订购出现异常," + e); e.printStackTrace(); errorcode = "8000"; errorinfo = "系统处理失败"; if ((e instanceof BusinessException)) { errorcode = ((BusinessException) e).getCode(); errorinfo = ((BusinessException) e).getMessage(); if (errorinfo.length() > 200) { errorinfo = errorinfo.substring(0, 200); } if (errorinfo.contains("cap订购失败")) { String errorinfo2 = "cap订购失败"; throw new BusinessException(errorcode, errorinfo2); } else if ("9068".equals(errorcode)) { String errorinfo2 = "账户或业务服务异常,暂无法订购!"; throw new BusinessException(errorcode, errorinfo2); } } if (!errorcode.equals("9999")) { log.error(errorcode + "==>" + errorinfo + "==>" + e.getMessage() + e); throw new BusinessException(errorcode, errorinfo); } } finally { //调CAP平台或能力平台返回了指定错误信息调CAP查询接口,如果有订购关系,则把数据添加到CAP反向通知表,使用反向通知流程落订购关系,此次流程不记录订购日志,以提高订购成功率 if ("9666".equals(errorcode) && ("CAP".equals(orderInfo.getChannel()) || "SHARE".equals(orderInfo.getChannel()))) { log.info("调CAP或调能力平台接口返回指定错误信息查询CAP落订购关系,不记录订购日志,userid=>" + orderInfo.getUserid() + " : " + orderInfo.getSpid()); } else { //20211115 实时订购落券码 yzr 伯源渠道号178916423536 发放979 券码 if ("178916423536".equals(orderInfo.getSubchannel()) && "979".equals(orderInfo.getSpid()) && "0".equals(errorcode)) { //订购时间在20211117~20211121 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date ordertime = new Date(); Map map = orderDao.getActiveTime(orderInfo.getSpid(), orderInfo.getSubchannel()); boolean hascoupon = orderDao.hasCoupon(orderInfo.getSpid(), orderInfo.getUserid()); if (map != null && map.size() > 0) { Date startime = sdf.parse(map.get("STARTTIME").toString()); Date endtime = sdf.parse(map.get("ENDTIME").toString()); if (ordertime.getTime() >= startime.getTime() && ordertime.getTime() <= endtime.getTime() && !hascoupon) { String orderid = orderDao.getOrderid(orderInfo.getUserid(), orderInfo.getSpid()); orderInfo.setOrderid(orderid); orderDao.addCoupon(orderInfo); } } } saveLog(orderInfo, errorcode, errorinfo); } CapKbxkQryBean capKbxkQryBean = new CapKbxkQryBean(); capKbxkQryBean.setUserid(orderInfo.getUserid()); capKbxkQryBean.setActtag(ACT_TAG); capKbxkQryBean.setBrandcode(BRAND_CODE); capKbxkQryBean.setCuststatus(CUST_STATUS); capKbxkQryBean.setRemovetag(REMOVE_TAG); capKbxkQryBean.setRspcode(RSP_CODE); capKbxkQryBean.setUserlevel(level); capKbxkQryBean.setValival(valiVal); capKbxkQryBean.setCpid(orderInfo.getCpid()); capKbxkQryBean.setSpid(orderInfo.getSpid()); if (logflag) { try { capKbxkQryDao.addCapKbxkQryLog(capKbxkQryBean); } catch (Exception e) { e.printStackTrace(); } } } } public void checkCancelOrder(OrderInfo orderInfo) throws Exception { String userid = orderInfo.getUserid(); checkUserid(orderInfo); AreaInfo areaInfo = getAreaInfo(userid); orderInfo.setProvince(areaInfo.getProvince()); orderInfo.setArea(areaInfo.getArea()); CPInfo cpInfo = ConfigUtil.getCPInfo(orderInfo.getCpid(), null); if (cpInfo == null) { throw new BusinessException("7005", "CP标识无效", new String[0]); } SPInfo spInfo = getSPInfo(orderInfo); if (spInfo.getCancancelorder() == 1 && StringUtils.isEmpty(orderInfo.getCancelchannel())) { throw new BusinessException("9011", "该产品不支持退订操作", new String[0]); } if (this.orderDao.hasTiyanValid(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid())) { throw new BusinessException("9015", "该产品体验期未结束不支持退订操作,如有疑问请咨询中国联通客服4000600611", new String[0]); } String spid = orderInfo.getSpid(); /* if ("1009".equals(spid)){ String activeTime = dictionaryDao.getValue("mangtv16ActiveTime"); String[] split = activeTime.split("\\|"); if(orderDao.isMangtvCancel(userid,spid,split[0],split[1])){ throw new BusinessException("9016", "该产品体验期未结束不支持退订操作", new String[0]); } }*/ if (orderDao.queryCancelConf(spid) && !"kf".equals(orderInfo.getChannel()) && !checkSpid(spid)) { Integer num = orderDao.getCancelMonth(spid); if (!orderDao.isCancel(userid, spid, num)) { throw new BusinessException("9016", "该产品合约期未结束不支持退订操作,如有疑问请咨询中国联通客服4000600611", new String[0]); } } } private boolean checkSpid(String spid) throws SQLException { boolean flag = false; String valueSpid = this.orderDao.getDictionryValue("hyCancelSpid"); if (valueSpid != null && valueSpid.length() > 0) { for (String sp : valueSpid.split(",")) { if (spid.equals(sp)) { flag = true; } } } return flag; } public void cancelOrder(OrderInfo orderInfo) throws Exception { cancelOrder(orderInfo, null); } public void cancelOrder(OrderInfo orderInfo, EcbProductInfo ecbProductInfo) throws Exception { String errorcode = "0"; String errorinfo = ""; String oldSpid = ""; try { OrderInfo relationOrder = null; boolean isHasOrder = false; boolean isHasOtherOrder = false; //20230103退订互斥产品 String hcspid = orderDao.getDictionryValue("hcspid"); if (!StringUtils.isEmpty(hcspid)){ String[] splits = hcspid.split(","); for (String split:splits){ if (orderInfo.getSpid().equals(split)){ boolean flag = orderDao.hasOrder(orderInfo.getUserid(), orderInfo.getSpid()); if (!flag){ String mutex = orderInfo.getMutex(); flag = orderDao.hasOrder(orderInfo.getUserid(), mutex); if (flag){ oldSpid = orderInfo.getSpid(); orderInfo.setSpid(mutex); getSPInfo(orderInfo); } } break; } } } //查询当前商品订购状态是否存在() List listOrderInfo = orderDao.findByUser(orderInfo.getUserid()); if(!"kf".equals(orderInfo.getChannel())) { log.info("======================进入不为kf分支========================" + orderInfo.getChannel()); if (listOrderInfo == null || listOrderInfo.size() == 0) { throw new BusinessException("9016", "退订失败,无该用户订购关系或者已失效", new String[0]); } for (OrderInfo oldOrderInfo : listOrderInfo) { if (orderInfo.getSpid().equals(oldOrderInfo.getSpid())) { orderInfo.setOrdertime(oldOrderInfo.getOrdertime()); //结束时间不为空就放进去 if (!StringUtils.isEmpty(oldOrderInfo.getEndtime())) { orderInfo.setEndtime(oldOrderInfo.getEndtime()); } //status不为零则已退订 if (oldOrderInfo.getStatus() != 0) { throw new BusinessException("9017", "退订失败,该用户已退订该产品", new String[0]); } isHasOrder = true; break; } } }else{ isHasOrder = true; } if (!StringUtils.isEmpty(orderInfo.getRelationSp())) { for (OrderInfo oldOrderInfo : listOrderInfo) { if (oldOrderInfo.getSpid().equals(orderInfo.getRelationSp()) && oldOrderInfo.getStatus() == 0) { relationOrder = orderInfo; relationOrder.setSpid(orderInfo.getRelationSp()); isHasOtherOrder = true; break; } } } if (!isHasOrder && !isHasOtherOrder) { throw new BusinessException("9018", "退订失败,该用户没有订购该产品或者已失效", new String[0]); } if (!("kf".equals(orderInfo.getChannel()) && !StringUtils.isEmpty(orderInfo.getIsvacorder()) && orderInfo.getIsvacorder().equals("0")) ) { if (!this.blackWhiteDao.isWhiteUser(orderInfo.getUserid(), orderInfo.getCpid())) { if (orderInfo.getPaytype() == 1) { if (ecbProductInfo == null || (ecbProductInfo != null && (!ecbProductInfo.getDiscntOrderState().equals("2") || !ecbProductInfo.getDiscntFee().equals("0")))) { errorcode = ecbService.cancelOrder(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid(), orderInfo.getOrdertime(), ecbProductInfo); if (ecbProductInfo != null) { ecbDiscntDao.cancel(ecbProductInfo, orderInfo); } } } else if (orderInfo.getPaytype() == 2) { } else if (orderInfo.getPaytype() == 3) { dingxiangOrderService.cancel(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid()); } else if (orderInfo.getPaytype() == 4) { /** * 增加能力共享平台订购入口 * zzb 2020-02-21 */ orderInfo.setChannel("SHARE"); //1为CAP短信接口,2为自有短信接口 if ("1".equals(orderInfo.getSubtype())) { orderInfo.setChannel("SMSCAPSHARE"); //代表走的是CAP短信订购接口获取TOKEN再调能力平台接口订购 } else if ("2".equals(orderInfo.getSubtype())) { orderInfo.setChannel("SMSSHARE");//代表是自有短信订购接口获取TOKEN,再调能力平台接口订购 } shareOrderService.cancel(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid()); if (this.checkSpid(orderInfo.getSpid())) { try { Integer num = orderDao.getCancelMonth(orderInfo.getSpid()); if (!orderDao.isCancel(orderInfo.getUserid(), orderInfo.getSpid(), num)) { String wyjSpid = orderDao.getWYJSpid(orderInfo.getSpid()); WyjLogBean wyjLogBean = new WyjLogBean(); wyjLogBean.setUserid(orderInfo.getUserid()); wyjLogBean.setProvince(orderInfo.getProvince()); wyjLogBean.setArea(orderInfo.getArea()); wyjLogBean.setCpid("wyj"); wyjLogBean.setChannel(orderInfo.getChannel()); wyjLogBean.setSpid(wyjSpid); wyjLogBean.setExtend1(orderInfo.getSpid()); log.info("合约包退订成功,违约包入库" + JSON.toJSONString(wyjLogBean)); orderDao.addWYJLog(wyjLogBean); } } catch (Exception e) { log.info("w违约包入库失败" + orderInfo.getUserid()); } } }else if(orderInfo.getPaytype() == 5){ orderInfo.setChannel("INTENSIVE"); currencyService.cancel(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid()); } else { /* //退订,选择走CAP接口或是VAC接口 boolean hasvac = true; //是否调老vac接口 if (capOrderService.hasCap(orderInfo)) {//产品配置是走CAP orderInfo.setChannel("CAP"); hasvac = false; String result = this.capOrderService.cancel(orderInfo); if ("0008".equals(result)) { //不是4G用户,走原vac hasvac = true; } } if (hasvac) { //没有走CAP业务配置,或者不是4G用户 orderInfo.setChannel("VAC"); this.vacOrderService.cancelOrder(orderInfo.getUserid(), orderInfo.getSpid()); }*/ //全部都走cap接口 orderInfo.setChannel("CAP"); //1为CAP短信接口,2为自有短信接口 if ("1".equals(orderInfo.getSubtype())) { orderInfo.setChannel("SMSCAP"); //代表走的是CAP短信订购接口获取TOKEN再调CAP接口订购 } //调用cap退订接口 Map map = this.capOrderService.cancelCap(orderInfo); String cancelTime = map.get("cancelTime"); if (!StringUtils.isEmpty(cancelTime)) { orderInfo.setCanceltime(cancelTime); } if (this.checkSpid(orderInfo.getSpid())) { try { Integer num = orderDao.getCancelMonth(orderInfo.getSpid()); if (!orderDao.isCancel(orderInfo.getUserid(), orderInfo.getSpid(), num)) { String wyjSpid = orderDao.getWYJSpid(orderInfo.getSpid()); WyjLogBean wyjLogBean = new WyjLogBean(); wyjLogBean.setUserid(orderInfo.getUserid()); wyjLogBean.setProvince(orderInfo.getProvince()); wyjLogBean.setArea(orderInfo.getArea()); wyjLogBean.setCpid("wyj"); wyjLogBean.setChannel(orderInfo.getChannel()); wyjLogBean.setSpid(wyjSpid); wyjLogBean.setExtend1(orderInfo.getSpid()); log.info("合约包退订成功,违约包入库" + JSON.toJSONString(wyjLogBean)); orderDao.addWYJLog(wyjLogBean); } } catch (Exception e) { log.info("w违约包入库失败" + orderInfo.getUserid()); } } } } }else{ log.info("======================进入不走平台退订流程分支========================" + orderInfo.getChannel()); } if (isHasOrder && isHasOtherOrder) { this.smCancelDao.cancelOrder(relationOrder); } if (!isHasOrder && isHasOtherOrder) { orderInfo.setSpid(orderInfo.getRelationSp()); } String currentTime = this.sysDao.getCurrentTime(); if (orderInfo.getCanceltime() != null) { orderInfo.setEndtime(getEndTime(orderInfo.getCanceltime())); } else { orderInfo.setCanceltime(currentTime); } if (orderInfo.getEffecttime() == null) { orderInfo.setEffecttime(currentTime); } if (orderInfo.getEndtime() == null) { orderInfo.setEndtime(this.sysDao.getEndDayOfCurrentMonth()); } //更新操作 this.orderDao.cancelOrder(orderInfo); } catch (Exception e) { log.error("userid:" + orderInfo.getUserid() + "退购出现异常," + e); errorcode = "8000"; errorinfo = "系统忙"; if ((e instanceof BusinessException)) { errorcode = ((BusinessException) e).getCode(); errorinfo = ((BusinessException) e).getMessage(); if (errorinfo.length() > 200) { errorinfo = errorinfo.substring(0, 200); } if (errorinfo.contains("cap退订失败")) { String errorinfo2 = "cap退订失败"; throw new BusinessException(errorcode, errorinfo2); } } if (!errorcode.equals("9998")) { throw e; } } finally { if (!StringUtils.isEmpty(oldSpid)){ errorinfo += "退订"+oldSpid+"实际退订"+orderInfo.getSpid(); } saveLog(orderInfo, errorcode, errorinfo); } } /** * 鉴权平台用退订接口 * * @param orderInfo * @param ecbProductInfo * @param channel * @throws Exception */ public void cancelOrder(OrderInfo orderInfo, EcbProductInfo ecbProductInfo, String channel) throws Exception { String errorcode = "0"; String errorinfo = ""; String oldSpid = ""; try { //20230201退订快手合约互斥产品 String hcspid = orderDao.getDictionryValue("hcspid"); if (!StringUtils.isEmpty(hcspid)){ String[] splits = hcspid.split(","); for (String split:splits){ if (orderInfo.getSpid().equals(split)){ boolean flag = orderDao.hasOrder(orderInfo.getUserid(), orderInfo.getSpid()); if (!flag){ String mutex = orderInfo.getMutex(); flag = orderDao.hasOrder(orderInfo.getUserid(), mutex); if (flag){ oldSpid = orderInfo.getSpid(); orderInfo.setSpid(mutex); getSPInfo(orderInfo); } } break; } } } List listOrderInfo = orderDao.findByUser(orderInfo.getUserid()); OrderInfo relationOrder = null; boolean isHasOrder = false; boolean isHasOtherOrder = false; if (!"kf".equals(orderInfo.getChannel())) { log.info("======================进入不为kf分支========================" + orderInfo.getChannel()); if (listOrderInfo == null || listOrderInfo.size() == 0) { throw new BusinessException("9016", "退订失败,无该用户订购关系或者已失效", new String[0]); } for (OrderInfo oldOrderInfo : listOrderInfo) { if (orderInfo.getSpid().equals(oldOrderInfo.getSpid())) { orderInfo.setOrdertime(oldOrderInfo.getOrdertime()); if (!StringUtils.isEmpty(oldOrderInfo.getEndtime())) { orderInfo.setEndtime(oldOrderInfo.getEndtime()); } if (oldOrderInfo.getStatus() != 0) { throw new BusinessException("9017", "退订失败,该用户已退订该产品", new String[0]); } isHasOrder = true; break; } } } else { isHasOrder = true; } if (!StringUtils.isEmpty(orderInfo.getRelationSp())) { for (OrderInfo oldOrderInfo : listOrderInfo) { if (oldOrderInfo.getSpid().equals(orderInfo.getRelationSp()) && oldOrderInfo.getStatus() == 0) { relationOrder = orderInfo; relationOrder.setSpid(orderInfo.getRelationSp()); isHasOtherOrder = true; break; } } } if (!isHasOrder && !isHasOtherOrder) { throw new BusinessException("9018", "退订失败,该用户没有订购该产品或者已失效", new String[0]); } if (!("kf".equals(orderInfo.getChannel()) && !StringUtils.isEmpty(orderInfo.getIsvacorder()) && orderInfo.getIsvacorder().equals("0"))) { if (!this.blackWhiteDao.isWhiteUser(orderInfo.getUserid(), orderInfo.getCpid())) { if (orderInfo.getPaytype() == 1) { if (ecbProductInfo == null || (ecbProductInfo != null && (!ecbProductInfo.getDiscntOrderState().equals("2") || !ecbProductInfo.getDiscntFee().equals("0")))) { errorcode = ecbService.cancelOrder(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid(), orderInfo.getOrdertime(), ecbProductInfo); if (ecbProductInfo != null) { ecbDiscntDao.cancel(ecbProductInfo, orderInfo); } } } else if (orderInfo.getPaytype() == 2) { } else if (orderInfo.getPaytype() == 3) { dingxiangOrderService.cancel(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid()); } else if (orderInfo.getPaytype() == 4) { /** * 增加能力共享平台订购入口 * zzb 2020-02-21 */ orderInfo.setChannel("SHARE"); shareOrderService.cancel(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid(), channel); if (this.checkSpid(orderInfo.getSpid())) { try { Integer num = orderDao.getCancelMonth(orderInfo.getSpid()); if (!orderDao.isCancel(orderInfo.getUserid(), orderInfo.getSpid(), num)) { String wyjSpid = orderDao.getWYJSpid(orderInfo.getSpid()); WyjLogBean wyjLogBean = new WyjLogBean(); wyjLogBean.setUserid(orderInfo.getUserid()); wyjLogBean.setProvince(orderInfo.getProvince()); wyjLogBean.setArea(orderInfo.getArea()); wyjLogBean.setCpid("wyj"); wyjLogBean.setChannel(orderInfo.getChannel()); wyjLogBean.setSpid(wyjSpid); wyjLogBean.setExtend1(orderInfo.getSpid()); log.info("合约包退订成功,违约包入库" + JSON.toJSONString(wyjLogBean)); orderDao.addWYJLog(wyjLogBean); } } catch (Exception e) { log.info("w违约包入库失败" + orderInfo.getUserid()); } } }else if(orderInfo.getPaytype() == 5){ orderInfo.setChannel("INTENSIVE"); currencyService.cancel(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid()); } else { /* //退订,选择走CAP接口或是VAC接口 boolean hasvac = true; //是否调老vac接口 if (capOrderService.hasCap(orderInfo)) {//产品配置是走CAP orderInfo.setChannel("CAP"); hasvac = false; String result = this.capOrderService.cancel(orderInfo); if ("0008".equals(result)) { //不是4G用户,走原vac hasvac = true; } } if (hasvac) { //没有走CAP业务配置,或者不是4G用户 orderInfo.setChannel("VAC"); this.vacOrderService.cancelOrder(orderInfo.getUserid(), orderInfo.getSpid()); }*/ //全部都走cap接口 orderInfo.setChannel("CAP"); this.capOrderService.cancel(orderInfo); if (this.checkSpid(orderInfo.getSpid())) { try { Integer num = orderDao.getCancelMonth(orderInfo.getSpid()); if (!orderDao.isCancel(orderInfo.getUserid(), orderInfo.getSpid(), num)) { String wyjSpid = orderDao.getWYJSpid(orderInfo.getSpid()); WyjLogBean wyjLogBean = new WyjLogBean(); wyjLogBean.setUserid(orderInfo.getUserid()); wyjLogBean.setProvince(orderInfo.getProvince()); wyjLogBean.setArea(orderInfo.getArea()); wyjLogBean.setCpid("wyj"); wyjLogBean.setChannel(orderInfo.getChannel()); wyjLogBean.setSpid(wyjSpid); wyjLogBean.setExtend1(orderInfo.getSpid()); log.info("合约包退订成功,违约包入库" + JSON.toJSONString(wyjLogBean)); orderDao.addWYJLog(wyjLogBean); } } catch (Exception e) { log.info("w违约包入库失败" + orderInfo.getUserid()); } } } } }else{ log.info("======================进入不走平台退订流程分支========================" + orderInfo.getChannel()); } if (isHasOrder && isHasOtherOrder) { this.smCancelDao.cancelOrder(relationOrder); } if (!isHasOrder && isHasOtherOrder) { orderInfo.setSpid(orderInfo.getRelationSp()); } String currentTime = this.sysDao.getCurrentTime(); if (orderInfo.getCanceltime() != null) { orderInfo.setEndtime(getEndTime(orderInfo.getCanceltime())); } else { orderInfo.setCanceltime(currentTime); } if (orderInfo.getEffecttime() == null) { orderInfo.setEffecttime(currentTime); } if (orderInfo.getEndtime() == null) { orderInfo.setEndtime(this.sysDao.getEndDayOfCurrentMonth()); } this.orderDao.cancelOrder(orderInfo); } catch (Exception e) { log.error("userid:" + orderInfo.getUserid() + "退购出现异常," + e); errorcode = "8000"; errorinfo = "系统忙"; if ((e instanceof BusinessException)) { errorcode = ((BusinessException) e).getCode(); errorinfo = ((BusinessException) e).getMessage(); if (errorinfo.length() > 200) { errorinfo = errorinfo.substring(0, 200); } if (errorinfo.contains("cap退订失败")) { String errorinfo2 = "cap退订失败"; throw new BusinessException(errorcode, errorinfo2); } } if (!errorcode.equals("9998")) { throw e; } } finally { log.info("=========================================进入finally"); if (!StringUtils.isEmpty(oldSpid)) { errorinfo = errorinfo + "退订" + oldSpid + "实际退订" + orderInfo.getSpid(); } saveLog(orderInfo, errorcode, errorinfo); } } public String getEndTime(String endTimeStr) throws ParseException { Calendar calendar = Calendar.getInstance(); Date date = DateUtils.parseDate(endTimeStr.substring(0, 8), new String[]{"yyyyMMdd"}); calendar.setTime(date); String day = calendar.getActualMaximum(Calendar.DAY_OF_MONTH) + ""; String year = calendar.get(Calendar.YEAR) + ""; String month = calendar.get(Calendar.MONTH) + 1 < 10 ? "0" + (calendar.get(Calendar.MONTH) + 1) : calendar.get(Calendar.MONTH) + 1 + ""; return year + month + day + "235959"; } public void saveLog(OrderInfo orderInfo, String errorcode, String errorinfo) { OrderLog orderLog = new OrderLog(); orderLog.setApptype(orderInfo.getApptype()); orderLog.setArea(orderInfo.getArea()); if (orderInfo.getOrderchannel() != null) { orderLog.setChannel(orderInfo.getOrderchannel()); } else { orderLog.setChannel(orderInfo.getCancelchannel()); } orderLog.setOrderstatus(orderInfo.getOrderstatus()); orderLog.setStatus(orderInfo.getStatus()); orderLog.setCpid(orderInfo.getCpid()); orderLog.setIsexperience(orderInfo.getIsexperience()); orderLog.setOrdertype(orderInfo.getOrdertype() + ""); orderLog.setProvince(orderInfo.getProvince()); orderLog.setArea(orderInfo.getArea()); orderLog.setSpid(orderInfo.getSpid()); orderLog.setUserid(orderInfo.getUserid()); orderLog.setErrorcode(errorcode); orderLog.setErrorinfo(errorinfo); if (!orderInfo.getTimes().isEmpty()) { orderLog.setTimes((System.currentTimeMillis() - NumberUtils.toLong(orderInfo.getTimes())) + ""); } this.orderLogDao.addOrderLog(orderLog); } public void inserArrearageData(OrderInfo orderInfo) throws SQLException { ReflowBean reflowBean = new ReflowBean(); reflowBean.setUserid(orderInfo.getUserid()); reflowBean.setSpid(orderInfo.getSpid()); reflowBean.setActivitycode("reflowActivityLevel3"); reflowBean.setResultcode("1"); reflowBean.setResultinfo("待处理"); orderDao.inserArrearageData(reflowBean); } public static void main(String args[]) throws Exception { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd"); System.out.println(simpleDateFormat.format(new Date())); System.out.println((Integer.parseInt("09")) > 30); System.out.println(Integer.parseInt("09")); } }