ab
2024-11-04 09d882262f530ded672f1c01fb65a1fefa00d52d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?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.nova.sankuai.infra.mapper.SysAlipayAccountUsageMapper">
    <insert id="insertWithSelect">
        insert into sys_alipay_account_usage
            (id, app_id, order_id, create_date, single_amount, status, create_datetime)
        select #{id}, app_id, #{orderId}, #{createDate}, #{singleAmount}, #{status}, #{createDatetime}
        from (
                 select a.app_id, a.single_day_limit, ifnull(b.total, 0) amount, a.seq
                 from sys_alipay_account a
                          left join (
                     select a.app_id, sum(a.single_amount) total
                     from sys_alipay_account_usage a
                     where a.create_date = #{createDate}
                       and (
                           a.status = 'ok' or (
                               a.status = 'init'
                                   and
                               timestampdiff(SECOND, a.create_datetime, now()) &lt; 1800
                           )
                       )
                     group by a.app_id
                 ) b on a.app_id = b.app_id
             ) t
        where t.amount + #{singleAmount} &lt;= t.single_day_limit order by t.seq limit 1
    </insert>
    <update id="updateStatus">
        update sys_alipay_account_usage set status = 'ok' where order_id = #{orderId}
    </update>
    <select id="selectSumAmountInDay" resultType="java.math.BigDecimal">
        select ifnull(sum(a.single_amount), 0)
          from sys_alipay_account_usage a
         where a.create_date = #{date}
           and (a.status = 'ok' or (a.status = 'init' and timestampdiff(SECOND, a.create_datetime, now()) &lt; 1800))
    </select>
</mapper>