RoleMapper.xml 6.5 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.RoleMapper">
    <resultMap id="BaseResultMap" type="cn.com.glsx.shield.modules.entity.Role">
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="role_name" jdbcType="VARCHAR" property="roleName"/>
        <result column="role_permission_type" jdbcType="TINYINT" property="rolePermissionType"/>
        <result column="max_user" jdbcType="INTEGER" property="maxUser"/>
        <result column="repel_roles" jdbcType="VARCHAR" property="repelRoles"/>
        <result column="remark" jdbcType="VARCHAR" property="remark"/>
        <result column="tenant_id" jdbcType="INTEGER" property="tenantId"/>
        <result column="role_visibility" jdbcType="INTEGER" property="roleVisibility"/>
        <!--        <result column="role_tenants" jdbcType="VARCHAR" property="roleTenants"/>-->
        <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>
    <sql id="Base_Column_List">
        id
        , role_name, role_permission_type, max_user, repel_roles,
        remark, tenant_id, role_visibility, 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_role
        where del_flag = 0
        and id = #{id}
    </select>

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

    <select id="selectList" resultMap="BaseResultMap"
            parameterType="cn.com.glsx.shield.modules.model.param.RoleSearch">
        select
        <include refid="Base_Column_List"/>
        from t_role
        where del_flag = 0
        <if test="roleName != null and roleName != ''">
            and role_name like concat('%',#{roleName},'%')
        </if>
        <if test="enableStatus != null">
            and enable_status = #{enableStatus}
        </if>
        <if test="roleVisibility != null">
            and role_visibility = #{roleVisibility}
        </if>
        order by id desc
    </select>

    <select id="selectAssignTenantsList" resultMap="BaseResultMap"
            parameterType="cn.com.glsx.shield.modules.model.param.RoleSearch">
        select * from (
        select tr1.*
        from t_role tr1
        where tr1.del_flag = 0
        and tr1.role_visibility = 0
        union
        select tr.*
        from t_role tr,
        t_role_tenant trt
        where tr.del_flag = 0
        and trt.del_flag = 0
        and tr.role_visibility = 2
        and tr.id = trt.role_id
        and trt.tenant_id in (select trdp.ref_id from t_role_data_permission trdp where trdp.type = 0 and trdp.role_id =
        #{roleId})
        ) tall where 1=1
        <if test="roleName != null and roleName != ''">
            and role_name like concat('%',#{roleName},'%')
        </if>
        <if test="enableStatus != null">
            and enable_status = #{enableStatus}
        </if>
        order by id desc
    </select>

    <select id="selectVisibilityList" resultMap="BaseResultMap"
            parameterType="cn.com.glsx.shield.modules.model.param.RoleSearch">
        select * from (
        select tr1.*
        from t_role tr1
        where tr1.del_flag = 0
        and tr1.role_visibility = 0
        union
        select tr.*
        from t_role tr,
        t_role_tenant trt
        where tr.del_flag = 0
        and trt.del_flag = 0
        and tr.role_visibility = 2
        and tr.id = trt.role_id
        and trt.tenant_id in
        <foreach collection="tenantIds" open="(" close=")" separator="," item="tenantId">
            #{tenantId}
        </foreach>
        ) tall where 1=1
        <if test="roleName != null and roleName != ''">
            and role_name like concat('%',#{roleName},'%')
        </if>
        <if test="enableStatus != null">
            and enable_status = #{enableStatus}
        </if>
        order by id desc
    </select>

    <select id="selectByIds" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_role
        where del_flag = 0
        and id in
        <foreach collection="ids" open="(" close=")" separator="," item="id">
            #{id}
        </foreach>
    </select>

    <select id="selectUserRoleList" resultType="cn.com.glsx.shield.modules.entity.Role">
        select r.id id, r.role_name roleName, r.role_permission_type rolePermissionType
        from t_role r,
             t_user_role_relation urr
        where r.del_flag = 0
          and urr.del_flag = 0
          and r.role_id = urr.role_id
          and urr.user_id = #{userId}
    </select>

    <select id="selectCntByName" resultType="java.lang.Integer">
        select count(role_name)
        from t_role
        where del_flag = 0
          and role_name = #{roleName}
    </select>

    <select id="selectByName" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_role
        where del_flag = 0
        and role_name = #{roleName}
        limit 1
    </select>

    <select id="selectByVisibilityType" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from t_role
        where del_flag = 0
        and enable_status = 1
        and role_visibility = #{roleVisibility}
    </select>

    <select id="selectRoleIdsByVisibilityType" resultMap="BaseResultMap">
        select id
        from t_role
        where del_flag = 0
          and enable_status = 1
          and role_visibility = #{roleVisibility}
    </select>

    <select id="selectByTenantIds" resultMap="BaseResultMap">
        select tr.*
        from t_role tr,t_role_tenant trt
        where tr.del_flag = 0
        and trt.del_flag = 0
        and tr.enable_status = 1
        and tr.id = trt.role_id
        and trt.tenant_id in
        <foreach collection="tenantIds" open="(" close=")" separator="," item="tenantId">
            #{tenantId}
        </foreach>
        order by tr.id
    </select>
</mapper>