<?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="cn.reghao.tnb.user.app.db.mapper.WalletBillMapper">
    <insert id="save" useGeneratedKeys="true" keyProperty="id">
        insert into user_wallet_bill
        (`type`,`quantity`,`create_at`,`owner`)
        values 
        (#{type},#{quantity},#{createAt},#{owner})
    </insert>
    <insert id="saveAll" useGeneratedKeys="true" keyProperty="id">
        insert into user_wallet_bill
        (`type`,`quantity`,`create_at`,`owner`)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.type},#{item.quantity},#{item.createAt},#{item.owner})
        </foreach>
    </insert>
    
    <select id="findByOwner" resultType="cn.reghao.tnb.user.app.model.po.WalletBill">
        select *
        from user_wallet_bill
        where `owner`=#{owner}
        order by create_at desc
        limit #{pageSize}
    </select>
    <select id="findByTypeAndOwner" resultType="cn.reghao.tnb.user.app.model.vo.WalletDetail">
        select `type`,`owner`, sum(quantity) as total
        from user_wallet_bill
        where type=#{type} and `owner`=#{owner}
    </select>
</mapper>
