package com.fdkankan.platform.user.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fdkankan.platform.user.entity.UserIncrement;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 用户增值权益表 Mapper 接口
 * </p>
 *
 * @author 
 * @since 2021-12-24
 */
@Mapper
public interface IUserIncrementMapper extends BaseMapper<UserIncrement> {

    @Select("SELECT * FROM t_user_increment x LEFT JOIN t_camera c ON x.camera_id = c.id and c.tb_status = 0 WHERE c.child_name = #{childName} AND x.tb_status = 0 ")
    List<UserIncrement> getByChildName(@Param("childName")String childName);

    @Select("SELECT * FROM `t_user_increment` WHERE DATEDIFF(increment_end_time,NOW()) <= -1 AND is_expired = 0 AND tb_status = 0 ")
    List<UserIncrement> findExpireData();

    @Select("SELECT * FROM `t_user_increment` WHERE DATEDIFF(increment_end_time,NOW()) = #{date} AND is_expired = #{isExpired} AND tb_status = 0 ")
    List<UserIncrement> findReadyExpire(@Param("date")Integer date, @Param("isExpired")Integer isExpired);
}
