<?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.lightinit.hsdataplatform.mapper.SentryRoleActionMapper">
  <resultMap id="BaseResultMap" type="com.lightinit.hsdataplatform.entity.SentryRoleAction">
    <result column="menucode" jdbcType="VARCHAR" property="menucode" />
    <result column="rolecode" jdbcType="VARCHAR" property="rolecode" />
    <result column="actioncode" jdbcType="VARCHAR" property="actioncode" />
  </resultMap>
  <select id="selectSentryRoleAction" parameterType="java.lang.String" resultMap="BaseResultMap">
    SELECT m.menucode,r.rolecode,a.action_code actioncode,a.id actionId FROM menu m JOIN role_module rm ON m.id=rm.moduleid JOIN sentry_role r ON r.id=rm.roleid LEFT JOIN role_module_action rma ON rm.id=rma.rolemoduleid LEFT JOIN module_action a ON a.id=rma.actionid
    <if test="roles!=null and roles.size()>0">
      <where>
        r.rolecode IN  <foreach collection="roles" item="item" index="index" open="(" separator="," close=")">#{item}</foreach>
      </where>
    </if>
  </select>
  <select id="selectSentryRoleActionByMenu" parameterType="map" resultMap="BaseResultMap">
    SELECT m.menucode,r.rolecode,a.action_code actioncode,a.id actionId FROM menu m JOIN role_module rm ON m.id=rm.moduleid JOIN sentry_role r ON r.id=rm.roleid JOIN role_module_action rma ON rm.id=rma.rolemoduleid JOIN module_action a ON a.id=rma.actionid
     <where>
        m.menucode=#{code,jdbcType=VARCHAR}
        <if test="roles!=null and roles.size()>0">
          and r.rolecode IN  <foreach collection="roles" item="item" index="index" open="(" separator="," close=")">#{item}</foreach>
        </if>
     </where>
  </select>
</mapper>