<?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.NotificationsMapper">
    
    <resultMap type="Notifications" id="NotificationsResult">
        <result property="id"    column="id"    />
        <result property="title"    column="title"    />
        <result property="content"    column="content"    />
        <result property="notificationType"    column="notification_type"    />
        <result property="extraData"    column="extra_data"    />
        <result property="creator"    column="creator"    />
        <result property="createTime"    column="create_time"    />
        <result property="updatedTime"    column="updated_time"    />
        <result property="sendTime"    column="send_time"    />
    </resultMap>

    <sql id="selectNotificationsVo">
        select id, title, content, notification_type, extra_data, creator, create_time, updated_time, send_time from notifications
    </sql>

    <select id="selectNotificationsList" parameterType="Notifications" resultMap="NotificationsResult">
        <include refid="selectNotificationsVo"/>
        <where>  
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="notificationType != null  and notificationType != ''"> and notification_type = #{notificationType}</if>
            <if test="extraData != null  and extraData != ''"> and extra_data = #{extraData}</if>
            <if test="creator != null  and creator != ''"> and creator = #{creator}</if>
            <if test="updatedTime != null "> and updated_time = #{updatedTime}</if>
            <if test="sendTime != null "> and send_time = #{sendTime}</if>
        </where>
    </select>
    
    <select id="selectNotificationsById" parameterType="Long" resultMap="NotificationsResult">
        <include refid="selectNotificationsVo"/>
        where id = #{id}
    </select>

    <insert id="insertNotifications" parameterType="Notifications" useGeneratedKeys="true" keyProperty="id">
        insert into notifications
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="title != null and title != ''">title,</if>
            <if test="content != null and content != ''">content,</if>
            <if test="notificationType != null">notification_type,</if>
            <if test="extraData != null">extra_data,</if>
            <if test="creator != null">creator,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updatedTime != null">updated_time,</if>
            <if test="sendTime != null">send_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="title != null and title != ''">#{title},</if>
            <if test="content != null and content != ''">#{content},</if>
            <if test="notificationType != null">#{notificationType},</if>
            <if test="extraData != null">#{extraData},</if>
            <if test="creator != null">#{creator},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updatedTime != null">#{updatedTime},</if>
            <if test="sendTime != null">#{sendTime},</if>
         </trim>
    </insert>

    <update id="updateNotifications" parameterType="Notifications">
        update notifications
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null and title != ''">title = #{title},</if>
            <if test="content != null and content != ''">content = #{content},</if>
            <if test="notificationType != null">notification_type = #{notificationType},</if>
            <if test="extraData != null">extra_data = #{extraData},</if>
            <if test="creator != null">creator = #{creator},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updatedTime != null">updated_time = #{updatedTime},</if>
            <if test="sendTime != null">send_time = #{sendTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteNotificationsById" parameterType="Long">
        delete from notifications where id = #{id}
    </delete>

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