package com.chinacreator.videoalliance.order.action; import com.chinacreator.common.exception.BusinessException; import com.chinacreator.common.pipe.DataOutPipe; import com.chinacreator.common.util.RequestUtil; import com.chinacreator.common.util.URLUtil; import com.chinacreator.videoalliance.common.annotation.DataOut; import com.chinacreator.videoalliance.common.dao.DictionaryDao; import com.chinacreator.videoalliance.common.util.ConfigUtil; import com.chinacreator.videoalliance.order.bean.OrderInfo; import com.chinacreator.videoalliance.order.dao.BusiOperlimitConfDao; import com.chinacreator.videoalliance.order.dao.BussinessDao; import com.chinacreator.videoalliance.order.dao.OrderDao; import com.chinacreator.videoalliance.order.dao.OrderSendVipDao; import com.chinacreator.videoalliance.order.dao.TcPreDao; import com.chinacreator.videoalliance.order.service.*; import com.chinacreator.videoalliance.order.util.JsonUtil; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import javax.servlet.http.HttpServletRequest; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; //import com.chinacreator.videoalliance.order.dao.OrderchannelIpmatchDao; @Controller public class OrderAction { private static Logger errorlog = Logger.getLogger("orderError"); private static OrderInfo orderInfo; @Autowired private OrderService orderService; @Autowired private OrderValiService orderValiService; @Autowired private WxcsHandleService wxcsHandleService; @Autowired private DictionaryDao dictionaryDao; @Autowired private OrderSendVipDao orderSendVipDao; @Autowired private OrderKsPreService orderKsPreService; @Autowired private OrderDao orderDao; @Autowired private BusiOperlimitConfDao busiOperlimitConfDao; @Autowired private BussinessDao bussinessDao; @Autowired private NextMonthEffectService nextMonthEffectService; @Autowired private WyjOrderService wyjOrderService; @RequestMapping({"/order.do"}) @DataOut(callback = "order") public DataOutPipe doOrder(HttpServletRequest request, OrderInfo orderInfo, String channel) throws Exception { long l = System.currentTimeMillis(); DataOutPipe pipe = new DataOutPipe(); orderInfo.setTimes(System.currentTimeMillis() + ""); String userid = ""; String spid = ""; String resultcode = ""; String errorinfo = ""; try { userid = orderInfo.getUserid(); spid = orderInfo.getSpid(); if (StringUtils.isNotEmpty(userid)) { orderInfo.setUserid(ConfigUtil.decrypt(userid, orderInfo.getCpid())); if ((orderInfo.getUserid() != null) && (orderInfo.getUserid().length() > 11)) { orderInfo.setUserid(ConfigUtil.getUserid(orderInfo.getUserid(), orderInfo.getCpid())); } } //渠道标识长度大于20,入库失败,截断 if (StringUtils.isNotEmpty(channel)) { if (channel.length() > 20) { if (channel.contains("bilibl")) { channel = "bilibl_app"; }else{ channel = channel.substring(0, 10); } orderInfo.setChannel(channel); } } //channel = channelIpmatch.getChannel(channel, orderInfo.getCpid(),orderInfo.getSpid(),request); orderInfo.setApptype(RequestUtil.getMobType(request)); orderInfo.setStatus(0); orderInfo.setOrderchannel(channel); orderInfo.setOrderstatus(2); orderInfo.setInvokeface("order"); this.orderService.checkOrder(orderInfo); //办理验证,产品验证、IP验证、下线验证 orderValiService.vali(request, orderInfo); //违约金产品订购 if ("wyj".equals(orderInfo.getCpid())) { wyjOrderService.process(orderInfo); } else { //能力平台次月生效产品 if (nextMonthEffectService.hasNextMonthBusi(orderInfo)) { //业务处理 nextMonthEffectService.process(orderInfo); } else if (orderInfo.getPaytype() == 1 && !orderInfo.getCpid().equals("changshi")) { if (StringUtils.isEmpty(channel)) { orderInfo.setOrderchannel(orderInfo.getCpid()); } if (true) { //20190115,xu.zhou 下线订购无限畅视产品 throw new BusinessException("7020", "该产品已下线。"); } orderInfo.setCpid("changshi"); orderInfo.setSpid("1150"); wxcsHandleService.handleOrder(orderInfo, "1"); } else { this.orderService.order(orderInfo); } } } catch (Exception e) { if (e instanceof BusinessException) { try { resultcode = ((BusinessException)e).getCode(); errorinfo = ((BusinessException)e).getMessage(); //已退订快手前向快手8元以及15元的用户,在收到用户重新发起快手8元及15元的订购请求且订购报错时,下发指定短信模板 if (("1022".equals(orderInfo.getSpid()) || "1023".equals(orderInfo.getSpid())) && "SHARE".equals(orderInfo.getChannel())) { //判断当月是否退订 OrderInfo currOrder = orderDao.findByUser(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid()); //已退订 if (currOrder != null && currOrder.getEndtime() != null) { SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM"); String currMonth = sdf.format(new Date()); //判断是否当月退订 if (currOrder.getEndtime().startsWith(currMonth)) { //发失败短信 inserSmstMqByKuaishou(orderInfo); } } } } catch (Exception e1) { e1.printStackTrace(); errorlog.error(orderInfo.getUserid() + ":快手前向快手8元以及15元处理失败," + e.getMessage(), e); } if ("9068".equals(resultcode)) { try { orderService.inserArrearageData(orderInfo); } catch (Exception ex) { e.printStackTrace(); errorlog.error("三级欠费回流数据入库出错 " + "==>" + orderInfo.getSpid() + "==>" + orderInfo.getUserid() + ex.getMessage() + ex); } } }else{ resultcode = "8000"; errorinfo = "办理出现异常,"+e.getMessage(); } try { String huashengfailpushswitch = dictionaryDao.getValue("huashengpushswitch"); if(!"OFF".equals(huashengfailpushswitch)){ //前向产品订购失败在推送给华胜 busiOperlimitConfDao.addHuashengSyncWait(orderInfo, resultcode, errorinfo); } } catch (Exception e2) { e2.printStackTrace(); } throw e; } pipe.add("userid", userid); pipe.add("channel", channel == null ? "" : channel); pipe.add("endtime", orderInfo.getEndtime() == null ? "" : orderInfo.getEndtime()); if (orderInfo.getOrdertype() == 1) { pipe.add("videoid", orderInfo.getVideoid()); } insertOrderMq(orderInfo); inserSmstMq(orderInfo); //log.info(orderInfo.getUserid()+"====订购结束时间==="+(System.currentTimeMillis()-l)/1000); return pipe; } public void insertOrderMq(OrderInfo orderInfo) { try { Map map = new HashMap(); map.put("userid", orderInfo.getUserid()); map.put("cpid", orderInfo.getCpid()); map.put("spid", orderInfo.getSpid()); map.put("province", orderInfo.getProvince()); map.put("area", orderInfo.getArea()); map.put("ordertime", orderInfo.getOrdertime()); map.put("canceltime", ""); map.put("status", "0"); map.put("orderchannel", orderInfo.getOrderchannel()); map.put("cancelchannel", ""); map.put("videoid", orderInfo.getVideoid()); map.put("type", "order"); //开发环境 //URLUtil.post("http://172.16.33.16:8082/mq-service/recive.do", JsonUtil.objectToJson(map)); //测试环境 // URLUtil.post("http://10.199.99.177:86/mq-service/recive.do", JsonUtil.objectToJson(map)); //走能力平台次月生效的订购,不生成活动关系 if (!nextMonthEffectService.hasNextMonthBusi(orderInfo)) { //添加数据到活动关系处理表 bussinessDao.addBussHandleWait(map); } URLUtil.post(dictionaryDao.getValue("mqReciveUrl"), JsonUtil.objectToJson(map)); } catch (Exception e) { e.printStackTrace(); } //} } public void inserSmstMq(OrderInfo orderInfo) { try { Map map = new HashMap(); map.put("userid", orderInfo.getUserid()); map.put("cpid", orderInfo.getCpid()); map.put("spid", orderInfo.getSpid()); map.put("result", "0"); map.put("channel", orderInfo.getOrderchannel()); map.put("subchannel", (orderInfo.getSubchannel() == null ? "" : orderInfo.getSubchannel())); //map.put("style",orderSmsMq.get(orderInfo.getSpid())); map.put("style", "0000"); map.put("times", ""); map.put("orderType", ""); map.put("type", "cssms"); String busiType = ""; boolean flag = false; //1.先判断省份 String province = orderDao.getHmdInfo(orderInfo.getUserid().substring(0, 7)); //2.获取活动配置 HashMap activitymap = orderDao.getCouponConfig(orderInfo.getSpid()); if (activitymap != null && !"云南".equals(province) && ("297".equals(orderInfo.getSpid()) || "1218".equals(orderInfo.getSpid()) ||"299".equals(orderInfo.getSpid()))) { String activitystarttime = activitymap.get("STARTTIME").toString(); String activityendtime = activitymap.get("ENDTIME").toString(); //订购时间小于活动开始时间,或者订购时间大于活动结束时间 String ordertime = orderInfo.getOrdertime(); if (Long.parseLong(ordertime) < Long.parseLong(activitystarttime) || Long.parseLong(ordertime) > Long.parseLong(activityendtime)) { //System.out.println("订购时间未在【517电信】活动期内,不下发活动短信"); } else { //发送短信 busiType = "tran_succ4"; flag = true; } } if (!flag) { if (orderSendVipDao.qryOrderSendvipConf(orderInfo.getOrderchannel(), orderInfo.getCpid(), orderInfo.getSpid())) { busiType = "vs_tran_succ"; //map.put("busiType", "vs_tran_succ"); } else { busiType = "tran_succ"; //map.put("busiType", "tran_succ"); } } map.put("busiType", busiType); if ("wyj".equals(orderInfo.getCpid())) { String spname = this.orderDao.getSpname(orderInfo.getExtend1()); map.put("param1", spname); } //开发环境 //URLUtil.post("http://172.16.33.16:8082/mq-service/recive.do", JsonUtil.objectToJson(map)); //测试环境 //URLUtil.post("http://10.199.99.177:86/mq-service/recive.do", JsonUtil.objectToJson(map)); //生产环境 URLUtil.post(dictionaryDao.getValue("mqReciveUrl"), JsonUtil.objectToJson(map)); //20211214 修改 新春活动 1214~0228 活动期间内的1017,979,1005产品发送短信 //20220412 下线,更改配置化,指定产品可发送短信 //Boolean hasSendCouponSms = orderDao.hasSendCouponSms(orderInfo.getUserid(),orderInfo.getSpid()); //if(hasSendCouponSms) { List sendsmsProduct = orderDao.querySendSmsProduct(); if (sendsmsProduct != null && sendsmsProduct.contains(orderInfo.getSpid())) { //System.out.println("下发订购后的定制短信"); map.put("busiType", "tran_succ3"); URLUtil.post(dictionaryDao.getValue("mqReciveUrl"), JsonUtil.objectToJson(map)); } /* //月末特殊福利短信发送 SimpleDateFormat simpleDateFormat=new SimpleDateFormat("dd"); String format = simpleDateFormat.format(new Date()); if (Integer.parseInt(format)>24 &&orderDao.isSendsms(orderInfo.getSpid())){ SendSmsUtil.send(orderInfo.getUserid(),"【中国联通】月末特殊福利,25日以后订购的用户额外赠送一个月定向流量服务,感谢您的订购! "); }*/ } catch (Exception e) { e.printStackTrace(); } } /** * 快手8元和15元订购失败,把指定短信 * * @param orderInfo */ private void inserSmstMqByKuaishou(OrderInfo orderInfo) { try { Map map = new HashMap(); map.put("userid", orderInfo.getUserid()); map.put("cpid", orderInfo.getCpid()); map.put("spid", orderInfo.getSpid()); map.put("result", "0"); map.put("channel", orderInfo.getOrderchannel()); map.put("subchannel", (orderInfo.getSubchannel() == null ? "" : orderInfo.getSubchannel())); map.put("style", "0000"); map.put("times", ""); map.put("orderType", ""); map.put("type", "cssms"); map.put("busiType", "ks_tran_fail"); URLUtil.post(dictionaryDao.getValue("mqReciveUrl"), JsonUtil.objectToJson(map)); } catch (Exception e) { e.printStackTrace(); } } }