<?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.member.mapper.MemberCardMapper">

    <resultMap type="MemberCard" id="MemberCardResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="userType"    column="user_type"    />
        <result property="cardId"    column="card_id"    />
        <result property="startDate"    column="start_date"    />
        <result property="endDate"    column="end_date"    />
        <result property="orderId"    column="order_id"    />
        <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="selectMemberCardVo">
        select id, user_id, user_type, card_id, start_date, end_date, order_id, creator, create_time, updater, update_time, del_flag from dl_member_card
    </sql>
    <select id="selectCardIdByUserId" resultType="com.ruoyi.member.domain.MemberCard">
        SELECT
        dmc.id,
        dmc.user_id,
        dmc.user_type,
        dmc.card_id
        FROM
        dl_member_card dmc
        WHERE
        dmc.del_flag = 0
          <if test="userId!=null">
              AND dmc.user_id = #{userId}
          </if>
        <if test="userType!=null and userType!=''">
            AND dmc.user_type = #{userType}
        </if>
        <if test="nowDate!=null and nowDate!=''">
            AND dmc.start_date &lt;= #{nowDate} AND dmc.end_date &gt;= #{nowDate}
        </if>
    </select>
    <select id="selectMemberCardList" resultType="com.ruoyi.member.domain.MemberCard">
        SELECT
            dmc.*
        FROM
            dl_member_card dmc
                LEFT JOIN dl_base_card dbc ON dmc.card_id = dbc.id
        WHERE dmc.user_id = #{userId}
          AND dmc.user_type = #{userType}
          AND dmc.end_date &gt;= #{nowDate}
          AND dmc.del_flag = 0
          AND dbc.is_system=0

        ORDER BY dmc.end_date DESC
    </select>


</mapper>