<?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.jumeirah.common.mapper.MerchantRolePermissionMapper">

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, role_id, permission_id, state, remark, version, create_time, update_time
    </sql>

    <select id="getMerchantRolePermissionById" resultType="com.jumeirah.common.vo.MerchantRolePermissionQueryVo">
        select
        <include refid="Base_Column_List"/>
        from merchant_role_permission where id = #{id}
    </select>

    <select id="getPermissionCodesByRoleId" resultType="java.lang.String">
        select p.code
        from merchant_role r
                 inner join merchant_role_permission rp
                            on r.id = rp.role_id
                 inner join merchant_permission p
                            on rp.permission_id = p.id
        where r.state = 1
          and rp.state = 1
          and p.state = 1
          and r.id = #{roleId};
    </select>

    <select id="getMerchantRolePermissionPageList"
            parameterType="com.jumeirah.common.param.MerchantRolePermissionPageParam"
            resultType="com.jumeirah.common.vo.MerchantRolePermissionQueryVo">
        select
        <include refid="Base_Column_List"/>
        from merchant_role_permission
    </select>

</mapper>
