package cn.hnthyy.thmz.mapper.thmz;

import cn.hnthyy.thmz.entity.thmz.Holidays;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;

public interface HolidaysMapper {

    @Insert("insert into t_holidays(begin_date,begin_ampm,end_date,end_ampm,create_id,create_date) values(#{beginDate},#{beginAmpm},#{endDate},#{endAmpm},#{createId,jdbcType=BIGINT},#{createDate,jdbcType=TIMESTAMP})")
    int insertHolidays(Holidays holidays);

    /**
     * 删除假期设置
     *
     * @param id
     * @return
     */
    @Delete("delete from t_holidays where id=#{id,jdbcType=BIGINT}")
    int deleteHolidays(@Param("id") Long id);


    /**
     * 分页查询假期
     *
     * @param holidays
     * @return
     */
    @Select({"<script>" +
            "select a.* " +
            " from t_holidays a join  (" +
            "select id from t_holidays where 1=1" +
            " order by id desc limit #{offset},#{pageSize} )b on a.id=b.id"
            + "</script>"})
    List<Holidays> selectHolidaysWithPage(Holidays holidays);

    /**
     * 查询节假日总数
     *
     * @param holidays
     * @return
     */
    @Select({"<script>" +
            "select count(id) from t_holidays where 1=1"
            + "</script>"})
    Integer selectCountHolidays(Holidays holidays);

    /**
     * 按照id查询
     *
     * @param id
     * @return
     */
    @Select("select * from t_holidays where id=#{id,jdbcType=BIGINT}")
    Holidays selectById(@Param("id") Long id);

    /**
     * 查询大于等于当前给定时间以后的节假日设置
     * @param beginDate
     * @return
     */
    @Select("select * from t_holidays where #{beginDate}>=begin_date and  #{beginDate}<=end_date")
    List<Holidays> selectHolidaysByDate(@Param("beginDate") Date beginDate);


}
