<?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.VisitorPersonMapper">

    <resultMap type="com.ics.admin.domain.meeting.VisitorPerson" id="ReservationPersonResult">
        <result property="id" column="id"/>
        <result property="userId" column="user_id"/>
        <result property="intervieweeId" column="interviewee_id"/>
        <result property="name" column="name"/>
        <result property="userName" column="user_name"/>
        <result property="userMobile" column="user_mobile"/>
        <result property="phone" column="phone"/>
        <result property="joinTime" column="join_time"/>
        <result property="visitTime" column="visit_time"/>
        <result property="customerId" column="customer_id"/>
        <result property="rejectContent" column="reject_content"/>
        <result property="leaveTime" column="leave_time"/>
        <result property="visitContent" column="visit_content"/>
        <result property="reviewers" column="reviewers"/>
        <result property="reviewersTime" column="reviewers_time"/>
        <result property="cardType" column="card_type"/>
        <result property="cardNo" column="card_no"/>
        <result property="status" column="status"/>
        <result property="photo" column="photo"/>
    </resultMap>

    <sql id="selectReservationPersonVo">
        SELECT id, user_id, interviewee_id, name, phone,reject_content,user_name,user_mobile, join_time,reviewers,reviewers_time, visit_time,photo,customer_id, leave_time, visit_content, card_type, card_no, status FROM tb_visitor_person
    </sql>

    <select id="selectReservationPersonList" parameterType="VisitorPerson" resultMap="ReservationPersonResult">
        <include refid="selectReservationPersonVo"/>
        <where>
            <if test="name != null  and name != ''"> AND name LIKE CONCAT('%', #{name}, '%')</if>
        </where>
    </select>

    <select id="selectReservationPersonById" parameterType="Long" resultMap="ReservationPersonResult">
        <include refid="selectReservationPersonVo"/>
        WHERE id = #{id}
    </select>

    <insert id="insertReservationPerson" parameterType="VisitorPerson">
        INSERT INTO tb_visitor_person
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null ">id,</if>
            <if test="userId != null ">user_id,</if>
            <if test="intervieweeId != null ">interviewee_id,</if>
            <if test="name != null  and name != ''">name,</if>
            <if test="phone != null ">phone,</if>
            <if test="joinTime != null ">join_time,</if>
            <if test="visitTime != null ">visit_time,</if>
            <if test="userName != null ">user_name,</if>
            <if test="userMobile != null ">user_mobile,</if>
            <if test="customerId != null ">customer_id,</if>
            <if test="reviewers != null ">reviewers,</if>
            <if test="reviewersTime != null ">reviewers_time,</if>
            <if test="leaveTime != null ">leave_time,</if>
            <if test="rejectContent != null ">reject_content,</if>
            <if test="visitContent != null  and visitContent != ''">visit_content,</if>
            <if test="cardType != null  and cardType != ''">card_type,</if>
            <if test="cardNo != null  and cardNo != ''">card_no,</if>
            <if test="status != null ">status,</if>
            <if test="photo != null ">photo,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null ">#{id},</if>
            <if test="userId != null ">#{userId},</if>
            <if test="intervieweeId != null ">#{intervieweeId},</if>
            <if test="name != null  and name != ''">#{name},</if>
            <if test="phone != null ">#{phone},</if>
            <if test="userName != null ">#{userName},</if>
            <if test="userMobile != null ">#{userMobile},</if>
            <if test="joinTime != null ">#{joinTime},</if>
            <if test="reviewers != null ">#{reviewers},</if>
            <if test="reviewersTime != null ">#{reviewersTime},</if>
            <if test="visitTime != null ">#{visitTime},</if>
            <if test="customerId != null ">#{customerId},</if>
            <if test="rejectContent != null ">#{rejectContent},</if>
            <if test="leaveTime != null ">#{leaveTime},</if>
            <if test="visitContent != null  and visitContent != ''">#{visitContent},</if>
            <if test="cardType != null  and cardType != ''">#{cardType},</if>
            <if test="cardNo != null  and cardNo != ''">#{cardNo},</if>
            <if test="status != null ">#{status},</if>
            <if test="photo != null ">#{photo},</if>
        </trim>
    </insert>

    <update id="updateReservationPerson" parameterType="VisitorPerson">
        UPDATE tb_visitor_person
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null ">user_id = #{userId},</if>
            <if test="intervieweeId != null ">interviewee_id = #{intervieweeId},</if>
            <if test="name != null  and name != ''">name = #{name},</if>
            <if test="phone != null ">phone = #{phone},</if>
            <if test="joinTime != null ">join_time = #{joinTime},</if>
            <if test="visitTime != null ">visit_time = #{visitTime},</if>
            <if test="userName != null ">user_name = #{userName},</if>
            <if test="userMobile != null ">user_mobile = #{userMobile},</if>
            <if test="customerId != null ">customer_id = #{customerId},</if>
            <if test="reviewersTime != null ">reviewers_time = #{reviewersTime},</if>
            <if test="reviewers != null ">reviewers = #{reviewers},</if>
            <if test="rejectContent != null ">reject_content = #{rejectContent},</if>
            <if test="leaveTime != null ">leave_time = #{leaveTime},</if>
            <if test="visitContent != null  and visitContent != ''">visit_content = #{visitContent},</if>
            <if test="cardType != null  and cardType != ''">card_type = #{cardType},</if>
            <if test="cardNo != null  and cardNo != ''">card_no = #{cardNo},</if>
            <if test="status != null ">status = #{status},</if>
            <if test="photo != null ">photo = #{photo},</if>
        </trim>
        WHERE id = #{id}
    </update>

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

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

</mapper>