<?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.CustomerCarRecMapper">
  <resultMap id="BaseResultMap" type="com.jkcredit.invoice.model.entity.customer.CustomerCarRec">
    <id column="customer_name" jdbcType="VARCHAR" property="customerName" />
    <result column="company_name" jdbcType="VARCHAR" property="companyName" />
    <result column="companyNum" jdbcType="VARCHAR" property="companyNum" />
    <result column="car_num" jdbcType="VARCHAR" property="carNum" />
    <result column="car_color" jdbcType="VARCHAR" property="carColor" />
    <result column="cust_phone" jdbcType="VARCHAR" property="custPhone" />
    <result column="etc_num" jdbcType="VARCHAR" property="etcNum" />
    <result column="succ_time" jdbcType="VARCHAR" property="succTime" />
    <result column="fail_time" jdbcType="VARCHAR" property="failTime" />
    <result column="rec_status" jdbcType="INTEGER" property="recStatus" />
    <result column="bussiness_type" jdbcType="INTEGER" property="businessType" />
    <result column="fail_reason" jdbcType="VARCHAR" property="failReason" />
    <result column="inter_type" jdbcType="VARCHAR" property="interType" />
  </resultMap>
  <sql id="Base_Column_List">
    customer_name,companyNum,company_name, car_num, car_color, cust_phone, etc_num, succ_time,
    fail_time, rec_status,bussiness_type, fail_reason,inter_type
  </sql>
    <select id="selectAllBindEtcNoGetInvoice" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from  t_customer_carRec where rec_status=1 and bussiness_type=0
    </select>
  <select id="selectAllByPage" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from  t_customer_carRec
    where
    ((rec_status=1 and bussiness_type =0) or (bussiness_type=2))
      <if test="query.customerName != null">
        and  customer_name = BINARY #{query.customerName,jdbcType=VARCHAR}
      </if>
      <if test="query.carNum != null and query.carNum != ''">
        and  car_num = BINARY #{query.carNum}
      </if>
      <if test="query.companyName != null and query.companyName != ''">
        and  company_name  LIKE BINARY CONCAT('%',#{query.companyName},'%')
      </if>
      <if test="query.companyNum != null and query.companyNum != ''">
        and  companyNum = BINARY #{query.companyNum}
      </if>
      <if test="query.etcNum != null and query.etcNum != ''">
        and  etc_num = BINARY #{query.etcNum}
      </if>
      <if test="query.recStatus != null and query.recStatus != ''">
        and rec_status = (#{query.recStatus}-1)
      </if>
      <if test="query.businessType != null and query.businessType != ''">
        and  bussiness_type = BINARY #{query.businessType}
      </if>
      <if test="query.startTime != null and query.startTime != ''">
        and (succ_time BETWEEN #{query.startTime} and #{query.endTime}

            or fail_time  BETWEEN #{query.startTime} and #{query.endTime}
        )
      </if>

    ORDER BY succ_time||fail_time DESC
  </select>
  <select id="selectByCustName" parameterType="java.lang.String" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from t_customer_carRec
    where  customer_name = BINARY #{customerName,jdbcType=VARCHAR}
  </select>
  <select id="selectByCarNum" parameterType="java.lang.String" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from t_customer_carRec
    where  car_num = BINARY #{carNum,jdbcType=VARCHAR} and bussiness_type=2
  </select>
  <select id="selectBySelfCarNum" parameterType="java.lang.String" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from t_customer_carRec
    where  car_num = BINARY #{carNum,jdbcType=VARCHAR} and bussiness_type=0 and rec_status = 1
  </select>
  <select id="selectAllEtcBySelfCarNum" parameterType="java.lang.String" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from t_customer_carRec
    where  car_num = BINARY #{carNum,jdbcType=VARCHAR} and bussiness_type=0
  </select>
  <select id="selectByETC" parameterType="java.lang.String" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from t_customer_carRec
    where  etc_num = BINARY #{etcNum,jdbcType=VARCHAR} AND bussiness_type=0
  </select>
  <select id="selectByETCForLock" parameterType="java.lang.String" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from t_customer_carRec
    where  etc_num = BINARY #{etcNum,jdbcType=VARCHAR} AND bussiness_type=0 FOR UPDATE
  </select>
  <update id="updateWaitETCStatus" parameterType="com.jkcredit.invoice.model.entity.customer.CustomerCarRec">
    update t_customer_carRec set rec_status = #{recStatus,jdbcType=INTEGER} ,succ_time = #{succTime,jdbcType=VARCHAR}, fail_time = #{failTime,jdbcType=VARCHAR}
    , fail_reason = #{failReason,jdbcType=VARCHAR}, inter_type = #{interType,jdbcType=VARCHAR}
    where  companyNum = BINARY #{companyNum,jdbcType=VARCHAR} and  cust_phone = BINARY #{custPhone,jdbcType=VARCHAR} AND bussiness_type=0 and rec_status = 3
  </update>
  <delete id="selectByCustomerName" parameterType="java.lang.String">
    delete from t_customer_carRec
    where  customer_name = BINARY #{customerName,jdbcType=VARCHAR}
  </delete>
  <insert id="insert" parameterType="com.jkcredit.invoice.model.entity.customer.CustomerCarRec">
    insert into t_customer_carRec (customer_name,companyNum, company_name, car_num,
      car_color, cust_phone, etc_num, 
      succ_time, fail_time, rec_status,bussiness_type,
      fail_reason,inter_type)
    values (#{customerName,jdbcType=VARCHAR},#{companyNum,jdbcType=VARCHAR}, #{companyName,jdbcType=VARCHAR}, #{carNum,jdbcType=VARCHAR},
      #{carColor,jdbcType=VARCHAR}, #{custPhone,jdbcType=VARCHAR}, #{etcNum,jdbcType=VARCHAR}, 
      #{succTime,jdbcType=VARCHAR}, #{failTime,jdbcType=VARCHAR}, #{recStatus,jdbcType=INTEGER},#{businessType,jdbcType=INTEGER},
      #{failReason,jdbcType=VARCHAR},#{interType,jdbcType=INTEGER})
  </insert>
  <insert id="insertSelective" parameterType="com.jkcredit.invoice.model.entity.customer.CustomerCarRec">
    insert into t_customer_carRec
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="customerName != null">
        customer_name,
      </if>
      <if test="companyNum != null">
        companyNum,
      </if>
      <if test="companyName != null">
        company_name,
      </if>
      <if test="carNum != null">
        car_num,
      </if>
      <if test="carColor != null">
        car_color,
      </if>
      <if test="custPhone != null">
        cust_phone,
      </if>
      <if test="etcNum != null">
        etc_num,
      </if>
      <if test="succTime != null">
        succ_time,
      </if>
      <if test="failTime != null">
        fail_time,
      </if>
      <if test="recStatus != null">
        rec_status,
      </if>
      <if test="failReason != null">
        fail_reason,
      </if>
      <if test="interType != null">
        inter_type = #{interType,jdbcType=INTEGER}
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="customerName != null">
        #{customerName,jdbcType=VARCHAR},
      </if>
      <if test="companyNum != null">
        #{companyNum,jdbcType=VARCHAR},
      </if>
      <if test="companyName != null">
        #{companyName,jdbcType=VARCHAR},
      </if>
      <if test="carNum != null">
        #{carNum,jdbcType=VARCHAR},
      </if>
      <if test="carColor != null">
        #{carColor,jdbcType=VARCHAR},
      </if>
      <if test="custPhone != null">
        #{custPhone,jdbcType=VARCHAR},
      </if>
      <if test="etcNum != null">
        #{etcNum,jdbcType=VARCHAR},
      </if>
      <if test="succTime != null">
        #{succTime,jdbcType=TIMESTAMP},
      </if>
      <if test="failTime != null">
        #{failTime,jdbcType=TIMESTAMP},
      </if>
      <if test="recStatus != null">
        #{recStatus,jdbcType=INTEGER},
      </if>
      <if test="failReason != null">
        #{failReason,jdbcType=VARCHAR},
      </if>
      <if test="interType != null">
        inter_type = #{interType,jdbcType=INTEGER}
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.jkcredit.invoice.model.entity.customer.CustomerCarRec">
    update t_customer_carRec
    <set>
      <if test="companyName != null">
        company_name = #{companyName,jdbcType=VARCHAR},
      </if>
      <if test="carNum != null">
         car_num = #{carNum,jdbcType=VARCHAR},
      </if>
      <if test="carColor != null">
        car_color = #{carColor,jdbcType=VARCHAR},
      </if>
      <if test="custPhone != null">
        cust_phone = #{custPhone,jdbcType=VARCHAR},
      </if>
      <if test="etcNum != null">
        etc_num = #{etcNum,jdbcType=VARCHAR},
      </if>
      <if test="succTime != null">
        succ_time = #{succTime,jdbcType=TIMESTAMP},
      </if>
      <if test="failTime != null">
        fail_time = #{failTime,jdbcType=TIMESTAMP},
      </if>
      <if test="recStatus != null">
        rec_status = #{recStatus,jdbcType=INTEGER},
      </if>
      <if test="failReason != null">
        fail_reason = #{failReason,jdbcType=VARCHAR},
      </if>
      <if test="interType != null">
        inter_type = #{interType,jdbcType=INTEGER}
      </if>
    </set>
    where  car_num = BINARY #{carNum,jdbcType=VARCHAR}  and bussiness_type=2
  </update>
  <update id="updateETCByPrimaryKeySelective" parameterType="com.jkcredit.invoice.model.entity.customer.CustomerCarRec">
    update t_customer_carRec
    <set>
      <if test="companyName != null">
        company_name = #{companyName,jdbcType=VARCHAR},
      </if>
      <if test="carNum != null">
         car_num = #{carNum,jdbcType=VARCHAR},
      </if>
      <if test="carColor != null">
        car_color = #{carColor,jdbcType=VARCHAR},
      </if>
      <if test="custPhone != null">
        cust_phone = #{custPhone,jdbcType=VARCHAR},
      </if>
      <if test="etcNum != null">
        etc_num = #{etcNum,jdbcType=VARCHAR},
      </if>
      <if test="succTime != null">
        succ_time = #{succTime,jdbcType=TIMESTAMP},
      </if>
      <if test="failTime != null">
        fail_time = #{failTime,jdbcType=TIMESTAMP},
      </if>
      <if test="recStatus != null">
        rec_status = #{recStatus,jdbcType=INTEGER},
      </if>
      <if test="failReason != null">
        fail_reason = #{failReason,jdbcType=VARCHAR},
      </if>
      <if test="interType != null">
        inter_type = #{interType,jdbcType=INTEGER}
      </if>
    </set>
    where  etc_num = BINARY #{etcNum,jdbcType=VARCHAR} and bussiness_type=0
  </update>
  <update id="updateByPrimaryKey" parameterType="com.jkcredit.invoice.model.entity.customer.CustomerCarRec">
    update t_customer_carRec
    set
      customer_name = #{customerName,jdbcType=VARCHAR},
      company_name = #{companyName,jdbcType=VARCHAR},
      car_num = #{carNum,jdbcType=VARCHAR},
      car_color = #{carColor,jdbcType=VARCHAR},
      cust_phone = #{custPhone,jdbcType=VARCHAR},
      etc_num = #{etcNum,jdbcType=VARCHAR},
      succ_time = #{succTime,jdbcType=TIMESTAMP},
      fail_time = #{failTime,jdbcType=TIMESTAMP},
      rec_status = #{recStatus,jdbcType=INTEGER},
      fail_reason = #{failReason,jdbcType=VARCHAR},
      inter_type = #{interType,jdbcType=INTEGER}
    where  car_num = BINARY #{carNum,jdbcType=VARCHAR}  and bussiness_type=2
  </update>

  <update id="updateETCByPrimaryKey" parameterType="com.jkcredit.invoice.model.entity.customer.CustomerCarRec">
    update t_customer_carRec
    set
    customer_name = #{customerName,jdbcType=VARCHAR},
    company_name = #{companyName,jdbcType=VARCHAR},
    car_num = #{carNum,jdbcType=VARCHAR},
    car_color = #{carColor,jdbcType=VARCHAR},
    cust_phone = #{custPhone,jdbcType=VARCHAR},
    etc_num = #{etcNum,jdbcType=VARCHAR},
    succ_time = #{succTime,jdbcType=TIMESTAMP},
    fail_time = #{failTime,jdbcType=TIMESTAMP},
    rec_status = #{recStatus,jdbcType=INTEGER},
    fail_reason = #{failReason,jdbcType=VARCHAR},
    inter_type = #{interType,jdbcType=INTEGER}
    where  etc_num = BINARY #{etcNum,jdbcType=VARCHAR} and bussiness_type=0
  </update>

  <update id="upDateCompanySelf" parameterType="com.jkcredit.invoice.model.vo.CompanyVo">
    UPDATE t_customer_carRec set company_Name = #{newCompanyName} where company_Name = #{oldCompanyName} and  bussiness_type=0
  </update>

  <update id="upDateCompanyNo" parameterType="com.jkcredit.invoice.model.vo.CompanyVo">
    UPDATE t_customer_carRec set company_Name = #{newCompanyName} where company_Name = #{oldCompanyName} and  bussiness_type=2
  </update>
</mapper>