lyh
2025-01-16 700ac5685214d37f128b3ad3dfda59e80381b9f6
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
<?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="org.jeecg.modules.dnc.mapper.MenuMapper">
    <select id="findByUserId" parameterType="String" resultType="org.jeecg.modules.dnc.entity.Menu">
        select m.menu_id
        , m.perm_code
        , m.menu_name
        , m.parent_id
        , m.menu_url
        , m.icon_cls
        , m.priority
        , m.rank_level
        from sys_menu m left join sys_menu_permission p on m.menu_id=p.menu_id
        left join sys_role r on p.role_id=r.id
        left join sys_user_role u
        on u.role_id=r.role_id
        ${ew.customSqlSegment}
    </select>
 
    <!--
        1、mybatis自动开启驼峰标识转换 menu_name 自动转为menuName
        2、实体类如果为扩展类型,需要加入id标签 标识id字段类 不然id对应的字段无法赋值
        3、多级关联语句是分开查询的  数据量大的情况下性能低下
        4、如果确定级树 可以使用级联查询一次查询 例子:
    -->
    <resultMap id="menuExtBaseResult" type="org.jeecg.modules.dnc.ext.MenuExt">
        <id column="menu_id"  property="menuId" />
        <collection column="menu_id" property="childList" select="findByParentId">
        </collection>
    </resultMap>
 
    <resultMap id="menuExtSingleSelectResult" type="org.jeecg.modules.dnc.ext.MenuExt">
        <id column="menu_id_one"  property="menuId" />
        <result column="perm_code_one" property="permCode" />
        <result column="menu_name_one" property="menuName" />
        <result column="parent_id_one" property="parentId" />
        <result column="menu_url_one" property="menuUrl" />
        <result column="icon_cls_one" property="iconCls" />
        <result column="priority_one" property="priority" />
        <result column="rank_level_one" property="rankLevel" />
        <collection  property="childList" ofType="org.jeecg.modules.dnc.ext.MenuExt">
            <id column="menu_id_two"  property="menuId" />
            <result column="perm_code_two" property="permCode" />
            <result column="menu_name_two" property="menuName" />
            <result column="parent_id_two" property="parentId" />
            <result column="menu_url_two" property="menuUrl" />
            <result column="icon_cls_two" property="iconCls" />
            <result column="priority_two" property="priority" />
            <result column="rank_level_two" property="rankLevel" />
            <collection  property="childList" ofType="org.jeecg.modules.dnc.ext.MenuExt">
                <id column="menu_id_three"  property="menuId" />
                <result column="perm_code_three" property="permCode" />
                <result column="menu_name_three" property="menuName" />
                <result column="parent_id_three" property="parentId" />
                <result column="menu_url_three" property="menuUrl" />
                <result column="icon_cls_three" property="iconCls" />
                <result column="priority_three" property="priority" />
                <result column="rank_level_three" property="rankLevel" />
            </collection>
        </collection>
    </resultMap>
 
    <select id="findExtAll" resultMap="menuExtBaseResult">
        select menu_id
        , perm_code
        , menu_name
        , parent_id
        , menu_url
        , icon_cls
        , priority
        , rank_level
        from sys_menu
        where rank_level=1
    </select>
 
    <select id="findByParentId" resultMap="menuExtBaseResult">
        select menu_id
        , perm_code
        , menu_name
        , parent_id
        , menu_url
        , icon_cls
        , priority
        , rank_level
        from sys_menu
        where parent_id=#{parentId}
    </select>
 
    <select id="findExtAllBySingleSelect" resultMap="menuExtSingleSelectResult">
        select am.menu_id as menu_id_one
        , am.perm_code as perm_code_one
        , am.menu_name as menu_name_one
        , am.parent_id as parent_id_one
        , am.menu_url as menu_url_one
        , am.icon_cls as icon_cls_one
        , am.priority as priority_one
        , am.rank_level as rank_level_one
 
        , bm.menu_id as menu_id_two
        , bm.perm_code as perm_code_two
        , bm.menu_name as menu_name_two
        , bm.parent_id as parent_id_two
        , bm.menu_url as menu_url_two
        , bm.icon_cls as icon_cls_two
        , bm.priority as priority_two
        , bm.rank_level as rank_level_two
 
        , cm.menu_id as menu_id_three
        , cm.perm_code as perm_code_three
        , cm.menu_name as menu_name_three
        , cm.parent_id as parent_id_three
        , cm.menu_url as menu_url_three
        , cm.icon_cls as icon_cls_three
        , cm.priority as priority_three
        , cm.rank_level as rank_level_three
        from sys_menu am
        left join (select * from sys_menu where delete_flag=0) bm
        on bm.parent_id = am.menu_id
        left join (select * from sys_menu where delete_flag=0) cm
        on cm.parent_id = bm.menu_id
        where am.rank_level=1 and am.delete_flag=0
    </select>
</mapper>