1
phpcjl
2024-12-16 c31c769b7c5864be9973d8dd7e11d9ff8e2ac3e9
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
<?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>
    <select id="findLatestUserPointByTypeForUser" resultType="com.ruoyi.account.api.model.UserPoint">
        SELECT
            t1.*
        FROM
            t_user_point t1
                INNER JOIN ( SELECT type, MAX( create_time ) AS max_create_time FROM t_user_point WHERE app_user_id = #{userId} GROUP BY type ) t2 ON t1.type = t2.type
                AND t1.create_time = t2.max_create_time
        WHERE
            t1.app_user_id = #{userId}
    </select>
    <select id="findLatestChangeByType" resultType="com.ruoyi.account.api.model.UserPoint">
        SELECT
            id,
            type,
            historical_point,
            variable_point,
            balance,
            create_time,
            app_user_id,
            object_id
        FROM (
                 SELECT
                     id,
                     type,
                     historical_point,
                     variable_point,
                     balance,
                     create_time,
                     app_user_id,
                     object_id,
                     ROW_NUMBER() OVER (PARTITION BY type ORDER BY create_time DESC) AS rn
                 FROM
                     t_user_point
             ) AS subquery
        WHERE
            rn = 1
        <if test="type != null">
            AND type = #{type}
        </if>
        <if test="appUserId != null">
            AND app_user_id = #{appUserId}
        </if>
    </select>
 
</mapper>