package com.chinacreator.video.mapper;

import com.chinacreator.video.bean.OrderInfo;
import com.chinacreator.video.bean.OrderLog;
import org.apache.ibatis.annotations.Param;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 查询公共配置
 * @author xu.zhou
 * @date 20190627
 */
@Component
public interface CommConfDao{

	//@Cacheable(value = "tranIpLimitConf",keyGenerator = "wiselyKeyGenerator")
	//public List<Map> getTranIpLimitConf(@Param("channel")String channel);

	//@Cacheable(value = "qryIpLimitConf",keyGenerator = "wiselyKeyGenerator")
	//public List<Map> getQryIpLimitConf(@Param("channel")String channel);

	@Cacheable(value = "allCpSpInfo",keyGenerator = "wiselyKeyGenerator")
	public List<Map> getCpSpInfo();

	@Cacheable("spinfo")
	public List<HashMap> findSpInfo(@Param("spid")String spid);

	/**
	 * 查询次数限制配置
	 * @return
	 */
	@Cacheable(value = "limitQryConf",keyGenerator = "wiselyKeyGenerator")
	public List<Map> getlimitQryConf();
	
	/**
	 * 根据渠道查询次数限制配置
	 * @param channel 渠道	 
	 * @return
	 */
	@Cacheable(value = "limitQryConfByChannel",keyGenerator = "wiselyKeyGenerator")
	public List<Map> getlimitQryConfByChannel(@Param("channel")String channel);

	/**
	 * 根据busitype和channel获取IP配置信息
	 * @param busitype
	 * @param channel
	 * @return
	 */
	@Cacheable(value = "ipLimitConf",keyGenerator = "wiselyKeyGenerator")
	public List<Map> getIpLimitConf(@Param("busitype")String busitype,@Param("channel")String channel);
	
	/**
	 * 根据busitype和channel、invokeface获取IP配置信息
	 * @param busitype
	 * @param channel
	 * @param invokeface 接口标识
	 * @return
	 */
	@Cacheable(value = "ipLimitConfByInvokeface",keyGenerator = "wiselyKeyGenerator")
	public List<Map> getIpLimitConfByInvokeface(@Param("busitype")String busitype,@Param("channel")String channel,@Param("invokeface")String invokeface);

	/**
	 * 根据手机号码查询所有订购数据
	 * @param userid
	 * @return
	 */
	public List<Map> getAllOrder(@Param("userid")String userid);

	@Cacheable("unvideo_areainfo")
	public List<Map> getAreaInfo(@Param("callerhead")String callerhead);

	/*
	 *  获取所有订购关系
	 */
	List<HashMap> findOrderRelaAll(String userid);

	/*
	 *  获取订购关系
	 */
	HashMap findOrderRela(@Param("userid") String userid,@Param("cpid") String cpid,@Param("spid") String spid);

	/**
	 * 获取ID
	 * @return
	 */
	public String generateId();

	/**
	 * 添加订购关系
	 * @param orderInfo
	 */
	public void addOrderRal(OrderInfo orderInfo);


	/**
	 * 添加退订关系
	 * @param orderInfo
	 */
	public void addCancelRal(OrderInfo orderInfo);

	/**
	 * 添加订购日志
	 * @param orderLog
	 */
	public void addOrderLog(OrderLog orderLog);

	/**
	 * 添加订购关系表和订单ID之间的关联日志
	 * @param hm
	 */
	public void addRelidLog(HashMap hm);

	/**
	 * 订购时添加订购关系表和订单ID之间的关联记录
	 * @param hm
	 */
	public void addOrderRelidRec(HashMap hm);

	/**
	 * 退订时添加订购关系表和订单ID之间的关联记录
	 * @param hm
	 */
	public void addCancelRelidRec(HashMap hm);

	/**
	 * 获取当前时间
	 * @return
	 */
	public String getCurrtime();

	/**
	 * 获取当月最后一天
	 * @return
	 * @throws SQLException
	 */
	public String getEndDayOfCurrentMonth();

	/**
	 * 根据操作时间获取操作时间的最后一天最后一秒
	 * @return
	 * @throws SQLException
	 */
	public String getEndDayOfOpertime(@Param("opertime")String opertime);
	
	/**
	 * 查询能力平台次月生效订购关系
	 * @param userid
	 * @return
	 */
	List<Map> findNmaOrderRela(String userid);
	
	/**
	 * 获取渠道业务限制表的配置信息
	 * @param channel 渠道
	 * @param cpid
	 * @param spid
	 * @param invokeface 接口名称
	 * @return
	 */
	//@Cacheable(value = "unvideo_ChannelSpidLimitConf",keyGenerator = "wiselyKeyGenerator")
	public List<HashMap<String, String>> qryChannelSpidLimitConf(@Param("channel")String channel,@Param("cpid")String cpid,@Param("spid")String spid,@Param("invokeface")String invokeface);
	
	/**
	 * 获取渠道业务限制表的配置信息
	 * @param channel
	 * @param unifychannel 主渠道+子渠道
	 * @param cpid
	 * @param spid
	 * @param invokeface 接口名称	 
	 * @return
	 */
	//@Cacheable(value = "unvideo_UnifychannelSpidLimitConf",keyGenerator = "wiselyKeyGenerator")
	public List<HashMap<String, String>> qryUnifychannelSpidLimitConf(@Param("channel")String channel,@Param("unifychannel")String unifychannel,@Param("cpid")String cpid,@Param("spid")String spid,@Param("invokeface")String invokeface);
	
	/**
	 * 根据手机号码获取有效的订购关系，未退订，或者已退订但结束时间大于当前时间
	 * @param userid
	 * @return
	 */
	public List<HashMap> qryEffectiveRela(@Param("userid")String userid);
	
	/**
	 * 接口省份限制表
	 * @param province
	 * @param channel
	 * @param invokeface
	 * @param type
	 * @return
	 */
	@Cacheable(value = "unvideo_ProvInvokeLimit",keyGenerator = "wiselyKeyGenerator")
	public List<HashMap> qryProvInvokeLimit(@Param("province")String province,  @Param("channel")String channel, @Param("invokeface")String invokeface, @Param("type")String type);
}