123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720 |
- package com.chinacreator.videoalliance.order.service;
- import com.alibaba.fastjson.JSONObject;
- import com.chinacreator.common.exception.BusinessException;
- import com.chinacreator.common.util.MD5;
- import com.chinacreator.videoalliance.common.bean.AreaInfo;
- import com.chinacreator.videoalliance.common.dao.DictionaryDao;
- 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.BackAESUtil;
- import com.chinacreator.videoalliance.order.util.URLUtil;
- import org.apache.commons.lang.math.NumberUtils;
- 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.sql.SQLException;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.*;
- /**
- * 后向产品异步处理
- * @author xu.zhou
- * @date 20200817
- */
- @Component
- public class BackBusiOrderAsynService_copy {
- private static Logger busilog = Logger.getLogger("youtuorder");
- private static Logger log = Logger.getLogger("orderpush");
- @Autowired
- private BlackWhiteDao blackWhiteDao;
- @Autowired
- private SPDao spDao;
- @Autowired
- private BackBusiOrderDao backBusiOrderDao;
- @Autowired
- private ShareOrderService shareOrderService;
- @Autowired
- private BackShareOrderDao backShareOrderDao;
- @Autowired
- private OrderDao orderDao;
- @Autowired
- private DictionaryDao dictionaryDao;
- /**
- * 验证及解密手机号码
- * @param orderInfo
- * @throws Exception
- */
- private void checkUserid(OrderInfo orderInfo) throws Exception {
- String userid = orderInfo.getUserid();
- if ((StringUtils.isEmpty(userid)) || ("null".equals(userid)))
- throw new BusinessException("9051", "手机号码无效", new String[0]);
- if (!isValid(userid)) {
- if(userid.length() >10){
- userid = ConfigUtil.decrypt(userid, orderInfo.getCpid());
- userid = ConfigUtil.getUserid(userid, orderInfo.getCpid());
- }
- }
- if (isValid(userid)) {
- if(userid.length() < 11){//QQ号
- //非指定渠道传入qq号码
- if(!"TX20_twback_old".equals(orderInfo.getChannel()) && !"TX20_twback".equals(orderInfo.getChannel())){
- throw new BusinessException("9051", "手机号码无效", new String[0]);
- }
- }
- }else{
- throw new BusinessException("9051", "手机号码无效", new String[0]);
- }
- orderInfo.setUserid(userid);
- }
- /**
- * 支持QQ号与手机号
- * zzb 2020/02/18
- * @throws BusinessException
- */
- private boolean isValid(String usermob) throws BusinessException{
- if (usermob == null) {
- return false;
- }
- usermob = usermob.replaceAll("[\\s-]", "");
- if(!usermob.matches("^[0-9]*$")){
- return false;
- }
- return true;
- }
- /**
- * 验证签名是否有效
- * @param orderInfo
- * @param deuserid 加密的手机号码
- * @throws Exception
- */
- public void checkSignChannel(OrderInfo orderInfo, String deuserid) throws Exception {
- String sign = orderInfo.getSignature();
- if (StringUtils.isEmpty(sign)) {
- throw new BusinessException("9054", "signature校验失败");
- }
- Map cpSpBean = backBusiOrderDao.getCpSp(orderInfo.getCpid(),orderInfo.getSpid());
- String pwd = cpSpBean.get("NETPWD").toString();
- //Md5(orderid+cpid+spid+userid+type+timestamp+pwd)
- String localSign = MD5.MD5Encode(orderInfo.getOrderid() + orderInfo.getCpid()
- + orderInfo.getSpid() + deuserid + orderInfo.getTimestamp() + pwd);
- if (!localSign.equals(orderInfo.getSignature())) {
- throw new BusinessException("9054", "signature校验失败");
- }
- }
- /**
- * 订购前验证
- * @param orderInfo
- * @throws Exception
- */
- public void checkOrder(OrderInfo orderInfo, String deuserid) throws Exception {
- checkCpSpInfo(orderInfo);
- checkSignChannel(orderInfo,deuserid);
- checkUserid(orderInfo);
- String userid = orderInfo.getUserid();
- //判断用户黑名单
- if (this.blackWhiteDao.isBlackUser(userid, orderInfo.getCpid())) {
- throw new BusinessException("9010", "用户为黑名单用户", new String[0]);
- }
- //获取地市信息
- AreaInfo areaInfo = getAreaInfo(userid);
- orderInfo.setProvince(areaInfo.getProvince());
- orderInfo.setArea(areaInfo.getArea());
- if(orderInfo.getProvince() != null && orderDao.isOpen(orderInfo.getSpid(),orderInfo.getCpid(),orderInfo.getProvince())){ // status 为2 表示省份尚未开通
- if(!this.blackWhiteDao.isWhiteUserBySpid(userid, orderInfo.getCpid(), orderInfo.getSpid())){//判断用户是否白名单,是则流程继续
- throw new BusinessException("9011", "省份尚未开通此业务,敬请期待!");
- }
- }
- }
- /**
- * 验证业务参数是否合法
- * @param orderInfo
- * @throws Exception
- */
- private void checkCpSpInfo(OrderInfo orderInfo)throws Exception {
- List<HashMap> confList = backBusiOrderDao.getBackBusiConf(orderInfo.getCpid(), orderInfo.getSpid());
- if(confList == null || confList.size() == 0){
- throw new BusinessException("9058", "无业务配置信息", new String[0]);
- }
- HashMap confHm = confList.get(0);
- //判断是否配置netdays参数
- if(("2".equals(confHm.get("BUSITYPE")) || "3".equals(confHm.get("BUSITYPE")))
- && (confHm.get("NETDAYS") == null || "".equals(confHm.get("NETDAYS")))){
- throw new BusinessException("9058", "无业务配置信息,NETDAYS", new String[0]);
- }
- if(!"1".equals(confHm.get("BUSITYPE")) && orderInfo.getUserid().length() != 11){
- throw new BusinessException("9051", "非纯免流产品只支持11位手机号码,USERID:"+orderInfo.getUserid()+", SPID:"+orderInfo.getSpid(), new String[0]);
- }
- getSPInfo(orderInfo); //设置SP其他信息
- }
- /**
- * 获取手机号码的地市信息
- * @param userid
- * @return
- * @throws Exception
- */
- private AreaInfo getAreaInfo(String userid) throws Exception {
- AreaInfo areaInfo = AreaUtil.getAreaInfoByUserid(userid);
- if (areaInfo == null) {
- areaInfo = new AreaInfo();
- }
- return areaInfo;
- }
- /**
- * 设置SP相关信息
- * @param orderInfo
- * @throws Exception
- */
- private void getSPInfo(OrderInfo orderInfo) throws Exception {
- SPInfo spInfo = this.spDao.findById(orderInfo.getSpid());
- if (spInfo != null) {
- orderInfo.setSpid(spInfo.getSpid());
- orderInfo.setMutex(spInfo.getMutex());
- orderInfo.setRelationSp(spInfo.getRelationSp());
- orderInfo.setPaytype(spInfo.getPaytype());
- orderInfo.setErrorhandle(spInfo.getErrorhandle());
- }
- }
- /**
- * 填充BackBusiOrderRec
- * @param orderInfo
- * @return
- * @throws Exception
- */
- private BackBusiOrderRec getOrderRecBean(OrderInfo orderInfo) throws Exception{
- BackBusiOrderRec bean = new BackBusiOrderRec();
- bean.setLogid(orderInfo.getReorderid());
- bean.setId(backBusiOrderDao.generateID());
- bean.setArea(orderInfo.getArea());
- bean.setCpid(orderInfo.getCpid());
- bean.setSpid(orderInfo.getSpid());
- bean.setOrderid(orderInfo.getOrderid());
- bean.setProvince(orderInfo.getProvince());
- bean.setUserid(orderInfo.getUserid());
- bean.setChannel(orderInfo.getOrderchannel());
- bean.setSubchannel((orderInfo.getSubchannel() != null && !"null".equals(orderInfo.getSubchannel())) ? orderInfo.getSubchannel() : "");
- bean.setVipstatus("4"); //默认设置为不赠送
- bean.setType(orderInfo.getType()+"");
- if("1".equals(bean.getType())){//退订
- bean.setVipstatus(""); //设置为空
- }
- return bean;
- }
- /**
- * 获取endtime
- * @param orderInfo
- * @return
- */
- private String getEndTime(OrderInfo orderInfo)throws Exception{
- String endtime = "";
- String currEndtime = "";
- Map reMap = this.hasEffect(orderInfo);
- if((Boolean)reMap.get("hasEffect")){ //存在有效订购关系
- Map currOrderInfo = (Map)reMap.get("currOrderInfo");
- currEndtime = (String)currOrderInfo.get("ENDTIME");
- }
- //[{PWD=kijkfds, NETDAYS=31, CHANNEL=test_01, NETDAYS=2, SPID=1168, BUSITYPE=3, CPID=youtu}]
- HashMap confHm = backBusiOrderDao.getBackBusiConf(orderInfo.getCpid(), orderInfo.getSpid()).get(0);
- //String busiType = confHm.get("BUSITYPE")+"";
- //免流或免流+会员两种产品要以netdays参数来确定endtime
- if("2".equals(confHm.get("BUSITYPE")) || "3".equals(confHm.get("BUSITYPE"))){
- if(currEndtime != null && !"".equals(currEndtime)){
- endtime = backBusiOrderDao.endtimeParamDay(confHm.get("NETDAYS")+"", currEndtime);
- }else{
- endtime = backBusiOrderDao.currParamDay(confHm.get("NETDAYS")+"");
- }
- }
- return endtime;
- }
- /**
- * 业务办理
- * @param orderInfo
- * @return
- * @throws Exception
- */
- public String orderBusi(OrderInfo orderInfo)throws Exception{
- if( 0 == orderInfo.getType()){//订购
- orderInfo.setType(0); ////设置为订购
- return this.order(orderInfo);
- }else{
- throw new BusinessException("8000", "不支持操作类型,"+orderInfo.getType(), new String[0]);
- }
- }
- /**
- * 判断结束时间是否大于当前时间
- * @param endTime
- * @param currTime
- * @return
- * @throws Exception
- */
- private boolean compareDate(String endTime, String currTime)throws Exception{
- boolean result = false;
- SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
- Date dateCurrTime = sdf.parse(currTime);
- Date dateEndTime = sdf.parse(endTime);
- //dateEndTime小于dateCurrTime返回-1,dateEndTime大于dateCurrTime返回1,相等返回0
- if(dateEndTime.compareTo(dateCurrTime)>0){
- result = true;
- }
- return result;
- }
- /**
- * 订购业务
- * @param orderInfo
- * @return
- */
- public String order(OrderInfo orderInfo)throws Exception{
- String errorcode = "-1";
- String errorinfo = "";
- String result = "-1";
- BackBusiOrderRec bean = getOrderRecBean(orderInfo);
- try {
- orderInfo.setType(0); //设置为订购
- List<HashMap> confList = backBusiOrderDao.getBackBusiConf(orderInfo.getCpid(), orderInfo.getSpid());
- //[{PWD=kijkfds, CHANNEL=test_01, VIPTYPE=2, VIPPOOL=vip_yout, SPID=1168, BUSITYPE=3, CPID=youtu}]
- HashMap confHm = confList.get(0);
- String busiType = confHm.get("BUSITYPE")+"";
- //是否为复合产品,0是,为空或为1时不是
- String hasfh = confHm.get("HASFH") == null ? "": confHm.get("HASFH")+"";
- //调能力平台标识:0调能力平台并以结果落订购关系,1调能力平台其结果不影响订购关系,为空时不调能力平台
- String hasshare = confHm.get("HASSHARE") == null ? "": confHm.get("HASSHARE")+"";
- bean.setBusitype(busiType);
- this.hasDupliOrderid(orderInfo);//判断是否重复订单ID
- this.hasMutual(orderInfo); //已办理互斥业务
- String newEndtime = ""; //业务结束时间
- String starttime = ""; //业务开始时间
- Map<String, String> resMap = this.getBusiTime(orderInfo);
- newEndtime = resMap.get("endtime");
- starttime = resMap.get("starttime");
- //赠送会员状态,0成功,1待赠送,2赠送中,3失败
- //bean.setVipstatus("1");
- //办理结果编码,0成功,1待处理,2处理中,其他为异常
- bean.setResultcode("2");
- bean.setResultinfo("处理中");
- if("1".equals(busiType)){ //会员
- bean.setVipstatus("1");
- bean.setStarttime("");
- bean.setEndtime("");
- backBusiOrderDao.addOrderRec(bean); //添加订购记录
- }else if("2".equals(busiType)){ //免流
- //指定产品要先办理依赖业务才能受理
- /**
- if("200".equals(orderInfo.getSpid()) || "201".equals(orderInfo.getSpid())){
- List<OrderInfo> orderlist = orderDao.findByUser(orderInfo.getUserid(),orderInfo.getCpid());
- if(orderlist.size()>0 && orderInfo != null){
- List<String> spidlist = new ArrayList<String>();
- for(OrderInfo oi : orderlist){
- String spid = oi.getSpid();
- spidlist.add(spid);
- }
-
- //联通bilibili定向流量5GB包(后向),没办理979
- if("200".equals(orderInfo.getSpid()) && !spidlist.contains("979")){
- throw new BusinessException("8051","您未订购相应的产品,不能办理此加油包");
- }
-
- //联通爱奇艺定向流量5GB包(后向),没办理1018也没办理1017
- if("201".equals(orderInfo.getSpid()) && !spidlist.contains("1018") && !spidlist.contains("1017")){
- throw new BusinessException("8051","您未订购相应的产品,不能办理此加油包");
- }
- }else{
- throw new BusinessException("8051","您未订购相应的产品,不能办理此加油包");
- }
- }
- **/
- bean.setVipstatus("4"); //设置为不赠送
- bean.setStarttime(starttime);
- bean.setEndtime(newEndtime);
- backBusiOrderDao.addOrderRec(bean); //添加订购记录
- orderInfo.setEndtime(newEndtime);
- //设置订购时间
- this.setOrderTime(orderInfo);
- //调能力平台
- this.shareOrder(orderInfo, hasshare);
- backBusiOrderDao.order(orderInfo); //新增或更新订购关系
- }else if("3".equals(busiType)){ //会员+免流
- bean.setVipstatus("1");
- bean.setEndtime(newEndtime);
- bean.setStarttime(starttime);
- if("TX20_twback".equals(orderInfo.getOrderchannel())){//拓维订购会员+免流业务
- bean.setResultcode("0");
- bean.setResultinfo("拓维触发送会员");
- bean.setVipendtime(newEndtime); //设置领取会员的最后时间,默认为订单的endtime
- backBusiOrderDao.addOrderRec(bean); //添加订购记录
- orderInfo.setEndtime(newEndtime);
- //设置订购时间
- this.setOrderTime(orderInfo);
- bean.setVipstatus("4"); //设置为不赠送,由拓维发短信给用户,由用户自己去领取
- //调能力平台
- this.shareOrder(orderInfo, hasshare);
- backBusiOrderDao.order(orderInfo); //新增或更新订购关系
- //更新其他未领取会员的最后领取时间
- backBusiOrderDao.updVipEndtime(bean.getUserid(),newEndtime);
- }else{
- backBusiOrderDao.addOrderRec(bean); //添加订购记录
- orderInfo.setEndtime(newEndtime);
- //设置订购时间
- this.setOrderTime(orderInfo);
- //调能力平台
- this.shareOrder(orderInfo, hasshare);
- backBusiOrderDao.order(orderInfo); //新增或更新订购关系
- }
- }
-
- result = "0";
- errorcode = "0";
- errorinfo = "成功";
- } catch (Exception e) {
- e.printStackTrace();
- busilog.error("userid:"+orderInfo.getUserid()+"订购出现异常,"+e);
- if ((e instanceof BusinessException)) {
- errorcode = ((BusinessException) e).getCode();
- errorinfo = ((BusinessException) e).getMessage();
- }else{
- errorcode = "8000";
- errorinfo ="系统忙,"+e.getMessage();
- }
- if(errorinfo != null && errorinfo.length()>2000){
- errorinfo = errorinfo.substring(0, 2000);
- }
- throw e;
- } finally {
- bean.setResultcode(errorcode);
- bean.setResultinfo(errorinfo);
- if(bean.getResultinfo().indexOf("重复订单") == -1){
- try{
- backBusiOrderDao.addOrderRec(bean); //添加订购记录
- }catch(Exception e){
- busilog.info(orderInfo.getUserid()+",更新订购记录表出现异常,"+e.getMessage());
- }
- //如果是上海权益的订单,要更新到上海权益订购表
- if("shanghaiqy".equals(orderInfo.getOrderchannel())){
- backBusiOrderDao.updShInPaInfo(bean);
- }
- }
- saveLog(orderInfo, errorcode, errorinfo);
- //调9楼接口往省里推送订购关系
- try {
- if ("0".equals(errorcode)){
- if (backBusiOrderDao.orderPush(bean.getCpid(),bean.getSpid())){
- String serialid = bean.getId();
- if (serialid!=null&&serialid.length()>20){
- serialid=serialid.substring(0,20);
- }
- orderPush(serialid,bean.getUserid());
- }
- }
- } catch (SQLException e) {
- e.printStackTrace();
- log.error("调9楼接口往省里推送订购关系出现异常"+e.getMessage());
- }
- }
- return result;
- }
- /**
- *
- * @param serialid 流水号
- * @param usermob 手机号
- * @throws Exception
- */
- public void orderPush(String serialid,String usermob) throws Exception {
- String busiid="order";
- String url = dictionaryDao.getValue("orderPushUrl");
- if (org.apache.commons.lang.StringUtils.isEmpty(url)){
- throw new BusinessException("8005","url为空");
- }
- String parmas = dictionaryDao.getValue("orderPushParmas");
- busilog.info("9楼提供的数据=========="+parmas);
- if (StringUtils.isEmpty(parmas)){
- throw new BusinessException("8006","参数为空");
- }
- Map<String,String> paramsMap = JSONObject.parseObject(parmas, Map.class);
- String cpid=paramsMap.get("cpid");
- String productid=paramsMap.get("productid");//产品id
- String channel=paramsMap.get("channel");//渠道
- String key=paramsMap.get("key");//密钥
- Map<String,Object> dataMap=new HashMap<String,Object>();
- dataMap.put("busiid",busiid);
- dataMap.put("serialid",serialid);
- dataMap.put("usermob",usermob);
- dataMap.put("productid",productid);
- dataMap.put("channel",channel);
- String dataJson = JSONObject.toJSONString(dataMap);
- String data= BackAESUtil.encrypt(dataJson, key);
- Map<String,Object> paramMap=new HashMap<String,Object>();
- paramMap.put("cpid",cpid);
- paramMap.put("data",data);
- String params = JSONObject.toJSONString(paramMap);
- String response = URLUtil.postJson(url, params);
- if (StringUtils.isEmpty(response)){
- throw new BusinessException("9000","9楼接口调用失败"+usermob+"======"+serialid);
- }
- log.info("调9楼接口结果:"+response+"==userid"+usermob+"==serialid"+serialid);
- }
- /**
- * 设置当前时间
- * @param orderInfo
- * @throws Exception
- */
- private void setOrderTime(OrderInfo orderInfo) throws Exception{
- String currtime = this.backBusiOrderDao.getCurrentTime();
- orderInfo.setOrdertime(currtime);
- orderInfo.setEffecttime(currtime);
- }
- /**
- * 调能力平台
- * @param orderInfo
- * @param hasshare //调能力平台标识:0调能力平台并以结果落订购关系,1调能力平台其结果不影响订购关系,为空时不调能力平台,
- * @throws Exception
- */
- private void shareOrder(OrderInfo orderInfo, String hasshare) throws Exception{
- if("0".equals(hasshare) || "1".equals(hasshare)){
- String shareErcode = "0";
- String shareErnfo = "成功";
- if("0".equals(hasshare)){//以能力平台调用结果落订购关系的要设置渠道为SHARE,此渠道记录在订购关系表和订购日志表中
- orderInfo.setChannel("SHARE");
- }else{
- orderInfo.setChannel("");
- }
- try {
- shareOrderService.order(orderInfo.getUserid(),orderInfo.getCpid(),orderInfo.getSpid());
- } catch (BusinessException e) {
- e.printStackTrace();
- shareErcode = e.getCode();
- shareErnfo = e.getMessage();
- if("0".equals(hasshare)){
- throw new BusinessException("8888","调用能力共享平台订购接口失败");
- }
- } finally {
- saveBackShareLog(orderInfo,shareErcode,shareErnfo);
- }
- }
- }
- /**
- * 查询本地订购关系表当前是否有已生效的订购关系
- * @param orderInfo
- * @return
- * @throws Exception
- */
- private Map hasEffect(OrderInfo orderInfo) throws Exception{
- Map reMap = new HashMap();
- boolean hasEffect = false;
- Map currOrderInfo = null;
- String currentTime = backBusiOrderDao.getCurrentTime();
- //查询用户本地订购关系表未失效的订购数据
- currOrderInfo = backBusiOrderDao.findByUserAndSpid(orderInfo.getUserid(),orderInfo.getCpid(),orderInfo.getSpid());
- if(currOrderInfo != null){//本地有订购关系
- if(Long.parseLong(currOrderInfo.get("ENDTIME").toString()) >= Long.parseLong(currentTime)){ //结束时间大于或等于当前时间,订购关系有效
- hasEffect = true;
- }
- }
- reMap.put("hasEffect", hasEffect);
- reMap.put("currOrderInfo", currOrderInfo);
- return reMap;
- }
- /**
- * 判断业务是否互斥
- * @param orderInfo
- * @throws Exception
- */
- private void hasMutual(OrderInfo orderInfo) throws Exception{
- boolean result = false;
- List<OrderInfo> listOrderInfo = backBusiOrderDao.findByUser(orderInfo.getUserid());
- if (listOrderInfo != null && listOrderInfo.size() > 0
- && !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.getSpid().equals(mutexSpid)) {
- result = true;
- break;
- }
- }
- }
- }
- if(result){
- throw new BusinessException("9003","已办理互斥业务", new String[0]);
- }
- }
- /**
- * 判断是否有相同订单
- * @param orderInfo
- * @return true是,false否
- */
- private void hasDupliOrderid(OrderInfo orderInfo) throws Exception{
- List<BackBusiOrderRec> list = backBusiOrderDao.findOrderRecByOrderid(orderInfo.getOrderid());
- if(list != null && list.size() > 0){
- throw new BusinessException("9001", "重复订单", new String[0]);
- }
- }
- 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";
- }
- /**
- * 写订购日志
- * @param orderInfo
- * @param errorcode
- * @param errorinfo
- */
- public void saveLog(OrderInfo orderInfo, String errorcode, String errorinfo) {
- try {
- OrderLog orderLog = new OrderLog();
- orderLog.setApptype(orderInfo.getApptype());
- orderLog.setArea(orderInfo.getArea());
- orderLog.setChannel(orderInfo.getOrderchannel());
- 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.backBusiOrderDao.addOrderLog(orderLog);
- } catch (Exception e) {
- e.printStackTrace();
- busilog.error("userid:"+orderInfo.getUserid()+",写订购日志出现异常,"+e.getMessage());
- }
- }
- /**
- * 写后向订购能力平台日志
- * @param orderInfo
- * @param errorcode
- * @param errorinfo
- */
- private void saveBackShareLog(OrderInfo orderInfo,String errorcode,String errorinfo){
- BackShareOrderBean bso = new BackShareOrderBean();
- bso.setUserid(orderInfo.getUserid());
- bso.setErrorcode(errorcode);
- bso.setErrorinfo(errorinfo);
- bso.setCpid(orderInfo.getCpid());
- bso.setSpid(orderInfo.getSpid());
- try {
- backShareOrderDao.addShareOrderLog(bso);
- } catch (Exception e) {
- e.printStackTrace();
- busilog.error("userid:"+orderInfo.getUserid()+",写后向订购能力平台日志出现异常,"+e.getMessage());
- }
- }
- /**
- * 获取开始时间和结束时间
- * @param orderInfo
- * @return
- * @throws Exception
- */
- private Map<String, String> getBusiTime(OrderInfo orderInfo)throws Exception{
- Map<String, String> resMap = new HashMap<String, String>();
- String starttime = ""; //业务开始时间
- String endtime = ""; //业务结束时间
- String currEndtime = "";
- Map reMap = this.hasEffect(orderInfo);
- HashMap confHm = backBusiOrderDao.getBackBusiConf(orderInfo.getCpid(), orderInfo.getSpid()).get(0);
- if((Boolean)reMap.get("hasEffect")){ //存在有效订购关系
- if("1".equals(confHm.get("ENDTYPE"))){
- throw new BusinessException("9005","本月已订购,请勿重复订购");
- }
- Map currOrderInfo = (Map)reMap.get("currOrderInfo");
- currEndtime = (String)currOrderInfo.get("ENDTIME");
- }
- //[{PWD=kijkfds, NETDAYS=31, CHANNEL=test_01, NETDAYS=2, SPID=1168, BUSITYPE=3, CPID=youtu}]
- //String busiType = confHm.get("BUSITYPE")+"";
- //业务类型,1会员,2免流,3会员+免流
- //ENDTYPE: 1:结束时间到月底且不能重复订购,2:结束时间到月底且能重复订购,结束时间累加一个月,3:结束时间到月底,能重复订购,结束时间不累加。其余结束时间按netdays算且能重复订购
- //免流或免流+会员两种产品要以netdays参数来确定endtime
- if("2".equals(confHm.get("BUSITYPE")) || "3".equals(confHm.get("BUSITYPE"))){
- if(currEndtime != null && !"".equals(currEndtime)){
- if("3".equals(confHm.get("ENDTYPE"))){
- endtime = backBusiOrderDao.endtimeTheMonthLastDay();
- }else if("2".equals(confHm.get("ENDTYPE"))){
- endtime = backBusiOrderDao.endtimeNextMonthLastDay(currEndtime);
- }else{
- endtime = backBusiOrderDao.endtimeParamDay(confHm.get("NETDAYS")+"", currEndtime);
- }
- }else{
- if("1".equals(confHm.get("ENDTYPE")) || "2".equals(confHm.get("ENDTYPE"))|| "3".equals(confHm.get("ENDTYPE"))){
- endtime = backBusiOrderDao.endtimeTheMonthLastDay(); //特殊产品的结束时间只到本月底
- }else {
- endtime = backBusiOrderDao.currParamDay(confHm.get("NETDAYS")+"");
- }
- }
- if("1".equals(confHm.get("ENDTYPE")) || "2".equals(confHm.get("ENDTYPE")) || "3".equals(confHm.get("ENDTYPE"))){
- starttime = backBusiOrderDao.getKsStartTime(); //特殊产品开始时间就是当天
- }else{
- starttime = backBusiOrderDao.getStartTime(endtime,confHm.get("NETDAYS")+"");
- }
- }
- resMap.put("starttime", starttime);
- resMap.put("endtime", endtime);
- return resMap;
- }
- }
|