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
<?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.NewStriveForDAO">
 
 
    <!--  通过用户id 查询人员的排名  -->
    <select id="getUserRank" resultType="com.panzhihua.common.model.dtos.partybuilding.UserRankDTO">
        SELECT
            tab2.community_id,
            tab2.check_unit_id,
            tab2.image_url,
            tab2.user_id,
            tab2.user_name,
            tab2.unit_name,
            tab2.community_name,
            tab2.amount,
            tab2.rank
        FROM(SELECT
                 tab.community_id,
                 tab.check_unit_id,
                 tab.image_url,
                 tab.user_id,
                 tab.user_name,
                 tab.unit_name,
                 tab.community_name,
                 tab.amount,
                 (@row_number:=@row_number+1) AS rank
             FROM (SELECT
                       cpm.community_id as community_id,
                       cpm.check_unit_id as check_unit_id,
                       su.image_url as image_url,
                       cpm.user_id as user_id,
                       cpm.`name` as user_name,
                       cpcu.`name` as unit_name,
                       ca.`name` as community_name,
                       IFNULL(SUM(caiu.integral_sum),0) as amount
                   FROM com_pb_member as cpm
                            LEFT JOIN com_pb_check_unit as cpcu on cpcu.id=cpm.check_unit_id
                            LEFT JOIN sys_user as su on su.user_id=cpm.user_id
                            LEFT JOIN com_act as ca on ca.community_id = cpm.community_id
                            LEFT JOIN com_act_integral_user as caiu on cpm.user_id=caiu.user_id and cpm.community_id=caiu.community_id
                   WHERE cpm.check_unit_id=(SELECT check_unit_id FROM com_pb_member WHERE user_id=#{userId} limit 1)
                   GROUP BY cpm.user_id
                   order by amount desc,user_id desc) as tab
                ,(SELECT @row_number:=0) AS t) tab2
        WHERE tab2.user_id =#{userId}
    </select>
 
    <!--  查询人员的排名  -->
    <select id="getUserRankList" resultType="com.panzhihua.common.model.dtos.partybuilding.UserRankDTO">
        SELECT
             tab.community_id,
             tab.check_unit_id,
             tab.image_url,
             tab.user_id,
             tab.user_name,
             tab.unit_name,
             tab.community_name,
             tab.amount,
             (@row_number:=@row_number+1) AS rank
        FROM (SELECT
               cpm.community_id as community_id,
               cpm.check_unit_id as check_unit_id,
               su.image_url as image_url,
               cpm.user_id as user_id,
               cpm.`name` as user_name,
               cpcu.`name` as unit_name,
               ca.`name` as community_name,
               IFNULL(SUM(caiu.integral_sum),0) as amount
           FROM com_pb_member as cpm
                    LEFT JOIN com_pb_check_unit as cpcu on cpcu.id=cpm.check_unit_id
                    LEFT JOIN sys_user as su on su.user_id=cpm.user_id
                    LEFT JOIN com_act as ca on ca.community_id = cpm.community_id
                    LEFT JOIN com_act_integral_user as caiu on cpm.user_id=caiu.user_id and cpm.community_id=caiu.community_id
           WHERE cpm.check_unit_id=(SELECT check_unit_id FROM com_pb_member WHERE user_id=#{userId}  limit 1)
           GROUP BY cpm.user_id
           order by amount desc,user_id desc) as tab
        ,(SELECT @row_number:=0) AS t
    </select>
 
    <select id="getAllintegral" resultType="String">
        SELECT
            SUM(integral_sum) as amount
        FROM
            com_act_integral_user
        <where>
            1=1
            <if test="userIds !=null ">
                and user_id in
                <foreach collection="userIds" item="ids" index="index"
                         open="(" close=")" separator=",">
                    #{ids}
                </foreach>
            </if>
        </where>
    </select>
 
    <select id="getPartyMember" resultType="String">
        SELECT
            cpm.user_id
        FROM com_pb_member as cpm
        WHERE cpm.check_unit_id=(SELECT check_unit_id FROM com_pb_member WHERE user_id=#{userId})
    </select>
 
 
 
</mapper>