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

  <select id="get" resultType="CustomerInfo" parameterType="java.lang.Integer" >
    select * from tb_customer_info where admin_id = #{customerId,jdbcType=INTEGER}
  </select>

  <delete id="del" parameterType="java.lang.Integer" >
    delete from tb_customer_info where customer_id = #{customerId,jdbcType=INTEGER}
  </delete>

  <insert id="add" parameterType="CustomerInfo" useGeneratedKeys="true" keyProperty="customerId">
    insert into tb_customer_info (admin_id, customer_nick,
      customer_head, customer_access, customer_pwd, 
      customer_state, customer_update_time, customer_create_time)
    values (#{adminId,jdbcType=INTEGER}, #{customerNick,jdbcType=VARCHAR},
      #{customerHead,jdbcType=VARCHAR}, #{customerAccess,jdbcType=VARCHAR}, #{customerPwd,jdbcType=VARCHAR}, 
      #{customerState,jdbcType=TINYINT}, NOW(), NOW())
  </insert>

  <update id="edit" parameterType="CustomerInfo" >
    update tb_customer_info
    <set >
      <if test="adminId != null" >
        admin_id = #{adminId,jdbcType=INTEGER},
      </if>
      <if test="customerNick != null" >
        customer_nick = #{customerNick,jdbcType=VARCHAR},
      </if>
      <if test="customerHead != null" >
        customer_head = #{customerHead,jdbcType=VARCHAR},
      </if>
      <if test="customerAccess != null" >
        customer_access = #{customerAccess,jdbcType=VARCHAR},
      </if>
      <if test="customerPwd != null" >
        customer_pwd = #{customerPwd,jdbcType=VARCHAR},
      </if>
      <if test="customerState != null" >
        customer_state = #{customerState,jdbcType=TINYINT},
      </if>
      <if test="customerUpdateTime != null" >
        customer_update_time = #{customerUpdateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="customerCreateTime != null" >
        customer_create_time = #{customerCreateTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where customer_id = #{customerId,jdbcType=INTEGER}
  </update>

  <select id="count" parameterType="Integer" resultType="Integer">
    select count(customer_id) from tb_customer_info where customer_state = #{customerState}
  </select>

</mapper>