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
<?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="privilegeDAOImpl">
 
    <select id="queryUserDefaultPrivilege" parameterType="map" resultType="map">
        SELECT a.`p_id` pId,a.`privilege_flag` privilegeFlag,a.`user_id` userId FROM p_privilege_user a WHERE a.`p_id` =
        #{pId}
        AND a.`user_id` = #{userId}
        AND a.`privilege_flag` = '1'
        AND a.`status_cd` = '0'
    </select>
 
    <!-- 保存属性信息 c_business_attrs -->
    <insert id="saveUserDefaultPrivilege" parameterType="Map">
        <![CDATA[
        INSERT INTO p_privilege_user(p_id,privilege_flag,user_id,store_id) VALUES(#{pId},'1',#{userId},#{storeId})
        ]]>
    </insert>
 
    <!-- 删除用户所有权限-->
    <update id="deleteUserAllPrivilege" parameterType="Map">
        UPDATE p_privilege_user a SET a.`status_cd` = '1' WHERE a.`user_id` = #{userId}
    </update>
 
    <insert id="savePrivilegeGroup" parameterType="map">
        INSERT INTO p_privilege_group(pg_id,`name`,description,store_id,domain)
        VALUES(#{pgId},#{name},#{description},#{storeId},#{storeTypeCd})
    </insert>
 
    <update id="updatePrivilegeGroup" parameterType="Map">
        UPDATE p_privilege_group a SET
        <if test="name != null and name != ''">
            a.name = #{name},
        </if>
        <if test="description != null and description != ''">
            a.description = #{description}
        </if>
        WHERE 1= 1
        <if test="storeId != null and storeId != ''">
            and a.store_id = #{storeId}
        </if>
        and a.pg_id = #{pgId}
        <if test="storeTypeCd != null and storeTypeCd != ''">
            and a.domain= #{storeTypeCd}
        </if>
    </update>
 
    <!-- 删除权限组 -->
    <update id="deletePrivilegeGroup" parameterType="Map">
        UPDATE p_privilege_group a SET a.`status_cd` = '1'
        WHERE 1= 1
        <if test="storeId != null and storeId != ''">
            and a.store_id = #{storeId}
        </if>
        and a.pg_id = #{pgId}
        <if test="storeTypeCd != null and storeTypeCd != ''">
            and a.domain= #{storeTypeCd}
        </if>
    </update>
 
    <!-- 删除权限组 -->
    <update id="deletePrivilegeRel" parameterType="Map">
        UPDATE p_privilege_rel a SET a.`status_cd` = '1'
        WHERE 1=1
        <if test="pgId != null and pgId != ''">
            and a.`pg_id` = #{pgId}
        </if>
        <if test="pId != null and pId != ''">
            and a.`p_id` = #{pId}
        </if>
    </update>
 
    <select id="queryPrivilegeRel" parameterType="Map" resultType="Map">
        SELECT
        pp.`name`,
        pp.`domain`,
        pp.`p_id` pId,
        pp.`description`,
        pp.`create_time` createTime
        FROM
        p_privilege pp,
        p_privilege_rel ppr
        WHERE ppr.`p_id` = pp.`p_id`
        AND ppr.`status_cd` = '0'
        AND pp.`status_cd` = '0'
        AND ppr.`pg_id` = #{pgId}
    </select>
 
    <select id="queryPrivilegeGroup" parameterType="Map" resultType="Map">
        select ppg.pg_id pgId,ppg.name,ppg.description,ppg.create_time createTime,ppg.store_id storeId,ppg.domain
        from p_privilege_group ppg
        where 1=1
        <if test="pgId !=null and pgId !=''">
            and ppg.pg_id = #{pgId}
        </if>
        <if test="storeId != null and storeId != ''">
            and ppg.store_id = #{storeId}
        </if>
        <if test="storeTypeCd != null and storeTypeCd != ''">
            and ppg.domain = #{storeTypeCd}
        </if>
        and ppg.status_cd = '0'
    </select>
 
    <insert id="addPrivilegeRel" parameterType="Map">
        insert into p_privilege_rel(p_id,pg_id)
        values(#{pId},#{pgId})
    </insert>
 
    <!-- 查询权限 -->
    <select id="queryPrivilege" parameterType="Map" resultType="Map">
        SELECT
        pp.`p_id` pId,pp.`name`,pp.`description`,pp.`create_time` createTime,pp.`domain`
        FROM p_privilege pp
        WHERE 1= 1
        <if test="pId != null and pId != ''">
            and pp.p_id = #{pId}
        </if>
        <if test="pId != null and pId != ''">
            AND pp.domain = '800900000003'
        </if>
        AND pp.`status_cd` = '0'
    </select>
 
    <!-- 查询用户权限 -->
    <select id="queryUserPrivilege" parameterType="Map" resultType="Map">
        SELECT
        ppu.`pu_id` puId,
        ppu.`p_id` pId,
        ppu.`privilege_flag` privilegeFlag,
        ppu.`user_id` userId
        FROM
        p_privilege_user ppu
        WHERE 1 = 1
        <if test="privilegeFlag != null and privilegeFlag != ''">
            AND ppu.`privilege_flag` = #{privilegeFlag}
        </if>
        <if test="pId != null and pId != ''">
            AND ppu.`p_id` = #{pId}
        </if>
        <if test="userId != null and userId != ''">
            AND ppu.`user_id` = #{userId}
        </if>
        AND ppu.`status_cd` = '0'
    </select>
 
    <!-- 保存属性信息 c_business_attrs -->
    <insert id="addUserPrivilege" parameterType="Map">
        <![CDATA[
        INSERT INTO p_privilege_user(p_id,privilege_flag,user_id,store_id) VALUES(#{pId},#{privilegeFlag},#{userId},#{storeId})
        ]]>
    </insert>
 
    <!-- 删除权限组 -->
    <update id="deleteUserPrivilege" parameterType="Map">
        update p_privilege_user ppu set ppu.status_cd = '1'
        where 1=1
        <if test="pId != null and pId != ''">
            and ppu.p_id= #{pId}
        </if>
        <if test="privilegeFlag != null and privilegeFlag != ''">
            and ppu.privilege_flag = #{privilegeFlag}
        </if>
        <if test="userId != null and userId != ''">
            and ppu.user_id = #{userId}
        </if>
        and ppu.status_cd = '0'
    </update>
 
    <select id="queryPrivilegeUsers" parameterType="map" resultType="map">
        select distinct t.user_id userId
        from p_privilege_user t
        INNER JOIN p_privilege p on t.p_id = p.p_id and p.status_cd = '0'
        where t.privilege_flag = '0'
        and t.status_cd = '0'
        <if test="resource != null and resource != ''">
            and p.resource = #{resource}
        </if>
        <if test="storeId != null and storeId != ''">
            and t.store_id = #{storeId}
        </if>
        union ALL
        select distinct t.user_id userId
        from p_privilege_user t
        inner join p_privilege_group pg on t.p_id = pg.pg_id and pg.status_cd = '0' and pg.pg_id != '600201904002'
        inner join p_privilege_rel pr on pg.pg_id = pr.pg_id and pr.status_cd ='0'
        INNER JOIN p_privilege p on pr.p_id = p.p_id and p.status_cd = '0'
        <if test="communityId != null and communityId != ''">
            LEFT JOIN u_role_community rc on pg.pg_id = rc.role_id and rc.status_cd = '0'
        </if>
        where t.status_cd = '0'
        and t.privilege_flag = '1'
        <if test="resource != null and resource != ''">
            and p.resource = #{resource}
        </if>
        <if test="storeId != null and storeId != ''">
            and t.store_id = #{storeId}
        </if>
    </select>
 
</mapper>