<?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.cai.mapper.UserGiftMapper">

    <resultMap type="com.ruoyi.cai.domain.UserGift" id="CaiUserGiftResult">
        <result property="id" column="id"/>
        <result property="type" column="type"/>
        <result property="fromUid" column="from_uid"/>
        <result property="toUid" column="to_uid"/>
        <result property="giftId" column="gift_id"/>
        <result property="giftCount" column="gift_count"/>
        <result property="giftAmount" column="gift_amount"/>
        <result property="createTime" column="create_time"/>
    </resultMap>
    <select id="selectGiftList" resultType="com.ruoyi.cai.dto.app.vo.index.UserGiftIndexVo">
        select
               from_uid,
               to_uid,
               gift_id,
               t2.name,
               t2.img,
               t2.price,
               sum(gift_count) as gift_count
        from cai_user_gift t1
        join cai_gift t2 on t1.gift_id = t2.id
        where to_uid = #{userId}
        group by gift_id
    </select>
    <select id="countGiftNum" resultType="java.lang.Long">
        select ifnull(sum(gift_count),0)
        from cai_user_gift
        <where>
            <if test="fromUid != null">
                and from_uid = #{fromUid}
            </if>
            <if test="toUid != null">
                and to_uid = #{toUid}
            </if>
        </where>
    </select>
</mapper>
