无关风月
2025-07-23 7fd053651ac11db87fe4f6c57e65eed3b9a59452
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
<?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.UserPointMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ruoyi.account.api.model.UserPoint">
        <id column="id" property="id" />
        <result column="type" property="type" />
        <result column="historical_point" property="historicalPoint" />
        <result column="variable_point" property="variablePoint" />
        <result column="create_time" property="createTime" />
        <result column="app_user_id" property="appUserId" />
        <result column="object_id" property="objectId" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, type, historical_point, variable_point, create_time, app_user_id, object_id
    </sql>
 
    <sql id="userPointList">
        SELECT
        tau.`name` userName,
        tau.phone,
        tup.type,
        tup.create_time,
        tup.variable_point,
        tup.historical_point,
        tup.balance
        FROM
        t_user_point tup
        LEFT JOIN t_app_user tau ON tup.app_user_id = tau.id
        <where>
            tup.type not in (8, 9, 14) and tau.status != 3 and tau.del_flag = 0
            <if test="userPoint.userName != null and userPoint.userName != ''">
                AND tau.`name` LIKE concat('%',#{userPoint.userName},'%')
            </if>
            <if test="userPoint.phone != null and userPoint.phone != ''">
                AND tau.phone LIKE concat('%',#{userPoint.phone},'%')
            </if>
            <if test="userPoint.type != null and userPoint.type != ''">
                AND tup.type = #{userPoint.type}
            </if>
            <if test="userPoint.startTime != null and userPoint.endTime != null">
                AND tup.create_time BETWEEN #{userPoint.startTime} AND #{userPoint.endTime}
            </if>
        </where>
        order by tup.create_time desc
    </sql>
 
    <select id="queryUserPointPage" resultType="com.ruoyi.account.api.model.UserPoint">
        <include refid="userPointList"/>
    </select>
    <select id="selectUserPoint" resultType="com.ruoyi.account.api.model.UserPoint">
        <include refid="userPointList"/>
    </select>
 
    
    
    <select id="getUserPointDetail" resultType="com.ruoyi.account.vo.UserPointDetailVO">
 
            select
            type,
            historical_point as historicalPoint,
            balance,
            variable_point as variablePoint,
            DATE_FORMAT(create_time, '%Y-%m-%d %H:%i:%s') as createTime,
            object_id as objectId
            from t_user_point where app_user_id = #{userId}
            <if test="null != startTime and null != endTime">
                and create_time between #{startTime} and #{endTime}
            </if>
            <if test="null != type">
                and type = #{type}
            </if>
 
        order by create_time desc
    </select>
    <select id="getUserPontDetailPageList" resultType="com.ruoyi.account.vo.UserPointDetailVO">
        select
            type,
            variable_point,
            DATE_FORMAT(create_time, '%Y-%m-%d %H:%i:%s') as createTime,
            object_id as objectId,
        CASE
        WHEN type = 17 THEN extention  -- 当 type=17 时取 extention
        ELSE CAST(object_id AS CHAR)     -- 否则取 object_id 的字符串形式
        END AS objectIdStr,
 
        CASE WHEN (balance - historical_point) > 0 THEN 1 ELSE 2 END AS flag
        from t_user_point where app_user_id = #{userId}
        <if test="types != null and types.size>0">
            AND type IN
            <foreach collection="types" item="type" open="(" separator="," close=")">
                #{type}
            </foreach>
        </if>
        <if test="objectIdStr != null and objectIdStr != ''">
            and (
                (type = 17 AND extention LIKE CONCAT('%', #{objectIdStr}, '%'))
            OR
                (type != 17 AND CAST(object_id AS CHAR) LIKE CONCAT('%', #{objectIdStr}, '%'))
                )
        </if>
    </select>
    <select id="selectRechargeAndUse" resultType="java.lang.Integer">
        select
            sum(tp.variable_point) as chargeTotalPoint
            from
                t_user_point tp
            left join t_app_user tu on tp.app_user_id = tu.id
        where
            tp.type =#{type}
        <if test="null != name and '' != name">
            AND tu.`name` LIKE concat('%',#{name},'%')
        </if>
        <if test="null != phone and '' != phone">
            AND tu.`phone` LIKE concat('%',#{phone},'%')
        </if>
 
        <if test="null != beginTime and null != endTime">
            and tp.create_time between #{beginTime} and #{endTime}
        </if>
 
    </select>
    <select id="getUserPointStatisticsPageList" resultType="com.ruoyi.account.vo.UserPointStatisticsPageVO">
        select
        tu.name,
        tu.phone,
        tp.type,
        tp.variable_point,
        tp.object_id,
        tp.create_time,
        CASE
        WHEN tp.type = 17 THEN tp.extention  -- 当 type=17 时取 extention
        ELSE CAST(tp.object_id AS CHAR)     -- 否则取 object_id 的字符串形式
        END AS objectIdStr
        from
        t_user_point tp
        left join t_app_user tu on tp.app_user_id = tu.id
        where
        1=1
        <if test="types != null and types.size>0">
            AND type IN
            <foreach collection="types" item="type" open="(" separator="," close=")">
                #{type}
            </foreach>
        </if>
        <if test="null != name and '' != name">
            AND tu.`name` LIKE concat('%',#{name},'%')
        </if>
        <if test="null != phone and '' != phone">
            AND tu.`phone` LIKE concat('%',#{phone},'%')
        </if>
 
        <if test="null != beginTime and null != endTime">
            and tp.create_time between #{beginTime} and #{endTime}
        </if>
        order by create_time desc
    </select>
    <select id="userPointExcel" resultType="com.ruoyi.account.vo.UserPointExcel">
        select
        tu.name,
        tu.phone,
        tp.type,
        tp.variable_point,
        tp.object_id,
        CASE
        WHEN tp.type = 17 THEN tp.extention  -- 当 type=17 时取 extention
        ELSE CAST(tp.object_id AS CHAR)     -- 否则取 object_id 的字符串形式
        END AS objectIdStr,
        tp.create_time
        from
        t_user_point tp
        left join t_app_user tu on tp.app_user_id = tu.id
        where
        1=1
        <if test="types != null and types.size>0">
            AND type IN
            <foreach collection="types" item="type" open="(" separator="," close=")">
                #{type}
            </foreach>
        </if>
        <if test="null != name and '' != name">
            AND tu.`name` LIKE concat('%',#{name},'%')
        </if>
        <if test="null != phone and '' != phone">
            AND tu.`phone` LIKE concat('%',#{phone},'%')
        </if>
 
        <if test="null != beginTime and null != endTime">
            and tp.create_time between #{beginTime} and #{endTime}
        </if>
        order by create_time desc
    </select>
</mapper>