<?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.UserAmountLogsMapper" >

  <select id="get" resultType="UserAmountLogs" parameterType="java.lang.Integer" >
    select * from tb_iamberry_user_amount_logs where logs_id = #{logsId,jdbcType=INTEGER}
  </select>

  <delete id="del" parameterType="java.lang.Integer" >
    delete from tb_iamberry_user_amount_logs where logs_id = #{logsId,jdbcType=INTEGER}
  </delete>

  <insert id="add" parameterType="UserAmountLogs" useGeneratedKeys="true" keyProperty="logsId">
    insert into tb_iamberry_user_amount_logs (user_openid, order_id,
      logs_type, logs_state, logs_amount, 
      logs_date, logs_update_time, logs_create_time)
    values (#{userOpenid,jdbcType=VARCHAR}, #{orderId,jdbcType=VARCHAR},
      #{logsType,jdbcType=TINYINT}, #{logsState,jdbcType=TINYINT}, #{logsAmount,jdbcType=INTEGER}, 
      #{logsDate,jdbcType=DATE}, NOW(), NOW())
  </insert>

  <update id="edit" parameterType="UserAmountLogs" >
    update tb_iamberry_user_amount_logs
    <set >
      <if test="userOpenid != null" >
        user_openid = #{userOpenid,jdbcType=VARCHAR},
      </if>
      <if test="orderId != null" >
        order_id = #{orderId,jdbcType=VARCHAR},
      </if>
      <if test="logsRemark != null" >
        logs_remark = #{logsRemark,jdbcType=VARCHAR},
      </if>
      <if test="logsType != null" >
        logs_type = #{logsType,jdbcType=TINYINT},
      </if>
      <if test="logsState != null" >
        logs_state = #{logsState,jdbcType=TINYINT},
      </if>
      <if test="logsAmount != null" >
        logs_amount = #{logsAmount,jdbcType=INTEGER},
      </if>
      <if test="logsDate != null" >
        logs_date = #{logsDate,jdbcType=DATE},
      </if>
      logs_update_time = NOW()
    </set>
    where logs_id = #{logsId,jdbcType=INTEGER}
  </update>

  <select id="list" parameterType="UserAmountLogs" resultType="UserAmountLogs">
    select * from tb_iamberry_user_amount_logs
    <where>
      <if test="userOpenid != null" >
        user_openid = #{userOpenid,jdbcType=VARCHAR}
      </if>
      <if test="logsDate != null" >
        AND logs_date = #{logsDate,jdbcType=DATE}
      </if>
      <if test="logsType != null" >
        AND logs_type = #{logsType,jdbcType=TINYINT}
      </if>
      <if test="logsState != null" >
        AND logs_state = #{logsState,jdbcType=TINYINT}
      </if>
    </where>
  </select>

</mapper>