<?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.iotechn.unimall.data.mapper.CardExchangeInfoMapper">


    <select id="getCardExchangeInfoPage" resultType="com.iotechn.unimall.data.domain.CardExchangeInfo">
        SELECT
        id,
        send_id AS sendId,
        receive_id AS receiveId,
        send_card_id AS sendCardId,
        receive_card_id AS receiveCardId,
        circle_name AS circleName,
        case when gmt_create &lt; DATE_SUB(now(), INTERVAL 5 DAY) and status=0 then 5 else `status` end as `status`,
        gmt_update AS gmtUpdate,
        gmt_create AS gmtCreate
        FROM
        card_exchange_info
        WHERE
        receive_id = #{receiveId}
        and delete_flag=0
        <if test="status != null">
            <if test="status == 1">
                AND status != 7
            </if>
            <if test="status == 2">
                AND status = 7
            </if>
        </if>
        ORDER BY gmt_update DESC
        LIMIT #{offset}, #{limit}

    </select>
    <select id="getCardExchangeCount" resultType="java.lang.Integer">
        SELECT
        count(1)
        FROM
        card_exchange_info
        WHERE
        receive_id = #{receiveId}
        and delete_flag=0
        <if test="status != null">
            <if test="status == 1">
                AND status != 7
            </if>
            <if test="status == 2">
                AND status = 7
            </if>
        </if>
    </select>
</mapper>