<?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.flossom.common.core.mapper.CtLeaveMessageMapper">

    <resultMap type="CtLeaveMessage" id="CtLeaveMessageResult">
        <result property="id"    column="id"    />
        <result property="source"    column="source"    />
        <result property="sourceName"    column="source_name"    />
        <result property="userImg"    column="user_img"    />
        <result property="userNumber"    column="user_number"    />
        <result property="userName"    column="user_name"    />
        <result property="userPhone"    column="user_phone"    />
        <result property="messageInfo"    column="message_info"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectCtLeaveMessageVo">
        select id, source, source_name, user_img,user_number, user_name, user_phone, message_info, create_time from ct_leave_message
    </sql>

    <select id="selectCtLeaveMessageList" parameterType="CtLeaveMessage" resultMap="CtLeaveMessageResult">
        <include refid="selectCtLeaveMessageVo"/>
        <where>
            <if test="source != null "> and source = #{source}</if>
            <if test="sourceName != null  and sourceName != ''"> and source_name like concat('%', #{sourceName}, '%')</if>
            <if test="userImg != null  and userImg != ''"> and user_img = #{userImg}</if>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="userNumber != null  and userNumber != ''"> and user_number like concat('%', #{userNumber}, '%')</if>
            <if test="userPhone != null  and userPhone != ''"> and user_phone = #{userPhone}</if>
            <if test="messageInfo != null  and messageInfo != ''"> and message_info = #{messageInfo}</if>
        </where>
    </select>

    <select id="selectCtLeaveMessageById" parameterType="Long" resultMap="CtLeaveMessageResult">
        <include refid="selectCtLeaveMessageVo"/>
        where id = #{id}
    </select>

    <insert id="insertCtLeaveMessage" parameterType="CtLeaveMessage" useGeneratedKeys="true" keyProperty="id">
        insert into ct_leave_message
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="source != null">source,</if>
            <if test="sourceName != null">source_name,</if>
            <if test="userImg != null">user_img,</if>
            <if test="userName != null">user_name,</if>
            <if test="userNumber != null">user_number,</if>
            <if test="userPhone != null">user_phone,</if>
            <if test="messageInfo != null">message_info,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="source != null">#{source},</if>
            <if test="sourceName != null">#{sourceName},</if>
            <if test="userImg != null">#{userImg},</if>
            <if test="userName != null">#{userName},</if>
            <if test="userNumber != null">#{userNumber},</if>
            <if test="userPhone != null">#{userPhone},</if>
            <if test="messageInfo != null">#{messageInfo},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateCtLeaveMessage" parameterType="CtLeaveMessage">
        update ct_leave_message
        <trim prefix="SET" suffixOverrides=",">
            <if test="source != null">source = #{source},</if>
            <if test="sourceName != null">source_name = #{sourceName},</if>
            <if test="userImg != null">user_img = #{userImg},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="userNumber != null">user_number = #{userNumber},</if>
            <if test="userPhone != null">user_phone = #{userPhone},</if>
            <if test="messageInfo != null">message_info = #{messageInfo},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCtLeaveMessageById" parameterType="Long">
        delete from ct_leave_message where id = #{id}
    </delete>

    <delete id="deleteCtLeaveMessageByIds" parameterType="String">
        delete from ct_leave_message where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <select id="selectCtLeaveMessageByCondition"  parameterType="CtLeaveMessage" resultMap="CtLeaveMessageResult">
        <include refid="selectCtLeaveMessageVo"/>
        where 1 = 1
        <if test="userNumberStr!=null and userNumberStr !=''">
            and
            <foreach collection="userNumberStr.split(',')" index="index" item="item" open="(" separator="OR"
                     close=")">
                user_number like concat('%', #{item}, '%')
            </foreach>
        </if>
        <if test="userPhone!=null and userPhone !=''">
            and
            <foreach collection="userPhone.split(',')" index="index" item="item" open="(" separator="OR"
                     close=")">
                user_phone like concat('%', #{item}, '%')
            </foreach>
        </if>
        <if test="params.beginTime != null and params.beginTime != ''">
            and create_time &gt;= #{params.beginTime}
         </if>
        <if test="params.endTime != null and params.endTime != ''">
            and create_time &lt;= #{params.endTime}
        </if>
    </select>
</mapper>
