<?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.njcn.msgpush.module.push.dal.mysql.retry.MessageRetryQueueMapper">

    <select id="selectNeedRetryMessages" resultType="com.njcn.msgpush.module.push.dal.dataobject.retry.MessageRetryQueueDO">
        SELECT *
        FROM message_retry_queue
        WHERE next_retry_time  <![CDATA[ <= ]]>  #{currentTime} and deleted != 0
        ORDER BY next_retry_time ASC
            LIMIT #{limit}
    </select>

    <update id="updateRetryInfo">
        UPDATE message_retry_queue
        SET retry_count     = #{retryCount},
            next_retry_time = #{nextRetryTime},
            last_retry_time = #{lastRetryTime},
            last_error_msg  = #{lastErrorMsg},
            update_time     = NOW()
        WHERE message_id = #{messageId}  and deleted != 0
    </update>

    <delete id="deleteByMessageId">
        DELETE
        FROM message_retry_queue
        WHERE message_id = #{messageId}
    </delete>

    <delete id="deleteByMessageIds">
        DELETE FROM message_retry_queue
        WHERE message_id IN
        <foreach collection="messageIds" item="messageId" open="(" separator="," close=")">
            #{messageId}
        </foreach>
    </delete>

</mapper>
