<?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.BaseCardRightsMapper">
    
    <resultMap type="BaseCardRights" id="BaseCardRightsResult">
        <result property="id"    column="id"    />
        <result property="cardId"    column="card_id"    />
        <result property="rightsId"    column="rights_id"    />
        <result property="rightsValue"    column="rights_value"    />
        <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="selectBaseCardRightsVo">
        select id, card_id, rights_id, rights_value, creator, create_time, updater, update_time, del_flag from dl_base_card_rights
    </sql>
    <update id="removeByCardId">
        UPDATE dl_base_card_rights
        SET del_flag = 1
        WHERE
            card_id = #{cardId}
    </update>

    <select id="queryListPage" parameterType="BaseCardRights" resultMap="BaseCardRightsResult">
        <include refid="selectBaseCardRightsVo"/>
        <where>
                        <if test="entity.rightsId != null  and entity.rightsId != ''"> and rights_id = #{entity.rightsId}</if>
        </where>
    </select>
    <select id="getByIdAndType" resultType="com.ruoyi.base.vo.CardRightsVO">
        SELECT
            dbr.*,
            dbcr.card_id,
            dbcr.rights_value
        FROM
            dl_base_rights dbr
                LEFT JOIN dl_base_card_rights dbcr ON dbr.id = dbcr.rights_id
                AND dbcr.del_flag = 0
                AND dbcr.card_id = #{cardId}
        WHERE
            dbr.del_flag = 0
          AND dbr.user_type = #{userType}
          AND dbr.id IS NOT NULL
        ORDER BY dbr.sort,dbr.create_time
    </select>
    <select id="queryByCardId" resultType="com.ruoyi.base.vo.CardRightsVO">
        SELECT
            dbr.*,
            dbcr.card_id,
            dbcr.rights_value
        FROM
            dl_base_rights dbr
                LEFT JOIN dl_base_card_rights dbcr ON dbr.id = dbcr.rights_id
                AND dbcr.del_flag = 0
        WHERE
            dbr.del_flag = 0
          AND dbcr.card_id = #{cardId}
        ORDER BY dbr.sort,dbr.create_time
    </select>

</mapper>