<?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.bonus.canteen.core.account.mapper.AccTradeWalletDetailMapper">
    <resultMap type="com.bonus.canteen.core.account.domain.AccTradeWalletDetail" id="AccTradeWalletDetailResult">
        <result property="id"    column="id"    />
        <result property="tradeId"    column="trade_id"    />
        <result property="userId"    column="user_id"    />
        <result property="walletType"    column="wallet_type"    />
        <result property="amount"    column="amount"    />
        <result property="walletBal"    column="wallet_bal"    />
        <result property="tradeType"    column="trade_type"    />
        <result property="frozenBalance"    column="frozen_balance"    />
        <result property="tradeTime"    column="trade_time"    />
        <result property="validateTime"    column="validate_time"    />
        <result property="useAmount"    column="use_amount"    />
        <result property="expiredClear"    column="expired_clear"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectAccTradeWalletDetailVo">
        select id, trade_id, user_id, wallet_type, amount, wallet_bal, trade_type,
               frozen_balance, trade_time, validate_time, use_amount, expired_clear,
               create_by, create_time, update_by, update_time
        from account_trade_wallet_detail
    </sql>

    <select id="selectAccTradeWalletDetailList" parameterType="com.bonus.canteen.core.account.domain.AccTradeWalletDetail" resultMap="AccTradeWalletDetailResult">
        <include refid="selectAccTradeWalletDetailVo"/>
        <where>  
            <if test="tradeId != null "> and trade_id = #{tradeId}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="walletType != null "> and wallet_type = #{walletType}</if>
            <if test="amount != null "> and amount = #{amount}</if>
            <if test="walletBal != null "> and wallet_bal = #{walletBal}</if>
            <if test="tradeType != null "> and trade_type = #{tradeType}</if>
            <if test="frozenBalance != null "> and frozen_balance = #{frozenBalance}</if>
            <if test="tradeTime != null "> and trade_time = #{tradeTime}</if>
            <if test="validateTime != null "> and validate_time = #{validateTime}</if>
            <if test="useAmount != null "> and use_amount = #{useAmount}</if>
            <if test="expiredClear != null "> and expired_clear = #{expiredClear}</if>
        </where>
    </select>
    
    <select id="selectAccTradeWalletDetailById" parameterType="Long" resultMap="AccTradeWalletDetailResult">
        <include refid="selectAccTradeWalletDetailVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertAccTradeWalletDetail" parameterType="com.bonus.canteen.core.account.domain.AccTradeWalletDetail" useGeneratedKeys="true" keyProperty="id">
        insert into account_trade_wallet_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="tradeId != null">trade_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="walletType != null">wallet_type,</if>
            <if test="amount != null">amount,</if>
            <if test="walletBal != null">wallet_bal,</if>
            <if test="tradeType != null">trade_type,</if>
            <if test="frozenBalance != null">frozen_balance,</if>
            <if test="tradeTime != null">trade_time,</if>
            <if test="validateTime != null">validate_time,</if>
            <if test="useAmount != null">use_amount,</if>
            <if test="expiredClear != null">expired_clear,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="tradeId != null">#{tradeId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="walletType != null">#{walletType},</if>
            <if test="amount != null">#{amount},</if>
            <if test="walletBal != null">#{walletBal},</if>
            <if test="tradeType != null">#{tradeType},</if>
            <if test="frozenBalance != null">#{frozenBalance},</if>
            <if test="tradeTime != null">#{tradeTime},</if>
            <if test="validateTime != null">#{validateTime},</if>
            <if test="useAmount != null">#{useAmount},</if>
            <if test="expiredClear != null">#{expiredClear},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateAccTradeWalletDetail" parameterType="com.bonus.canteen.core.account.domain.AccTradeWalletDetail">
        update account_trade_wallet_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="tradeId != null">trade_id = #{tradeId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="walletType != null">wallet_type = #{walletType},</if>
            <if test="amount != null">amount = #{amount},</if>
            <if test="walletBal != null">wallet_bal = #{walletBal},</if>
            <if test="tradeType != null">trade_type = #{tradeType},</if>
            <if test="frozenBalance != null">frozen_balance = #{frozenBalance},</if>
            <if test="tradeTime != null">trade_time = #{tradeTime},</if>
            <if test="validateTime != null">validate_time = #{validateTime},</if>
            <if test="useAmount != null">use_amount = #{useAmount},</if>
            <if test="expiredClear != null">expired_clear = #{expiredClear},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAccTradeWalletDetailById" parameterType="Long">
        delete from account_trade_wallet_detail where id = #{id}
    </delete>

    <delete id="deleteAccTradeWalletDetailByIds" parameterType="String">
        delete from account_trade_wallet_detail where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>