<?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.leromro.core.mapper.VolunteerWorkDateMapper">
    
    <resultMap type="VolunteerWorkDate" id="VolunteerWorkDateResult">
        <result property="volunteerWorkDateId"    column="volunteer_work_date_id"    />
        <result property="volunteerId"    column="volunteer_id"    />
        <result property="workDate"    column="work_date"    />
        <result property="workStartTime"    column="work_start_time"    />
        <result property="workEndTime"    column="work_end_time"    />
        <result property="hasReservation"    column="has_reservation"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectVolunteerWorkDateVo">
        select volunteer_work_date_id, volunteer_id, work_date, work_start_time, work_end_time, has_reservation, create_by, create_time, update_by, update_time, remark from l_volunteer_work_date
    </sql>

    <select id="selectVolunteerWorkDateList" parameterType="VolunteerWorkDate" resultMap="VolunteerWorkDateResult">
        <include refid="selectVolunteerWorkDateVo"/>
        <where>  
            <if test="volunteerId != null "> and volunteer_id = #{volunteerId}</if>
            <if test="workDate != null "> and work_date = #{workDate}</if>
            <if test="workStartTime != null "> and work_start_time = #{workStartTime}</if>
            <if test="workEndTime != null "> and work_end_time = #{workEndTime}</if>
            <if test="hasReservation != null "> and has_reservation = #{hasReservation}</if>
        </where>
    </select>
    
    <select id="selectVolunteerWorkDateByVolunteerWorkDateId" parameterType="Long" resultMap="VolunteerWorkDateResult">
        <include refid="selectVolunteerWorkDateVo"/>
        where volunteer_work_date_id = #{volunteerWorkDateId}
    </select>

    <insert id="insertVolunteerWorkDate" parameterType="VolunteerWorkDate" useGeneratedKeys="true" keyProperty="volunteerWorkDateId">
        insert into l_volunteer_work_date
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="volunteerId != null">volunteer_id,</if>
            <if test="workDate != null">work_date,</if>
            <if test="workStartTime != null">work_start_time,</if>
            <if test="workEndTime != null">work_end_time,</if>
            <if test="hasReservation != null">has_reservation,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="volunteerId != null">#{volunteerId},</if>
            <if test="workDate != null">#{workDate},</if>
            <if test="workStartTime != null">#{workStartTime},</if>
            <if test="workEndTime != null">#{workEndTime},</if>
            <if test="hasReservation != null">#{hasReservation},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateVolunteerWorkDate" parameterType="VolunteerWorkDate">
        update l_volunteer_work_date
        <trim prefix="SET" suffixOverrides=",">
            <if test="volunteerId != null">volunteer_id = #{volunteerId},</if>
            <if test="workDate != null">work_date = #{workDate},</if>
            <if test="workStartTime != null">work_start_time = #{workStartTime},</if>
            <if test="workEndTime != null">work_end_time = #{workEndTime},</if>
            <if test="hasReservation != null">has_reservation = #{hasReservation},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where volunteer_work_date_id = #{volunteerWorkDateId}
    </update>

    <delete id="deleteVolunteerWorkDateByVolunteerWorkDateId" parameterType="Long">
        delete from l_volunteer_work_date where volunteer_work_date_id = #{volunteerWorkDateId}
    </delete>

    <delete id="deleteVolunteerWorkDateByVolunteerWorkDateIds" parameterType="String">
        delete from l_volunteer_work_date where volunteer_work_date_id in 
        <foreach item="volunteerWorkDateId" collection="array" open="(" separator="," close=")">
            #{volunteerWorkDateId}
        </foreach>
    </delete>
</mapper>