Files
usdt/ruoyi-system/src/main/resources/mapper/system/AppsBalanceLedgerMapper.xml
T
2026-10-13 11:24:20 -04:00

228 lines
14 KiB
XML

<?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.AppsBalanceLedgerMapper">
<resultMap type="AppsBalanceLedger" id="AppsBalanceLedgerResult">
<result property="id" column="id" />
<result property="tradeNo" column="trade_no" />
<result property="idempotencyKey" column="idempotency_key" />
<result property="appId" column="app_id" />
<result property="userId" column="user_id" />
<result property="currency" column="currency" />
<result property="balanceType" column="balance_type" />
<result property="businessType" column="business_type" />
<result property="direction" column="direction" />
<result property="amount" column="amount" />
<result property="balanceBefore" column="balance_before" />
<result property="balanceAfter" column="balance_after" />
<result property="availableBefore" column="available_before" />
<result property="availableAfter" column="available_after" />
<result property="frozenBefore" column="frozen_before" />
<result property="frozenAfter" column="frozen_after" />
<result property="orderId" column="order_id" />
<result property="merchantOrderId" column="merchant_order_id" />
<result property="aggregationTaskId" column="aggregation_task_id" />
<result property="walletLedgerId" column="wallet_ledger_id" />
<result property="transactionId" column="transaction_id" />
<result property="operatorId" column="operator_id" />
<result property="requestId" column="request_id" />
<result property="remark" column="remark" />
<result property="createdAt" column="created_at" />
</resultMap>
<sql id="selectAppsBalanceLedgerVo">
select id, 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, aggregation_task_id, wallet_ledger_id, transaction_id, operator_id, request_id, remark, created_at from apps_balance_ledger
</sql>
<select id="selectAppsBalanceLedgerList" parameterType="AppsBalanceLedger" resultMap="AppsBalanceLedgerResult">
<include refid="selectAppsBalanceLedgerVo"/>
<where>
<if test="tradeNo != null and tradeNo != ''"> and trade_no = #{tradeNo}</if>
<if test="idempotencyKey != null and idempotencyKey != ''"> and idempotency_key = #{idempotencyKey}</if>
<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="balanceType != null "> and balance_type = #{balanceType}</if>
<if test="businessType != null and businessType != ''"> and business_type = #{businessType}</if>
<if test="direction != null "> and direction = #{direction}</if>
<if test="amount != null "> and amount = #{amount}</if>
<if test="balanceBefore != null "> and balance_before = #{balanceBefore}</if>
<if test="balanceAfter != null "> and balance_after = #{balanceAfter}</if>
<if test="availableBefore != null "> and available_before = #{availableBefore}</if>
<if test="availableAfter != null "> and available_after = #{availableAfter}</if>
<if test="frozenBefore != null "> and frozen_before = #{frozenBefore}</if>
<if test="frozenAfter != null "> and frozen_after = #{frozenAfter}</if>
<if test="orderId != null "> and order_id = #{orderId}</if>
<if test="merchantOrderId != null and merchantOrderId != ''"> and merchant_order_id = #{merchantOrderId}</if>
<if test="aggregationTaskId != null "> and aggregation_task_id = #{aggregationTaskId}</if>
<if test="walletLedgerId != null "> and wallet_ledger_id = #{walletLedgerId}</if>
<if test="transactionId != null and transactionId != ''"> and transaction_id = #{transactionId}</if>
<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 &gt;= #{params.beginTime}</if>
<if test="params.endTime != null and params.endTime != ''">and created_at &lt;= #{params.endTime}</if>
</where>
order by created_at desc, id desc
</select>
<select id="selectAppsBalanceLedgerById" parameterType="Long" resultMap="AppsBalanceLedgerResult">
<include refid="selectAppsBalanceLedgerVo"/>
where id = #{id}
</select>
<insert id="insertAppsBalanceLedger" parameterType="AppsBalanceLedger" useGeneratedKeys="true" keyProperty="id">
insert into apps_balance_ledger
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="tradeNo != null and tradeNo != ''">trade_no,</if>
<if test="idempotencyKey != null and idempotencyKey != ''">idempotency_key,</if>
<if test="appId != null">app_id,</if>
<if test="userId != null">user_id,</if>
<if test="currency != null and currency != ''">currency,</if>
<if test="balanceType != null">balance_type,</if>
<if test="businessType != null and businessType != ''">business_type,</if>
<if test="direction != null">direction,</if>
<if test="amount != null">amount,</if>
<if test="balanceBefore != null">balance_before,</if>
<if test="balanceAfter != null">balance_after,</if>
<if test="availableBefore != null">available_before,</if>
<if test="availableAfter != null">available_after,</if>
<if test="frozenBefore != null">frozen_before,</if>
<if test="frozenAfter != null">frozen_after,</if>
<if test="orderId != null">order_id,</if>
<if test="merchantOrderId != null">merchant_order_id,</if>
<if test="aggregationTaskId != null">aggregation_task_id,</if>
<if test="walletLedgerId != null">wallet_ledger_id,</if>
<if test="transactionId != null">transaction_id,</if>
<if test="operatorId != null">operator_id,</if>
<if test="requestId != null">request_id,</if>
<if test="remark != null">remark,</if>
<if test="createdAt != null">created_at,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="tradeNo != null and tradeNo != ''">#{tradeNo},</if>
<if test="idempotencyKey != null and idempotencyKey != ''">#{idempotencyKey},</if>
<if test="appId != null">#{appId},</if>
<if test="userId != null">#{userId},</if>
<if test="currency != null and currency != ''">#{currency},</if>
<if test="balanceType != null">#{balanceType},</if>
<if test="businessType != null and businessType != ''">#{businessType},</if>
<if test="direction != null">#{direction},</if>
<if test="amount != null">#{amount},</if>
<if test="balanceBefore != null">#{balanceBefore},</if>
<if test="balanceAfter != null">#{balanceAfter},</if>
<if test="availableBefore != null">#{availableBefore},</if>
<if test="availableAfter != null">#{availableAfter},</if>
<if test="frozenBefore != null">#{frozenBefore},</if>
<if test="frozenAfter != null">#{frozenAfter},</if>
<if test="orderId != null">#{orderId},</if>
<if test="merchantOrderId != null">#{merchantOrderId},</if>
<if test="aggregationTaskId != null">#{aggregationTaskId},</if>
<if test="walletLedgerId != null">#{walletLedgerId},</if>
<if test="transactionId != null">#{transactionId},</if>
<if test="operatorId != null">#{operatorId},</if>
<if test="requestId != null">#{requestId},</if>
<if test="remark != null">#{remark},</if>
<if test="createdAt != null">#{createdAt},</if>
</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 &gt;= #{beginTime}</if>
<if test="endTime != null">and created_at &lt;= #{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=",">
<if test="tradeNo != null and tradeNo != ''">trade_no = #{tradeNo},</if>
<if test="idempotencyKey != null and idempotencyKey != ''">idempotency_key = #{idempotencyKey},</if>
<if test="appId != null">app_id = #{appId},</if>
<if test="userId != null">user_id = #{userId},</if>
<if test="currency != null and currency != ''">currency = #{currency},</if>
<if test="balanceType != null">balance_type = #{balanceType},</if>
<if test="businessType != null and businessType != ''">business_type = #{businessType},</if>
<if test="direction != null">direction = #{direction},</if>
<if test="amount != null">amount = #{amount},</if>
<if test="balanceBefore != null">balance_before = #{balanceBefore},</if>
<if test="balanceAfter != null">balance_after = #{balanceAfter},</if>
<if test="availableBefore != null">available_before = #{availableBefore},</if>
<if test="availableAfter != null">available_after = #{availableAfter},</if>
<if test="frozenBefore != null">frozen_before = #{frozenBefore},</if>
<if test="frozenAfter != null">frozen_after = #{frozenAfter},</if>
<if test="orderId != null">order_id = #{orderId},</if>
<if test="merchantOrderId != null">merchant_order_id = #{merchantOrderId},</if>
<if test="aggregationTaskId != null">aggregation_task_id = #{aggregationTaskId},</if>
<if test="walletLedgerId != null">wallet_ledger_id = #{walletLedgerId},</if>
<if test="transactionId != null">transaction_id = #{transactionId},</if>
<if test="operatorId != null">operator_id = #{operatorId},</if>
<if test="requestId != null">request_id = #{requestId},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="createdAt != null">created_at = #{createdAt},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteAppsBalanceLedgerById" parameterType="Long">
delete from apps_balance_ledger where id = #{id}
</delete>
<delete id="deleteAppsBalanceLedgerByIds" parameterType="String">
delete from apps_balance_ledger where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>