Pu Zhibing
2025-02-27 f0a9a41697a8568e8b3bd3436c450e68b3298916
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<?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.panzhihua.service_community.dao.ComActUserWalletTradeMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.panzhihua.service_community.model.dos.ComActUserWalletTradeDO">
        <id column="id" property="id" />
        <result column="user_id" property="userId" />
        <result column="community_id" property="communityId" />
        <result column="service_id" property="serviceId" />
        <result column="amount" property="amount" />
        <result column="type" property="type" />
        <result column="remark" property="remark" />
        <result column="create_at" property="createAt" />
        <result column="create_by" property="createBy" />
        <result column="wallet_id" property="walletId" />
        <result column="change_type" property="changeType" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, user_id, community_id, service_id, amount, type, remark, create_at, create_by, wallet_id, change_type
    </sql>
 
    <select id="getUserWalletTradeList" resultType="com.panzhihua.common.model.vos.community.wallet.ComActWalletTradeVO"
            parameterType="com.panzhihua.common.model.dtos.community.wallet.PageComActWalletTradeDTO">
        SELECT
            cauwt.id,
            ca.`name` AS communityName,
            cauwt.type,
            cauwt.remark,
            cauwt.change_type,
            cauwt.amount,
            cauwt.create_at
        FROM
            com_act_user_wallet_trade AS cauwt
            LEFT JOIN com_act AS ca ON ca.community_id = cauwt.community_id
            where cauwt.community_id = ${walletTradeDTO.communityId}
            and cauwt.user_id = #{walletTradeDTO.userId}
 
            order by cauwt.create_at desc
    </select>
 
    <select id="getUserWalletTradeAdmin" parameterType="com.panzhihua.common.model.dtos.community.wallet.PageComActWalletTradeAdminDTO"
            resultType="com.panzhihua.common.model.vos.community.wallet.ComActWalletTradeAdminVO">
        SELECT
            cauwt.id,
            su.user_id,
            cauwt.amount,
            cauwt.service_id,
            cauwt.remark,
            cauwt.type,
            su.`name` AS userName,
            su.nick_name,
            cauwt.change_type,
            su.phone,
            cauwt.create_at,
            su1.`name` AS operationUserName
        FROM
            com_act_user_wallet_trade AS cauwt
            LEFT JOIN sys_user AS su ON su.user_id = cauwt.user_id
            LEFT JOIN sys_user AS su1 ON su1.user_id = cauwt.create_by
        <where>
            <if test="walletTradeDTO.communityId != null">
                and cauwt.community_id = ${walletTradeDTO.communityId}
            </if>
            <if test="walletTradeDTO.userId != null">
                and cauwt.user_id = #{walletTradeDTO.userId}
            </if>
            <if test="walletTradeDTO.type != null">
                and cauwt.type = #{walletTradeDTO.type}
            </if>
            <if test="walletTradeDTO.changeType != null">
                and cauwt.change_type = #{walletTradeDTO.changeType}
            </if>
            <if test="walletTradeDTO.name != null and walletTradeDTO.name != &quot;&quot;">
                AND (su.nick_name like concat (#{walletTradeDTO.name},'%') or su.name like concat (#{walletTradeDTO.name},'%'))
            </if>
            <if test="walletTradeDTO.phone != null and walletTradeDTO.phone != &quot;&quot;">
                AND su.phone like concat (#{walletTradeDTO.phone},'%')
            </if>
            <if test="walletTradeDTO.startTime != null and walletTradeDTO.startTime != &quot;&quot;">
                AND cauwt.create_at <![CDATA[>=]]> #{walletTradeDTO.startTime}
            </if>
            <if test="walletTradeDTO.endTime != null and walletTradeDTO.endTime != &quot;&quot;">
                AND cauwt.create_at <![CDATA[<=]]> #{walletTradeDTO.endTime}
            </if>
            <if test="walletTradeDTO.keyWord != null and walletTradeDTO.keyWord != &quot;&quot;">
                AND (su.phone like concat (#{walletTradeDTO.keyWord},'%') or su.name like concat (#{walletTradeDTO.keyWord},'%'))
            </if>
            <if test="walletTradeDTO.expenditureKeyWord != null and walletTradeDTO.expenditureKeyWord != &quot;&quot;">
                AND (cauwt.remark like concat (#{walletTradeDTO.expenditureKeyWord},'%') or su1.name like concat (#{walletTradeDTO.expenditureKeyWord},'%'))
            </if>
            <if test="walletTradeDTO.remark != null and walletTradeDTO.remark != &quot;&quot;">
                AND cauwt.remark like concat (#{walletTradeDTO.remark},'%')
            </if>
        </where>
        <if test="walletTradeDTO.sort == null">
            order by cauwt.create_at desc
        </if>
        <if test="walletTradeDTO.sort != null and walletTradeDTO.sort == 1">
            order by cauwt.amount asc
        </if>
        <if test="walletTradeDTO.sort != null and walletTradeDTO.sort == 2">
            order by cauwt.amount desc
        </if>
 
    </select>
 
    <select id="getTradeUserTotalWalletTradeAdmin" resultType="java.math.BigDecimal"
            parameterType="com.panzhihua.common.model.dtos.community.wallet.PageComActWalletTradeAdminDTO">
        SELECT
        sum(cauwt.amount)
        FROM
        com_act_user_wallet_trade AS cauwt
        LEFT JOIN sys_user AS su ON su.user_id = cauwt.user_id
        LEFT JOIN sys_user AS su1 ON su1.user_id = cauwt.create_by
        <where>
            <if test="walletTradeDTO.communityId != null">
                and cauwt.community_id = ${walletTradeDTO.communityId}
            </if>
            <if test="walletTradeDTO.userId != null">
                and cauwt.user_id = #{walletTradeDTO.userId}
            </if>
            <if test="walletTradeDTO.type != null">
                and cauwt.type = #{walletTradeDTO.type}
            </if>
            <if test="walletTradeDTO.changeType != null">
                and cauwt.change_type = #{walletTradeDTO.changeType}
            </if>
            <if test="walletTradeDTO.keyWord != null and walletTradeDTO.keyWord != &quot;&quot;">
                AND (su.phone like concat (#{walletTradeDTO.keyWord},'%') or su.name like concat (#{walletTradeDTO.keyWord},'%'))
            </if>
            <if test="walletTradeDTO.expenditureKeyWord != null and walletTradeDTO.expenditureKeyWord != &quot;&quot;">
                AND (cauwt.remark like concat (#{walletTradeDTO.expenditureKeyWord},'%') or su1.name like concat (#{walletTradeDTO.expenditureKeyWord},'%'))
            </if>
            <if test="walletTradeDTO.phone != null and walletTradeDTO.phone != &quot;&quot;">
                AND su.phone like concat (#{walletTradeDTO.phone},'%')
            </if>
            <if test="walletTradeDTO.remark != null and walletTradeDTO.remark != &quot;&quot;">
                AND cauwt.remark like concat (#{walletTradeDTO.remark},'%')
            </if>
            <if test="walletTradeDTO.startTime != null and walletTradeDTO.startTime != &quot;&quot;">
                AND cauwt.create_at <![CDATA[>=]]> #{walletTradeDTO.startTime}
            </if>
            <if test="walletTradeDTO.endTime != null and walletTradeDTO.endTime != &quot;&quot;">
                AND cauwt.create_at <![CDATA[<=]]> #{walletTradeDTO.endTime}
            </if>
        </where>
 
        <if test="walletTradeDTO.sort == null">
            order by cauwt.create_at desc
        </if>
        <if test="walletTradeDTO.sort != null and walletTradeDTO.sort == 1">
            order by cauwt.amount asc
        </if>
        <if test="walletTradeDTO.sort != null and walletTradeDTO.sort == 2">
            order by cauwt.amount desc
        </if>
    </select>
 
    <select id="getTradeUserTotalWalletTradeExportAdmin" parameterType="com.panzhihua.common.model.dtos.community.wallet.PageComActWalletTradeAdminDTO"
            resultType="com.panzhihua.common.model.vos.community.ComActUserWalletTradeExcelVO">
        SELECT
            cauwt.amount,su1.`name` as userName,su1.phone,cauwt.create_at,su.`name` as createBy
        FROM
            com_act_user_wallet_trade AS cauwt
            LEFT JOIN sys_user AS su ON su.user_id = cauwt.create_by
            LEFT JOIN sys_user AS su1 ON su1.user_id = cauwt.user_id
        <where>
            <if test="walletTradeDTO.communityId != null">
                and cauwt.community_id = ${walletTradeDTO.communityId}
            </if>
            <if test="walletTradeDTO.userId != null">
                and cauwt.user_id = #{walletTradeDTO.userId}
            </if>
            <if test="walletTradeDTO.type != null">
                and cauwt.type = #{walletTradeDTO.type}
            </if>
            <if test="walletTradeDTO.changeType != null">
                and cauwt.change_type = #{walletTradeDTO.changeType}
            </if>
            <if test="walletTradeDTO.keyWord != null and walletTradeDTO.keyWord != &quot;&quot;">
                AND (su.phone like concat (#{walletTradeDTO.keyWord},'%') or su.name like concat (#{walletTradeDTO.keyWord},'%'))
            </if>
            <if test="walletTradeDTO.startTime != null and walletTradeDTO.startTime != &quot;&quot;">
                AND cauwt.create_at <![CDATA[>=]]> #{walletTradeDTO.startTime}
            </if>
            <if test="walletTradeDTO.endTime != null and walletTradeDTO.endTime != &quot;&quot;">
                AND cauwt.create_at <![CDATA[<=]]> #{walletTradeDTO.endTime}
            </if>
            <if test="walletTradeDTO.tradeIds != null and walletTradeDTO.tradeIds.size > 0">
                AND cauwt.id in
                <foreach collection='walletTradeDTO.tradeIds' item='id' index='index' open='(' close=')' separator=',' >
                    #{id}
                </foreach>
            </if>
        </where>
 
        <if test="walletTradeDTO.sort == null">
            order by cauwt.create_at desc
        </if>
        <if test="walletTradeDTO.sort != null and walletTradeDTO.sort == 1">
            order by cauwt.amount asc
        </if>
        <if test="walletTradeDTO.sort != null and walletTradeDTO.sort == 2">
            order by cauwt.amount desc
        </if>
 
    </select>
 
    <select id="getTradeUserTotalJLWalletTradeExportAdmin" parameterType="com.panzhihua.common.model.dtos.community.wallet.PageComActWalletTradeAdminDTO"
            resultType="com.panzhihua.common.model.vos.community.ComActUserWalletTradeRewardExcelVO">
        SELECT
        cauwt.amount,su1.`name` as userName,su1.phone,cauwt.create_at,su.`name` as createBy,cauwt.type,cauwt.remark
        FROM
        com_act_user_wallet_trade AS cauwt
        LEFT JOIN sys_user AS su ON su.user_id = cauwt.create_by
        LEFT JOIN sys_user AS su1 ON su1.user_id = cauwt.user_id
        <where>
            <if test="walletTradeDTO.communityId != null">
                and cauwt.community_id = ${walletTradeDTO.communityId}
            </if>
            <if test="walletTradeDTO.userId != null">
                and cauwt.user_id = #{walletTradeDTO.userId}
            </if>
            <if test="walletTradeDTO.type != null">
                and cauwt.type = #{walletTradeDTO.type}
            </if>
            <if test="walletTradeDTO.changeType != null">
                and cauwt.change_type = #{walletTradeDTO.changeType}
            </if>
            <if test="walletTradeDTO.keyWord != null and walletTradeDTO.keyWord != &quot;&quot;">
                AND (su.phone like concat (#{walletTradeDTO.keyWord},'%') or su.name like concat (#{walletTradeDTO.keyWord},'%'))
            </if>
            <if test="walletTradeDTO.startTime != null and walletTradeDTO.startTime != &quot;&quot;">
                AND cauwt.create_at <![CDATA[>=]]> #{walletTradeDTO.startTime}
            </if>
            <if test="walletTradeDTO.endTime != null and walletTradeDTO.endTime != &quot;&quot;">
                AND cauwt.create_at <![CDATA[<=]]> #{walletTradeDTO.endTime}
            </if>
            <if test="walletTradeDTO.tradeIds != null and walletTradeDTO.tradeIds.size > 0">
                AND cauwt.id in
                <foreach collection='walletTradeDTO.tradeIds' item='id' index='index' open='(' close=')' separator=',' >
                    #{id}
                </foreach>
            </if>
        </where>
 
        <if test="walletTradeDTO.sort == null">
            order by cauwt.create_at desc
        </if>
        <if test="walletTradeDTO.sort != null and walletTradeDTO.sort == 1">
            order by cauwt.amount asc
        </if>
        <if test="walletTradeDTO.sort != null and walletTradeDTO.sort == 2">
            order by cauwt.amount desc
        </if>
 
    </select>
 
    <select id="getTradeUserStatisticsAdmin" parameterType="com.panzhihua.common.model.dtos.community.wallet.PageComActWalletTradeAdminDTO"
            resultType="com.panzhihua.common.model.vos.community.wallet.ComActWalletTradeStatisticsAdminVO">
        SELECT
            sum( amount ) as dayTotal,
            (select sum(amount) from com_act_user_wallet_trade where community_id = ${walletTradeDTO.communityId} and change_type = #{walletTradeDTO.changeType} and create_at between timestamp(DATE_ADD(curdate(),interval -day(curdate())+1 day)) and now()) as monthTotal,
            (select sum(amount) from com_act_user_wallet_trade where community_id = ${walletTradeDTO.communityId} and change_type = #{walletTradeDTO.changeType}) as total
        FROM
            com_act_user_wallet_trade
            where community_id = ${walletTradeDTO.communityId} and change_type = #{walletTradeDTO.changeType}
            and create_at between timestamp(date_add(curdate(), interval - 0 day)) and now()
    </select>
</mapper>