<?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.ruoyi.base.mapper.BaseRightsMapper">
    
    <resultMap type="BaseRights" id="BaseRightsResult">
        <result property="id"    column="id"    />
        <result property="userType"    column="user_type"    />
        <result property="code"    column="code"    />
        <result property="name"    column="name"    />
        <result property="image"    column="image"    />
        <result property="sort"    column="sort"    />
        <result property="rightsType"    column="rights_type"    />
        <result property="rightsCycle"    column="rights_cycle"    />
        <result property="remark"    column="remark"    />
        <result property="creator"    column="creator"    />
        <result property="createTime"    column="create_time"    />
        <result property="updater"    column="updater"    />
        <result property="updateTime"    column="update_time"    />
        <result property="delFlag"    column="del_flag"    />
    </resultMap>

    <sql id="selectBaseRightsVo">
        select id, user_type, code, name, image, sort, rights_type, rights_cycle, remark, creator, create_time, updater, update_time, del_flag from dl_base_rights
    </sql>

    <select id="queryListPage" parameterType="BaseRights" resultMap="BaseRightsResult">
        <include refid="selectBaseRightsVo"/>
        <where>
del_flag=0
                        <if test="entity.userType != null  and entity.userType != ''"> and user_type = #{entity.userType}</if>
                        <if test="entity.code != null  and entity.code != ''"> and code = #{entity.code}</if>
                        <if test="entity.name != null  and entity.name != ''"> and name like concat('%', #{entity.name}, '%')</if>
                        <if test="entity.rightsType != null  and entity.rightsType != ''"> and rights_type = #{entity.rightsType}</if>
                        <if test="entity.rightsCycle != null  and entity.rightsCycle != ''"> and rights_cycle = #{entity.rightsCycle}</if>
        </where>
        order by user_type,sort asc,create_time asc
    </select>
    <select id="rightList" resultType="com.ruoyi.base.vo.CardRightsVO">
        SELECT
            main.id AS id,
            main.`name` AS name,
            main.rights_type as rightsType,
            dbcr.rights_value AS rightsValue,
            dbcr.card_id AS cardId,
            dbc.card_name AS cardName
        FROM
            dl_base_rights main
                LEFT JOIN dl_base_card_rights dbcr ON dbcr.rights_id = main.id AND dbcr.del_flag = 0
                LEFT JOIN dl_base_card dbc ON dbcr.card_id = dbc.id AND dbc.del_flag = 0
        WHERE
            main.user_type = #{userType}
          AND main.del_flag = 0
        ORDER BY dbc.sort,main.sort ASC
    </select>
</mapper>