liuxiaolong
2019-05-06 f99bc8c6a1d10610373738edd7d0aa0181c81d99
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
<?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.cloud.user.dao.SysRoleMenuDao">
  <resultMap id="BaseResultMap" type="com.cloud.model.sys.SysRoleMenu">
    <result column="roleId" jdbcType="INTEGER" property="roleId" />
    <result column="menuId" jdbcType="INTEGER" property="menuId" />
    <result column="orgId" jdbcType="INTEGER" property="orgId" />
  </resultMap>
  <insert id="insert" parameterType="com.cloud.model.sys.SysRoleMenu">
    insert into sys_role_menu (roleId, menuId, orgId
      )
    values (#{roleId,jdbcType=INTEGER}, #{menuId,jdbcType=INTEGER}, #{orgId,jdbcType=INTEGER}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.cloud.model.sys.SysRoleMenu">
    insert into sys_role_menu
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="roleId != null">
        roleId,
      </if>
      <if test="menuId != null">
        menuId,
      </if>
      <if test="orgId != null">
        orgId,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="roleId != null">
        #{roleId,jdbcType=INTEGER},
      </if>
      <if test="menuId != null">
        #{menuId,jdbcType=INTEGER},
      </if>
      <if test="orgId != null">
        #{orgId,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
 
  <select id="findPermissionsByRoleIds" resultType="com.cloud.model.sys.SysMenu">
    select m.* from
    sys_menu m
    inner join sys_role_menu rm on
    m.id = rm.menuId
    <where>
      rm.roleId in
      <foreach collection="roleIds" item="roleId" open="("
               separator="," close=")">
        #{roleId}
      </foreach>
    </where>
    <if test="orgId != null and orgId != ''">
      and m.orgId = #{orgId}
    </if>
  </select>
 
  <select id="findMenusByRoleIds" resultType="com.cloud.model.sys.SysMenu">
    select t.* from sys_menu t
    inner join sys_role_menu r on r.menuId = t.id
    where t.enabled = '0' and t.delFlag = '0' and
    r.roleId in
    <foreach collection="roleIds" index="index" item="roleId"
             open="(" separator="," close=")">
      #{roleId}
    </foreach>
    <if test="module != null and module != ''">
        and t.module = #{module}
    </if>
    <if test="type != null and type != ''">
       and t.type != #{type}
    </if>
    order by t.sort
  </select>
 
  <insert id="save" parameterType="com.cloud.model.sys.SysMenu">
    insert into sys_menu
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="orgId != null">
        orgId,
      </if>
      <if test="parentId != null">
        parentId,
      </if>
      <if test="parentIds != null">
        parentIds,
      </if>
      <if test="orgIdsShow != null">
        orgIdsShow,
      </if>
      <if test="orgIdsHide != null">
        orgIdsHide,
      </if>
      <if test="name != null">
        name,
      </if>
      <if test="sort != null">
        sort,
      </if>
      <if test="url != null">
        url,
      </if>
      <if test="icon != null">
        icon,
      </if>
      <if test="type != null">
        type,
      </if>
      <if test="isSystem != null">
        isSystem,
      </if>
      <if test="permission != null">
        permission,
      </if>
      <if test="remarks != null">
        remarks,
      </if>
      <if test="enabled != null">
        enabled,
      </if>
      <if test="delFlag != null">
        delFlag,
      </if>
      <if test="createTime != null">
        createTime,
      </if>
      <if test="updateTime != null">
        updateTime,
      </if>
      <if test="revJson != null">
        revJson,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="orgId != null">
        #{orgId,jdbcType=INTEGER},
      </if>
      <if test="parentId != null">
        #{parentId,jdbcType=INTEGER},
      </if>
      <if test="parentIds != null">
        #{parentIds,jdbcType=VARCHAR},
      </if>
      <if test="orgIdsShow != null">
        #{orgIdsShow,jdbcType=VARCHAR},
      </if>
      <if test="orgIdsHide != null">
        #{orgIdsHide,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="sort != null">
        #{sort,jdbcType=INTEGER},
      </if>
      <if test="url != null">
        #{url,jdbcType=VARCHAR},
      </if>
      <if test="icon != null">
        #{icon,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        #{type,jdbcType=INTEGER},
      </if>
      <if test="isSystem != null">
        #{isSystem,jdbcType=INTEGER},
      </if>
      <if test="permission != null">
        #{permission,jdbcType=VARCHAR},
      </if>
      <if test="remarks != null">
        #{remarks,jdbcType=VARCHAR},
      </if>
      <if test="enabled != null">
        #{enabled},
      </if>
      <if test="delFlag != null">
        #{delFlag,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="revJson != null">
        #{revJson,jdbcType=CHAR},
      </if>
    </trim>
  </insert>
 
  <update id="update" parameterType="com.cloud.model.sys.SysMenu">
    update sys_menu
    <set>
      <if test="orgId != null">
        orgId = #{orgId,jdbcType=INTEGER},
      </if>
      <if test="parentId != null">
        parentId = #{parentId,jdbcType=INTEGER},
      </if>
      <if test="parentIds != null">
        parentIds = #{parentIds,jdbcType=VARCHAR},
      </if>
      <if test="orgIdsShow != null">
        orgIdsShow = #{orgIdsShow,jdbcType=VARCHAR},
      </if>
      <if test="orgIdsHide != null">
        orgIdsHide = #{orgIdsHide,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        name = #{name,jdbcType=VARCHAR},
      </if>
      <if test="sort != null">
        sort = #{sort,jdbcType=INTEGER},
      </if>
      <if test="url != null">
        url = #{url,jdbcType=VARCHAR},
      </if>
      <if test="icon != null">
        icon = #{icon,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        type = #{type,jdbcType=INTEGER},
      </if>
      <if test="isSystem != null">
        isSystem = #{isSystem,jdbcType=INTEGER},
      </if>
      <if test="permission != null">
        permission = #{permission,jdbcType=VARCHAR},
      </if>
      <if test="remarks != null">
        remarks = #{remarks,jdbcType=VARCHAR},
      </if>
      <if test="enabled != null">
        enabled = #{enabled,jdbcType=VARCHAR},
      </if>
      <if test="delFlag != null">
        delFlag = #{delFlag,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        createTime = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null">
        updateTime = #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="revJson != null">
        revJson = #{revJson,jdbcType=CHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
    and orgId = #{orgId,jdbcType=INTEGER}
  </update>
 
  <delete id="delete">
    delete from sys_menu
    where id = #{id,jdbcType=INTEGER}
    and orgId = #{orgId,jdbcType=INTEGER}
  </delete>
 
  <select id="findById"  resultType="com.cloud.model.sys.SysMenu">
    select *
    from sys_menu
    where id = #{id,jdbcType=INTEGER}
    and orgId = #{orgId,jdbcType=INTEGER}
  </select>
 
  <delete id="deleteRolePermissionByParams">
    delete from sys_role_menu
    <where>
      <if test="id != null">
        and roleId = #{id}
      </if>
      <if test="orgId != null">
        and orgId = #{orgId}
      </if>
    </where>
  </delete>
 
  <select id="findMenuByUser"  resultType="map">
    SELECT
      c.`name` as lable,c.module as value,c.icon,c.id
    FROM
        sys_role_user a
    LEFT JOIN sys_role_menu b ON a.roleId = b.roleId
    LEFT JOIN sys_menu c ON b.menuId = c.id
    <where>
      c.delFlag = #{delFlag}
      <if test="userId != null">
        and a.userId = #{userId}
      </if>
      <if test="type != null">
        and c.type = #{type}
      </if>
      <if test="tags != null">
        AND json_extract (c.revJson, '$.tags') LIKE "%${tags}%"
      </if>
      <if test="orgId != null">
        and a.orgId = #{orgId}
        and b.orgId = #{orgId}
      </if>
    </where>
    GROUP BY c.id
  </select>
  <select id="findAllMenuByUser"  resultType="map">
      SELECT T.*,CASE WHEN #{userId} is not NULL THEN 1 ELSE 0 END as state from (SELECT
        a.icon,a.id,a.module,a.`name`,a.orgId,a.url
      FROM
        sys_menu a
      LEFT JOIN sys_role_menu b ON a.id = b.menuId
      LEFT JOIN sys_role_user c ON c.roleId = b.roleId AND c.userId = #{userId}
      <where>
        a.delFlag = #{delFlag}
        <if test="type != null">
          and a.type = #{type}
        </if>
        <if test="tags != null">
          AND json_extract (a.revJson, '$.tags') LIKE "%${tags}%"
        </if>
      </where>
      GROUP BY a.id,a.icon,a.module,a.`name`,a.orgId,a.url)T
    </select>
 
</mapper>