<?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.jkcredit.invoice.mapper.customer.CustomerMapper" >
  <resultMap id="BaseResultMap" type="com.jkcredit.invoice.model.entity.customer.Customer" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="customer_name" property="customerName" jdbcType="VARCHAR" />
    <result column="invoice_time" property="invoiceTime" jdbcType="VARCHAR" />
    <result column="usenum_all" property="usenumAll" jdbcType="INTEGER" />
    <result column="usenum_interface" property="usenumInterface" jdbcType="INTEGER" />
    <result column="usenum_plat" property="usenumPlat" jdbcType="INTEGER" />
    <result column="account_balance" property="accountBalance" jdbcType="DOUBLE" />
    <result column="bussiness_type" property="bussinessType" jdbcType="INTEGER" />
    <result column="integration_type" property="integrationType" jdbcType="INTEGER" />
    <result column="first_sign" property="firstSign" jdbcType="VARCHAR" />
    <result column="accStatus" property="accstatus" jdbcType="INTEGER" />
    <result column="company" property="company" jdbcType="VARCHAR" />
    <result column="fee" property="fee" jdbcType="DOUBLE" />
  </resultMap>



  <resultMap id="BaseResultMapByAppKeyAndAppSecret" type="com.jkcredit.invoice.model.entity.customer.Customer" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="customer_name" property="customerName" jdbcType="VARCHAR" />
    <result column="app_secret" property="appSecret" jdbcType="VARCHAR" />
    <result column="invoice_time" property="invoiceTime" jdbcType="VARCHAR" />
    <result column="usenum_all" property="usenumAll" jdbcType="INTEGER" />
    <result column="usenum_interface" property="usenumInterface" jdbcType="INTEGER" />
    <result column="usenum_plat" property="usenumPlat" jdbcType="INTEGER" />
    <result column="account_balance" property="accountBalance" jdbcType="DOUBLE" />
    <result column="bussiness_type" property="bussinessType" jdbcType="INTEGER" />
    <result column="integration_type" property="integrationType" jdbcType="INTEGER" />
    <result column="first_sign" property="firstSign" jdbcType="VARCHAR" />
    <result column="accStatus" property="accstatus" jdbcType="INTEGER" />
    <result column="company" property="company" jdbcType="VARCHAR" />
    <result column="fee" property="fee" jdbcType="DOUBLE" />
  </resultMap>


  <sql id="Base_Column_List" >
    id, customer_name, invoice_time, usenum_all, usenum_interface, usenum_plat, account_balance,
    bussiness_type, integration_type, first_sign, accStatus, company,fee
  </sql>

  <sql id="Base_Column_List_app_secret" >
    id, app_secret, customer_name, invoice_time, usenum_all, usenum_interface, usenum_plat, account_balance,
    bussiness_type, integration_type, first_sign, accStatus, company,fee
  </sql>

  <select id="selectAllByPage" resultMap="BaseResultMap">
     select
      <include refid="Base_Column_List_app_secret" />
     from t_customer
    <where>
      <if test="customer.customerName != null and customer.customerName != ''">
        and  customer_name = BINARY #{customer.customerName}
      </if>
      <if test="customer.company != null and customer.company != ''">
        and  company LIKE BINARY CONCAT('%',#{customer.company},'%')
      </if>
      <if test="customer.subCompany != null and customer.subCompany != ''">
        and EXISTS (select 1 from t_customer_rec t where t.customerName = BINARY customer_name and t.company_Name LIKE BINARY CONCAT('%',#{customer.subCompany},'%'))
      </if>
    </where>
    order by first_sign desc
  </select>
  <select id="selectAllByPageForNoMoney" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List_app_secret" />
    from t_customer
    <where>
      <if test="customer.customerName != null and customer.customerName != ''">
        and  customer_name = BINARY #{customer.customerName}
      </if>
      <if test="customer.company != null and customer.company != ''">
        and  company LIKE BINARY CONCAT('%',#{customer.company},'%')
      </if>
      <if test="customer.moneyUpper != null and customer.moneyUpper != ''">
        and  #{customer.moneyUpper}>=account_balance
      </if>
      <if test="customer.moneyLower != null and customer.moneyLower != ''">
        and  account_balance>=#{customer.moneyLower}
      </if>
    </where>
    order by first_sign desc
  </select>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from t_customer
    where id = #{id,jdbcType=INTEGER}
  </select>
  <select id="selectByCustomerName" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select
    <include refid="Base_Column_List" />
    from t_customer
    where  customer_name = BINARY #{customerName,jdbcType=VARCHAR}
  </select>
  <select id="selectByCustomerNameForLock" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select
    <include refid="Base_Column_List" />
    from t_customer
    where  customer_name = BINARY #{customerName,jdbcType=VARCHAR} for update
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from t_customer
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.jkcredit.invoice.model.entity.customer.Customer" >
    insert into t_customer (app_secret, customer_name, invoice_time,
      usenum_all, usenum_interface, usenum_plat, 
      account_balance, bussiness_type, integration_type, 
      first_sign, accStatus, company,fee
      )
    values ( #{appSecret,jdbcType=VARCHAR},#{customerName,jdbcType=VARCHAR}, #{invoiceTime,jdbcType=TIMESTAMP},
      #{usenumAll,jdbcType=INTEGER}, #{usenumInterface,jdbcType=INTEGER}, #{usenumPlat,jdbcType=INTEGER}, 
      #{accountBalance,jdbcType=DOUBLE}, #{bussinessType,jdbcType=INTEGER}, #{integrationType,jdbcType=INTEGER}, 
      #{firstSign,jdbcType=VARCHAR}, #{accstatus,jdbcType=INTEGER}, #{company,jdbcType=VARCHAR},#{fee,jdbcType=DOUBLE}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.jkcredit.invoice.model.entity.customer.Customer" >
    insert into t_customer
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="customerName != null" >
        customer_name,
      </if>
      <if test="invoiceTime != null" >
        invoice_time,
      </if>
      <if test="usenumAll != null" >
        usenum_all,
      </if>
      <if test="usenumInterface != null" >
        usenum_interface,
      </if>
      <if test="usenumPlat != null" >
        usenum_plat,
      </if>
      <if test="accountBalance != null" >
        account_balance,
      </if>
      <if test="bussinessType != null" >
        bussiness_type,
      </if>
      <if test="integrationType != null" >
        integration_type,
      </if>
      <if test="firstSign != null" >
        first_sign,
      </if>
      <if test="accstatus != null" >
        accStatus,
      </if>
      <if test="company != null" >
        company,
      </if>
      <if test="fee != null" >
        fee,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=INTEGER},
      </if>
      <if test="customerName != null" >
        #{customerName,jdbcType=VARCHAR},
      </if>
      <if test="invoiceTime != null" >
        #{invoiceTime,jdbcType=TIMESTAMP},
      </if>
      <if test="usenumAll != null" >
        #{usenumAll,jdbcType=INTEGER},
      </if>
      <if test="usenumInterface != null" >
        #{usenumInterface,jdbcType=INTEGER},
      </if>
      <if test="usenumPlat != null" >
        #{usenumPlat,jdbcType=INTEGER},
      </if>
      <if test="accountBalance != null" >
        #{accountBalance,jdbcType=DOUBLE},
      </if>
      <if test="bussinessType != null" >
        #{bussinessType,jdbcType=INTEGER},
      </if>
      <if test="integrationType != null" >
        #{integrationType,jdbcType=INTEGER},
      </if>
      <if test="firstSign != null" >
        #{firstSign,jdbcType=VARCHAR},
      </if>
      <if test="accstatus != null" >
        #{accstatus,jdbcType=INTEGER},
      </if>
      <if test="company != null" >
        #{company,jdbcType=VARCHAR},
      </if>
      <if test="company != null" >
        #{fee,jdbcType=DOUBLE},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.jkcredit.invoice.model.entity.customer.Customer" >
    update t_customer
    <set >
      <if test="customerName != null" >
        customer_name = #{customerName,jdbcType=VARCHAR},
      </if>
      <if test="invoiceTime != null" >
        invoice_time = #{invoiceTime,jdbcType=TIMESTAMP},
      </if>
      <if test="usenumAll != null" >
        usenum_all = #{usenumAll,jdbcType=INTEGER},
      </if>
      <if test="usenumInterface != null" >
        usenum_interface = #{usenumInterface,jdbcType=INTEGER},
      </if>
      <if test="usenumPlat != null" >
        usenum_plat = #{usenumPlat,jdbcType=INTEGER},
      </if>
      <if test="accountBalance != null" >
        account_balance = #{accountBalance,jdbcType=DOUBLE},
      </if>
      <if test="bussinessType != null" >
        bussiness_type = #{bussinessType,jdbcType=INTEGER},
      </if>
      <if test="integrationType != null" >
        integration_type = #{integrationType,jdbcType=INTEGER},
      </if>
      <if test="firstSign != null" >
        first_sign = #{firstSign,jdbcType=VARCHAR},
      </if>
      <if test="accstatus != null" >
        accStatus = #{accstatus,jdbcType=INTEGER},
      </if>
      <if test="company != null" >
        company = #{company,jdbcType=VARCHAR},
      </if>
      <if test="fee != null" >
        fee = #{fee,jdbcType=DOUBLE},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.jkcredit.invoice.model.entity.customer.Customer" >
    update t_customer
    set customer_name = #{customerName,jdbcType=VARCHAR},
      invoice_time = #{invoiceTime,jdbcType=TIMESTAMP},
      usenum_all = #{usenumAll,jdbcType=INTEGER},
      usenum_interface = #{usenumInterface,jdbcType=INTEGER},
      usenum_plat = #{usenumPlat,jdbcType=INTEGER},
      account_balance = #{accountBalance,jdbcType=DOUBLE},
      bussiness_type = #{bussinessType,jdbcType=INTEGER},
      integration_type = #{integrationType,jdbcType=INTEGER},
      first_sign = #{firstSign,jdbcType=VARCHAR},
      accStatus = #{accstatus,jdbcType=INTEGER},
      company = #{company,jdbcType=VARCHAR},
      fee = #{fee,jdbcType=DOUBLE}
    where id = #{id,jdbcType=INTEGER}
  </update>




  <select id="selectByAppKeyAndAppSecret" resultMap="BaseResultMapByAppKeyAndAppSecret" parameterType="java.lang.String" >
    select
    <include refid="Base_Column_List_app_secret" />
    from t_customer
    where  customer_name = BINARY #{customerName,jdbcType=VARCHAR}
          and  app_secret = BINARY #{appSecret,jdbcType=VARCHAR}
  </select>

</mapper>