<?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.iamberry.wechat.service.mapper.UserAmountMapper" >

  <select id="get" resultType="UserAmount" parameterType="String" >
    select * from tb_iamberry_user_amount where user_openid = #{userOpenid}
  </select>

  <delete id="del" parameterType="java.lang.Integer" >
    delete from tb_iamberry_user_amount where amount_id = #{amountId,jdbcType=INTEGER}
  </delete>

  <insert id="add" parameterType="UserAmount" useGeneratedKeys="true" keyProperty="amountId">
    insert into tb_iamberry_user_amount (user_openid, amonut_usable,
      amonut_await, amonut_total, amonut_lock)
    values (#{userOpenid,jdbcType=VARCHAR}, #{amonutUsable,jdbcType=INTEGER},
      #{amonutAwait,jdbcType=INTEGER}, #{amonutTotal,jdbcType=INTEGER}, #{amonutLock,jdbcType=INTEGER})
  </insert>

  <update id="edit" parameterType="UserAmount" >
    update tb_iamberry_user_amount
    <set >
      <if test="amonutUsable != null" >
        amonut_usable = (amonut_usable+#{amonutUsable,jdbcType=INTEGER}),
      </if>
      <if test="amonutAwait != null" >
        amonut_await = (amonut_await+#{amonutAwait,jdbcType=INTEGER}),
      </if>
      <if test="amonutTotal != null" >
        amonut_total = (amonut_total+#{amonutTotal,jdbcType=INTEGER}),
      </if>
      <if test="amonutLock != null" >
        amonut_lock = (amonut_lock+#{amonutLock,jdbcType=INTEGER}),
      </if>
    </set>
    where amount_id = #{amountId,jdbcType=INTEGER}
  </update>
</mapper>