<?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.NotificationRecordsMapper">
    
    <resultMap type="NotificationRecords" id="NotificationRecordsResult">
        <result property="id"    column="id"    />
        <result property="notificationId"    column="notification_id"    />
        <result property="userId"    column="user_id"    />
        <result property="channel"    column="channel"    />
        <result property="status"    column="status"    />
        <result property="sentTime"    column="sent_time"    />
        <result property="readTime"    column="read_time"    />
        <result property="failureReason"    column="failure_reason"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectNotificationRecordsVo">
        select id, notification_id, user_id, channel, status, sent_time, read_time, failure_reason, create_time, update_time from notification_records
    </sql>

    <select id="selectNotificationRecordsList" parameterType="NotificationRecords" resultMap="NotificationRecordsResult">
        <include refid="selectNotificationRecordsVo"/>
        <where>  
            <if test="notificationId != null "> and notification_id = #{notificationId}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="channel != null  and channel != ''"> and channel = #{channel}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="sentTime != null "> and sent_time = #{sentTime}</if>
            <if test="readTime != null "> and read_time = #{readTime}</if>
            <if test="failureReason != null  and failureReason != ''"> and failure_reason = #{failureReason}</if>
        </where>
    </select>
    
    <select id="selectNotificationRecordsById" parameterType="Long" resultMap="NotificationRecordsResult">
        <include refid="selectNotificationRecordsVo"/>
        where id = #{id}
    </select>

    <insert id="insertNotificationRecords" parameterType="NotificationRecords" useGeneratedKeys="true" keyProperty="id">
        insert into notification_records
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="notificationId != null">notification_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="channel != null">channel,</if>
            <if test="status != null">status,</if>
            <if test="sentTime != null">sent_time,</if>
            <if test="readTime != null">read_time,</if>
            <if test="failureReason != null">failure_reason,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="notificationId != null">#{notificationId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="channel != null">#{channel},</if>
            <if test="status != null">#{status},</if>
            <if test="sentTime != null">#{sentTime},</if>
            <if test="readTime != null">#{readTime},</if>
            <if test="failureReason != null">#{failureReason},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateNotificationRecords" parameterType="NotificationRecords">
        update notification_records
        <trim prefix="SET" suffixOverrides=",">
            <if test="notificationId != null">notification_id = #{notificationId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="channel != null">channel = #{channel},</if>
            <if test="status != null">status = #{status},</if>
            <if test="sentTime != null">sent_time = #{sentTime},</if>
            <if test="readTime != null">read_time = #{readTime},</if>
            <if test="failureReason != null">failure_reason = #{failureReason},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteNotificationRecordsById" parameterType="Long">
        delete from notification_records where id = #{id}
    </delete>

    <delete id="deleteNotificationRecordsByIds" parameterType="String">
        delete from notification_records where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    
    <insert id="batchInsertNotificationRecords" parameterType="java.util.List">
        insert into notification_records
        (notification_id, user_id, channel, status, sent_time, read_time, failure_reason, create_time, update_time)
        values
        <foreach collection="list" item="item" separator=",">
            (
            #{item.notificationId},
            #{item.userId},
            #{item.channel},
            #{item.status},
            #{item.sentTime},
            #{item.readTime},
            #{item.failureReason},
            #{item.createTime},
            #{item.updateTime}
            )
        </foreach>
    </insert>

    <update id="updateStatusNotificationRecords">

    </update>
</mapper>