<?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.ics.admin.mapper.meeting.ReservationPersonMapper">
    
    <resultMap type="com.ics.admin.domain.meeting.ReservationPerson" id="ReservationPersonResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="participantId"    column="participant_id"    />
        <result property="status"    column="status"    />
        <result property="joinTime"    column="join_time"    />
        <result property="reservationId"    column="reservation_id"    />
        <result property="participantName"    column="participant_name"    />
        <result property="participantPhone"    column="participant_phone"    />
    </resultMap>

    <sql id="selectReservationPersonVo">
        SELECT id, user_id, participant_id, status, join_time, reservation_id, participant_name, participant_phone FROM tb_reservation_person
    </sql>

    <select id="selectReservationPersonList" parameterType="ReservationPerson" resultMap="ReservationPersonResult">
        <include refid="selectReservationPersonVo"/>
        <where>  
            <if test="participantName != null  and participantName != ''"> AND participant_name LIKE CONCAT('%', #{participantName}, '%')</if>
        </where>
    </select>
    
    <select id="selectReservationPersonById" parameterType="Long" resultMap="ReservationPersonResult">
        <include refid="selectReservationPersonVo"/>
        WHERE id = #{id}
    </select>
        
    <insert id="insertReservationPerson" parameterType="ReservationPerson">
        INSERT INTO tb_reservation_person
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null ">id,</if>
            <if test="userId != null ">user_id,</if>
            <if test="participantId != null ">participant_id,</if>
            <if test="status != null  and status != ''">status,</if>
            <if test="joinTime != null ">join_time,</if>
            <if test="reservationId != null ">reservation_id,</if>
            <if test="participantName != null  and participantName != ''">participant_name,</if>
            <if test="participantPhone != null  and participantPhone != ''">participant_phone,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null ">#{id},</if>
            <if test="userId != null ">#{userId},</if>
            <if test="participantId != null ">#{participantId},</if>
            <if test="status != null  and status != ''">#{status},</if>
            <if test="joinTime != null ">#{joinTime},</if>
            <if test="reservationId != null ">#{reservationId},</if>
            <if test="participantName != null  and participantName != ''">#{participantName},</if>
            <if test="participantPhone != null  and participantPhone != ''">#{participantPhone},</if>
         </trim>
    </insert>

    <update id="updateReservationPerson" parameterType="ReservationPerson">
        UPDATE tb_reservation_person
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null ">user_id = #{userId},</if>
            <if test="participantId != null ">participant_id = #{participantId},</if>
            <if test="status != null  and status != ''">status = #{status},</if>
            <if test="joinTime != null ">join_time = #{joinTime},</if>
            <if test="reservationId != null ">reservation_id = #{reservationId},</if>
            <if test="participantName != null  and participantName != ''">participant_name = #{participantName},</if>
            <if test="participantPhone != null  and participantPhone != ''">participant_phone = #{participantPhone},</if>
        </trim>
        WHERE id = #{id}
    </update>

    <delete id="deleteReservationPersonById" parameterType="Long">
        DELETE FROM tb_reservation_person WHERE id = #{id}
    </delete>

    <delete id="deleteReservationPersonByIds" parameterType="String">
        DELETE FROM tb_reservation_person where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    
</mapper>