<?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.limap.core.basic.mapper.AquPayOrderMapper">
    <update id="updatePayDeviceStatus">
        update aqu_pay_device set profit_status = 1
        where id in
        <foreach collection="list" item="item" open="(" separator="," close=")">
            #{item.id}
        </foreach>
    </update>
    <update id="dealRechargeWarnCode">
        update aqu_device set warn_code = 0 where serial_num in(
            SELECT DISTINCT apd.serial_num FROM aqu_pay_order apo
            INNER JOIN aqu_pay_device apd on apo.id = apd.order_id
            where apo.order_status = 2 
              and apo.success_time &gt;= now() - interval '2 minute'
              and apd.serial_num is not null)
    </update>


    <select id="selectInfoByHour" resultType="com.limap.core.basic.domain.AquPayDevice">
        select id, user_id, pay_amount, pay_type, create_time as "createdTime",
               device_type, serial_num, order_id, profit_status
        from aqu_pay_device
        where create_time &gt;= now() - interval '${hour} hour'
        AND create_time &lt;= now() - interval '1 hour'
        AND (profit_status IS NULL OR profit_status = 0)
        AND pay_type = 1
    </select>

    <!-- 补录用: 查询指定时间范围内所有订单(忽略profit_status) -->
    <select id="selectInfoForBackfill" resultType="com.limap.core.basic.domain.AquPayDevice">
        select id, user_id, pay_amount, pay_type, create_time as "createdTime",
               device_type, serial_num, order_id, profit_status
        from aqu_pay_device
        where create_time &gt;= now() - interval '${hour} hour'
        AND create_time &lt;= now() - interval '1 hour'
        AND pay_type = 1
    </select>
</mapper>
