xiejun
2024-01-23 f09e05514d9a9e2623cfa73c4de1ffa98bb30bf8
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
<?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.vci.ubcs.system.mapper.MenuMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="menuResultMap" type="com.vci.ubcs.system.entity.Menu">
        <id column="id" property="id"/>
        <result column="code" property="code"/>
        <result column="parent_id" property="parentId"/>
        <result column="name" property="name"/>
        <result column="alias" property="alias"/>
        <result column="path" property="path"/>
        <result column="source" property="source"/>
        <result column="sort" property="sort"/>
        <result column="category" property="category"/>
        <result column="action" property="action"/>
        <result column="is_open" property="isOpen"/>
        <result column="remark" property="remark"/>
        <result column="is_deleted" property="isDeleted"/>
    </resultMap>
 
    <resultMap id="menuVOResultMap" type="com.vci.ubcs.system.vo.MenuVO">
        <id column="id" property="id"/>
        <result column="code" property="code"/>
        <result column="parent_id" property="parentId"/>
        <result column="name" property="name"/>
        <result column="alias" property="alias"/>
        <result column="path" property="path"/>
        <result column="source" property="source"/>
        <result column="sort" property="sort"/>
        <result column="category" property="category"/>
        <result column="action" property="action"/>
        <result column="is_open" property="isOpen"/>
        <result column="remark" property="remark"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="has_children" property="hasChildren"/>
    </resultMap>
 
    <resultMap id="treeNodeResultMap" type="org.springblade.core.tool.node.TreeNode">
        <id column="id" property="id"/>
        <result column="parent_id" property="parentId"/>
        <result column="title" property="title"/>
        <result column="value" property="value"/>
        <result column="key" property="key"/>
    </resultMap>
 
    <select id="lazyList" resultMap="menuVOResultMap">
        SELECT
        menu.*,
        (
        SELECT
        CASE WHEN count( 1 ) > 0 THEN 1 ELSE 0 END
        FROM
        pl_sys_menu
        WHERE
        parent_id = menu.id AND is_deleted = 0
        ) AS "has_children"
        FROM
        pl_sys_menu menu
        WHERE menu.is_deleted = 0
        <if test="param1!=null">
            and menu.parent_id = #{param1}
        </if>
        <if test="param2.name!=null and param2.name!=''">
            and menu.name like concat(concat('%', #{param2.name}),'%')
        </if>
        <if test="param2.code!=null and param2.code!=''">
            and menu.code like concat(concat('%', #{param2.code}),'%')
        </if>
        <if test="param2.alias!=null and param2.alias!=''">
            and menu.alias like concat(concat('%', #{param2.alias}),'%')
        </if>
        ORDER BY menu.sort
    </select>
 
    <select id="lazyMenuPage" resultMap="menuVOResultMap">
        SELECT
        menu.*,
        (
        SELECT
        CASE WHEN count( 1 ) > 0 THEN 1 ELSE 0 END
        FROM
        pl_sys_menu
        WHERE
        parent_id = menu.id AND is_deleted = 0 AND category = 1
        ) AS "has_children"
        FROM
        pl_sys_menu menu
        WHERE menu.is_deleted = 0 AND menu.category = 1
        <if test="param1!=null">
            and menu.parent_id = #{param1}
        </if>
        <if test="param2.name!=null and param2.name!=''">
            and menu.name like concat(concat('%', #{param2.name}),'%')
        </if>
        <if test="param2.code!=null and param2.code!=''">
            and menu.code like concat(concat('%', #{param2.code}),'%')
        </if>
        <if test="param2.alias!=null and param2.alias!=''">
            and menu.alias like concat(concat('%', #{param2.alias}),'%')
        </if>
        ORDER BY menu.sort
    </select>
 
    <select id="tree" resultMap="treeNodeResultMap">
        select id, parent_id, name as title, id as "value", id as "key"
        from pl_sys_menu
        where is_deleted = 0
          and category = 1
    </select>
 
    <select id="allMenu" resultMap="menuResultMap">
        select *
        from pl_sys_menu
        where is_deleted = 0
          and category = 1
    </select>
 
    <select id="roleMenu" resultMap="menuResultMap">
        select * from pl_sys_menu where is_deleted = 0 and id IN
        ( SELECT menu_id FROM pl_org_role_menu WHERE role_id IN
        <foreach collection="param1" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        )
        <if test="param2!=null and param2>0">
            AND id IN
            (
            SELECT menu_id FROM pl_sys_top_menu_setting WHERE top_menu_id = #{param2}
            )
        </if>
    </select>
 
    <select id="roleMenuByRoleId" resultMap="menuResultMap">
        select * from pl_sys_menu where is_deleted = 0 and id IN
        ( SELECT menu_id FROM pl_org_role_menu WHERE role_id IN
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        )
    </select>
 
    <select id="roleMenuByTopMenuId" resultMap="menuResultMap">
        select *
        from pl_sys_menu
        where is_deleted = 0
          and id IN
              (
                  SELECT menu_id
                  FROM pl_sys_top_menu_setting
                  WHERE top_menu_id = #{param1}
              )
    </select>
 
    <select id="routes" resultMap="menuResultMap">
        SELECT
        *
        FROM
        pl_sys_menu
        WHERE
        is_deleted = 0 and category = 1
        and id IN ( SELECT menu_id FROM pl_org_role_menu WHERE role_id IN
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        )
    </select>
 
    <select id="allButtons" resultMap="menuResultMap">
        SELECT id,
               parent_id,
               CODE,
               NAME,
               alias,
               path,
               source,
            action,
            sort
        FROM
            pl_sys_menu
        WHERE
            (
            category = 2
           OR id IN ( SELECT parent_id FROM pl_sys_menu WHERE is_deleted = 0
          AND category = 2 )
            )
          AND is_deleted = 0
        ORDER BY sort
    </select>
 
    <select id="buttons" resultMap="menuResultMap">
        SELECT * FROM (
        SELECT
        id,
        parent_id,
        code,
        name,
        alias,
        path,
        source,
        action,
        sort
        FROM
        pl_sys_menu
        WHERE
        is_deleted = 0 and id IN (
        SELECT parent_id FROM pl_sys_menu
        WHERE ( category = 2 AND id IN ( SELECT menu_id FROM pl_org_role_menu WHERE role_id IN
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        ) ) )
        UNION ALL
 
        SELECT
        id,
        parent_id,
        code,
        name,
        alias,
        path,
        source,
        action,
        sort
        FROM
        pl_sys_menu
        WHERE
        is_deleted = 0 and category = 2 AND id IN ( SELECT menu_id FROM pl_org_role_menu WHERE role_id IN
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>)
        ) menu ORDER BY sort
    </select>
 
    <select id="getButtonsByRoleIdAndCode" resultMap="menuResultMap">
        SELECT pm.*
        FROM PL_SYS_MENU ps,
        PL_SYS_MENU pm
        <if test="roleId != null and roleId != ''">
            ,PL_ORG_ROLE_MENU prom
        </if>
        WHERE
        ps."CATEGORY" = 1
        <if test="roleId != null and roleId != ''">
            AND pm.ID = prom.MENU_ID
            AND prom.ROLE_ID = #{roleId}
        </if>
        AND pm.IS_DELETED = 0
        <if test="code != null and code != ''">
            AND ps.ID = pm.PARENT_ID
            AND ps.CODE = #{code}
        </if>
        ORDER BY pm.SORT ASC
    </select>
 
    <select id="grantTree" resultMap="treeNodeResultMap">
        select id,
               parent_id,
               name as title,
               id   as "value",
               id   as "key"
        from pl_sys_menu
        where is_deleted = 0
        order by sort
    </select>
 
    <select id="grantTreeByRole" resultMap="treeNodeResultMap">
        select id, parent_id, name as title, id as "value", id as "key" from pl_sys_menu where is_deleted = 0
        and id in ( select menu_id from pl_org_role_menu where role_id in
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        )
        or id in (
        select parent_id from pl_sys_menu where is_deleted = 0
        and id in ( select menu_id from pl_org_role_menu where role_id in
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        )
        )
        order by sort
    </select>
 
    <select id="grantTopTree" resultMap="treeNodeResultMap">
        select id, parent_id, name as title, id as "value", id as "key"
        from pl_sys_menu
        where category = 1
          and is_deleted = 0
        order by sort
    </select>
 
    <select id="grantTopTreeByRole" resultMap="treeNodeResultMap">
        select id, parent_id, name as title, id as "value", id as "key" from pl_sys_menu where category = 1 and
        is_deleted = 0
        and id in ( select menu_id from pl_org_role_menu where role_id in
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        )
        or id in (
        select parent_id from pl_sys_menu where is_deleted = 0
        and id in ( select menu_id from pl_org_role_menu where role_id in
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        )
        )
        order by sort
    </select>
 
    <select id="grantDataScopeTree" resultMap="treeNodeResultMap">
        SELECT *
        FROM (
                 SELECT id,
                        parent_id,
                        NAME AS title,
                        id   AS "value",
                        id   AS "key"
                 FROM pl_sys_menu
                 WHERE category = 1
                   AND is_deleted = 0
                   AND id IN (SELECT menu_id FROM pl_auth_scope_data WHERE is_deleted = 0 AND menu_id IS NOT NULL)
             ) menu
 
        UNION ALL
 
        SELECT id,
               menu_id    AS parent_id,
               scope_name AS title,
               id         AS "value",
               id         AS "key"
        FROM pl_auth_scope_data
        WHERE is_deleted = 0
          AND menu_id IS NOT NULL
    </select>
 
    <select id="grantApiScopeTree" resultMap="treeNodeResultMap">
        SELECT *
        FROM (
                 SELECT id,
                        parent_id,
                        NAME AS title,
                        id   AS "value",
                        id   AS "key"
                 FROM pl_sys_menu
                 WHERE category = 1
                   AND is_deleted = 0
                   AND id IN (SELECT menu_id FROM pl_auth_scope_api WHERE is_deleted = 0 AND menu_id IS NOT NULL)
             ) menu
 
        UNION ALL
 
        SELECT id,
               menu_id    AS parent_id,
               scope_name AS title,
               id         AS "value",
               id         AS "key"
        FROM pl_auth_scope_api
        WHERE is_deleted = 0
          AND menu_id IS NOT NULL
    </select>
 
    <select id="grantDataScopeTreeByRole" resultMap="treeNodeResultMap">
        SELECT
        *
        FROM
        (
        SELECT
        id,
        parent_id,
        NAME AS title,
        id AS "value",
        id AS "key"
        FROM
        pl_sys_menu
        WHERE
        category = 1
        AND is_deleted = 0
        AND id IN ( SELECT menu_id FROM pl_auth_scope_data WHERE is_deleted = 0 AND menu_id IS NOT NULL )
        AND (
        id IN (
        select menu_id from pl_org_role_menu where role_id in
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        )
        OR id IN (
        select parent_id from pl_sys_menu where is_deleted = 0
        and id in ( select menu_id from pl_org_role_menu where role_id in
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        )
        )
        )
        ) menu
 
        UNION ALL
 
        SELECT
        id,
        menu_id AS parent_id,
        scope_name AS title,
        id AS "value",
        id AS "key"
        FROM
        pl_auth_scope_data
        WHERE
        is_deleted = 0
        AND (
        menu_id IN (
        select menu_id from pl_org_role_menu where role_id in
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        )
        OR menu_id IN (
        select parent_id from pl_sys_menu where is_deleted = 0
        and id in ( select menu_id from pl_org_role_menu where role_id in
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        )
        )
        )
        AND menu_id IS NOT NULL
    </select>
 
    <select id="grantApiScopeTreeByRole" resultMap="treeNodeResultMap">
        SELECT
        *
        FROM
        (
        SELECT
        id,
        parent_id,
        NAME AS title,
        id AS "value",
        id AS "key"
        FROM
        pl_sys_menu
        WHERE
        category = 1
        AND is_deleted = 0
        AND id IN ( SELECT menu_id FROM pl_auth_scope_api WHERE is_deleted = 0 AND menu_id IS NOT NULL )
        AND (
        id IN (
        select menu_id from pl_org_role_menu where role_id in
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        )
        OR id IN (
        select parent_id from pl_sys_menu where is_deleted = 0
        and id in (
        select menu_id from pl_org_role_menu where role_id in
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        )
        )
        )
        ) menu
 
        UNION ALL
 
        SELECT
        id,
        menu_id AS parent_id,
        scope_name AS title,
        id AS "value",
        id AS "key"
        FROM
        pl_auth_scope_api
        WHERE
        is_deleted = 0
        AND
        (
        menu_id IN (
        select menu_id from pl_org_role_menu where role_id in
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        )
        OR menu_id IN (
        select parent_id from pl_sys_menu where is_deleted = 0
        and id in ( select menu_id from pl_org_role_menu where role_id in
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        )
        )
        )
        AND menu_id IS NOT NULL
    </select>
 
    <select id="authRoutes" resultType="com.vci.ubcs.system.dto.MenuDTO">
        SELECT
        GROUP_CONCAT(r.role_alias) as alias,
        m.path
        FROM
        pl_org_role_menu rm
        LEFT JOIN pl_sys_menu m ON rm.menu_id = m.id
        LEFT JOIN pl_org_role r ON rm.role_id = r.id
        WHERE
        rm.role_id IN
        <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        AND m.path IS NOT NULL and m.is_deleted = 0
        GROUP BY m.path
    </select>
 
    <select id="selectMenuChildByBtnType" resultMap="menuResultMap">
        select pm.*
        from pl_sys_menu ps, pl_sys_menu pm
        where pm.is_deleted = 0
        and ps.category = 1
        and ps.CODE = #{btmType}
        and ps.ID = pm.PARENT_ID
        <if test="roleIds != null and roleIds != ''">
            and ps.ID in
            SELECT menu_id FROM pl_org_role_menu WHERE role_id IN
            <foreach collection="roleIds" index="index" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        order by pm.sort asc
    </select>
 
    <select id="getButtonByIdsOrByParentCode" resultMap="menuResultMap">
        SELECT
            pm.*
        FROM
            PL_SYS_MENU pm
            <if test="code != null and code != ''">
                ,PL_SYS_MENU ps
            </if>
            <if test="roleIds != null and roleIds != ''">
                ,PL_ORG_ROLE_MENU prom
            </if>
        WHERE
            pm.IS_DELETED = 0
            AND pm."CATEGORY" = 2
            <if test="code != null and code != ''">
                AND ps."CATEGORY" = 1
                AND ps.ID = pm.PARENT_ID
                AND ps.CODE = #{code}
            </if>
            <if test="roleIds != null and roleIds != ''">
                AND pm.ID = prom.MENU_ID
                AND prom.ROLE_ID in (#{roleIds})
            </if>
            <if test="ids != null and ids != ''">
                AND pm.ID IN
                <foreach collection="ids" index="index" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        ORDER BY SORT ASC
    </select>
 
</mapper>