<?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.ey.biz.module.system.dal.mapper.permission.DataRoleMapper">


 <select id="selectDataRoles" resultType="cn.ey.biz.module.system.controller.admin.permission.vo.role.RoleSimpleDataRespVO">
     SELECT a.id,a.name as roleName,s.app_code as appName,s.app_name as appName
     FROM(
     SELECT id, name,app FROM system_data_role WHERE deleted=0
     ) a
     LEFT JOIN system_app s
     on a.app=s.app_code
     <where>
         <if test="roleName != null and roleName!=''">
             a.name like   concat('%',#{roleName},'%')
         </if>
         <if test="appName != null and appName!=''">
             and s.app_name like  concat('%',#{appName},'%')
         </if>
     </where>
 </select>

    <select id="getUserDataRole" resultType="cn.ey.biz.module.system.dal.dataobject.permission.DataRoleDO">
        select
        dr.id,
        dr.name,
        dr.app,
        dr.sl,
        dr.mr,
        dr.note as 'explain',
        dr.type
        from system_data_role dr
        LEFT JOIN system_user_data_role udr on udr.role_id=dr.id
        where dr.deleted=0
        and udr.deleted=0
        <if test="userId != null and userId!=''">
            and udr.user_id=#{userId}
        </if>
    </select>

</mapper>

