package com.chinacreator.video.restful.service;

import java.nio.channels.Channel;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Pattern;

import com.chinacreator.video.bean.*;
import com.chinacreator.video.mapper.*;
import com.chinacreator.video.restful.dao.HsQueryVipDao;
import org.apache.commons.lang.math.NumberUtils;
import org.apache.commons.lang.time.DateFormatUtils;
import org.jboss.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.chinacreator.video.exception.BussinessException;
import com.chinacreator.video.restful.dao.VipJoinSpidDao;
import com.chinacreator.video.util.DesUtil;
import com.chinacreator.video.util.MD5;
import com.chinacreator.video.validate.BusiValidate;


/**
 * 腾讯，爱奇艺，优酷，芒果,b站会员领取查询状态接口
 *
 * @author guangshu.li
 * @date 20210507
 */
@Component
public class QueryFiveVipsService {

    @Autowired
    private BusiValidate busiVali;

    @Autowired
    private ChannelDao channelDao;

    @Autowired
    private DictionaryDao dictionaryDao;

    @Autowired
    private QueryFiveVipsDao queryFiveVipsDao;

    @Autowired
    private UserMsgDao userMsgDao;

    @Autowired
    ActivityProductDao activityProductDao;

    @Autowired
    private QueryOderRelationDao queryOderRelationDao;

    @Value("${spid.BLACKLIST}")
    private String BLACKLIST;

    @Autowired
    private ActiveTimeDao activeTimeDao;

    @Autowired
    private VipJoinSpidDao vipJoinSpidDao;

    @Autowired
    private HsQueryVipDao hsQueryVipDao;

    //private static String tencentorderChannels = "110101831058,110101516931,110101106139,110101129643,110101971768,110101824561,110101706791,110101508415,110101160776,110101813371";

    //private static String mangtv1051orderChannels = "166887208127,189676964717,171876601373,100001830817,137459471825,145637904257";
    //private static String mangtv1052orderChannels = "185403370158,185403106589";
    //private static Logger log = Logger.getLogger("smsorder");

    private static Logger log = Logger.getLogger("queryFiveVipReq");

    public void busiCheck(JSONObject inputObj) throws Exception {

        OrderInfo orderInfo = new OrderInfo();
        orderInfo.setChannel("queryvip");
        //ip校验
        busiVali.valiIp(orderInfo);
        //参数验证
        paramValidate(inputObj);
        //时间错验证
        checkTimestamp(inputObj.getString("timestamp"));
        //签名验证
        signValidate(inputObj);
        //手机号码验证
        mobValidate(inputObj);

    }


    /**
     * 参数验证
     *
     * @param inputObj
     * @param
     * @throws Exception
     */
    private void paramValidate(JSONObject inputObj) throws Exception {
        if (StringUtils.isEmpty(inputObj.getString("userid"))
                || StringUtils.isEmpty(inputObj.getString("timestamp"))
                || StringUtils.isEmpty(inputObj.getString("channel"))
                || StringUtils.isEmpty(inputObj.getString("signature"))
        ) {
            throw new BussinessException("80015", "参数异常，");
        }

    }

    /**
     * 拼接签名信息 userid+pwd+timestamp+channel
     *
     * @param inputObj
     * @return
     */
    public void signValidate(JSONObject inputObj) throws BussinessException {
        String data = inputObj.getString("userid") + "taykv9kq" + inputObj.getString("timestamp") + inputObj.getString("channel");
        String localSig = MD5.MD5Encode(data);
        if (!localSig.equals(inputObj.getString("signature"))) {
            throw new BussinessException("9054", "signature校验失败");
        }


    }

    /**
     * 手机号码验证
     *
     * @param inputObj
     * @throws Exception
     */
    private void mobValidate(JSONObject inputObj) throws Exception {
        String userid = inputObj.getString("userid");
        if (StringUtils.isEmpty(userid)) {
            throw new BussinessException("9057", "userid不能为空");
        }
        try {
            userid = DesUtil.decode(userid, "taykv9kq");
        } catch (Exception e) {
            throw new BussinessException("9056", "userid加密错误");
        }
		/*if (!UsermobUtil.isValid(userid)) {
			throw new BussinessException("9055", "userid不正确");
		}*/
        if (userid == null || userid.trim().length() != 11) {
            throw new BussinessException("9055", "userid不正确");
        }
        if (!Pattern.matches("^1[0-9]{10}", userid)) {
            throw new BussinessException("9055", "userid不正确");
        }
        inputObj.put("userid", userid);
    }


    public void checkTimestamp(String strtimestamp) throws BussinessException {
        if (StringUtils.isEmpty(strtimestamp)) {
            throw new BussinessException("9052", "timestamp参数不能为空");
        }
        long timestamp = Long.parseLong(strtimestamp);
        long nowTimestamp = System.currentTimeMillis() / 1000;
        if ((nowTimestamp - timestamp) > 300) {
            throw new BussinessException("9053", "timestamp已失效");
        }
    }

    public List<HashMap> addActivity(String channel) {

        List<HashMap> hashMaps = activityProductDao.findboyuanActivity(channel);
        return hashMaps;

    }


    public List<Vip> queryVip(List<HashMap> list, String userid) throws BussinessException {
        List<Vip> vips = new ArrayList<Vip>();
        List<String> blacklist = null;
        if (!StringUtils.isEmpty(BLACKLIST)) {
            blacklist = Arrays.asList(BLACKLIST.split(","));
        }
        for (HashMap map : list) {
            Vip vip = new Vip();
            vip.setUserid(userid);
            String cpid = (String) map.get("CPID");
            String spid = (String) map.get("SPID");
            String activetype = map.get("ACTIVETYPE") + "";
            //System.out.println(cpid);
            //System.out.println(spid);
            //System.out.println(activetype);
            vip.setCpid(cpid);
            vip.setSpid(spid);
            try {
                ActivityBean activityBean = queryFiveVipsDao.getActivityInfo(userid, cpid, spid, activetype);
                //20220721 新增领取规则
                List<HashMap> channelData = hsQueryVipDao.findUserChannelData(userid, spid);
			/*	//取第一条
				String channel = "";
				String subchannel = "";
				if(channelData!=null && channelData.size()>0){
					channel = channelData.get(0).get("ORDERCHANNEL")==null?"":channelData.get(0).get("ORDERCHANNEL").toString();
					subchannel = channelData.get(0).get("ORDERCHANNEL2")==null?"":channelData.get(0).get("ORDERCHANNEL2").toString();
				}
				*//**
                 订购当月务必手动领取会员，次月续订时会员自动续送。 --既不在 tb_order_sendvip_conf （查渠道） 也不在 tb_vip_joinspid_conf （查渠道）
                 订购期间，会员权益每月将自动入充值到您当前手机号。--在tb_order_sendvip_conf  （查渠道），不在tb_vip_joinspid_conf （查渠道）
                 订购期间务必每月手动领取当月会员逾期不补。--在tb_vip_joinspid_conf   （查渠道）,不在tb_order_sendvip_conf  （查渠道）
                 **//*
				List<HashMap> sendvipMap = hsQueryVipDao.getSendvip_conf(channel,subchannel,spid);
				List<HashMap> joinvipMap = hsQueryVipDao.getJoinspid_conf(channel,subchannel,spid);

				if((sendvipMap!=null && sendvipMap.size()>0) && (joinvipMap==null || joinvipMap.size()==0)){
					vip.setReceiverule("订购期间，会员权益每月将自动入充值到您当前手机号。");//领取规则
				}else if ((joinvipMap!=null && joinvipMap.size()>0) && (sendvipMap==null || sendvipMap.size()==0)){
					vip.setReceiverule("订购期间务必每月手动领取当月会员逾期不补.");//领取规则
				}else if((sendvipMap==null || sendvipMap.size()==0) && (joinvipMap==null || joinvipMap.size()==0)){
					vip.setReceiverule("订购当月务必手动领取会员，次月续订时会员自动续送。");//领取规则
				}else{
					vip.setReceiverule("");//领取规则
				}*/
                //取第一条
                String channel = "";
                String subchannel = "";
                String ordertime = null;
                if (channelData != null && channelData.size() > 0) {
                    channel = channelData.get(0).get("ORDERCHANNEL") == null ? "" : channelData.get(0).get("ORDERCHANNEL").toString();
                    subchannel = channelData.get(0).get("ORDERCHANNEL2") == null ? "" : channelData.get(0).get("ORDERCHANNEL2").toString();
                    ordertime = channelData.get(0).get("ORDERTIME") == null ? "" : channelData.get(0).get("ORDERTIME").toString();
                }
                String time = "20221101000000";
                long time_long = Long.parseLong(time);
                long ordertime_long = 0;
                if (ordertime != null) {
                    ordertime_long = Long.parseLong(ordertime);
                    log.info("ordertime:" + ordertime_long + "==========>" + "time" + time_long);
                    /**
                     * 原逻辑
                     订购当月务必手动领取会员，次月续订时会员自动续送。 --既不在 tb_order_sendvip_conf （查渠道） 也不在 tb_vip_joinspid_conf （查渠道）
                     订购期间，会员权益每月将自动入充值到您当前手机号。--在tb_order_sendvip_conf  （查渠道），不在tb_vip_joinspid_conf （查渠道）
                     订购期间务必每月手动领取当月会员逾期不补。--在tb_vip_joinspid_conf   （查渠道）,不在tb_order_sendvip_conf  （查渠道）
                     **/
//                    List<HashMap> sendvipMap = hsQueryVipDao.getSendvip_conf(channel, subchannel, spid);
				List<HashMap> sendvipMap = hsQueryVipDao.getSendvip_conf_new(channel,subchannel,spid);
                    List<HashMap> joinvipMap = hsQueryVipDao.getJoinspid_conf(channel, subchannel, spid, ordertime);
                    List<HashMap> joinvipMap_new = hsQueryVipDao.getJoinspid_conf_new(channel, subchannel, spid, ordertime);
                    log.info("sendvipMap" + sendvipMap);
                    log.info("joinvipMap" + joinvipMap);
                    log.info("joinvipMap_new" + joinvipMap_new);
                    // 2022年11月1号之前订购的用户保持原来的逻辑
                    if (ordertime_long < time_long) {
                        log.info("11.1之前订购的老用户原来的逻辑" + userid + "===>" + spid);
                        if ((sendvipMap != null && sendvipMap.size() > 0) && (joinvipMap == null || joinvipMap.size() == 0)) {
                            vip.setReceiverule("订购期间，会员权益每月将自动充值到您当前手机号。");//领取规则
                        } else if ((joinvipMap != null && joinvipMap.size() > 0) && (sendvipMap == null || sendvipMap.size() == 0)) {
                            vip.setReceiverule("订购期间务必每月手动领取当月会员逾期不补。");//领取规则
                        } else if ((sendvipMap == null || sendvipMap.size() == 0) && (joinvipMap == null || joinvipMap.size() == 0)) {
                            vip.setReceiverule("订购当月务必手动领取会员，次月续订时会员自动续送。");//领取规则
                        } else {
                            vip.setReceiverule("");//领取规则
                        }
                    } else {
					/*
					原来次月续送的用户改为每月需手动领取
					除部分特殊渠道的产品还是原来首月手动领取次月续送
					*/
                        log.info("11.1之后订购的新用户新逻辑" + userid + "===>" + spid);
                        if ((sendvipMap != null && sendvipMap.size() > 0) && (joinvipMap_new == null || joinvipMap_new.size() == 0)) {
                            vip.setReceiverule("订购期间，会员权益每月将自动充值到您当前手机号。");//领取规则
                        } else if ((joinvipMap_new != null && joinvipMap_new.size() > 0)) {
                            String specialchannels = dictionaryDao.getValue("specialchannels_" + spid);
                            log.info("specialchannels " + specialchannels);
                            if ((sendvipMap == null || sendvipMap.size() == 0)) {
                                if (!StringUtils.isEmpty(specialchannels)){
                                    if (!StringUtils.isEmpty(subchannel) && specialchannels.contains(subchannel)) {
                                        vip.setReceiverule("订购当月务必手动领取会员，次月续订时会员自动续送。");//领取规则
                                    }else {
                                        vip.setReceiverule( "订购期间务必每月手动领取当月会员逾期不补。");//领取规则
                                    }
                                }else {
                                    vip.setReceiverule( "订购期间务必每月手动领取当月会员逾期不补。");//领取规则
                                }
                            } else {
                                if (!StringUtils.isEmpty(specialchannels)){
                                    if (!StringUtils.isEmpty(subchannel) && specialchannels.contains(subchannel)) {
                                        vip.setReceiverule("订购期间，会员权益每月将自动充值到您当前手机号。");//领取规则
                                    }else {
                                        vip.setReceiverule( "订购期间务必每月手动领取当月会员逾期不补。");//领取规则
                                    }
                                }else {
                                    vip.setReceiverule( "订购期间务必每月手动领取当月会员逾期不补。");//领取规则
                                }
                            }

                        } else if ((sendvipMap == null || sendvipMap.size() == 0) && (joinvipMap_new == null || joinvipMap_new.size() == 0)) {
                            vip.setReceiverule("订购当月务必手动领取会员，次月续订时会员自动续送。");//领取规则
                        } else {
                            vip.setReceiverule("");//领取规则
                        }
                    }
                } else {
                    log.info("该数据无订购关系" + channelData + "========>" + "spid:" + spid + "=====>" + "userid:" + userid);
                }
                if (activityBean == null) {
                    throw new BussinessException("9081", "用户无订购不能赠送会员");
                }
                if (activityBean.getOrderstatus().equals("1") && NumberUtils.toLong(activityBean.getEndtime()) < NumberUtils.toLong(DateFormatUtils.format(new Date(), "yyyyMMddHHmmss"))) {
                    throw new BussinessException("9084", "用户为无效订购状态不能赠送会员");
                }
                if (activityBean.getVipstatus().equals("2")) {
                    throw new BussinessException("9083", "可赠送会员，用户未领取");
                }
                if (activityBean.getVipstatus().equals("1")) {
                    throw new BussinessException("9082", "会员赠送失败");
                }
                if (activityBean.getVipstatus().equals("4")) {
                    throw new BussinessException("9090", "该活动已暂停赠送会员");
                }
                if (activityBean.getVipstatus().equals("3")) {
                    throw new BussinessException("9091", "会员赠送中");
                }
                if (activityBean.getVipstatus().equals("990099")) {
                    throw new BussinessException("9091", "会员赠送中");
                }
                /***
                 if("1016".equals(spid) && activityBean.getVipstatus().equals("0")){
                 List<String> channelList = Arrays.asList(tencentorderChannels.split(","));
                 if(channelList != null && channelList.size()> 0){
                 Map result = null;
                 result = queryOderRelationDao.findByUserAndSpid(userid,cpid,spid);
                 if(result != null && result.get("ORDERCHANNEL2") != null && !"".equals(result.get("ORDERCHANNEL2")) && channelList.contains(result.get("ORDERCHANNEL2"))){
                 if(!queryOderRelationDao.getSysTime().substring(0, 6).equals(activityBean.getViptime().substring(0,6))){
                 throw new BussinessException("9083", "可赠送会员，用户未领取");
                 }
                 }
                 }

                 }else if(("1051".equals(spid) || "1052".equals(spid)) && activityBean.getVipstatus().equals("0")){
                 if(activeTimeDao.isActiveTime("mangtvtime") > 0){  //
                 List<String> channelList = null;
                 if("1051".equals(spid)){
                 channelList = Arrays.asList(mangtv1051orderChannels.split(","));
                 }
                 if("1052".equals(spid)){
                 channelList = Arrays.asList(mangtv1052orderChannels.split(","));
                 }
                 System.out.println("在时间范围内-----"+channelList);
                 if(channelList != null && channelList.size()> 0){
                 Map result = null;
                 result = queryOderRelationDao.findByUserAndSpid(userid,cpid,spid);
                 if(result != null && result.get("ORDERCHANNEL2") != null && !"".equals(result.get("ORDERCHANNEL2")) && channelList.contains(result.get("ORDERCHANNEL2"))){
                 if(!queryOderRelationDao.getSysTime().substring(0, 6).equals(activityBean.getViptime().substring(0,6))){
                 throw new BussinessException("9083", "可赠送会员，用户未领取");
                 }
                 }
                 }
                 }
                 }else
                 *****/
                if (activityBean.getVipstatus().equals("0") && (blacklist != null && blacklist.size() > 0 && blacklist.contains(spid))) {
                    //系统时间大于活动配置表配置的开始时间，开始走手动领取逻辑
                    if (activeTimeDao.isActiveTime("begintime") > 0) {
                        if (!queryOderRelationDao.getSysTime().substring(0, 6).equals(activityBean.getViptime().substring(0, 6))) {
                            throw new BussinessException("9083", "可赠送会员，用户未领取");
                        }
                    }
                    //当会员领取状态是已领取时，按渠道配置的手动会员领取验证
                } else if (activityBean.getVipstatus().equals("0")) {
                    //只䏍验证通过的才能领取
                    vailVipJoinSpidConf(userid, cpid, spid, activityBean,ordertime);
                }
                UserMsgBean userMsgBean = userMsgDao.getMsg(userid, cpid, spid, activetype);
                if (userMsgBean != null) {
                    vip.setUsertype(userMsgBean.getMsg2());
                    vip.setUserval(userMsgBean.getMsg1());
                    vip.setVipname(userMsgBean.getMsg3());
                    vip.setViptime(userMsgBean.getInserttime());
                    //System.out.println(userMsgBean.getInserttime());
                }

            } catch (Exception e) {
                if (e instanceof BussinessException) {
                    vip.setResultcode(((BussinessException) e).getCode());
                    vip.setErrorinfo(e.getMessage());
                } else {
                    e.printStackTrace();
                    log.info("userid=>" + userid + "，出现异常，" + e.getMessage(), e);
                    vip.setResultcode("系统忙，请稍后再试");
                    vip.setErrorinfo("8000");
                }
            }
            vips.add(vip);

        }
        return vips;
    }

    /**
     * 当活动表的会员领取状态为已领取时，判断是否当月还能再手动领取会员
     *
     * @return
     * @throws Exception
     */
    public void vailVipJoinSpidConf(String userid, String cpid, String spid, ActivityBean activityBean,String ordertime) throws Exception {
        try {
            boolean contains = false;
            //获取手动赠送配置表的信息
            List<HashMap> dataList = vipJoinSpidDao.getVipJoinSpidConf(spid);
            if (dataList != null && dataList.size() > 0) {
                //查询订购关系表获取订购信息
                Map order = queryOderRelationDao.findByUserAndSpid(userid, cpid, spid);  //orderDao.getOrder(orderInfo);
                if (order == null) {
                    //throw new BussinessException("9085", "用户无订购不能赠送会员");
                    throw new BussinessException("9081", "用户无订购不能赠送会员");
                }
                //获取子渠道
                String orderchannel2 = (String) order.get("ORDERCHANNEL2");
                //获取主渠道
                String orderchannel = (String) order.get("ORDERCHANNEL");
                log.info("手动领取会员配置：" + dataList + "，orderchannel2=>" + orderchannel2 + "，orderchannel=>" + orderchannel + "，userid=>" + userid + "，spid=>" + spid);
                //子渠道标识或主渠道标识不为空
                if (!StringUtils.isEmpty(orderchannel2) || !StringUtils.isEmpty(orderchannel)) {
                    //渠道是否有配置
                    for (HashMap hm : dataList) {
                        if ("0".equals(hm.get("HASSUBCHANNEL"))) {//子渠道
                            //配置渠道与子渠道相同，SPID相同，当前月份与已领取月份不相同
                            if (!StringUtils.isEmpty(orderchannel2)
                                    && (orderchannel2.equals(hm.get("CHANNEL")))
                                    && spid.equals(hm.get("SPID"))
                                    && this.valiConfDate(userid, spid, activityBean, hm)) {
                                    contains = true;
                                break;
                            }
                        } else {//主渠道
                            //配置渠道为 * ，SPID相同，当前月份与已领取月份不相同
                            if (!StringUtils.isEmpty(orderchannel)
                                    && ("*".equals(hm.get("CHANNEL")))
                                    && spid.equals(hm.get("SPID"))
                                    && this.valiConfDate(userid, spid, activityBean, hm)) {
                                String time = "20221101000000";
                                final long time_long = Long.parseLong(time);
                                final long ordertime_long = Long.parseLong(ordertime);
                                /*
                                 * 修改新逻辑
                                 * 11.1之前订购的不变
                                 * 1011,1012,1016,1047,1048,1049,1051,1052（根据业务变化）
                                 * 11.1之后订购的，除部分产品的几个特殊渠道，以上spid由续送改为手动领取
                                 * */
                                if (!StringUtils.isEmpty(ordertime)) {
                                    String contractspids = dictionaryDao.getValue("contractspids");
                                    if (!StringUtils.isEmpty(contractspids) && contractspids.contains(spid)){
                                        if (ordertime_long >= time_long) {
                                            String specialchannels = dictionaryDao.getValue("specialchannels_" + spid);
                                            if (!StringUtils.isEmpty(specialchannels)){
                                                if (specialchannels.contains(orderchannel2)) {
                                                    log.info("该产品渠道为需续送的特殊渠道" + spid + "=======>" + orderchannel2);
                                                } else {
                                                    contains = true;
                                                }
                                            }else {
                                                contains = true;
                                            }
                                        }else {
                                            // 11.1之前领取配置无*的概念
                                            continue;
                                        }
                                    }else {
                                        contains = true;
                                    }
                                }else {
                                    log.info("该数据无订购关系" + userid +"=====>" +spid);
                                }
                                break;
                            }else if (!StringUtils.isEmpty(orderchannel)
                                    && (orderchannel.equals(hm.get("CHANNEL")))
                                    && spid.equals(hm.get("SPID"))
                                    && this.valiConfDate(userid, spid, activityBean, hm)){
                                //配置渠道与主渠道相同，SPID相同，当前月份与已领取月份不相同
                                contains = true;
                                break;
                            }
                        }
                    }
                } else {//子渠道标识他和主渠道标识都为空
                    //渠道是否有配置
                    for (HashMap hm : dataList) {
                        //配置渠道与主渠道相同，SPID相同，当前月份与已领取月份不相同
                        if ("*".equals(hm.get("CHANNEL"))
                                && spid.equals(hm.get("SPID"))
                                && this.valiConfDate(userid, spid, activityBean, hm)) {
                            contains = true;
                            break;
                        }
                    }
                }
            }
            //可以领取会员
            if (contains) {
                //代表可以领取
                throw new BussinessException("9083", "可赠送会员，用户未领取");
            }
        } catch (Exception e) {
            if (e instanceof BussinessException) {
                throw e;
            } else {
                //throw new BussinessException("8000","验证手动赠送会员出现异常，"+e.getMessage());
                throw e;
            }
        }
    }

    /**
     * 验证业务是否在配置时间内
     *
     * @param userid
     * @param spid
     * @param activityBean
     * @param confmap
     * @return
     */
    private boolean valiConfDate(String userid, String spid, ActivityBean activityBean, HashMap confmap) {
        boolean res = false;
        String starttime = null;
        String endtime = null;
        String systime = queryOderRelationDao.getSysTime();
        String viptime = activityBean.getViptime();

        //判断当月是否已领取过会员（系统时间的月份与已领取时间的月份相同）
        if (!StringUtils.isEmpty(viptime) && systime.substring(0, 6).equals(viptime.substring(0, 6))) {
            log.info("userid=>" + userid + "，spid=>" + spid + "，当月已领取");
            return res;
        }

        //判断开始时间和结束时间是否合法
        if (confmap.get("STARTTIME") != null && confmap.get("STARTTIME").toString().length() == 14) {
            starttime = confmap.get("STARTTIME").toString();
        }
        if (confmap.get("ENDTIME") != null && confmap.get("ENDTIME").toString().length() == 14) {
            endtime = confmap.get("ENDTIME").toString();
        }

        //有时间配置
        if (!StringUtils.isEmpty(starttime) || !StringUtils.isEmpty(endtime)) {
            //开始时间和结束时间都有配置
            if (!StringUtils.isEmpty(starttime) && !StringUtils.isEmpty(endtime)
                    && Long.parseLong(systime) >= Long.parseLong(starttime)
                    && Long.parseLong(systime) <= Long.parseLong(endtime)) {
                res = true;
                //只配置了开始时间
            } else if (!StringUtils.isEmpty(starttime) && StringUtils.isEmpty(endtime)
                    && Long.parseLong(systime) >= Long.parseLong(starttime)) {
                res = true;
                //只配置了结束时间
            } else if (StringUtils.isEmpty(starttime) && !StringUtils.isEmpty(endtime)
                    && Long.parseLong(systime) <= Long.parseLong(endtime)) {
                res = true;
            }
        } else { //时间无配置
            res = true;
        }

        if (res) {//时间验证通过
            //判断当月是否已领取过会员（系统时间的月份与已领取时间的月份相同）
            if (!StringUtils.isEmpty(viptime) && systime.substring(0, 6).equals(viptime.substring(0, 6))) {
                res = false;
            }
        }

        log.info("userid=>" + userid + "，spid=>" + spid + "，手动领取时间验证结果=>" + res + "，systime=>" + systime + "，starttime=>" + starttime + "，endtime=>" + endtime + "，viptime=>" + viptime);

        return res;
    }
}
