apps流水逻辑
This commit is contained in:
1 parent
0ff174e872
commit
15cc537639
10 files changed
+256
-232
No files matched your search
@@ -62,7 +62,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="operatorId != null "> and operator_id = #{operatorId}</if>
|
||||
<if test="requestId != null and requestId != ''"> and request_id = #{requestId}</if>
|
||||
<if test="createdAt != null "> and created_at = #{createdAt}</if>
|
||||
<if test="params.beginTime != null and params.beginTime != ''">and created_at >= #{params.beginTime}</if>
|
||||
<if test="params.endTime != null and params.endTime != ''">and created_at <= #{params.endTime}</if>
|
||||
</where>
|
||||
order by created_at desc, id desc
|
||||
</select>
|
||||
|
||||
<select id="selectAppsBalanceLedgerById" parameterType="Long" resultMap="AppsBalanceLedgerResult">
|
||||
@@ -126,6 +129,60 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<insert id="insertSystemLedgerIgnoreDuplicate" parameterType="AppsBalanceLedger">
|
||||
insert into apps_balance_ledger
|
||||
(trade_no, idempotency_key, app_id, user_id, currency, balance_type,
|
||||
business_type, direction, amount, balance_before, balance_after,
|
||||
available_before, available_after, frozen_before, frozen_after,
|
||||
order_id, merchant_order_id, transaction_id, remark, created_at)
|
||||
values
|
||||
(#{tradeNo}, #{idempotencyKey}, #{appId}, #{userId}, #{currency}, #{balanceType},
|
||||
#{businessType}, #{direction}, #{amount}, #{balanceBefore}, #{balanceAfter},
|
||||
#{availableBefore}, #{availableAfter}, #{frozenBefore}, #{frozenAfter},
|
||||
#{orderId}, #{merchantOrderId}, #{transactionId}, #{remark}, #{createdAt})
|
||||
on duplicate key update id = id
|
||||
</insert>
|
||||
|
||||
<sql id="statisticsConditions">
|
||||
1 = 1
|
||||
<if test="appId != null">and app_id = #{appId}</if>
|
||||
<if test="userId != null">and user_id = #{userId}</if>
|
||||
<if test="currency != null and currency != ''">and currency = #{currency}</if>
|
||||
<if test="businessType != null and businessType != ''">and business_type = #{businessType}</if>
|
||||
<if test="beginTime != null">and created_at >= #{beginTime}</if>
|
||||
<if test="endTime != null">and created_at <= #{endTime}</if>
|
||||
</sql>
|
||||
|
||||
<select id="selectStatisticsSummary" resultType="com.ruoyi.system.domain.vo.WalletLedgerSummaryVo">
|
||||
select currency,
|
||||
coalesce(sum(case when direction = 1 then amount else 0 end), 0) as incomeAmount,
|
||||
coalesce(sum(case when direction = 2 then amount else 0 end), 0) as expenseAmount,
|
||||
coalesce(sum(case when direction = 1 then amount else -amount end), 0) as netAmount,
|
||||
count(1) as count
|
||||
from apps_balance_ledger
|
||||
where <include refid="statisticsConditions"/>
|
||||
group by currency
|
||||
order by currency
|
||||
</select>
|
||||
|
||||
<select id="selectStatisticsTrend" resultType="com.ruoyi.system.domain.vo.WalletLedgerTrendVo">
|
||||
select
|
||||
<choose>
|
||||
<when test="granularity == 'YEAR'">date_format(created_at, '%Y')</when>
|
||||
<when test="granularity == 'MONTH'">date_format(created_at, '%Y-%m')</when>
|
||||
<otherwise>date_format(created_at, '%Y-%m-%d')</otherwise>
|
||||
</choose> as period,
|
||||
currency,
|
||||
coalesce(sum(case when direction = 1 then amount else 0 end), 0) as incomeAmount,
|
||||
coalesce(sum(case when direction = 2 then amount else 0 end), 0) as expenseAmount,
|
||||
coalesce(sum(case when direction = 1 then amount else -amount end), 0) as netAmount,
|
||||
count(1) as count
|
||||
from apps_balance_ledger
|
||||
where <include refid="statisticsConditions"/>
|
||||
group by period, currency
|
||||
order by period, currency
|
||||
</select>
|
||||
|
||||
<update id="updateAppsBalanceLedger" parameterType="AppsBalanceLedger">
|
||||
update apps_balance_ledger
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
@@ -167,4 +224,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
||||
</mapper>
|
||||
Reference in new issue
Block a user