<?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.agri.system.mapper.SysMessageMapper">
    
    <resultMap type="SysMessage" id="SysMessageResult">
        <result property="id"    column="id"    />
        <result property="receiver"    column="receiver"    />
        <result property="title"    column="title"    />
        <result property="msgType"    column="msg_type"    />
        <result property="readStatus"    column="read_status"    />
        <result property="content"    column="content"    />
        <result property="richContent"    column="rich_content"    />
        <result property="imgUrl"    column="img_url"    />
        <result property="linkUrl"    column="link_url"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectSysMessageVo">
        select id, receiver, title, msg_type, read_status, content, rich_content, img_url, link_url, create_by, create_time, update_by, update_time, remark from sys_message
    </sql>

    <select id="selectSysMessageList" parameterType="SysMessage" resultMap="SysMessageResult">
        <include refid="selectSysMessageVo"/>
        <where>  
            <if test="receiver != null  and receiver != ''"> and receiver = #{receiver}</if>
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="msgType != null  and msgType != ''"> and msg_type = #{msgType}</if>
            <if test="readStatus != null "> and read_status = #{readStatus}</if>
            <if test="content != null  and content != ''"> and content like concat('%', #{content}, '%')</if>
        </where>
    </select>
    
    <select id="selectSysMessageById" parameterType="Long" resultMap="SysMessageResult">
        <include refid="selectSysMessageVo"/>
        where id = #{id}
    </select>

    <insert id="insertSysMessage" parameterType="SysMessage" useGeneratedKeys="true" keyProperty="id">
        insert into sys_message
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="receiver != null and receiver != ''">receiver,</if>
            <if test="title != null and title != ''">title,</if>
            <if test="msgType != null and msgType != ''">msg_type,</if>
            <if test="readStatus != null">read_status,</if>
            <if test="content != null">content,</if>
            <if test="richContent != null">rich_content,</if>
            <if test="imgUrl != null">img_url,</if>
            <if test="linkUrl != null">link_url,</if>
    create_by,
    create_time,
    update_by,
    update_time,
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="receiver != null and receiver != ''">#{receiver},</if>
            <if test="title != null and title != ''">#{title},</if>
            <if test="msgType != null and msgType != ''">#{msgType},</if>
            <if test="readStatus != null">#{readStatus},</if>
            <if test="content != null">#{content},</if>
            <if test="richContent != null">#{richContent},</if>
            <if test="imgUrl != null">#{imgUrl},</if>
            <if test="linkUrl != null">#{linkUrl},</if>
        #{createBy},
        #{createTime},
        #{updateBy},
        #{updateTime},
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateSysMessage" parameterType="SysMessage">
        update sys_message
        <trim prefix="SET" suffixOverrides=",">
            <if test="receiver != null and receiver != ''">receiver = #{receiver},</if>
            <if test="title != null and title != ''">title = #{title},</if>
            <if test="msgType != null and msgType != ''">msg_type = #{msgType},</if>
            <if test="readStatus != null">read_status = #{readStatus},</if>
            <if test="content != null">content = #{content},</if>
            <if test="richContent != null">rich_content = #{richContent},</if>
            <if test="imgUrl != null">img_url = #{imgUrl},</if>
            <if test="linkUrl != null">link_url = #{linkUrl},</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>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysMessageById" parameterType="Long">
        delete from sys_message where id = #{id}
    </delete>

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