2
sunshine
2024-11-05 d1f9fb55a136e589a5ad588ed9a93ce9272917da
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?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 &gt;= #{customerPageDto.applyDateStart}
            </if>
            <if test="customerPageDto.applyDateEnd != null">
                and c.apply_date &lt;= #{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 &lt;=#{endOfDay} and apply_date &gt;=#{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 &gt;=#{beginOfDay}
            </if>
            <if test="endOfDay != null">
                and apply_date &lt;=#{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 &gt;= #{startDate} and cu.apply_date &lt;= #{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 &gt;= #{startDate} and od.creation_date &lt;= #{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 &gt;= #{startDate} and od.creation_date &lt;= #{endDate}
        GROUP BY tHour ORDER BY tHour DESC
        ) AS C ON D.tHour = C.tHour;
    </select>
</mapper>