MenuMapper.xml 8.48 KB
<?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="cn.com.glsx.shield.modules.mapper.MenuMapper">
    <resultMap id="BaseResultMap" type="cn.com.glsx.shield.modules.entity.Menu">
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="menu_no" jdbcType="INTEGER" property="menuNo"/>
        <result column="menu_name" jdbcType="VARCHAR" property="menuName"/>
        <result column="front_route" jdbcType="VARCHAR" property="frontRoute"/>
        <result column="permission_tag" jdbcType="VARCHAR" property="permissionTag"/>
        <result column="parent_id" jdbcType="INTEGER" property="parentId"/>
        <result column="type" jdbcType="TINYINT" property="type"/>
        <result column="icon" jdbcType="VARCHAR" property="icon"/>
        <result column="order_num" jdbcType="INTEGER" property="orderNum"/>
        <result column="enable_status" jdbcType="TINYINT" property="enableStatus"/>
        <result column="del_flag" jdbcType="TINYINT" property="delFlag"/>
        <result column="created_date" jdbcType="TIMESTAMP" property="createdDate"/>
        <result column="created_by" jdbcType="INTEGER" property="createdBy"/>
        <result column="updated_date" jdbcType="TIMESTAMP" property="updatedDate"/>
        <result column="updated_by" jdbcType="INTEGER" property="updatedBy"/>
    </resultMap>
    <resultMap id="DTOResultMap" type="cn.com.glsx.shield.modules.model.view.MenuDTO">
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="menu_no" jdbcType="INTEGER" property="menuNo"/>
        <result column="menu_name" jdbcType="VARCHAR" property="menuName"/>
        <result column="front_route" jdbcType="VARCHAR" property="frontRoute"/>
        <result column="permission_tag" jdbcType="VARCHAR" property="permissionTag"/>
        <result column="parent_id" jdbcType="INTEGER" property="parentId"/>
        <result column="type" jdbcType="TINYINT" property="type"/>
        <result column="icon" jdbcType="VARCHAR" property="icon"/>
        <result column="order_num" jdbcType="INTEGER" property="orderNum"/>
        <result column="enable_status" jdbcType="TINYINT" property="enableStatus"/>
    </resultMap>

    <sql id="Base_Column_List">
        id
        , menu_no, menu_name, front_route, permission_tag, parent_id, `type`, icon, order_num, enable_status,
        del_flag, created_date, created_by, updated_date, updated_by
    </sql>

    <select id="selectById" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_menu
        where id = #{id}
        and del_flag = 0
    </select>

    <select id="selectByMenuNo" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_menu
        where menu_no = #{menuNo}
        and del_flag = 0
    </select>

    <update id="logicDeleteById">
        update t_menu
        set del_flag = -1
        where id = #{id}
    </update>

    <select id="search" resultMap="DTOResultMap">
        select distinct tm.id,tm.menu_no,tm.menu_name,tm.front_route,tm.permission_tag,
        tm.parent_id,tm.type,tm.icon,tm.order_num,tm.enable_status
        from t_menu tm
        left join t_role_menu trm on trm.menu_id = tm.menu_no
        where tm.del_flag = 0 and trm.del_flag = 0
        <if test="name != null and name != ''">
            and tm.menu_name LIKE CONCAT('%',#{name},'%')
        </if>
        <if test="enableStatus != null">
            and tm.enable_status = #{enableStatus}
        </if>
        <choose>
            <when test="parentId !=null">
                and tm.parent_id LIKE CONCAT(#{parentId},'%')
            </when>
            <otherwise>
                and tm.type = 1
            </otherwise>
        </choose>
        and trm.role_id in
        <foreach collection="roleIds" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        order by tm.order_num
    </select>

    <select id="selectChildren" resultMap="DTOResultMap">
        select distinct tm.id,tm.menu_no,tm.menu_name,tm.front_route,tm.permission_tag,
        tm.parent_id,tm.type,tm.icon,tm.order_num,tm.enable_status
        from t_menu tm
        left join t_role_menu trm on trm.menu_id = tm.menu_no
        where tm.del_flag = 0 and trm.del_flag = 0
        and tm.parent_id = #{parentId}
        <if test="name != null and name != ''">
            and tm.menu_name LIKE CONCAT('%',#{name},'%')
        </if>
        <if test="enableStatus != null">
            and tm.enable_status = #{enableStatus}
        </if>
        and trm.role_id in
        <foreach collection="roleIds" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        order by tm.order_num
    </select>

    <select id="selectMenuFullTree" resultType="cn.com.glsx.shield.modules.model.MenuModel">
        select m.menu_no menuNo, m.parent_id parentId, m.menu_name menuName, m.order_num orderNum, m.type, m.icon
        from t_menu m
        where m.del_flag = 0
          and m.enable_status = 1
    </select>

    <select id="selectMenuPermTree" resultType="cn.com.glsx.shield.modules.model.MenuModel">
        select m.menu_no menuNo,m.parent_id parentId,m.menu_name menuName,m.order_num orderNum,
        m.type,m.front_route frontRoute,m.icon
        from t_menu m,t_role_menu rm
        where m.menu_no = rm.menu_id
        and m.del_flag = 0
        and rm.del_flag = 0
        and m.enable_status = 1
        <if test="roleIds != null and roleIds.size() > 0">
            and rm.role_id in
            <foreach collection="roleIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="menuIds != null and menuIds.size() > 0">
            and m.id in
            <foreach collection="menuIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="menuTypes != null and menuTypes.size() > 0">
            and m.type in
            <foreach collection="menuTypes" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
    </select>

    <select id="selectMenuTreeByParentId" resultType="cn.com.glsx.shield.modules.model.MenuModel">
        select m.menu_no menuNo,m.parent_id parentId,
        m.menu_name menuName,
        m.permission_tag permissionTag,
        m.order_num orderNum,m.type,m.icon
        from t_menu m,t_role_menu rm
        where m.menu_no = rm.menu_id
        and m.del_flag = 0
        and rm.del_flag = 0
        and m.enable_status = 1
        <if test="roleIds != null and roleIds.size() > 0">
            and rm.role_id in
            <foreach collection="roleIds" item="roleId" open="(" close=")" separator=",">
                #{roleId}
            </foreach>
        </if>
        and m.parent_id = #{parentNo}
    </select>

    <select id="selectByParentId" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_menu
        where parent_id = #{parentNo}
        and del_flag = 0
        order by order_num
    </select>

    <select id="selectByLikeParentNo" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_menu
        where menu_no like #{parentNo}
        and del_flag = 0
        order by order_num
    </select>

    <select id="selectChildrenCntByParentId" resultType="java.lang.Integer">
        select count(1)
        from t_menu
        where parent_id = #{parentNo}
          and del_flag = 0
    </select>

    <select id="getMenuByPermissionTag" resultType="cn.com.glsx.usercenter.api.dto.response.MenuDto">
        select turr.user_id as userId ,
        turr.role_id as roleId,
        tm.menu_no as menuNo,
        tm.menu_name as menuName,
        tm.permission_tag as permissionTag
        from t_role_menu trm
        left join t_menu tm on trm.menu_id = tm.menu_no
        left join t_user_role_relation turr on trm.role_id = turr.role_id
        where trm.del_flag = 0
        and tm.del_flag=0
        and turr.del_flag = 0
        and tm.enable_status = 1
        <if test="permissionTag != null and permissionTag != ''">
            and tm.permission_tag =#{permissionTag}
        </if>
        <if test="userIds != null and userIds.size() > 0">
            and turr.user_id in
            <foreach collection="userIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
    </select>
</mapper>