Files
pj_service_cloud/pjcloud-wallet/pjcloud-wallet-biz/src/main/resources/mapper/WalletTransactionMapper.xml
T
2025-06-18 17:03:13 +08:00

180 lines
6.5 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.bsd.pjcloud.wallet.mapper.WalletTransactionMapper">
<resultMap id="walletTransactionMap" type="com.bsd.pjcloud.wallet.api.entity.WalletTransactionEntity">
<id property="id" column="id"/>
<result property="walletId" column="wallet_id"/>
<result property="bizType" column="biz_type"/>
<result property="bizId" column="biz_id"/>
<result property="title" column="title"/>
<result property="price" column="price"/>
<result property="balance" column="balance"/>
</resultMap>
<sql id="selectA">
select a.id,
a.wallet_id,
a.user_id,
a.dept_id,
a.biz_type,
a.biz_id,
a.title,
a.price,
a.balance,
a.create_by,
a.create_time,
a.update_by,
a.update_time,
a.del_flag,
a.tenant_id,
</sql>
<sql id="whereA">
a.del_flag = '0'
<if test="dto.walletId != null">
and a.wallet_id = #{dto.walletId}
</if>
<if test="dto.userId != null">
and a.user_id = #{dto.userId}
</if>
<if test="dto.bizId != null">
and a.biz_id = #{dto.bizId}
</if>
<if test="dto.bizType != null">
and a.biz_type = #{dto.bizType}
</if>
<if test="dto.type != null and dto.type == 1 ">
and a.price &gt; 0
</if>
<if test="dto.type != null and dto.type == 2 ">
and a.price &lt; 0
</if>
</sql>
<select id="scopeJzPageList" resultType="com.bsd.pjcloud.wallet.api.vo.transaction.WalletTransactionVo">
<include refid="selectA"/>
y.process_id as processId
from wallet_transaction a
inner join wallet_recharge_import i on i.id = a.biz_id and i.del_flag = '0'
inner join wallet_recharge_apply y on y.id = i.apply_id and y.del_flag = '0'
<where>
<include refid="whereA"/>
</where>
order by a.create_time desc , a.id desc
</select>
<select id="getTransactionPriceCount" resultType="java.lang.Integer">
select sum(a.price)
from wallet_transaction a
<where>
<if test="month != null and month != '' ">
and DATE_FORMAT(a.create_time, '%Y-%m') = #{month}
</if>
<if test="walletId != null">
and a.wallet_id = #{walletId}
</if>
<if test="bizType != null and bizType != '' ">
and a.biz_type = #{bizType}
</if>
</where>
</select>
<select id="selectCompare" resultType="com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargeApplySelectCompareVo">
SELECT w.user_id,
SUM(a.price) as price
FROM wallet_transaction a
INNER JOIN
wallet_manage w ON w.id = a.wallet_id
WHERE
a.del_flag = '0'
and a.biz_type = #{bizType}
and DATE_FORMAT(a.create_time, '%Y-%m') = #{dateTime}
and w.user_id in
<foreach collection="userIdList" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
GROUP BY w.user_id
</select>
<select id="sumAndCount" resultType="com.bsd.pjcloud.wallet.api.vo.WalletTransactionSumAndCountVo">
select
a.dept_id,
sum(a.price) as sum,
count(0) as count
from wallet_transaction a
<where>
a.del_flag = 0 and a.dept_id is not null
<if test="dto.walletId != null">
a.wallet_id = ${dto.walletId}
</if>
<if test="dto.walletTypeId != null">
</if>
<if test="dto.type != null">
<if test="dto.type == 1">
and a.price &gt; 0
</if>
<if test="dto.type == 2">
and a.price &lt; 0
</if>
</if>
<if test="dto.bizTypes != null and dto.bizTypes.size() != 0">
and a.biz_type in
<foreach collection="dto.bizTypes" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="dto.deptIds != null and dto.deptIds.size() != 0">
and a.dept_id in
<foreach collection="dto.deptIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="dto.createTimeList != null and dto.createTimeList.length == 2">
and a.create_time between #{dto.createTimeList[0]} and #{dto.createTimeList[1]}
</if>
</where>
group by a.dept_id
</select>
<select id="sumAndCountUser" resultType="com.bsd.pjcloud.wallet.api.vo.WalletTransactionSumAndCountVo">
select a.dept_id,
sum(a.price) as sum,
count(0) as count
from wallet_transaction a
left join wallet_manage m on a.wallet_id = m.id
left join wallet_type t on t.id = m.wallet_type_id
<where>
a.del_flag = 0 and a.dept_id is not null
<if test="dto.walletId != null">
and a.wallet_id = #{dto.walletId}
</if>
<if test="dto.walletTypeId != null">
and m.wallet_type_id = #{dto.walletTypeId}
</if>
<if test="dto.type != null">
<if test="dto.type == 1">
and a.price &gt; 0
</if>
<if test="dto.type == 2">
and a.price &lt; 0
</if>
</if>
<if test="dto.bizTypes != null and dto.bizTypes.size() != 0">
and a.biz_type in
<foreach collection="dto.bizTypes" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="dto.deptIds != null and dto.deptIds.size() != 0">
and a.dept_id in
<foreach collection="dto.deptIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="dto.createTimeList != null and dto.createTimeList.length == 2">
and a.create_time between #{dto.createTimeList[0]} and #{dto.createTimeList[1]}
</if>
</where>
</select>
</mapper>