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

  <select id="get" resultType="UserAtLogs" parameterType="java.lang.Integer" >
    select * from tb_iamberry_user_at_logs where at_id = #{atId,jdbcType=INTEGER}
  </select>

  <delete id="del" parameterType="java.lang.Integer" >
    delete from tb_iamberry_user_at_logs where at_id = #{atId,jdbcType=INTEGER}
  </delete>

  <insert id="add" parameterType="UserAtLogs" useGeneratedKeys="true" keyProperty="atId">
    insert into tb_iamberry_user_at_logs (user_openid, at_amonut,
      at_state, at_name, at_tel, 
      at_card_no, at_bank_name, at_create_time, 
      at_deal_time, at_remark,at_zfb,at_type)
    values (#{userOpenid,jdbcType=VARCHAR}, #{atAmonut,jdbcType=INTEGER},
      #{atState,jdbcType=TINYINT}, #{atName,jdbcType=VARCHAR}, #{atTel,jdbcType=VARCHAR}, 
      #{atCardNo,jdbcType=VARCHAR}, #{atBankName,jdbcType=VARCHAR}, NOW(),
      #{atDealTime,jdbcType=TIMESTAMP}, #{atRemark,jdbcType=VARCHAR}, #{atZfb,jdbcType=VARCHAR}, #{atType,jdbcType=VARCHAR})
  </insert>

  <update id="edit" parameterType="UserAtLogs" >
    update tb_iamberry_user_at_logs
    <set >
      <if test="userOpenid != null" >
        user_openid = #{userOpenid,jdbcType=VARCHAR},
      </if>
      <if test="atAmonut != null" >
        at_amonut = #{atAmonut,jdbcType=INTEGER},
      </if>
      <if test="atState != null" >
        at_state = #{atState,jdbcType=TINYINT},
      </if>
      <if test="atName != null" >
        at_name = #{atName,jdbcType=VARCHAR},
      </if>
      <if test="atTel != null" >
        at_tel = #{atTel,jdbcType=VARCHAR},
      </if>
      <if test="atCardNo != null" >
        at_card_no = #{atCardNo,jdbcType=VARCHAR},
      </if>
      <if test="atBankName != null" >
        at_bank_name = #{atBankName,jdbcType=VARCHAR},
      </if>
      <if test="atDealTime != null" >
        at_deal_time = #{atDealTime,jdbcType=TIMESTAMP},
      </if>
      <if test="atRemark != null" >
        at_remark = #{atRemark,jdbcType=VARCHAR},
      </if>
      <if test="atIsMoney != null" >
        at_is_money = #{atIsMoney,jdbcType=VARCHAR}
      </if>
    </set>
    where at_id = #{atId,jdbcType=INTEGER}
  </update>

  <select id="list" parameterType="UserAtLogs" resultType="UserAtLogs">
    select * from tb_iamberry_user_at_logs
    <where>
      <if test="userOpenid != null" >
        user_openid = #{userOpenid,jdbcType=VARCHAR}
      </if>
    </where>
  </select>

  <!-- 查询所有提现记录并分页 -->
  <select id="selectAtlogsInfo" resultType="UserAtLogs" parameterType="UserAtLogs">
    SELECT
    al.at_id atId,
    al.user_openid userOpenid,
    al.at_amonut atAmonut,
    al.at_state atState,
    al.at_name atName,
    al.at_tel atTel,
    al.at_card_no atCardNo,
    al.at_bank_name atBankName,
    al.at_create_time atCreateTime,
    al.at_deal_time atDealTime,
    al.at_remark atRemark,
    al.at_zfb atZfb,
    al.at_type atType,
    al.at_is_money atIsMoney,
    uu.user_head userHead,
    uu.user_nickname userNickname,
    ua.amonut_usable amonutUsable
    FROM tb_iamberry_user_at_logs al
    JOIN tb_iamberry_user_userinfo uu ON al.user_openid = uu.user_openid
    JOIN tb_iamberry_user_amount ua ON al.user_openid = ua.user_openid
    <where>
      <if test="atState != null and atState != ''">
        al.at_state = #{atState}
      </if>
      <if test="atName != null and atName != ''">
        AND al.at_name = #{atName}
      </if>
      <if test="atTel != null and atTel != ''">
        AND al.at_tel = #{atTel}
      </if>
      <if test="atType != null and atType != ''">
        AND al.at_type = #{atType}
      </if>
      <if test="atIsMoney != null and atIsMoney != ''">
        AND al.at_is_money = #{atIsMoney}
      </if>
    </where>
    <if test="page!=null and page.recordBegin>0 and page.pageSize>0 ">
      limit ${page.recordBegin},${page.pageSize}
    </if>
    <if test="page!=null and page.recordBegin==0 and page.pageSize>0 ">
      limit ${page.pageSize}
    </if>
  </select>
  <!-- 查询所有提现记录条数 -->
  <select id="selectAtlogsInfoCount" resultType="Integer" parameterType="UserAtLogs">
    SELECT
    COUNT(at_id)
    FROM tb_iamberry_user_at_logs
    <where>
      <if test="atState != null and atState != ''">
        at_state = #{atState}
      </if>
      <if test="atName != null and atName != ''">
        AND at_state = #{atName}
      </if>
      <if test="atTel != null and atTel != ''">
        AND at_tel = #{atTel}
      </if>
      <if test="atType != null and atType != ''">
        AND at_type = #{atType}
      </if>
      <if test="atIsMoney != null and atIsMoney != ''">
        AND at_is_money = #{atIsMoney}
      </if>
    </where>
  </select>
</mapper>