EntmicroCustomerFollowMapper.xml
14.3 KB
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
<?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.entmicro.mapper.EntmicroCustomerFollowMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.entmicro.entity.EntmicroCustomerFollow">
<!--
WARNING - @mbg.generated
-->
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="customer_id" jdbcType="INTEGER" property="customerId"/>
<result column="staff_id" jdbcType="INTEGER" property="staffId"/>
<result column="remark" jdbcType="VARCHAR" property="remark"/>
<result column="description" jdbcType="VARCHAR" property="description"/>
<result column="remark_mobiles" jdbcType="VARCHAR" property="remarkMobiles"/>
<result column="add_way" jdbcType="TINYINT" property="addWay"/>
<result column="oper_userid" jdbcType="VARCHAR" property="operUserid"/>
<result column="created_by" jdbcType="INTEGER" property="createdBy"/>
<result column="created_time" jdbcType="TIMESTAMP" property="createdTime"/>
<result column="updated_by" jdbcType="INTEGER" property="updatedBy"/>
<result column="updated_time" jdbcType="TIMESTAMP" property="updatedTime"/>
<result column="del_flag" jdbcType="TINYINT" property="delFlag"/>
<result column="externalUserId" jdbcType="VARCHAR" property="externalUserId"/>
<result column="user_id" jdbcType="VARCHAR" property="userid"/>
</resultMap>
<resultMap id="CustomerRelationDataPushModelMap"
type="cn.com.glsx.entmicro.model.customer.CustomerRelationDataPushModel">
<result column="merchantId" jdbcType="INTEGER" property="merchantId"/>
<result column="addWay" jdbcType="INTEGER" property="addWay"/>
<result column="customerPhone" jdbcType="VARCHAR" property="customerPhone"/>
<result column="userId" jdbcType="VARCHAR" property="userId"/>
<result column="addWechatStatus" jdbcType="INTEGER" property="addWechatStatus"/>
<result column="joinGroupStatus" jdbcType="INTEGER" property="joinGroupStatus"/>
</resultMap>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
-->
id, customer_id, staff_id, remark, description, remark_mobiles, add_way,oper_userid, created_by,
created_time, updated_by, updated_time, del_flag
</sql>
<update id="deleteRelation">
update entmicro_customer_follow scf2
set scf2.del_flag = -1
where scf2.id=#{id}
</update>
<update id="deleteCustomer">
update entmicro_customer_follow
set del_flag = -1
where `customer_id` = #{id}
</update>
<update id="updatelist">
<foreach collection="list" item="item" index="index" open="" close="" separator=";">
update entmicro_customer_follow
<set>
updated_time=NOW(),
remark=#{item.remark},
description=#{item.description},
<if test="item.remarkMobiles != null and item.remarkMobiles != ''">
remark_mobiles=#{item.remarkMobiles}
</if>
</set>
where
customer_id = #{item.customerId}
and
staff_id = #{item.staffId}
</foreach>
</update>
<select id="findFollowByExternalUserId" resultType="cn.com.glsx.entmicro.entity.EntmicroCustomerFollow">
select scf.id,
scf.customer_id as customerId,
es.user_id as userid
from entmicro_customer_follow scf
left join scrm_customer sc on scf.customer_id = sc.id
left join entmicro_staff es on scf.staff_id = es.id and es.del_flag = 0
where sc.user_id = #{externalUserId}
and scf.del_flag = 0
GROUP BY scf.id
</select>
<select id="findAllFollowByExternalUserId" resultType="cn.com.glsx.entmicro.entity.EntmicroCustomerFollow">
select scf.id,
scf.customer_id as customerId,
scf.staff_id as staffId,
es.user_id as userid
from entmicro_customer_follow scf
left join scrm_customer sc on scf.customer_id = sc.id
left join entmicro_staff es on scf.staff_id = es.id
where sc.user_id = #{externalUserId}
group by scf.id
</select>
<select id="findRelationByStaffId" resultMap="BaseResultMap">
select customer_id,
staff_id
from entmicro_customer_follow
where del_flag = 0
and customer_id = #{customerId}
and staff_id in
<foreach collection="staffId" open="(" close=")" item="staffId" separator=",">
#{staffId}
</foreach>
</select>
<select id="findRelationById" resultType="cn.com.glsx.entmicro.model.response.CustomerFollowStaffResponse">
SELECT t1.id as id,
t2.customer_name as customerName,
t3.user_id as staffUserId,
t2.user_id as customerUserId,
t3.staff_name as staffName,
t4.relevance_merchant AS relevanceMerchant
FROM entmicro_customer_follow t1
LEFT JOIN `scrm_customer` t2 ON t1.customer_id = t2.id
LEFT JOIN `entmicro_staff` t3 ON t1.staff_id = t3.id
LEFT JOIN `entmicro_staff_depart_relation` t4 ON t3.id = t4.staff_id
WHERE t1.id = #{id}
GROUP BY t1.id
</select>
<select id="findRelationByUserId" resultType="cn.com.glsx.entmicro.model.response.CustomerFollowStaffResponse">
SELECT t1.id as id,
t2.customer_name as customerName,
t2.user_id as customerUserId,
t3.user_id as staffUserId,
t3.staff_name as staffName,
t1.created_time as createdTime
FROM entmicro_customer_follow t1
LEFT JOIN `scrm_customer` t2 ON t1.customer_id = t2.id
LEFT JOIN `entmicro_staff` t3 ON t1.staff_id = t3.id
WHERE t2.del_flag = 0 and t1.del_flag = 0 and t3.del_flag = 0
and (t2.user_id = #{id} or t2.one_id = #{id})
order by t1.created_time desc
</select>
<update id="updatePhone">
update entmicro_customer_follow
set remark_mobiles = #{remarkMobiles},
updated_time = NOW()
where id = #{id}
</update>
<select id="findByRelationId" resultType="cn.com.glsx.entmicro.model.response.CustomerInfo">
SELECT t2.one_id as oneId,
t2.customer_name as customerName
FROM `entmicro_customer_follow` t1
LEFT JOIN `scrm_customer` t2 ON t1.customer_id = t2.id
WHERE t1.id = #{id}
</select>
<select id="findByStaffId" resultMap="BaseResultMap">
SELECT customer_id,
staff_id
FROM `entmicro_customer_follow`
WHERE staff_id = #{staffId}
AND del_flag = 0
</select>
<update id="updateBatchInfo">
<foreach collection="customer" separator=";" item="item">
update entmicro_customer_follow
set remark_mobiles = #{item.remarkPhone},
updated_time = NOW()
where customer_id = #{item.id}
and del_flag = 0
and (remark_mobiles is null
OR remark_mobiles = "")
</foreach>
</update>
<select id="findBatchRelationInfo" resultMap="BaseResultMap">
select scf.id,
scf.customer_id,
scf.staff_id,
scf.remark_mobiles,
es.user_id,
sc.user_id as externalUserId
from entmicro_customer_follow scf
left join scrm_customer sc on scf.customer_id = sc.id
left join entmicro_staff es on scf.staff_id = es.id
where sc.user_id in
<foreach collection="userIdList" open="(" close=")" item="item" separator=",">
#{item}
</foreach>
and scf.del_flag = 0
group by scf.id
</select>
<select id="mapByState" resultMap="BaseResultMap">
SELECT state,
id,
created_time
FROM `entmicro_customer_follow`
WHERE state IN
<foreach collection="stateList" item="state" open="(" separator="," close=")">
#{state}
</foreach>
<if test="date != null">
AND TO_DAYS(created_time) = TO_DAYS(#{date})
</if>
<if test="startTime != null">
AND TO_DAYS(created_time) <![CDATA[>=]]> TO_DAYS(#{startTime})
</if>
<if test="endTime != null">
AND TO_DAYS(created_time) <![CDATA[<=]]> TO_DAYS(#{endTime})
</if>
</select>
<select id="findCustomerRelationByUserIdOrPhone" resultMap="CustomerRelationDataPushModelMap">
select
#{param.addWay} addWay,
t.userId,
t.customerPhone,
(case when t.isJoin = 1 and esdrId is not null and t.ecfFlag = 0 then 2
when t.isJoin = 1 and esdrId is not null and ecfFlag = -1 then 3 else 1 end) addWechatStatus,
(case t.scbrFlag when 0 then 2 when -1 then 3 else 1 end) joinGroupStatus,
t.merchantId
from (
select
sc.id id,
sc.user_id userId,
scm.customer_phone customerPhone,
scm.status status,
scm.is_join isJoin,
t.scbrFlag scbrFlag,
scm.merchant_id merchantId,
ecf.del_flag ecfFlag,
esdr.id esdrId
from scrm_customer_merge scm
left join scrm_customer sc on sc.one_id = scm.one_id and scm.del_flag = 0
left join entmicro_customer_follow ecf on sc.id = ecf.customer_id
left join entmicro_staff es on ecf.staff_id = es.id and es.del_flag = 0
<if test="param.staffUserIdList != null and param.staffUserIdList.size > 0">
and es.user_id in
<foreach collection="param.staffUserIdList" item="staffUserId" open="(" separator="," close=")">
#{staffUserId}
</foreach>
</if>
left join entmicro_staff_depart_relation esdr on es.id = esdr.staff_id and esdr.del_flag = 0
<if test="merchantIds != null and merchantIds.size > 0">
and esdr.relevance_merchant in
<foreach collection="merchantIds" item="merchantId" open="(" separator="," close=")">
#{merchantId}
</foreach>
</if>
left join scrm_customer_base_relation scbr on sc.id = scbr.customer_id
left join (
select scbr.customer_id customer_id,scbr.del_flag scbrFlag from scrm_customer_base_relation scbr
left join scrm_customer_base scb on scbr.customer_base_id = scb.id and scb.del_flag = 0
<where>
<if test="param.chatIdList != null and param.chatIdList.size > 0">
and scb.chat_id in
<foreach collection="param.chatIdList" item="chatId" open="(" separator="," close=")">
#{chatId}
</foreach>
</if>
</where>
)t on sc.id = t.customer_id
where scm.merchant_id in
<foreach collection="merchantIds" item="merchantId" open="(" separator="," close=")">
#{merchantId}
</foreach>
<choose>
<when test="param.phoneList != null and param.phoneList.size > 0 and param.userIdList != null and param.userIdList.size > 0">
and (sc.customer_phone in
<foreach collection="param.phoneList" item="phone" open="(" separator="," close=")">
#{phone}
</foreach>
or sc.user_id in
<foreach collection="param.userIdList" item="userId" open="(" separator="," close=")">
#{userId}
</foreach>
)
</when>
<when test="param.phoneList!= null and param.phoneList.size > 0">
and sc.customer_phone in
<foreach collection="param.phoneList" item="phone" open="(" separator="," close=")">
#{phone}
</foreach>
</when>
<when test="param.userIdList!= null and param.userIdList.size > 0">
and sc.user_id in
<foreach collection="param.userIdList" item="userId" open="(" separator="," close=")">
#{userId}
</foreach>
</when>
</choose>
<!-- <if test="param.eventChatId != null">-->
<!-- AND scb.chat_id = #{param.eventChatId}-->
<!-- </if>-->
having 1
order by t.scbrFlag desc,esdr.id desc,ecf.del_flag desc
)t group by t.id,t.merchantId
</select>
<select id="findCustomerStaffFollow" resultMap="BaseResultMap">
select ecf.*
from scrm_customer sc
left join entmicro_customer_follow ecf on sc.id = ecf.customer_id and ecf.del_flag = 0
left join entmicro_staff es on ecf.staff_id = es.id and es.del_flag = 0
left join entmicro_staff_depart_relation esdr on es.id = esdr.staff_id and esdr.del_flag = 0
left join scrm_customer_merge scm on sc.one_id = scm.one_id and scm.del_flag = 0
where sc.del_flag = 0 and scm.customer_phone = #{customerPhone}
and esdr.relevance_merchant in
<foreach collection="merchantIdList" item="merchantId" open="(" separator="," close=")">
#{merchantId}
</foreach>
<if test="staffUserIdList != null and staffUserIdList.size() >0">
and es.user_id in
<foreach collection="staffUserIdList" item="userId" open="(" separator="," close=")">
#{userId}
</foreach>
</if>
</select>
<select id="selectCustomerFollowRemark" resultType="java.util.Map">
select scm.customer_phone,ecf.description remark,101 as add_way,esdr.relevance_merchant merchant_id,
sc.union_id,sc.user_id
from scrm_customer sc
left join scrm_customer_merge scm on sc.one_id = scm.one_id and scm.del_flag = 0
left join entmicro_customer_follow ecf on sc.id = ecf.customer_id and ecf.del_flag = 0
left join entmicro_staff es on ecf.staff_id = es.id and es.del_flag = 0
left join entmicro_staff_depart_relation esdr on es.id = esdr.staff_id and esdr.del_flag = 0 and ecf.description is not null
where sc.del_flag = 0 and ecf.description != ''
<if test="merchantIdList != null and merchantIdList.size() >0">
and esdr.relevance_merchant in
<foreach collection="merchantIdList" item="merchantId" open="(" separator="," close=")">
#{merchantId}
</foreach>
</if>
<if test="updateTime != null">
AND TO_DAYS(ecf.updated_time) <![CDATA[>=]]> TO_DAYS(#{updateTime})
</if>
</select>
</mapper>