lyh
2025-06-16 24e0bdd24a10449c98013cdb5bcc5e37735f5a91
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
<?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.ComponentInfoMapper">
 
    <!--
        1、mybatis自动开启驼峰标识转换 menu_name 自动转为menuName
        2、实体类如果为扩展类型,需要加入id标签 标识id字段类 不然id对应的字段无法赋值
        3、多级关联语句是分开查询的  数据量大的情况下性能低下
        4、如果确定级树 可以使用级联查询一次查询 例子:
    -->
    <resultMap id="componentExtBaseMap" type="org.jeecg.modules.dnc.dto.ComponentExt">
        <id column="component_id"  property="componentId" />
        <collection column="component_id" property="children" select="findByParentId">
        </collection>
    </resultMap>
 
    <resultMap id="componentExtPermsMap" type="org.jeecg.modules.dnc.dto.ComponentExt">
        <id column="component_id"  property="componentId" />
        <result column="user_id" property="userId" />
        <association property="parent" column="{id=parent_id}" select="findById">
        </association>
        <collection column="{parentId=component_id, userId=user_id}" property="children"
                    javaType="ArrayList" ofType="org.jeecg.modules.dnc.dto.ComponentExt" select="getByParentIdAndUserPerms">
            <id column="component_id"  property="componentId" />
            <result column="user_id" property="userId" />
        </collection>
    </resultMap>
 
    <resultMap id="componentExtPermsMapAs" type="org.jeecg.modules.dnc.dto.ComponentExt">
        <id column="component_id"  property="componentId" />
        <association property="parent" column="{id=parent_id}" select="findById">
        </association>
    </resultMap>
 
    <select id="findExtAll" resultMap="componentExtBaseMap">
       select component_id
        , parent_id
        , product_id
        , component_name
        , materiel_code
        , materiel_desp
        , component_model
        , component_scale
        , component_weight
        , rank_level
        , assemble_type
        , produce_type
        , process_type
        , structure_type
        , component_code
        , component_status
        , description
        from nc_component_info
        where rank_level=1 and delete_flag = 0
    </select>
 
    <select id="findByParentId" resultMap="componentExtBaseMap">
        select component_id
        , parent_id
        , product_id
        , component_name
        , materiel_code
        , materiel_desp
        , component_model
        , component_scale
        , component_weight
        , rank_level
        , assemble_type
        , produce_type
        , process_type
        , structure_type
        , component_code
        , component_status
        , description
        from nc_component_info
        where delete_flag = 0 and parent_id=#{parentId}
    </select>
 
    <select id="getByUserPerms" resultMap="componentExtPermsMap" parameterType="String">
       select comp.component_id
        , comp.parent_id
        , comp.product_id
        , comp.component_name
        , comp.materiel_code
        , comp.materiel_desp
        , comp.component_model
        , comp.component_scale
        , comp.component_weight
        , comp.rank_level
        , comp.assemble_type
        , comp.produce_type
        , comp.process_type
        , comp.structure_type
        , comp.component_code
        , comp.component_status
        , comp.description
        , s.user_id
        from nc_component_info comp
        inner join
        (select distinct component_id, user_id from nc_permission_stream where delete_flag = 0 and user_id=#{userId}) s
        on comp.component_id=s.component_id
        where rank_level=1 and delete_flag = 0
    </select>
 
    <select id="getByUserPermsAs" resultMap="componentExtPermsMapAs" parameterType="String">
       select comp.component_id
        , comp.parent_id
        , comp.product_id
        , comp.component_name
        , comp.materiel_code
        , comp.materiel_desp
        , comp.component_model
        , comp.component_scale
        , comp.component_weight
        , comp.rank_level
        , comp.assemble_type
        , comp.produce_type
        , comp.process_type
        , comp.structure_type
        , comp.component_code
        , comp.component_status
        , comp.description
        , comp.create_time
        , comp.update_time
        , comp.update_by
        , comp.create_by
        , (select sys_user.realname from sys_user where comp.create_by=sys_user.username) as createName
        , (select sys_user.realname from sys_user where comp.update_by=sys_user.username) as updateName
        from nc_component_info comp
        inner join
             (select business_id,business_type from nc_permission_stream_new where delete_flag = 0 and user_id=#{userId}) s
             on comp.component_id = s.business_id and s.business_type='2'
        where delete_flag = 0
    </select>
 
    <select id="getByParentIdAndUserPerms" resultMap="componentExtPermsMap" parameterType="java.util.Map">
        select comp.component_id
        , comp.parent_id
        , comp.product_id
        , comp.component_name
        , comp.materiel_code
        , comp.materiel_desp
        , comp.component_model
        , comp.component_scale
        , comp.component_weight
        , comp.rank_level
        , comp.assemble_type
        , comp.produce_type
        , comp.process_type
        , comp.structure_type
        , comp.component_code
        , comp.component_status
        , comp.description
        , s.user_id
        from nc_component_info comp
        inner join
        (select distinct component_id, user_id from nc_permission_stream where delete_flag = 0 and user_id=#{userId}) s
        on comp.component_id=s.component_id
        where delete_flag = 0 and parent_id=#{parentId}
    </select>
    <select id="findComponentHierarchy" resultType="org.jeecg.modules.dnc.entity.ComponentInfo">
        WITH component_tree AS (
            SELECT
                *,
                0 AS LEVEL
            FROM
                nc_component_info
            WHERE
                component_id = #{componentId} UNION ALL
            SELECT
                c.*,
                ct.level + 1
            FROM
                nc_component_info c
                    INNER JOIN component_tree ct ON c.component_id = ct.parent_id
        ) SELECT
            *
        FROM
            component_tree
        ORDER BY
            LEVEL ASC
    </select>
</mapper>