CustomerVisitsInfoMapper.xml 9.77 KB
<?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="cn.com.glsx.dj.mindworkplate.mapper.CustomerVisitsInfoMapper" >
  <resultMap id="BaseResultMap" type="cn.com.glsx.dj.mindworkplate.model.CustomerVisitsInfo" >
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="owner_name" property="ownerName" jdbcType="VARCHAR" />
    <result column="owner_phone" property="ownerPhone" jdbcType="VARCHAR" />
    <result column="brand_model" property="brandModel" jdbcType="VARCHAR" />
    <result column="reception_scene" property="receptionScene" jdbcType="INTEGER" />
    <result column="bussiness_scene" property="bussinessScene" jdbcType="INTEGER" />
    <result column="customer_tag" property="customerTag" jdbcType="VARCHAR" />
    <result column="arrival_date" property="arrivalDate" jdbcType="TIMESTAMP" />
    <result column="receptionTime" property="receptionTime" jdbcType="TIMESTAMP" />
    <result column="receptionist" property="receptionist" jdbcType="VARCHAR" />
    <result column="receptionResult" property="receptionResult" jdbcType="TINYINT" />
    <result column="receptionStatus" property="receptionStatus" jdbcType="TINYINT" />
    <result column="merchant_id" property="merchantId" jdbcType="INTEGER" />
    <result column="created_at" property="createdAt" jdbcType="TIMESTAMP" />
    <result column="created_by" property="createdBy" jdbcType="VARCHAR" />
    <result column="updated_at" property="updatedAt" jdbcType="TIMESTAMP" />
    <result column="updated_by" property="updatedBy" jdbcType="VARCHAR" />
    <result column="del_flag" property="delFlag" jdbcType="CHAR" />
    <result column="customer_tag_name" property="customerTagName" jdbcType="VARCHAR" />
  </resultMap>

  <resultMap id="searchResultMap" type="cn.com.glsx.dj.mindworkplate.dto.CustomerVisitsInfoDTO" >
    <!--
      WARNING - @mbg.generated
    -->
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="owner_name" property="ownerName" jdbcType="VARCHAR" />
    <result column="owner_phone" property="ownerPhone" jdbcType="VARCHAR" />
    <result column="brand_model" property="brandModel" jdbcType="VARCHAR" />
    <result column="reception_scene" property="receptionScene" jdbcType="INTEGER" />
    <result column="bussiness_scene" property="bussinessScene" jdbcType="INTEGER" />
    <result column="customer_tag" property="customerTag" jdbcType="VARCHAR" />
    <result column="arrival_date" property="arrivalDate" jdbcType="TIMESTAMP" />
    <result column="receptionTime" property="receptionTime" jdbcType="TIMESTAMP" />
    <result column="created_at" property="createdDate" jdbcType="TIMESTAMP" />
    <result column="created_by" property="createdBy" jdbcType="VARCHAR" />
    <result column="receptionist" property="receptionist" jdbcType="VARCHAR" />
    <result column="receptionResult" property="receptionResult" jdbcType="TINYINT" />
    <result column="receptionStatus" property="receptionStatus" jdbcType="TINYINT" />
    <result column="merchant_id" property="merchantId" jdbcType="INTEGER" />
    <result column="customer_tag_name" property="customerTagName" jdbcType="VARCHAR" />
    <result column="car_model_id" property="carModelId" jdbcType="INTEGER" />
    <result column="car_brand" property="carBrand" jdbcType="VARCHAR" />
    <result column="car_brand_id" property="carBrandId" jdbcType="INTEGER" />
    <result column="one_car_brand" property="oneCarBrand" jdbcType="VARCHAR" />
    <result column="one_car_brand_id" property="oneCarBrandId" jdbcType="INTEGER" />
  </resultMap>
  <sql id="Base_Column_List" >
    <!--
      WARNING - @mbg.generated
    -->
    id, owner_name, owner_phone, brand_model, reception_scene, customer_tag, arrival_date, merchant_id, created_at,
    created_by, updated_at, updated_by, del_flag, customer_tag_name
  </sql>
  <select id="findVisitsInfoByPhone"
          resultMap="BaseResultMap">
      SELECT * FROM customer_visits_info
    WHERE del_flag='N' and
    owner_phone=#{customerVisitsInfo.ownerPhone} and bussiness_scene=#{customerVisitsInfo.bussinessScene}
    and merchant_id=#{customerVisitsInfo.merchantId} and date_format (arrival_date,'%Y-%m-%d')=date_format (#{customerVisitsInfo.arrivalDate},'%Y-%m-%d')
  </select>

  <select id="customerInfoPage"
    resultMap="searchResultMap">
    select t1.*,t2.reception_start_time as receptionTime,t2.staff_uuid as receptionist,t2.reception_status as receptionResult  from customer_visits_info t1
    left join reception_customer_info t2 on (t1.owner_phone=t2.phone_number and t1.merchant_id=t2.merchant_id and
    t1.bussiness_scene=t2.bussiness_type and t1.arrival_date<![CDATA[ <= ]]> t2.reception_start_time)
    where t1.del_flag='N' and t1.merchant_id=#{customerVisitsInfo.merchantId} and t1.bussiness_scene=#{customerVisitsInfo.bussinessScene}
    <if test="customerVisitsInfo.ownerPhone != null">
      and t1.owner_phone = #{customerVisitsInfo.ownerPhone}
    </if>
    <if test="customerVisitsInfo.receptionStatus == 1">
      and t2.id is null
      <if test="customerVisitsInfo.startTime != null">
        and date_format (t1.arrival_date,'%Y-%m-%d') <![CDATA[ >= ]]> date_format (#{customerVisitsInfo.startTime},'%Y-%m-%d')
      </if>
      <if test="customerVisitsInfo.endTime != null">
        and date_format (t1.arrival_date,'%Y-%m-%d') <![CDATA[ <= ]]> date_format (#{customerVisitsInfo.endTime},'%Y-%m-%d')
      </if>
      order by arrival_date desc,created_at desc
    </if>
    <if test="customerVisitsInfo.receptionStatus == 2">
      and t2.id is not null
      <if test="customerVisitsInfo.startTime != null">
        and date_format (reception_start_time,'%Y-%m-%d') <![CDATA[ >= ]]> date_format (#{customerVisitsInfo.startTime},'%Y-%m-%d')
      </if>
      <if test="customerVisitsInfo.endTime != null">
        and date_format (reception_start_time,'%Y-%m-%d') <![CDATA[ <= ]]> date_format (#{customerVisitsInfo.endTime},'%Y-%m-%d')
      </if>
      order by t2.reception_start_time desc
    </if>
  </select>
  <select id="customerInfoList"
    resultMap="searchResultMap">
    select t1.*,t2.reception_start_time as receptionTime,t2.staff_uuid as receptionist,t2.reception_status as receptionResult  from customer_visits_info t1
    left join reception_customer_info t2 on (t1.owner_phone=t2.phone_number and t1.merchant_id=t2.merchant_id and
    t1.bussiness_scene=t2.bussiness_type and t1.arrival_date<![CDATA[ <= ]]> t2.reception_start_time)
    where t1.del_flag='N' and t1.merchant_id=#{customerVisitsInfo.merchantId} and t1.bussiness_scene=#{customerVisitsInfo.bussinessScene}
    and t2.id is null
    <if test="customerVisitsInfo.ownerPhone != null">
      and t1.owner_phone like concat('%',#{customerVisitsInfo.ownerPhone},'%')
    </if>
    <if test="customerVisitsInfo.ownerName != null">
      and t1.owner_name like concat('%',#{customerVisitsInfo.ownerName},'%')
    </if>
    order by arrival_date desc
  </select>
  <select id="findCustomerInfoWait"
    resultMap="searchResultMap">
    select * from reception_customer_info   where date_format (#{customerVisitsInfo.arrivalDate},'%Y-%m-%d') <![CDATA[ <= ]]> reception_start_time
     and merchant_id=#{customerVisitsInfo.merchantId} and bussiness_type=#{customerVisitsInfo.bussinessScene} and phone_number
    = #{customerVisitsInfo.ownerPhone}
  </select>
  <select id="customerVisitsPage"
    resultMap="searchResultMap">
    select t1.* from customer_visits_info t1
    left join customer_visit_scripts t2 on t1.id=t2.customer_visits_id
    where t1.del_flag='N'
    <if test="customerVisitsInfo.merchantId != null">
    and t1.merchant_id=#{customerVisitsInfo.merchantId}
    </if>
    <if test="customerVisitsInfo.bussinessScene != null">
      and t1.bussiness_scene=#{customerVisitsInfo.bussinessScene}
    </if>
    <if test="customerVisitsInfo.startTime != null">
      and date_format (t1.created_at,'%Y-%m-%d') <![CDATA[ >= ]]> date_format (#{customerVisitsInfo.startTime},'%Y-%m-%d')
    </if>
    <if test="customerVisitsInfo.endTime != null">
      and date_format (t1.created_at,'%Y-%m-%d') <![CDATA[ <= ]]> date_format (#{customerVisitsInfo.endTime},'%Y-%m-%d')
    </if>
    <if test="customerVisitsInfo.createdByList != null">
     and t1.created_by in
    <foreach collection="customerVisitsInfo.createdByList" item="item" separator="," open="(" close=")">
      #{item}
    </foreach>
    </if>
    <if test="customerVisitsInfo.solutionBrowsing != null and customerVisitsInfo.solutionBrowsing==1">
      <if test="customerVisitsInfo.visitsList != null">
        and t1.id in
        <foreach collection="customerVisitsInfo.visitsList" item="item" separator="," open="(" close=")">
          #{item}
        </foreach>
      </if>
    </if>
    <if test="customerVisitsInfo.solutionBrowsing != null and customerVisitsInfo.solutionBrowsing==0">
      <if test="customerVisitsInfo.visitsList != null">
        and t1.id not in
        <foreach collection="customerVisitsInfo.visitsList" item="item" separator="," open="(" close=")">
          #{item}
        </foreach>
      </if>
    </if>
    <if test="customerVisitsInfo.scriptMatching != null">
      AND CASE
      WHEN t2.customer_visits_id IS NOT NULL THEN 1
      ELSE 0
      END = #{customerVisitsInfo.scriptMatching}
    </if>
    group by t1.id
    order by t1.created_at desc
  </select>
  <select id="findNeedUpateVisit"
          resultMap="searchResultMap">
    SELECT * FROM customer_visits_info where created_at >= CURDATE() - INTERVAL 1 MONTH;
  </select>
  <select id="findAllScriptMatching" resultType="java.lang.Integer">
    select distinct t1.visits_id from use_info_log t1
    left join customer_visit_scripts t2 on (t1.visits_id=t2.customer_visits_id  and t1.script_id=t2.script_id)
    where t1.visits_id is not null and t1.script_id is not null and t2.delete_flag ='N'
  </select>
</mapper>