package com.fs.store.mapper;

import java.util.List;
import com.fs.store.domain.FsUserSign;
import com.fs.store.param.FsUserSignQueryParam;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 签到记录Mapper接口
 * 
 * @author fs
 * @date 2022-03-15
 */
public interface FsUserSignMapper 
{
    /**
     * 查询签到记录
     * 
     * @param int 签到记录ID
     * @return 签到记录
     */
    public FsUserSign selectFsUserSignById(Long id);

    /**
     * 查询签到记录列表
     * 
     * @param fsUserSign 签到记录
     * @return 签到记录集合
     */
    public List<FsUserSign> selectFsUserSignList(FsUserSign fsUserSign);

    /**
     * 新增签到记录
     * 
     * @param fsUserSign 签到记录
     * @return 结果
     */
    public int insertFsUserSign(FsUserSign fsUserSign);

    /**
     * 修改签到记录
     * 
     * @param fsUserSign 签到记录
     * @return 结果
     */
    public int updateFsUserSign(FsUserSign fsUserSign);

    /**
     * 删除签到记录
     * 
     * @param int 签到记录ID
     * @return 结果
     */
    public int deleteFsUserSignById(Long id);

    /**
     * 批量删除签到记录
     * 
     * @param ints 需要删除的数据ID
     * @return 结果
     */
    public int deleteFsUserSignByIds(Long[] ids);
    @Select("select ifnull(count(1),0) from fs_user_sign where user_id=#{userId} and DATE_FORMAT(create_time, '%Y-%m-%d')  = DATE_FORMAT(NOW(), '%Y-%m-%d') ")
    int getToDayIsSign(Long userId);
    @Select("select ifnull(count(1),0) from fs_user_sign where user_id=#{userId} and DATE_FORMAT(create_time, '%Y-%m-%d')  = DATE_FORMAT( DATE_SUB(CURDATE(), INTERVAL 1 DAY), '%Y-%m-%d')  ")
    int getYesterDayIsSign(Long userId);
    @Select({"<script> " +
            "select *  from fs_user_sign   " +
            "where is_del=0 " +
            "<if test = 'maps.userId != null    '> " +
            "and user_id =#{maps.userId} " +
            "</if>" +
            " order by id desc "+
            "</script>"})
    List<FsUserSign> selectFsUserSignListQuery(@Param("maps")FsUserSignQueryParam param);
}
