<?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.hz.pm.api.sys.mapper.RoleMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hz.pm.api.sys.model.entity.Role">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="created_by" jdbcType="BIGINT" property="createBy"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createOn"/>
        <result column="updated_by" jdbcType="BIGINT" property="updateBy"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateOn"/>
        <result column="manage_role_id" jdbcType="VARCHAR" property="manageRoleId"/>
        <result column="name" jdbcType="VARCHAR" property="name"/>
        <result column="code" jdbcType="VARCHAR" property="code"/>
        <result column="describe_" jdbcType="VARCHAR" property="describe"/>
    </resultMap>

    <select id="findRoleByUserId" parameterType="map" resultMap="BaseResultMap">
        select r.* from nd_role r INNER JOIN nd_user_role ur on r.id = ur.role_id
        where ur.user_id = #{userId}
    </select>


    <select id="findUserIdByCode" parameterType="map" resultType="java.lang.Long">
        select ur.user_id from nd_user_role ur INNER JOIN nd_role r on r.id = ur.role_id
        where and r.`code` in
        <foreach close=")" collection="codes" item="code" open="(" separator=",">
            #{code}
        </foreach>
    </select>

</mapper>
