<?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.leromro.core.mapper.VolunteerAccountMapper">
    
    <resultMap type="VolunteerAccount" id="VolunteerAccountResult">
        <result property="volunteerAccountId"    column="volunteer_account_id"    />
        <result property="volunteerId"    column="volunteer_id"    />
        <result property="balance"    column="balance"    />
        <result property="totalBalance"    column="total_balance"    />
        <result property="orderFrozenBalance"    column="order_frozen_balance"    />
        <result property="beBalance"    column="be_balance"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectVolunteerAccountVo">
        select volunteer_account_id, volunteer_id, balance, total_balance, order_frozen_balance, be_balance, create_by, create_time, update_by, update_time, remark from l_volunteer_account
    </sql>

    <select id="selectVolunteerAccountList" parameterType="VolunteerAccount" resultMap="VolunteerAccountResult">
        <include refid="selectVolunteerAccountVo"/>
        <where>  
            <if test="volunteerId != null "> and volunteer_id = #{volunteerId}</if>
            <if test="balance != null "> and balance = #{balance}</if>
            <if test="totalBalance != null "> and total_balance = #{totalBalance}</if>
            <if test="orderFrozenBalance != null "> and order_frozen_balance = #{orderFrozenBalance}</if>
            <if test="beBalance != null "> and be_balance = #{beBalance}</if>
        </where>
    </select>
    
    <select id="selectVolunteerAccountByVolunteerAccountId" parameterType="Long" resultMap="VolunteerAccountResult">
        <include refid="selectVolunteerAccountVo"/>
        where volunteer_account_id = #{volunteerAccountId}
    </select>

    <insert id="insertVolunteerAccount" parameterType="VolunteerAccount" useGeneratedKeys="true" keyProperty="volunteerAccountId">
        insert into l_volunteer_account
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="volunteerId != null">volunteer_id,</if>
            <if test="balance != null">balance,</if>
            <if test="totalBalance != null">total_balance,</if>
            <if test="orderFrozenBalance != null">order_frozen_balance,</if>
            <if test="beBalance != null">be_balance,</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>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="volunteerId != null">#{volunteerId},</if>
            <if test="balance != null">#{balance},</if>
            <if test="totalBalance != null">#{totalBalance},</if>
            <if test="orderFrozenBalance != null">#{orderFrozenBalance},</if>
            <if test="beBalance != null">#{beBalance},</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>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateVolunteerAccount" parameterType="VolunteerAccount">
        update l_volunteer_account
        <trim prefix="SET" suffixOverrides=",">
            <if test="volunteerId != null">volunteer_id = #{volunteerId},</if>
            <if test="balance != null">balance = #{balance},</if>
            <if test="totalBalance != null">total_balance = #{totalBalance},</if>
            <if test="orderFrozenBalance != null">order_frozen_balance = #{orderFrozenBalance},</if>
            <if test="beBalance != null">be_balance = #{beBalance},</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>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where volunteer_account_id = #{volunteerAccountId}
    </update>

    <delete id="deleteVolunteerAccountByVolunteerAccountId" parameterType="Long">
        delete from l_volunteer_account where volunteer_account_id = #{volunteerAccountId}
    </delete>

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