<?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.amms.mapper.TouristMapper">

    <resultMap type="com.amms.domain.Tourist" id="TouristResult">
        <result property="id"    column="id"    />
        <result property="realName"    column="real_name"    />
        <result property="idCard"    column="id_card"    />
        <result property="phone"    column="phone"    />
        <result property="email"    column="email"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectTouristVo">
        select id, real_name, id_card, phone, email, update_time from tourist
    </sql>

    <select id="selectTouristList" parameterType="com.amms.domain.Tourist" resultMap="TouristResult">
        <include refid="selectTouristVo"/>
        <where>
            <if test="realName != null  and realName != ''"> and real_name like concat('%', #{realName}, '%')</if>
            <if test="idCard != null  and idCard != ''"> and id_card = #{idCard}</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="email != null  and email != ''"> and email = #{email}</if>
        </where>
    </select>

    <select id="selectTouristById" parameterType="Long" resultMap="TouristResult">
        <include refid="selectTouristVo"/>
        where id = #{id}
    </select>

    <insert id="insertTourist" parameterType="com.amms.domain.Tourist">
        insert into tourist
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="realName != null">real_name,</if>
            <if test="idCard != null">id_card,</if>
            <if test="phone != null">phone,</if>
            <if test="email != null">email,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="realName != null">#{realName},</if>
            <if test="idCard != null">#{idCard},</if>
            <if test="phone != null">#{phone},</if>
            <if test="email != null">#{email},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateTourist" parameterType="com.amms.domain.Tourist">
        update tourist
        <trim prefix="SET" suffixOverrides=",">
            <if test="realName != null">real_name = #{realName},</if>
            <if test="idCard != null">id_card = #{idCard},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="email != null">email = #{email},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTouristById" parameterType="Long">
        delete from tourist where id = #{id}
    </delete>
</mapper>
