<?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.nova.sankuai.infra.mapper.CustomerMapper">
|
|
<select id="pageModel" resultType="com.nova.sankuai.domain.vo.customer.CustomerVo">
|
select c.id as id,
|
c.name as name,
|
c.phone as phone,
|
cr.status as status,
|
cr.star_rating as starRating,
|
cr.description as description,
|
c.apply_date as applyDate,
|
su.company_name as mechanismName,
|
su.id as mechanismId
|
from customer c
|
left join communication_results cr on c.id = cr.customer_id and cr.delete_flag = 0
|
left join sys_user su on c.mechanism_id = su.id and su.delete_flag = 0
|
<where>
|
c.delete_flag = 0
|
<if test="customerPageDto.id != null and customerPageDto.id !=''">
|
and c.id like concat('%',#{customerPageDto.id},'%')
|
</if>
|
<if test="customerPageDto.mechanismName != null and customerPageDto.mechanismName !=''">
|
and su.company_name like concat('%',#{customerPageDto.mechanismName},'%')
|
</if>
|
<if test="customerPageDto.phone != null and customerPageDto.phone !=''">
|
and c.phone like concat('%',#{customerPageDto.phone},'%')
|
</if>
|
<if test="customerPageDto.city != null and customerPageDto.city !=''">
|
and c.city_name like concat('%',#{customerPageDto.city},'%')
|
</if>
|
<if test="customerPageDto.communicationStatus != null ">
|
and cr.status = #{customerPageDto.communicationStatus}
|
</if>
|
<if test="customerPageDto.applyDateStart != null">
|
and c.apply_date >= #{customerPageDto.applyDateStart}
|
</if>
|
<if test="customerPageDto.applyDateEnd != null">
|
and c.apply_date <= #{customerPageDto.applyDateEnd}
|
</if>
|
<if test="customerPageDto.mechanismId != null">
|
and c.mechanism_id = #{customerPageDto.mechanismId}
|
</if>
|
</where>
|
order by c.apply_date desc
|
</select>
|
|
<select id="getCustomersOfDay" resultType="com.nova.sankuai.domain.vo.customer.CustomerCountVo">
|
select mechanism_id as mechanismId,
|
count(mechanism_id) as count
|
from customer
|
<where>
|
delete_flag = 0 and apply_date <=#{endOfDay} and apply_date >=#{beginOfDay}
|
<if test="list != null and !list.isEmpty()">
|
and mechanism_id in
|
<foreach collection="list" item="item" open="(" separator="," close=")" index="i">
|
#{item}
|
</foreach>
|
</if>
|
</where>
|
group by mechanism_id
|
</select>
|
|
<select id="getCustomerCounts" resultType="com.nova.sankuai.domain.vo.customer.CustomerCountVo">
|
select mechanism_id as mechanismId,
|
count(mechanism_id) as count
|
from customer
|
<where>
|
delete_flag = 0 and mechanism_id in
|
<foreach collection="ids" item="item" open="(" separator="," close=")" index="i">
|
#{item}
|
</foreach>
|
</where>
|
group by mechanism_id
|
</select>
|
|
<select id="getCustomerCount" resultType="com.nova.sankuai.domain.vo.customer.CustomerCountVo">
|
select mechanism_id as mechanismId,
|
count(mechanism_id) as count
|
from customer
|
<where>
|
delete_flag = 0 and mechanism_id = #{id}
|
<if test="beginOfDay != null">
|
and apply_date >=#{beginOfDay}
|
</if>
|
<if test="endOfDay != null">
|
and apply_date <=#{endOfDay}
|
</if>
|
</where>
|
</select>
|
|
<select id="getUserRecord" resultType="com.nova.sankuai.domain.entity.Customer">
|
select * from customer
|
where phone = #{phone}
|
and name is not null
|
and delete_flag = 0
|
</select>
|
|
<select id="getLatestCustomerRecord" resultType="com.nova.sankuai.domain.entity.Customer">
|
select * from customer c
|
where c.phone = #{phone}
|
and c.name is not null
|
and c.delete_flag = 0
|
order by c.apply_date desc limit 1
|
</select>
|
|
<select id="getInletFlowProportion" resultType="com.nova.sankuai.domain.vo.InletFlowProportionVo">
|
SELECT
|
D.tHour AS tHour,
|
D.hHour AS hHour,
|
D.hDay AS hDay,
|
A.chName AS chName,
|
A.uvSum AS uvSum,
|
B.pkSum AS pkSum,
|
concat(ROUND(B.pkSum / A.uvSum*100, 2),"%") AS pkPropertion,
|
C.vipSum AS vipSum,
|
concat(ROUND(C.vipSum / A.uvSum*100, 2),"%") AS vipPropertion
|
FROM (
|
select
|
DATE_FORMAT(tHour,'%m-%d') AS hDay,
|
DATE_FORMAT(tHour,'%H') AS hHour,
|
tHour AS tHour
|
from(
|
<foreach collection="hourStr" item="item" index="index">
|
<if test="item=='00'">
|
select concat(#{startDayStr},' ',#{item}) as tHour
|
</if>
|
<if test="item!='00'">
|
union select concat(#{startDayStr},' ',#{item}) as tHour
|
</if>
|
</foreach>
|
<foreach collection="hourStr" item="item" index="index">
|
union select concat(#{endDayStr},' ',#{item}) as tHour
|
</foreach>
|
) as tmp
|
) as D
|
left join
|
(SELECT
|
ci.name AS chName,
|
count(cu.id) AS uvSum,
|
DATE_FORMAT(cu.apply_date,'%Y-%m-%d %H') AS tHour
|
FROM customer cu
|
LEFT JOIN channel_info ci ON cu.source_channel = ci.code
|
WHERE ci.code = #{chCode}
|
and cu.apply_date >= #{startDate} and cu.apply_date <= #{endDate}
|
GROUP BY tHour ORDER BY tHour DESC
|
) AS A ON D.tHour = A.tHour
|
LEFT JOIN (SELECT
|
count(od.id) AS pkSum,
|
date_format(od.creation_date,'%Y-%m-%d %H') AS tHour
|
FROM vip_card_order od
|
LEFT JOIN customer_user cu ON od.user_id = cu.id
|
LEFT JOIN channel_info ci ON cu.source_channel = ci.code
|
WHERE ci.code =#{chCode}
|
AND od.status = 'END' AND od.vip_type = 1
|
and od.creation_date >= #{startDate} and od.creation_date <= #{endDate}
|
GROUP BY tHour ORDER BY tHour DESC
|
) AS B ON D.tHour = B.tHour
|
LEFT JOIN (
|
SELECT count(od.id) AS vipSum,
|
date_format(od.creation_date,'%Y-%m-%d %H') AS tHour
|
FROM vip_card_order od
|
LEFT JOIN customer_user cu ON od.user_id = cu.id
|
LEFT JOIN channel_info ci ON cu.source_channel = ci.code
|
WHERE ci.code =#{chCode}
|
AND od.status = 'END' AND od.vip_type = 0
|
and od.creation_date >= #{startDate} and od.creation_date <= #{endDate}
|
GROUP BY tHour ORDER BY tHour DESC
|
) AS C ON D.tHour = C.tHour;
|
</select>
|
</mapper>
|