zhangherong
2025-06-25 23855599412c4d61b38d78f0f3abd3430a48b5b1
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/mapper/xml/ComponentInfoMapper.xml
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,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>