|
|
@@ -717,5 +717,371 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|
|
|
|
|
</select>
|
|
|
|
|
|
+ <select id="selectTransferCustomerList" resultType="com.fs.crm.vo.CrmLineCustomerListQueryVO">
|
|
|
+ select c.*,u.nick_name as company_user_nick_name,u2.nick_name as create_user_name
|
|
|
+ from crm_customer c
|
|
|
+ left join company_user u on u.user_id=c.receive_user_id
|
|
|
+ left join company_user u2 on u2.user_id=c.create_user_id
|
|
|
+ where c.is_del = 0 and (u.status = 1 or u.del_flag = 2)
|
|
|
+ <if test="maps.isLine != null">
|
|
|
+ and c.is_line = #{maps.isLine}
|
|
|
+ </if>
|
|
|
+ <if test="maps.customerCode != null and maps.customerCode !='' ">
|
|
|
+ and c.customer_code like CONCAT('%',#{maps.customerCode},'%')
|
|
|
+ </if>
|
|
|
+ <if test="maps.customerName != null and maps.customerName !='' ">
|
|
|
+ and c.customer_name like CONCAT('%',#{maps.customerName},'%')
|
|
|
+ </if>
|
|
|
+ <if test="maps.customerCompanyName != null and maps.customerCompanyName !='' ">
|
|
|
+ and c.customer_company_name like CONCAT('%',#{maps.customerCompanyName},'%')
|
|
|
+ </if>
|
|
|
+ <if test="maps.companyUserNickName != null and maps.companyUserNickName !=''">
|
|
|
+ and u.nick_name like CONCAT('%',#{maps.companyUserNickName},'%')
|
|
|
+ </if>
|
|
|
+ <if test="maps.createUserName != null and maps.createUserName !='' ">
|
|
|
+ and u2.nick_name like CONCAT('%',#{maps.createUserName},'%')
|
|
|
+ </if>
|
|
|
+ <if test="maps.mobile != null and maps.mobile !='' ">
|
|
|
+ and c.mobile like CONCAT('%',#{maps.mobile},'%')
|
|
|
+ </if>
|
|
|
+ <if test="maps.receiveUserId == -1">
|
|
|
+ and c.receive_user_id is NULL
|
|
|
+ </if>
|
|
|
+ <if test="maps.receiveUserId == 0">
|
|
|
+ and c.receive_user_id is NOT NULL
|
|
|
+ </if>
|
|
|
+ <if test="maps.receiveUserId != null and maps.receiveUserId != 0 and maps.receiveUserId != -1">
|
|
|
+ and c.receive_user_id = #{maps.receiveUserId}
|
|
|
+ </if>
|
|
|
+ <if test="maps.status != null and maps.status !='' ">
|
|
|
+ and c.status =#{maps.status}
|
|
|
+ </if>
|
|
|
+ <if test="maps.isReceive != null ">
|
|
|
+ and c.is_receive =#{maps.isReceive}
|
|
|
+ </if>
|
|
|
+ <if test="maps.customerType != null ">
|
|
|
+ and c.customer_type =#{maps.customerType}
|
|
|
+ </if>
|
|
|
+ <if test="maps.companyId != null ">
|
|
|
+ and c.company_id =#{maps.companyId}
|
|
|
+ </if>
|
|
|
+ <if test="maps.source != null and maps.source !='' ">
|
|
|
+ and c.source =#{maps.source}
|
|
|
+ </if>
|
|
|
+ <if test="maps.tags != null ">
|
|
|
+ and
|
|
|
+ <foreach collection="maps.tags.split(',')" item="tag" open="(" close=")" separator="OR">
|
|
|
+ find_in_set(#{tag},c.tags)
|
|
|
+ </foreach>
|
|
|
+ </if>
|
|
|
+ <if test="maps.isPool != null ">
|
|
|
+ and c.is_pool = #{maps.isPool}
|
|
|
+ </if>
|
|
|
+ <if test="maps.createTime != null ">
|
|
|
+ and DATE_FORMAT(c.create_time, '%Y-%m-%d') = DATE_FORMAT(#{maps.createTime}, '%Y-%m-%d')
|
|
|
+ </if>
|
|
|
+ <if test="maps.beginTime != null and maps.beginTime !='' ">
|
|
|
+ and date_format(c.create_time,'%y%m%d') >= date_format(#{maps.beginTime},'%y%m%d')
|
|
|
+ </if>
|
|
|
+ <if test="maps.endTime != null and maps.endTime !='' ">
|
|
|
+ and date_format(c.create_time,'%y%m%d') <= date_format(#{maps.endTime},'%y%m%d')
|
|
|
+ </if>
|
|
|
+ <if test="maps.beginReceiveTime != null and maps.beginReceiveTime !='' ">
|
|
|
+ and date_format(c.receive_time,'%y%m%d') >= date_format(#{maps.beginReceiveTime},'%y%m%d')
|
|
|
+ </if>
|
|
|
+ <if test="maps.endReceiveTime != null and maps.endReceiveTime !='' ">
|
|
|
+ and date_format(c.receive_time,'%y%m%d') <= date_format(#{maps.endReceiveTime},'%y%m%d')
|
|
|
+ </if>
|
|
|
+
|
|
|
+
|
|
|
+ ${maps.params.dataScope}
|
|
|
+ <if test="maps.orderBy != null and maps.orderBy != ''">
|
|
|
+ order by c.next_time ${maps.orderBy} ,c.customer_id desc
|
|
|
+ </if>
|
|
|
+ <if test="maps.orderBy == null or maps.orderBy == ''">
|
|
|
+ order by c.customer_id desc
|
|
|
+ </if>
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="selectCrmCustomerListByUnPool" resultType="com.fs.crm.vo.CrmCustomerUnPoolListQueryVO">
|
|
|
+ WITH RankedCustomers AS (
|
|
|
+ select c.*,ROW_NUMBER() OVER (PARTITION BY c.customer_id ORDER BY c.create_time DESC) AS rn from (
|
|
|
+ <if test="param1 != null">
|
|
|
+ (SELECT
|
|
|
+ *,
|
|
|
+ '领取未跟进' AS pool_type,
|
|
|
+ (receive_time+ INTERVAL ${param1.limitDay} DAY) AS pooling_time,
|
|
|
+ TIMESTAMPDIFF(MINUTE, NOW(), (receive_time + INTERVAL ${param1.limitDay} DAY)) AS `time`
|
|
|
+ from crm_customer n
|
|
|
+ WHERE n.is_del = 0
|
|
|
+ AND n.is_pool = 0
|
|
|
+ AND n.is_receive = 1
|
|
|
+ <if test="param2 != null">
|
|
|
+ AND n.visit_status IS NULL
|
|
|
+ AND n.receive_user_id IS NOT NULL
|
|
|
+ AND n.customer_id NOT IN (SELECT v.customer_id FROM `crm_customer_visit` v GROUP BY v.customer_id HAVING v.customer_id is NOT NULL)
|
|
|
+ </if>
|
|
|
+
|
|
|
+ )
|
|
|
+
|
|
|
+ </if>
|
|
|
+ <if test="param2 != null">
|
|
|
+ UNION(
|
|
|
+ SELECT *,
|
|
|
+ '未继续跟进' AS pool_type,
|
|
|
+ (GREATEST(
|
|
|
+ IFNULL(visit_time, '1000-01-01'),
|
|
|
+ IFNULL(sys_visit_time, '1000-01-01')
|
|
|
+ ) + INTERVAL ${param2.limitDay} DAY) AS pooling_time,
|
|
|
+ TIMESTAMPDIFF(
|
|
|
+ MINUTE,
|
|
|
+ NOW(),
|
|
|
+ (GREATEST(
|
|
|
+ IFNULL(visit_time, '1000-01-01'),
|
|
|
+ IFNULL(sys_visit_time, '1000-01-01')
|
|
|
+ ) + INTERVAL ${param2.limitDay} DAY)
|
|
|
+ ) AS `time`
|
|
|
+ FROM crm_customer
|
|
|
+ WHERE is_del = 0
|
|
|
+ AND is_pool = 0
|
|
|
+ AND visit_status IS NOT NULL
|
|
|
+ AND visit_time IS NOT NULL
|
|
|
+ )
|
|
|
+ </if>
|
|
|
+ <if test="param3!=null">
|
|
|
+ UNION(SELECT c.*,
|
|
|
+ '未有商机' AS pool_type,
|
|
|
+ (c.create_time + INTERVAL ${param3.limitDay} DAY) AS pooling_time,
|
|
|
+ TIMESTAMPDIFF(MINUTE, NOW(), (c.create_time + INTERVAL ${param3.limitDay} DAY)) AS `time`
|
|
|
+ FROM `crm_customer` c
|
|
|
+ WHERE c.is_del = 0
|
|
|
+ AND c.is_pool = 0
|
|
|
+ AND c.customer_id NOT IN (
|
|
|
+ SELECT b.customer_id FROM crm_business b WHERE b.create_time > (NOW()-INTERVAL ${param3.limitDay} DAY)
|
|
|
+ AND b.customer_id
|
|
|
+ IS NOT NULL GROUP BY b.customer_id)
|
|
|
+ )
|
|
|
+ </if>
|
|
|
+
|
|
|
+ ) as c
|
|
|
+ where c.is_del = 0 and c.is_pool_rule = 1
|
|
|
+ <if test="param.customerCode != null and param.customerCode != ''"> and c.customer_code = #{param.customerCode}</if>
|
|
|
+ <if test="param.customerName != null and param.customerName !=''"> and c.customer_name like concat('%', #{param.customerName}, '%')</if>
|
|
|
+ <if test="param.customerCompanyName != null and param.customerCompanyName !=''"> and c.customer_company_name like concat('%', #{param.customerCompanyName}, '%')</if>
|
|
|
+ <if test="param.mobile != null and param.mobile != ''"> and c.mobile= #{param.mobile}</if>
|
|
|
+ <if test="param.sex != null "> and c.sex =#{param.sex}</if>
|
|
|
+ <if test="param.weixin != null and param.weixin != ''"> and c.weixin= #{param.weixin}</if>
|
|
|
+ <if test="param.createUserId != null "> and c.create_user_id = #{param.createUserId}</if>
|
|
|
+ <if test="param.receiveUserId != null "> and c.receive_user_id = #{param.receiveUserId}</if>
|
|
|
+ <if test="param.customerUserId != null "> and c.customer_user_id = #{param.customerUserId}</if>
|
|
|
+ <if test="param.deptId != null "> and c.dept_id = #{deptId}</if>
|
|
|
+ <if test="param.customerType != null "> and c.customer_type = #{param.customerType}</if>
|
|
|
+ <if test="param.companyId != null "> and c.company_id = #{param.companyId}</if>
|
|
|
+ <if test="param.source != null and param.source != ''"> and c.source = #{param.source}</if>
|
|
|
+ <if test="param.tags != null and param.tags != ''"> and c.tags = #{param.tags}</if>
|
|
|
+ <if test="param.beginTime != null and param.beginTime !='' ">
|
|
|
+ and date_format(c.create_time,'%y%m%d') >= date_format(#{param.beginTime},'%y%m%d')
|
|
|
+ </if>
|
|
|
+ <if test="param.endTime != null and param.endTime !='' ">
|
|
|
+ and date_format(c.create_time,'%y%m%d') <= date_format(#{param.endTime},'%y%m%d')
|
|
|
+ </if>
|
|
|
+ <if test="param.beginReceiveTime != null and param.beginReceiveTime !='' ">
|
|
|
+ and date_format(c.receive_time,'%y%m%d%H%i%s') >= date_format(#{param.beginReceiveTime},'%y%m%d%H%i%s')
|
|
|
+ </if>
|
|
|
+ <if test="param.endReceiveTime != null and param.endReceiveTime !='' ">
|
|
|
+ and date_format(c.receive_time,'%y%m%d%H%i%s') <= date_format(#{param.endReceiveTime},'%y%m%d%H%i%s')
|
|
|
+ </if>
|
|
|
+ <if test="param.companyUserNickName != null and param.companyUserNickName !='' ">
|
|
|
+ and cu.nick_name like CONCAT('%',#{param.companyUserNickName},'%')
|
|
|
+ </if>
|
|
|
+ )
|
|
|
+ SELECT r.*,cu.nick_name as company_user_nick_name
|
|
|
+ FROM RankedCustomers r
|
|
|
+ left join company_user cu on cu.user_id=r.receive_user_id
|
|
|
+ WHERE r.rn = 1
|
|
|
+ <if test="param.orderBy != null and param.orderBy != ''">
|
|
|
+ order by r.next_time ${param.orderBy} ,r.`time` asc
|
|
|
+ </if>
|
|
|
+ <if test="param.orderBy == null or param.orderBy == ''">
|
|
|
+ order by r.`time` asc
|
|
|
+ </if>
|
|
|
+ limit #{param.start}, #{param.pageSize};
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <select id="countCrmCustomerListByUnPool" resultType="long">
|
|
|
+ WITH RankedCustomers AS (
|
|
|
+ select c.*,ROW_NUMBER() OVER (PARTITION BY c.customer_id ORDER BY c.create_time DESC) AS rn from (
|
|
|
+ <if test="param1 != null">
|
|
|
+ (SELECT *,
|
|
|
+ (receive_time+ INTERVAL ${param1.limitDay} DAY) AS pooling_time,
|
|
|
+ TIMESTAMPDIFF(MINUTE, NOW(), (receive_time + INTERVAL ${param1.limitDay} DAY)) AS `time`
|
|
|
+ from crm_customer
|
|
|
+ WHERE is_del = 0
|
|
|
+ AND is_pool = 0
|
|
|
+ AND is_receive = 1
|
|
|
+ <if test="param2 != null">
|
|
|
+ AND visit_status IS NULL
|
|
|
+ AND receive_user_id IS NOT NULL
|
|
|
+ AND customer_id NOT IN (SELECT v.customer_id FROM `crm_customer_visit` v GROUP BY v.customer_id HAVING v.customer_id is NOT NULL)
|
|
|
+ </if>
|
|
|
+ )
|
|
|
+
|
|
|
+ </if>
|
|
|
+ <if test="param2 != null">
|
|
|
+ UNION(
|
|
|
+ SELECT *,
|
|
|
+ (GREATEST(
|
|
|
+ IFNULL(visit_time, '1000-01-01'),
|
|
|
+ IFNULL(sys_visit_time, '1000-01-01')
|
|
|
+ ) + INTERVAL ${param2.limitDay} DAY) AS pooling_time,
|
|
|
+ TIMESTAMPDIFF(
|
|
|
+ MINUTE,
|
|
|
+ NOW(),
|
|
|
+ (GREATEST(
|
|
|
+ IFNULL(visit_time, '1000-01-01'),
|
|
|
+ IFNULL(sys_visit_time, '1000-01-01')
|
|
|
+ ) + INTERVAL ${param2.limitDay} DAY)
|
|
|
+ ) AS `time`
|
|
|
+ FROM crm_customer
|
|
|
+ WHERE is_del = 0
|
|
|
+ AND is_pool = 0
|
|
|
+ AND visit_status IS NOT NULL
|
|
|
+ AND visit_time IS NOT NULL
|
|
|
+ )
|
|
|
+ </if>
|
|
|
+ <if test="param3!=null">
|
|
|
+ UNION(SELECT c.*,
|
|
|
+ (c.create_time + INTERVAL ${param3.limitDay} DAY) AS pooling_time,
|
|
|
+ TIMESTAMPDIFF(MINUTE, NOW(), (c.create_time + INTERVAL ${param3.limitDay} DAY)) AS `time`
|
|
|
+ FROM `crm_customer` c
|
|
|
+ WHERE c.is_del = 0
|
|
|
+ AND c.is_pool = 0
|
|
|
+ AND c.customer_id NOT IN (
|
|
|
+ SELECT b.customer_id FROM crm_business b WHERE b.create_time > (NOW()-INTERVAL ${param3.limitDay} DAY)
|
|
|
+ AND b.customer_id
|
|
|
+ IS NOT NULL GROUP BY b.customer_id)
|
|
|
+ )
|
|
|
+ </if>
|
|
|
+ ) as c
|
|
|
+ where c.is_del = 0 and c.is_pool_rule = 1
|
|
|
+ <if test="param.customerCode != null and param.customerCode != ''"> and c.customer_code = #{param.customerCode}</if>
|
|
|
+ <if test="param.customerName != null and param.customerName !=''"> and c.customer_name like concat('%', #{param.customerName}, '%')</if>
|
|
|
+ <if test="param.customerCompanyName != null and param.customerCompanyName !=''"> and c.customer_company_name like concat('%', #{param.customerCompanyName}, '%')</if>
|
|
|
+ <if test="param.mobile != null and param.mobile != ''"> and c.mobile= #{param.mobile}</if>
|
|
|
+ <if test="param.sex != null "> and c.sex =#{param.sex}</if>
|
|
|
+ <if test="param.weixin != null and param.weixin != ''"> and c.weixin= #{param.weixin}</if>
|
|
|
+ <if test="param.createUserId != null "> and c.create_user_id = #{param.createUserId}</if>
|
|
|
+ <if test="param.receiveUserId != null "> and c.receive_user_id = #{param.receiveUserId}</if>
|
|
|
+ <if test="param.customerUserId != null "> and c.customer_user_id = #{param.customerUserId}</if>
|
|
|
+ <if test="param.deptId != null "> and c.dept_id = #{deptId}</if>
|
|
|
+ <if test="param.customerType != null "> and c.customer_type = #{param.customerType}</if>
|
|
|
+ <if test="param.companyId != null "> and c.company_id = #{param.companyId}</if>
|
|
|
+ <if test="param.source != null and param.source != ''"> and c.source = #{param.source}</if>
|
|
|
+ <if test="param.tags != null and param.tags != ''"> and c.tags = #{param.tags}</if>
|
|
|
+ <if test="param.beginTime != null and param.beginTime !='' ">
|
|
|
+ and date_format(c.create_time,'%y%m%d') >= date_format(#{param.beginTime},'%y%m%d')
|
|
|
+ </if>
|
|
|
+ <if test="param.endTime != null and param.endTime !='' ">
|
|
|
+ and date_format(c.create_time,'%y%m%d') <= date_format(#{param.endTime},'%y%m%d')
|
|
|
+ </if>
|
|
|
+ <if test="param.beginReceiveTime != null and param.beginReceiveTime !='' ">
|
|
|
+ and date_format(c.receive_time,'%y%m%d%H%i%s') >= date_format(#{param.beginReceiveTime},'%y%m%d%H%i%s')
|
|
|
+ </if>
|
|
|
+ <if test="param.endReceiveTime != null and param.endReceiveTime !='' ">
|
|
|
+ and date_format(c.receive_time,'%y%m%d%H%i%s') <= date_format(#{param.endReceiveTime},'%y%m%d%H%i%s')
|
|
|
+ </if>
|
|
|
+ <if test="param.companyUserNickName != null and param.companyUserNickName !='' ">
|
|
|
+ and cu.nick_name like CONCAT('%',#{param.companyUserNickName},'%')
|
|
|
+ </if>
|
|
|
+ )
|
|
|
+ SELECT count(1)
|
|
|
+ FROM RankedCustomers r
|
|
|
+ left join company_user cu on cu.user_id=r.receive_user_id
|
|
|
+ WHERE r.rn = 1
|
|
|
+
|
|
|
+ ;
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <update id="recoverCrmLineCustomerList">
|
|
|
+ update crm_customer c set c.is_pool = 1,c.pool_time = now()
|
|
|
+ <where>
|
|
|
+ <if test="maps.isLine != null">
|
|
|
+ and c.is_line = #{maps.isLine}
|
|
|
+ </if>
|
|
|
+ <if test="maps.customerCode != null and maps.customerCode !='' ">
|
|
|
+ and c.customer_code like CONCAT('%',#{maps.customerCode},'%')
|
|
|
+ </if>
|
|
|
+ <if test="maps.customerName != null and maps.customerName !='' ">
|
|
|
+ and c.customer_name like CONCAT('%',#{maps.customerName},'%')
|
|
|
+ </if>
|
|
|
+ <if test="maps.mobile != null and maps.mobile !='' ">
|
|
|
+ and c.mobile like CONCAT('%',#{maps.mobile},'%')
|
|
|
+ </if>
|
|
|
+ <if test="maps.receiveUserId == -1">
|
|
|
+ and c.receive_user_id is NULL
|
|
|
+ </if>
|
|
|
+ <if test="maps.receiveUserId == 0">
|
|
|
+ and c.receive_user_id is NOT NULL
|
|
|
+ </if>
|
|
|
+ <if test="maps.receiveUserId != null and maps.receiveUserId != 0 and maps.receiveUserId != -1">
|
|
|
+ and c.receive_user_id = #{maps.receiveUserId}
|
|
|
+ </if>
|
|
|
+ <if test="maps.status != null and maps.status !='' ">
|
|
|
+ and c.status =#{maps.status}
|
|
|
+ </if>
|
|
|
+ <if test="maps.isReceive != null ">
|
|
|
+ and c.is_receive =#{maps.isReceive}
|
|
|
+ </if>
|
|
|
+ <if test="maps.customerType != null ">
|
|
|
+ and c.customer_type =#{maps.customerType}
|
|
|
+ </if>
|
|
|
+ <if test="maps.companyId != null ">
|
|
|
+ and c.company_id =#{maps.companyId}
|
|
|
+ </if>
|
|
|
+ <if test="maps.source != null and maps.source !='' ">
|
|
|
+ and c.source =#{maps.source}
|
|
|
+ </if>
|
|
|
+ <if test="maps.tags != null ">
|
|
|
+ and
|
|
|
+ <foreach collection="maps.tags.split(',')" item="tag" open="(" close=")" separator="OR">
|
|
|
+ find_in_set(#{tag},c.tags)
|
|
|
+ </foreach>
|
|
|
+ </if>
|
|
|
+ <if test="maps.isPool != null ">
|
|
|
+ and c.is_pool = #{maps.isPool}
|
|
|
+ </if>
|
|
|
+ <if test="maps.createTime != null ">
|
|
|
+ and DATE_FORMAT(c.create_time, '%Y-%m-%d') = DATE_FORMAT(#{maps.createTime}, '%Y-%m-%d')
|
|
|
+ </if>
|
|
|
+ <if test="maps.beginTime != null and maps.beginTime !='' ">
|
|
|
+ and date_format(c.create_time,'%y%m%d') >= date_format(#{maps.beginTime},'%y%m%d')
|
|
|
+ </if>
|
|
|
+ <if test="maps.endTime != null and maps.endTime !='' ">
|
|
|
+ and date_format(c.create_time,'%y%m%d') <= date_format(#{maps.endTime},'%y%m%d')
|
|
|
+ </if>
|
|
|
+ </where>
|
|
|
+ </update>
|
|
|
+
|
|
|
+ <select id="selectCrmCustomerByCondition" resultType="com.fs.crm.domain.CrmCustomer">
|
|
|
+ <include refid="selectCrmCustomerVo"/>
|
|
|
+ where is_del = 0
|
|
|
+ <if test="(customerCompanyName != null and customerCompanyName !='') and (mobile != null and mobile !='')">
|
|
|
+ and(
|
|
|
+ <if test="customerCompanyName != null and customerCompanyName !=''">
|
|
|
+ customer_company_name like #{customerCompanyName}
|
|
|
+ </if>
|
|
|
+ <if test="mobile != null and mobile !=''">
|
|
|
+ or mobile like #{mobile}
|
|
|
+ </if>
|
|
|
+ )
|
|
|
+ </if>
|
|
|
+ <if test="(customerCompanyName != null and customerCompanyName !='') and (mobile == null or mobile =='')">
|
|
|
+ and customer_company_name like #{customerCompanyName}
|
|
|
+ </if>
|
|
|
+ <if test="(customerCompanyName == null or customerCompanyName =='') and (mobile != null and mobile !='')">
|
|
|
+ and mobile like #{mobile}
|
|
|
+ </if>
|
|
|
+
|
|
|
+ </select>
|
|
|
|
|
|
</mapper>
|