<?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.MerchantUserPermissionMapper">
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
                                id, user_id, permission_id, state, remark, version, create_time, update_time

    </sql>

    <select id="getPermissionCodesByUserId" resultType="java.lang.String">
                                SELECT
                                    mp.CODE
                                FROM
                                    merchant_user_permission mup
                                    INNER JOIN merchant_permission mp ON mp.id = mup.permission_id
                                WHERE
                                    mup.user_id = #{userId}
    </select>

    <select id="getMerchantUserPermissionByUserId"
            resultType="com.jumeirah.common.param.MerchantUserPermissionDetailVo">


                            SELECT
                            mp.id AS permissionId,
                            mp.name as permissionName,
                            mp.code as permissionCode,
                        CASE
                                WHEN ISNULL( mup.id ) THEN
                                0 ELSE 1
                            END AS isHasPermission
                        FROM
                            merchant_permission mp
                            LEFT JOIN ( SELECT mup.id, mup.permission_id FROM merchant_user_permission mup WHERE mup.user_id =  #{userId} ) AS mup ON mup.permission_id = mp.id




    </select>

    <select id="getMerchantUserPermissionById" resultType="com.jumeirah.common.param.MerchantUserPermissionQueryVo">
        select
        <include refid="Base_Column_List"/>
        from merchant_user_permission where id = #{id}
    </select>

    <select id="getMerchantUserPermissionPageList"
            parameterType="com.jumeirah.common.param.MerchantUserPermissionPageParam"
            resultType="com.jumeirah.common.param.MerchantUserPermissionQueryVo">
        select
        <include refid="Base_Column_List"/>
        from merchant_user_permission
    </select>
</mapper>
