<?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.reptileclient.jlifeapp.dao.jz.JzbmLeadMapper">
  <resultMap id="BaseResultMap" type="com.reptileclient.jlifeapp.entity.jz.JzbmLead">
    <!--@mbg.generated-->
    <!--@Table jzbm_lead-->
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="lead_no" jdbcType="VARCHAR" property="leadNo" />
    <result column="source_id" jdbcType="INTEGER" property="sourceId" />
    <result column="source_name" jdbcType="VARCHAR" property="sourceName" />
    <result column="service_city" jdbcType="INTEGER" property="serviceCity" />
    <result column="service_city_name" jdbcType="VARCHAR" property="serviceCityName" />
    <result column="customer_id" jdbcType="BIGINT" property="customerId" />
    <result column="gender" jdbcType="INTEGER" property="gender" />
    <result column="customer_name" jdbcType="VARCHAR" property="customerName" />
    <result column="customer_tel" jdbcType="VARCHAR" property="customerTel" />
    <result column="customer_addr" jdbcType="VARCHAR" property="customerAddr" />
    <result column="service_model" jdbcType="INTEGER" property="serviceModel" />
    <result column="state" jdbcType="INTEGER" property="state" />
    <result column="service_content" jdbcType="VARCHAR" property="serviceContent" />
    <result column="order_form_time" jdbcType="TIMESTAMP" property="orderFormTime" />
    <result column="follow_id" jdbcType="INTEGER" property="followId" />
    <result column="follow_person" jdbcType="VARCHAR" property="followPerson" />
    <result column="allocation_time" jdbcType="TIMESTAMP" property="allocationTime" />
    <result column="next_follow_time" jdbcType="TIMESTAMP" property="nextFollowTime" />
    <result column="create_id" jdbcType="BIGINT" property="createId" />
    <result column="create_user" jdbcType="VARCHAR" property="createUser" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="remark" jdbcType="VARCHAR" property="remark" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, lead_no, source_id, source_name, service_city, service_city_name, customer_id,
    gender, customer_name, customer_tel, customer_addr, service_model, `state`, service_content,
    order_form_time, follow_id, follow_person, allocation_time, next_follow_time, create_id,
    create_user, create_time, update_time, remark
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    <!--@mbg.generated-->
    select
    <include refid="Base_Column_List" />
    from jzbm_lead
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    <!--@mbg.generated-->
    delete from jzbm_lead
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.reptileclient.jlifeapp.entity.jz.JzbmLead" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into jlife_nurse.jzbm_lead (lead_no, source_id, source_name,
      service_city, service_city_name, customer_id,
      gender, customer_name, customer_tel,
      customer_addr, service_model, `state`,
      service_content, order_form_time, follow_id,
      follow_person, allocation_time, next_follow_time,
      create_id, create_user, create_time,
      update_time, remark)
    values (#{leadNo,jdbcType=VARCHAR}, #{sourceId,jdbcType=INTEGER}, #{sourceName,jdbcType=VARCHAR},
      #{serviceCity,jdbcType=INTEGER}, #{serviceCityName,jdbcType=VARCHAR}, #{customerId,jdbcType=BIGINT},
      #{gender,jdbcType=INTEGER}, #{customerName,jdbcType=VARCHAR}, #{customerTel,jdbcType=VARCHAR},
      #{customerAddr,jdbcType=VARCHAR}, #{serviceModel,jdbcType=INTEGER}, #{state,jdbcType=INTEGER},
      #{serviceContent,jdbcType=VARCHAR}, #{orderFormTime,jdbcType=TIMESTAMP}, #{followId,jdbcType=INTEGER},
      #{followPerson,jdbcType=VARCHAR}, #{allocationTime,jdbcType=TIMESTAMP}, #{nextFollowTime,jdbcType=TIMESTAMP},
      #{createId,jdbcType=BIGINT}, #{createUser,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP},
      #{updateTime,jdbcType=TIMESTAMP}, #{remark,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.reptileclient.jlifeapp.entity.jz.JzbmLead" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into jzbm_lead
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="leadNo != null and leadNo != ''">
        lead_no,
      </if>
      <if test="sourceId != null">
        source_id,
      </if>
      <if test="sourceName != null and sourceName != ''">
        source_name,
      </if>
      <if test="serviceCity != null">
        service_city,
      </if>
      <if test="serviceCityName != null and serviceCityName != ''">
        service_city_name,
      </if>
      <if test="customerId != null">
        customer_id,
      </if>
      <if test="gender != null">
        gender,
      </if>
      <if test="customerName != null and customerName != ''">
        customer_name,
      </if>
      <if test="customerTel != null and customerTel != ''">
        customer_tel,
      </if>
      <if test="customerAddr != null and customerAddr != ''">
        customer_addr,
      </if>
      <if test="serviceModel != null">
        service_model,
      </if>
      <if test="state != null">
        `state`,
      </if>
      <if test="serviceContent != null and serviceContent != ''">
        service_content,
      </if>
      <if test="orderFormTime != null">
        order_form_time,
      </if>
      <if test="followId != null">
        follow_id,
      </if>
      <if test="followPerson != null and followPerson != ''">
        follow_person,
      </if>
      <if test="allocationTime != null">
        allocation_time,
      </if>
      <if test="nextFollowTime != null">
        next_follow_time,
      </if>
      <if test="createId != null">
        create_id,
      </if>
      <if test="createUser != null and createUser != ''">
        create_user,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="updateTime != null">
        update_time,
      </if>
      <if test="remark != null and remark != ''">
        remark,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="leadNo != null and leadNo != ''">
        #{leadNo,jdbcType=VARCHAR},
      </if>
      <if test="sourceId != null">
        #{sourceId,jdbcType=INTEGER},
      </if>
      <if test="sourceName != null and sourceName != ''">
        #{sourceName,jdbcType=VARCHAR},
      </if>
      <if test="serviceCity != null">
        #{serviceCity,jdbcType=INTEGER},
      </if>
      <if test="serviceCityName != null and serviceCityName != ''">
        #{serviceCityName,jdbcType=VARCHAR},
      </if>
      <if test="customerId != null">
        #{customerId,jdbcType=BIGINT},
      </if>
      <if test="gender != null">
        #{gender,jdbcType=INTEGER},
      </if>
      <if test="customerName != null and customerName != ''">
        #{customerName,jdbcType=VARCHAR},
      </if>
      <if test="customerTel != null and customerTel != ''">
        #{customerTel,jdbcType=VARCHAR},
      </if>
      <if test="customerAddr != null and customerAddr != ''">
        #{customerAddr,jdbcType=VARCHAR},
      </if>
      <if test="serviceModel != null">
        #{serviceModel,jdbcType=INTEGER},
      </if>
      <if test="state != null">
        #{state,jdbcType=INTEGER},
      </if>
      <if test="serviceContent != null and serviceContent != ''">
        #{serviceContent,jdbcType=VARCHAR},
      </if>
      <if test="orderFormTime != null">
        #{orderFormTime,jdbcType=TIMESTAMP},
      </if>
      <if test="followId != null">
        #{followId,jdbcType=INTEGER},
      </if>
      <if test="followPerson != null and followPerson != ''">
        #{followPerson,jdbcType=VARCHAR},
      </if>
      <if test="allocationTime != null">
        #{allocationTime,jdbcType=TIMESTAMP},
      </if>
      <if test="nextFollowTime != null">
        #{nextFollowTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createId != null">
        #{createId,jdbcType=BIGINT},
      </if>
      <if test="createUser != null and createUser != ''">
        #{createUser,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="remark != null and remark != ''">
        #{remark,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.reptileclient.jlifeapp.entity.jz.JzbmLead">
    <!--@mbg.generated-->
    update jzbm_lead
    <set>
      <if test="leadNo != null and leadNo != ''">
        lead_no = #{leadNo,jdbcType=VARCHAR},
      </if>
      <if test="sourceId != null">
        source_id = #{sourceId,jdbcType=INTEGER},
      </if>
      <if test="sourceName != null and sourceName != ''">
        source_name = #{sourceName,jdbcType=VARCHAR},
      </if>
      <if test="serviceCity != null">
        service_city = #{serviceCity,jdbcType=INTEGER},
      </if>
      <if test="serviceCityName != null and serviceCityName != ''">
        service_city_name = #{serviceCityName,jdbcType=VARCHAR},
      </if>
      <if test="customerId != null">
        customer_id = #{customerId,jdbcType=BIGINT},
      </if>
      <if test="gender != null">
        gender = #{gender,jdbcType=INTEGER},
      </if>
      <if test="customerName != null and customerName != ''">
        customer_name = #{customerName,jdbcType=VARCHAR},
      </if>
      <if test="customerTel != null and customerTel != ''">
        customer_tel = #{customerTel,jdbcType=VARCHAR},
      </if>
      <if test="customerAddr != null and customerAddr != ''">
        customer_addr = #{customerAddr,jdbcType=VARCHAR},
      </if>
      <if test="serviceModel != null">
        service_model = #{serviceModel,jdbcType=INTEGER},
      </if>
      <if test="state != null">
        `state` = #{state,jdbcType=INTEGER},
      </if>
      <if test="serviceContent != null and serviceContent != ''">
        service_content = #{serviceContent,jdbcType=VARCHAR},
      </if>
      <if test="orderFormTime != null">
        order_form_time = #{orderFormTime,jdbcType=TIMESTAMP},
      </if>
      <if test="followId != null">
        follow_id = #{followId,jdbcType=INTEGER},
      </if>
      <if test="followPerson != null and followPerson != ''">
        follow_person = #{followPerson,jdbcType=VARCHAR},
      </if>
      <if test="allocationTime != null">
        allocation_time = #{allocationTime,jdbcType=TIMESTAMP},
      </if>
      <if test="nextFollowTime != null">
        next_follow_time = #{nextFollowTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createId != null">
        create_id = #{createId,jdbcType=BIGINT},
      </if>
      <if test="createUser != null and createUser != ''">
        create_user = #{createUser,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null">
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="remark != null and remark != ''">
        remark = #{remark,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.reptileclient.jlifeapp.entity.jz.JzbmLead">
    <!--@mbg.generated-->
    update jzbm_lead
    set lead_no = #{leadNo,jdbcType=VARCHAR},
      source_id = #{sourceId,jdbcType=INTEGER},
      source_name = #{sourceName,jdbcType=VARCHAR},
      service_city = #{serviceCity,jdbcType=INTEGER},
      service_city_name = #{serviceCityName,jdbcType=VARCHAR},
      customer_id = #{customerId,jdbcType=BIGINT},
      gender = #{gender,jdbcType=INTEGER},
      customer_name = #{customerName,jdbcType=VARCHAR},
      customer_tel = #{customerTel,jdbcType=VARCHAR},
      customer_addr = #{customerAddr,jdbcType=VARCHAR},
      service_model = #{serviceModel,jdbcType=INTEGER},
      `state` = #{state,jdbcType=INTEGER},
      service_content = #{serviceContent,jdbcType=VARCHAR},
      order_form_time = #{orderFormTime,jdbcType=TIMESTAMP},
      follow_id = #{followId,jdbcType=INTEGER},
      follow_person = #{followPerson,jdbcType=VARCHAR},
      allocation_time = #{allocationTime,jdbcType=TIMESTAMP},
      next_follow_time = #{nextFollowTime,jdbcType=TIMESTAMP},
      create_id = #{createId,jdbcType=BIGINT},
      create_user = #{createUser,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_time = #{updateTime,jdbcType=TIMESTAMP},
      remark = #{remark,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>

  <select id="selectMaxNo" resultType="java.lang.String">
    select IFNULL(max(right(lead_no, 7)), '')
    from jlife_nurse.jzbm_lead
  </select>
<!--  and service_model = #{serviceModel,jdbcType=INTEGER}-->
  <select id="selectByCustomerTelAndServiceModel" resultType="int">
    select count(1) from jlife_nurse.jzbm_lead where customer_tel = #{customerTel,jdbcType=VARCHAR}
    and service_city = #{serviceCity,jdbcType=INTEGER}
    and (state in (1,2,6)  or (state =4 and create_time >=now() - interval  7 day ))
    </select>
</mapper>
