<?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.ruoyi.system.mapper.PushMessageMapper">

    <resultMap type="PushMessage" id="PushMessageResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="title"    column="title"    />
        <result property="content"    column="content"    />
        <result property="body"    column="body"    />
        <result property="time"    column="time"    />
    </resultMap>

    <sql id="selectPushMessageVo">
        select id, user_id, title, content, body, time from push_message
    </sql>

    <select id="selectPushMessageList" parameterType="PushMessage" resultMap="PushMessageResult">
        <include refid="selectPushMessageVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="body != null  and body != ''"> and body = #{body}</if>
            <if test="time != null "> and time = #{time}</if>
        </where>
    </select>

    <select id="selectPushMessageById" parameterType="Long" resultMap="PushMessageResult">
        <include refid="selectPushMessageVo"/>
        where id = #{id}
    </select>

    <insert id="insertPushMessage" parameterType="PushMessage" useGeneratedKeys="true" keyProperty="id">
        insert into push_message
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="title != null">title,</if>
            <if test="content != null">content,</if>
            <if test="body != null">body,</if>
            <if test="time != null">time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="title != null">#{title},</if>
            <if test="content != null">#{content},</if>
            <if test="body != null">#{body},</if>
            <if test="time != null">#{time},</if>
        </trim>
    </insert>

    <update id="updatePushMessage" parameterType="PushMessage">
        update push_message
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="title != null">title = #{title},</if>
            <if test="content != null">content = #{content},</if>
            <if test="body != null">body = #{body},</if>
            <if test="time != null">time = #{time},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePushMessageById" parameterType="Long">
        delete from push_message where id = #{id}
    </delete>

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