<?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="com.fdage.dao.cust.TbResourceMapperCust">

  <select id="findAll" parameterType="java.lang.Long" resultMap="com.fdage.dao.base.TbResourceMapper.BaseResultMap">
    select 
    <include refid="com.fdage.dao.base.TbResourceMapper.Base_Column_List" />
    from tb_resource WHERE rec_status = 'A'
  </select>

  <select id="findResourceByUserId" parameterType="java.lang.Long" resultMap="com.fdage.dao.base.TbResourceMapper.BaseResultMap">
    select b.id, b.name, b.parent_id, b.resource_type, b.resource_key from
      ((tb_user u left join tb_user_role ur on u.id = ur.user_id)
      join tb_role r on r.id = ur.role_id)
      join tb_role_resource a on r.id = a.role_id
      join tb_resource b on b.id = a.resource_id WHERE u.id = #{userId}
  </select>

  <select id="findResourceByRoleId" parameterType="java.lang.Long" resultMap="com.fdage.dao.base.TbResourceMapper.BaseResultMap">
    SELECT b.id, b.name, b.parent_id, b.resource_type, b.resource_key FROM
        tb_role_resource a
        JOIN tb_resource b ON b.id = a.resource_id WHERE a.role_id = #{roleId}
  </select>

</mapper>