Pu Zhibing
2025-04-22 fd7b8fb7c89832c28a838b0449bbb8a392433ee2
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?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.account.mapper.BalanceChangeRecordMapper">
 
    <select id="pageList" resultType="com.ruoyi.account.api.model.BalanceChangeRecord">
                select t1.*,t2.name as userName,t2.phone as userPhone
                from t_balance_change_record t1
                left join  t_app_user t2 on t1.app_user_id = t2.id
                <where>
                    <if test="agentQuery.userName != null and agentQuery.userName != ''">
                        and t2.name like concat('%',#{agentQuery.userName},'%')
                    </if>
                    <if test="agentQuery.userPhone != null and agentQuery.userPhone != ''">
                        and t2.phone like concat('%',#{agentQuery.userPhone},'%')
                    </if>
                    <if test="agentQuery.changeType != null">
                        and t1.change_type = #{agentQuery.changeType}
                    </if>
                    <if test="agentQuery.localDate1 != null">
                        and DATE(t1.create_time) between  #{agentQuery.localDate1} and #{agentQuery.localDate2}
                    </if>
                </where>
                order by t1.create_time desc
    </select>
 
    <sql id="balanceChangeRecordList">
        SELECT
            tau.`name` userName,
            tau.phone userPhone,
            tbcr.change_type,
            tbcr.create_time,
            tbcr.change_amount,
        tbcr.before_amount,
        tbcr.after_amount,
        tbcr.change_direction
        FROM
            (select * from t_balance_change_record union all select * from t_balance_change_record_copy) tbcr
        LEFT JOIN t_app_user tau ON tbcr.app_user_id = tau.id
        <where>
            <if test="changeRecord.changeType == null">
                and tbcr.change_type = #{changeRecord.changeType}
            </if>
            <if test="changeRecord.userName != null and changeRecord.userName != ''">
                and tau.name like concat('%',#{changeRecord.userName},'%')
            </if>
            <if test="changeRecord.userPhone != null and changeRecord.userPhone != ''">
                and tau.phone like concat('%',#{changeRecord.userPhone},'%')
            </if>
            <if test="changeRecord.startTime != null and changeRecord.endTime != null">
                and (tbcr.create_time between  #{changeRecord.startTime} and #{changeRecord.endTime})
            </if>
            <if test="changeRecord.changeType != null">
                and tbcr.change_type = #{changeRecord.changeType}
            </if>
        </where>
        order by tbcr.create_time desc
    </sql>
 
    <select id="selectBalanceChangeRecordList" resultType="com.ruoyi.account.api.model.BalanceChangeRecord">
        <include refid="balanceChangeRecordList"/>
    </select>
    
    <select id="selectBalanceChangeRecordList1" resultType="com.ruoyi.account.api.model.BalanceChangeRecord">
        SELECT
        tau.`name` userName,
        tau.phone userPhone,
        tbcr.change_type,
        tbcr.create_time,
        tbcr.change_amount,
        tbcr.before_amount,
        tbcr.after_amount,
        tbcr.change_direction
        FROM
        t_balance_change_record tbcr
        LEFT JOIN t_app_user tau ON tbcr.app_user_id = tau.id and tau.del_flag = 0
        <where>
            <if test="changeRecord.userName != null and changeRecord.userName != ''">
                and tau.name like concat('%',#{changeRecord.userName},'%')
            </if>
            <if test="changeRecord.userPhone != null and changeRecord.userPhone != ''">
                and tau.phone like concat('%',#{changeRecord.userPhone},'%')
            </if>
            <if test="changeRecord.startTime != null and changeRecord.endTime != null">
                and (tbcr.create_time between  #{changeRecord.startTime} and #{changeRecord.endTime})
            </if>
            <if test="changeRecord.changeType != null">
                and tbcr.change_type = #{changeRecord.changeType}
            </if>
        </where>
    </select>
    
    <select id="queryCommissionStatistics" resultType="com.ruoyi.account.api.model.BalanceChangeRecord">
        <include refid="balanceChangeRecordList"/>
    </select>
    
    
    <select id="change" resultType="com.ruoyi.account.api.model.BalanceChangeRecordCopy">
        select * from (
        select * from t_balance_change_record where app_user_id = #{userId}
        <if test="null != changeType">
            and change_type = #{changeType}
        </if>
        <if test="null != startTime and null != endTime">
            and create_time between  #{startTime} and #{endTime}
        </if>
        union all
        select * from t_balance_change_record_copy where app_user_id = #{userId}
        <if test="null != changeType">
            and change_type = #{changeType}
        </if>
        <if test="null != startTime and null != endTime">
            and create_time between  #{startTime} and #{endTime}
        </if>
        ) as a order by a.create_time desc
    </select>
</mapper>