<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bonus.canteen.core.allocation.holiday.mapper.MktHolidayMapper">

    <resultMap id="BaseResultMap" type="com.bonus.canteen.core.allocation.holiday.model.MktHoliday">
        <id property="id" column="id" jdbcType="BIGINT"/>
        <result property="holId" column="hol_id" jdbcType="BIGINT"/>
        <result property="holYear" column="hol_year" jdbcType="INTEGER"/>
        <result property="holName" column="hol_name" jdbcType="VARCHAR"/>
        <result property="holDate" column="hol_date" jdbcType="TIMESTAMP"/>
        <result property="holType" column="hol_type" jdbcType="INTEGER"/>
        <result property="ifDel" column="if_del" jdbcType="INTEGER"/>
        <result property="crby" column="crby" jdbcType="VARCHAR"/>
        <result property="crtime" column="crtime" jdbcType="TIMESTAMP"/>
        <result property="upby" column="upby" jdbcType="VARCHAR"/>
        <result property="uptime" column="uptime" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,hol_id,
        hol_year,hol_name,hol_date,
        hol_type,if_del,crby,
        crtime,upby,uptime
    </sql>

    <select id="selectAllList" resultType="com.bonus.canteen.core.allocation.holiday.vo.MktHolidayPageVO">
        SELECT *
        FROM
        mkt_holiday mth
        <where>
            mth.if_del = #{holidayDTO.ifDel}
            <if test="holidayDTO.holYear != null">
                AND mth.hol_year = #{holidayDTO.holYear}
            </if>
            <if test="holidayDTO.holName != null and holidayDTO.holName != ''">
                AND mth.hol_name LIKE #{holidayDTO.holName}
            </if>
            <if test="holidayDTO.holType != null">
                AND mth.hol_type = #{holidayDTO.holType}
            </if>
        </where>
        ORDER BY mth.hol_year DESC,mth.hol_date ASC
    </select>
    <!--    根据年份获取所有节假日-->
    <select id="selectAllDate" resultType="java.util.Date">
        SELECT hol_date
        FROM mkt_holiday
        WHERE hol_year = #{holYear}
          and if_del = 2
    </select>

    <select id="selectAllDateBySpecifyDay" resultType="com.bonus.canteen.core.allocation.holiday.model.MktHoliday">
        SELECT
            *
        FROM
            mkt_holiday
        WHERE
            hol_year = #{holYear}
          AND hol_date <![CDATA[ >= ]]> #{specifyDay}
          AND if_del = 2
    </select>

    <delete id="customBatchRemove" >
        DELETE
        FROM
            mkt_holiday
        WHERE
            hol_year = #{holYear}
          AND hol_type = #{holidayType}
          AND hol_date <![CDATA[ >= ]]> #{specifyDay}
    </delete>

</mapper>
