mitao
2025-02-21 31573d6180d15ef65ed0df9c2732495f40b12663
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
<?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_dangjian.dao.ComActIntegralUsersMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.panzhihua.service_dangjian.entity.ComActIntegralUser">
        <id column="id" property="id" />
        <result column="user_id" property="userId" />
        <result column="community_id" property="communityId" />
        <result column="integral_sum" property="integralSum" />
        <result column="integral_available_sum" property="integralAvailableSum" />
        <result column="integral_frozen_sum" property="integralFrozenSum" />
        <result column="integral_party" property="integralParty" />
        <result column="integral_available_party" property="integralAvailableParty" />
        <result column="integral_frozen_party" property="integralFrozenParty" />
        <result column="integral_volunteer" property="integralVolunteer" />
        <result column="integral_available_volunteer" property="integralAvailableVolunteer" />
        <result column="integral_frozen_volunteer" property="integralFrozenVolunteer" />
        <result column="integral_resident" property="integralResident" />
        <result column="integral_available_resident" property="integralAvailableResident" />
        <result column="integral_frozen_resident" property="integralFrozenResident" />
        <result column="create_at" property="createAt" />
        <result column="update_at" property="updateAt" />
        <result column="status" property="status" />
    </resultMap>
 
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, user_id, community_id, integral_sum, integral_available_sum, integral_frozen_sum, integral_party, integral_available_party, integral_frozen_party, integral_volunteer, integral_available_volunteer, integral_frozen_volunteer, integral_resident, integral_available_resident, integral_frozen_resident, create_at, update_at
    </sql>
 
    <select id="getIntegralUserListApplets" resultType="com.panzhihua.common.model.vos.community.integral.ComActIntegralUserListVO">
        SELECT
            SUM(t.amount) AS amount,
            t1.community_id,
            t1.`name` AS communityName
        FROM
            com_act_integral_user_trade t
                INNER JOIN com_act t1 ON t.community_id = t1.community_id
        WHERE
            t.change_type = 1 AND t.user_id = #{userId}
        GROUP BY t1.community_id
        ORDER BY amount DESC
    </select>
 
    <select id="getIntegralUserRank" resultType="com.panzhihua.common.model.vos.community.integral.IntegralUserRankVO">
        SELECT
            *
        FROM
            (
                SELECT
                    t1.user_id,
                    @rank := @rank + 1 AS rank
                FROM
                    (
                    SELECT
                    caiu.user_id,
                    caiu.integral_sum
                    FROM
                    com_act_integral_user as caiu
                    left join sys_user as su on su.user_id = caiu.user_id
                    WHERE
                    caiu.community_id = #{communityId}
                    ORDER BY
                    caiu.integral_sum DESC,su.create_at asc
                    ) AS t1,
                    ( SELECT @rank := 0 ) AS t2
            ) AS m
        WHERE
            user_id = #{userId} limit 1
    </select>
 
    <select id="getIntegralCommunityRankApplets" parameterType="com.panzhihua.common.model.dtos.community.integral.ComActIntegralCommunityRankDTO"
            resultType="com.panzhihua.common.model.vos.community.integral.ComActIntegralCommunityRankVO">
        SELECT
        su.nick_name,
        su.image_url,
        <if test="communityRankDTO.type == 1">
            SUM(caiu.integral_sum) as amount,
        </if>
        <if test="communityRankDTO.type == 2">
            SUM(caiu.integral_resident) as amount,
        </if>
        <if test="communityRankDTO.type == 3">
            SUM(caiu.integral_volunteer) as amount,
        </if>
        <if test="communityRankDTO.type == 4">
            SUM(caiu.integral_party) as amount,
        </if>
        su.is_partymember,
        su.is_volunteer
        FROM
        com_act_integral_user AS caiu
        LEFT JOIN sys_user AS su ON su.user_id = caiu.user_id
        WHERE su.nick_name is not null
        <if test="communityRankDTO.communityId != null">
            AND caiu.community_id = ${communityRankDTO.communityId}
        </if>
        <if test="communityRankDTO.type == 3">
            and su.is_volunteer = 1
        </if>
        <if test="communityRankDTO.type == 4">
            and su.is_partymember = 1
        </if>
        GROUP BY caiu.user_id
        ORDER BY amount desc
    </select>
 
    <select id="getTaskActivityPeopleList" resultType="com.panzhihua.common.model.vos.community.integral.admin.ComActActivityPeopleVO">
        select caas.user_id,caas.activity_id,caa.community_id,caas.sign_identity
        from (SELECT * FROM com_act_act_sign WHERE `status` = 1) as caas
                 left join com_act_activity as caa on caa.id = caas.activity_id
                 left join com_act_act_regist AS caar ON caas.user_id = caar.user_id AND caas.activity_id = caar.activity_id
        where caa.id = #{activityId}  AND caar.id IS NULL
    </select>
    <select id="getUserIntegralStatistics"
            resultType="com.panzhihua.common.model.vos.community.integral.ComActIntegralUserVO">
        SELECT
        SUM(t.amount) AS amount,
        SUM(IF(t.service_type IN(4,5,6),t.amount,0)) AS actAmount,
        SUM(IF(t.service_type = 4,t.amount,0)) AS residentAmount,
        SUM(IF(t.service_type = 5,t.amount,0)) AS partyMemberAmount,
        SUM(IF(t.service_type = 6,t.amount,0)) AS volunteerAmount,
        SUM(IF(t.service_type = 9,t.amount,0)) AS unitPartyMemberAmount
        <if test="communityId != null">
            ,t1.community_id,
            t1.`name` AS communityName
        </if>
        FROM
        com_act_integral_user_trade t
        INNER JOIN com_act t1 ON t.community_id = t1.community_id
        WHERE
        t.change_type = 1 AND t.user_id = #{userId}
        <if test="communityId != null">
            AND t.community_id = #{communityId}
        </if>
    </select>
 
</mapper>