<?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.huashe.common.data.mapper.AdmHolidayMapper">
    <resultMap id="BaseResultMap" type="com.huashe.common.domain.model.Holiday">
        <result column="date" property="date" jdbcType="DATE"/>
        <result column="name" property="name" jdbcType="VARCHAR"/>
        <result column="name_cn" property="nameCn" jdbcType="VARCHAR"/>
        <result column="name_en" property="nameEn" jdbcType="VARCHAR"/>
        <result column="type" property="type" jdbcType="VARCHAR"/>
    </resultMap>

    <insert id="insertBatch" parameterType="com.huashe.common.domain.model.Holiday">
        INSERT INTO `adm_holiday`
        (`date`, `name`, `name_cn`, `name_en`, `type`)
        VALUES
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.date}, #{item.name}, #{item.nameCn}, #{item.nameEn}, #{item.type})
        </foreach>
    </insert>

    <select id="selectByDate" parameterType="java.lang.String" resultMap="BaseResultMap">
        SELECT `date`, `name`, `name_cn`, `name_en`, `type` from `adm_holiday` where `date` = #{date}
    </select>

    <select id="selectBetween" resultMap="BaseResultMap">
        select
            `date`, `name`, `name_cn`, `name_en`, `type` from `adm_holiday` where `date` &gt;= STR_TO_DATE(#{startDate},'%Y-%m-%d') and date &lt;= STR_TO_DATE(#{endDate},'%Y-%m-%d')
    </select>

    <delete id="deleteByYear" parameterType="java.lang.String">
        DELETE FROM `adm_holiday` WHERE DATE_FORMAT(`date`, '%Y') = #{year}
    </delete>

</mapper>
