<?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.sien.common.mapper.DonationRecordMapper">

        <!-- 通用查询结果列 -->
        <sql id="Base_Column_List">
            id
            , fk_user_id, money, purpose, way, remark, create_time, update_time, is_replace,wx_mer_pay_id,pay_status,pay_time
        </sql>

        <select id="getDonationRecordById" resultType="com.sien.common.vo.DonationRecordQueryVo">
            select
            <include refid="Base_Column_List"/>
            from donation_record where id = #{id}
        </select>

    <select id="getDonationRecordPageList" parameterType="com.sien.common.param.DonationRecordPageParam"
            resultType="com.sien.common.vo.DonationRecordQueryVo">
        select
        <include refid="Base_Column_List"/>
        from donation_record
        where pay_status=1
        and fk_user_id=#{userId}
    </select>
    <select id="getDonationRankAndTotal" resultType="com.sien.common.vo.DonationRankAndTotal">
        SELECT
            tb.*,
            @curRank := @curRank + 1 AS rank
        FROM
            ( SELECT fk_user_id, sum( money ) AS drTotal FROM donation_record WHERE donation_record.pay_status = 1 GROUP BY fk_user_id ORDER BY drTotal DESC ) AS tb,
            ( SELECT @curRank := 0 ) r
        WHERE
            fk_user_id = #{userId}
    </select>

</mapper>
