<?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.srs.comprehensive.mapper.CphMsgMapper">
    
    <resultMap type="CphMsg" id="CphMsgResult">
        <result property="id"    column="id"    />
        <result property="sender"    column="sender"    />
        <result property="receiver"    column="receiver"    />
        <result property="content"    column="content"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectCphMsgVo">
        select id, sender, receiver, content, create_by, create_time, update_by, update_time from cph_msg
    </sql>

    <select id="selectCphMsgList" parameterType="CphMsg" resultMap="CphMsgResult">
        <include refid="selectCphMsgVo"/>
        <where>  
            <if test="sender != null "> and sender = #{sender}</if>
            <if test="receiver != null "> and receiver = #{receiver}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
        </where>
        order by id desc
    </select>
    
    <select id="selectCphMsgById" parameterType="Long" resultMap="CphMsgResult">
        <include refid="selectCphMsgVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertCphMsg" parameterType="CphMsg" useGeneratedKeys="true" keyProperty="id">
        insert into cph_msg
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="sender != null">sender,</if>
            <if test="receiver != null">receiver,</if>
            <if test="content != null">content,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="sender != null">#{sender},</if>
            <if test="receiver != null">#{receiver},</if>
            <if test="content != null">#{content},</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>
         </trim>
    </insert>

    <update id="updateCphMsg" parameterType="CphMsg">
        update cph_msg
        <trim prefix="SET" suffixOverrides=",">
            <if test="sender != null">sender = #{sender},</if>
            <if test="receiver != null">receiver = #{receiver},</if>
            <if test="content != null">content = #{content},</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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCphMsgById" parameterType="Long">
        delete from cph_msg where id = #{id}
    </delete>

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