傅行帆 пре 3 година
родитељ
комит
d4e60f252f

+ 44
- 2
src/main/java/com/yunzhi/marketing/xlk/service/impl/CustomerInfoServiceImpl.java Прегледај датотеку

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6 6
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
7 7
 import com.yunzhi.marketing.common.StringUtils;
8 8
 import com.yunzhi.marketing.drainage.entity.TaDrainage;
9
+import com.yunzhi.marketing.drainage.mapper.TaDrainageMapper;
9 10
 import com.yunzhi.marketing.entity.*;
10 11
 import com.yunzhi.marketing.mapper.*;
11 12
 import com.yunzhi.marketing.service.IMiniAppService;
@@ -47,6 +48,19 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
47 48
     @Autowired
48 49
     private TaBuildingDynamicMapper taBuildingDynamicMapper;
49 50
 
51
+    @Autowired
52
+    private TaShareActivityMapper taShareActivityMapper;
53
+
54
+    @Autowired
55
+    private HelpActivityMapper helpActivityMapper;
56
+
57
+    @Autowired
58
+    private TaNewsMapper taNewsMapper;
59
+
60
+    @Autowired
61
+    private TaDrainageMapper taDrainageMapper;
62
+
63
+
50 64
     /**
51 65
      * 获取其他信息
52 66
      *
@@ -66,13 +80,41 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
66 80
             List<TaPersonVisitRecord> records = taPersonVisitRecordMapper.visitRecordByPersonIdNew(personId);
67 81
             records.forEach(e -> {
68 82
                 //获取活动标题
69
-                if ("activity".equals(e.getEventType()) && null != e.getTargetId()) {
83
+                if ("activity".equals(e.getEventType()) && null != e.getTargetId()){
70 84
                     TaBuildingDynamic taBuildingDynamic = taBuildingDynamicMapper.selectById(e.getTargetId());
71
-                    if (null != taBuildingDynamic) {
85
+                    if (null != taBuildingDynamic){
72 86
                         e.setActivityName(taBuildingDynamic.getTitle());
73 87
                     }
74 88
 
75 89
                 }
90
+                //获取拼团标题
91
+                if ("group".equals(e.getEventType()) && null != e.getTargetId()){
92
+                    TaShareActivity taShareActivity = taShareActivityMapper.selectById(e.getTargetId());
93
+                    if (null != taShareActivity){
94
+                        e.setActivityName(taShareActivity.getActivityName());
95
+                    }
96
+                }
97
+                //获取助力标题
98
+                if ("help".equals(e.getEventType()) && null != e.getTargetId()){
99
+                    HelpActivity helpActivity = helpActivityMapper.selectById(e.getTargetId());
100
+                    if (null != helpActivity){
101
+                        e.setActivityName(helpActivity.getTitle());
102
+                    }
103
+                }
104
+                //获取咨询标题
105
+                if ("news".equals(e.getEventType()) && null != e.getTargetId()){
106
+                    TaNews taNews = taNewsMapper.selectById(e.getTargetId());
107
+                    if (null != taNews){
108
+                        e.setActivityName(taNews.getNewsName());
109
+                    }
110
+                }
111
+                //获取H5活动标题
112
+                if ("h5".equals(e.getEventType()) && null != e.getTargetId()){
113
+                    TaDrainage taDrainage = taDrainageMapper.selectById(e.getTargetId());
114
+                    if (null != taDrainage){
115
+                        e.setActivityName(taDrainage.getName());
116
+                    }
117
+                }
76 118
             });
77 119
             customerInfoVO.setPersonVisitRecords(records);
78 120
             customerInfoVO.setVisitTimes(records.size());

+ 459
- 455
src/main/resources/mapper/TaPersonVisitRecordMapper.xml Прегледај датотеку

@@ -1,455 +1,459 @@
1
-<?xml version="1.0" encoding="UTF-8"?>
2
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
-<mapper namespace="com.yunzhi.marketing.mapper.TaPersonVisitRecordMapper">
4
-
5
-    <sql id="columnSql">
6
-        <trim suffixOverrides=",">
7
-            t.record_id,
8
-            t.person_id,
9
-            c.person_type,
10
-            t.visit_time,
11
-            t.leave_time,
12
-            t.visit_duration,
13
-            t.event,
14
-            t.data,
15
-            t.activity,
16
-            t.org_id,
17
-            t.building_id,
18
-            t.event_type,
19
-            t.target_id,
20
-            t.consultant_id,
21
-            t.share_person_id,
22
-        </trim>
23
-    </sql>
24
-
25
-    <select id="visitRecordByPersonId" resultType="com.yunzhi.marketing.entity.TaPersonVisitRecord">
26
-        select
27
-            t.* ,
28
-            b.parent_type_id from ta_person_visit_record t
29
-        left join td_biz_event_type b on t.event_type = b.type_id
30
-        where t.person_id = #{personId}
31
-        <if test="personBuildingList != null and personBuildingList.size > 0">
32
-            AND (b.parent_type_id = 'public' or t.building_id in
33
-            <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
34
-                #{personBuilding.buildingId}
35
-            </foreach>
36
-            )
37
-        </if>
38
-        <if test="buildingId != null and buildingId != ''">
39
-            AND (b.parent_type_id = 'public' or t.building_id = #{buildingId} )
40
-        </if>
41
-        order by t.visit_time desc
42
-    </select>
43
-
44
-    <select id="visitRecordByPersonIdNew" resultType="com.yunzhi.marketing.entity.TaPersonVisitRecord">
45
-        select
46
-        t.* ,
47
-        b.parent_type_id from ta_person_visit_record t
48
-        left join td_biz_event_type b on t.event_type = b.type_id
49
-        where t.person_id = #{personId}
50
-        order by t.visit_time desc
51
-    </select>
52
-
53
-    <select id="selectAll" resultType="com.yunzhi.marketing.entity.TaPersonVisitRecord">
54
-        SELECT
55
-            tpvr.record_id as recordId,
56
-            tpvr.person_id as personId,
57
-            tpvr.person_type as personType,
58
-            tpvr.building_id as buildingId,
59
-            tpvr.activity as activity,
60
-            tpvr.event as event,
61
-            tpvr.event_type as eventType,
62
-            tpvr.visit_duration as visitDuration,
63
-            (SELECT MIN(t.visit_time) FROM ta_person_visit_record t WHERE t.person_id = tpvr.person_id and t.event = tpvr.event and t.org_id = #{orgId} ) as visitTime,
64
-            (SELECT MAX(t.leave_time) FROM ta_person_visit_record t WHERE t.person_id = tpvr.person_id and t.event = tpvr.event and t.org_id = #{orgId} ) as leaveTime,
65
-            ifnull(tp.name, tp.nickname) as userName,
66
-            tbe.event_name as eventName,
67
-            COUNT(1) as accessCount
68
-        FROM
69
-            ta_person_visit_record tpvr
70
-            LEFT JOIN ta_person tp ON tpvr.person_id = tp.person_id
71
-            LEFT JOIN td_biz_event tbe on tpvr.event = tbe.event_code
72
-            <trim prefix="where" prefixOverrides="and | or">
73
-                tpvr.org_id = #{orgId}
74
-                and tp.org_id = #{orgId}
75
-                <if test="startDate != null and endDate != null">
76
-                    and tpvr.visit_time between #{startDate} and #{endDate}
77
-                </if>
78
-                <if test="buildingId != null and buildingId != ''">
79
-                    and tpvr.building_id = #{buildingId}
80
-                </if>
81
-                <if test="eventType != null and eventType != ''">
82
-                    and tpvr.event_type = #{eventType}
83
-                </if>
84
-                <if test="event != null and event != ''">
85
-                    and tpvr.event = #{event}
86
-                </if>
87
-                <if test="activity != null and activity != ''">
88
-                    and tpvr.activity = #{activity}
89
-                </if>
90
-            </trim>
91
-
92
-        GROUP BY tpvr.person_id, tpvr.event
93
-        ORDER BY 	accessCount DESC,tpvr.visit_time DESC
94
-    </select>
95
-    <select id="getPersonVisitRecordList" resultType="com.yunzhi.marketing.entity.TaPersonVisitRecord">
96
-        SELECT
97
-            t.*,
98
-            b.building_name
99
-        FROM
100
-            ta_person_visit_record t
101
-            LEFT JOIN ta_building b ON t.building_id = b.building_id
102
-        WHERE
103
-            t.person_id = #{personId}
104
-        ORDER BY
105
-            t.visit_time DESC
106
-    </select>
107
-
108
-    <select id="getDurationByPersonId" resultType="java.lang.Integer">
109
-        select SUM(visit_duration) from ta_person_visit_record where person_id = #{personId}
110
-    </select>
111
-
112
-    <select id="getFirstVisitTimeByPersonId" resultType="java.time.LocalDateTime">
113
-        select visit_time from ta_person_visit_record where person_id = #{personId} order by visit_time asc limit 1
114
-    </select>
115
-    <select id="getWxVisitRecordList" resultType="com.yunzhi.marketing.entity.TaPersonVisitRecord">
116
-        SELECT
117
-            t.* ,
118
-	        p.`name` as user_name,
119
-	        p.`nickname` as nickname,
120
-	        p.avatarurl,
121
-	        d.name as activity_name,
122
-	        d.create_date
123
-        FROM
124
-            ( SELECT * FROM ta_person_visit_record WHERE org_id = #{orgId} and event_type = #{eventType} AND consultant_id = #{userId} and person_id != #{personId} ORDER BY visit_time DESC LIMIT 999) t
125
-            left JOIN ta_person p on t.person_id = p.person_id
126
-            LEFT join ta_drainage d on t.target_id = d.drainage_id
127
-        GROUP BY
128
-            t.person_id
129
-        ORDER BY
130
-	        t.visit_time DESC
131
-    </select>
132
-
133
-    <select id="getWxActivityVisitRecordList" resultType="com.yunzhi.marketing.entity.TaPersonVisitRecord">
134
-        SELECT
135
-            t.share_from_id, t.share_person as consultant_id, t.share_person_type, t.person_id, t.target_type, t.target_id, t.create_date as visit_time, t.org_id ,t.building_id, t.status, t.is_first_time,
136
-	        p.`name` as user_name,
137
-	        p.`nickname` as nickname,
138
-	        p.avatarurl
139
-        FROM
140
-            ( SELECT * FROM ta_share_person_from WHERE org_id = #{orgId} and target_id = #{targetId} AND (share_person = #{userId} or share_person = #{personId}) and target_type = #{eventType} ORDER BY create_date DESC LIMIT 999) t
141
-            left JOIN ta_person p on t.person_id = p.person_id
142
-            where t.person_id != #{personId}
143
-        GROUP BY
144
-            t.person_id
145
-        ORDER BY
146
-	        t.create_date DESC
147
-    </select>
148
-
149
-
150
-    <select id="getWxVisitRecordActivityList" resultType="com.yunzhi.marketing.entity.TaPersonVisitRecord">
151
-            SELECT
152
-                t.*,
153
-                d.NAME AS activity_name,
154
-                d.create_date
155
-            FROM
156
-                ( SELECT * FROM ta_person_visit_record WHERE event_type = #{eventType} AND consultant_id = #{userId} AND person_id = #{personId} ORDER BY visit_time DESC ) t
157
-                LEFT JOIN ta_drainage d ON t.target_id = d.drainage_id
158
-            GROUP BY
159
-                t.target_id
160
-            ORDER BY
161
-	            t.visit_time DESC
162
-    </select>
163
-
164
-    <select id="getDrainageVisitRecord" resultType="com.yunzhi.marketing.entity.TaPersonVisitRecord">
165
-        select * from (
166
-            select
167
-            t.share_person as share_person_id,
168
-            t.person_id,
169
-            c.person_type,
170
-            t.create_date as visit_time,
171
-            t.target_type as event_type,
172
-            t.target_id as target_id,
173
-            b.name as drainageName,
174
-            d.building_name as buildingName,
175
-            tn.news_name as newsName,
176
-            tha.title as helpActivityName,
177
-            tsa.activity_name as groupActivityName,
178
-            tbd.title as activityName,
179
-            b.drainage_id
180
-            from ta_share_person_from t
181
-            left join ta_drainage b on t.target_id = b.drainage_id
182
-            left join ta_building d on t.target_id = d.building_id
183
-            left join ta_news tn on t.target_id = tn.news_id
184
-            left join ta_help_activity tha on t.target_id = tha.help_activity_id
185
-            left join ta_share_activity tsa on t.target_id = tsa.group_activity_id
186
-            left join ta_building_dynamic tbd on t.target_id = tbd.dynamic_id
187
-            left join ta_person c on t.org_id = c.org_id and (t.share_person = c.person_id or t.share_person = c.user_id)
188
-            where t.org_id = #{orgId}
189
-            and t.target_type in ('h5_share','group_share','help_share','news_share','dynamic_share','building_share')
190
-            <if test="eventType !=null and eventType != ''">
191
-                and t.target_type = #{eventType}
192
-            </if>
193
-            <if test="activityName !=null and activityName != ''">
194
-                and (
195
-                (b.name like concat('%',#{activityName},'%') and t.target_type = 'h5_share')or (d.name like concat('%',#{activityName},'%') and t.target_type = 'building_share') or (tn.news_name like concat('%',#{activityName},'%') and t.target_type = 'news_share')
196
-                or (tha.title like concat( '%', #{activityName}, '%' ) and t.target_type = 'help_share')  or (tsa.activity_name like concat('%',#{activityName},'%') and t.target_type = 'group_share') or (tbd.title like concat('%',#{activityName},'%') and t.target_type = 'dynamic_share')
197
-                )
198
-            </if>
199
-            <if test="shareName !=null and shareName != ''">
200
-                and c.nickname like concat('%',#{shareName},'%')
201
-            </if>
202
-            <if test="shareTel !=null and shareTel != ''">
203
-                and c.phone = #{shareTel}
204
-            </if>
205
-            <if test="personType == 'Realty Consultant'">
206
-                and c.person_type = 'Realty Consultant'
207
-            </if>
208
-            <if test="personType == 'customer'">
209
-                and c.person_type != 'Realty Consultant'
210
-            </if>
211
-            <if test="buildingId !=null and buildingId != ''">
212
-                and d.building_id = #{buildingId}
213
-            </if>
214
-            <if test="personBuildingList != null and personBuildingList.size > 0">
215
-                AND d.building_id in
216
-                <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
217
-                    #{personBuilding.buildingId}
218
-                </foreach>
219
-            </if>
220
-            order by t.create_date desc
221
-        ) t
222
-        group by t.person_id, t.target_id,t.event_type, t.share_person_id
223
-        order by t.visit_time desc
224
-    </select>
225
-
226
-    <select id="getConsultantShareInfoList" resultType="com.yunzhi.marketing.entity.TaConsultantInfo">
227
-        select * From (
228
-            select * from (
229
-                select
230
-                t.be_share as target_id,
231
-                a.url as activity_img,
232
-                a.building_name as activity_name,
233
-                a.building_name,
234
-                a.address,
235
-                a.price,
236
-                a.building_type_id,
237
-                t.tagert_type as eventType,
238
-				t.create_date as visit_time
239
-                from ta_share t
240
-                left join (select b.url, a.building_name,a.address,a.price,a.building_id,a.building_type_id from ta_building a left join ta_building_img b on a.building_id = b.building_id where b.img_type = 'list') a on t.be_share = a.building_id
241
-                where t.tagert_type = 'building'
242
-                and t.person_id = #{personId} order by t.create_date desc limit 9999
243
-            ) t
244
-            group by t.target_id
245
-
246
-        union all
247
-
248
-        select * from (
249
-        select
250
-        t.be_share as target_id,
251
-        b.list_img_url as activity_img,
252
-        b.title as activity_name,
253
-        '1' as price,
254
-        '2' as building_name,
255
-        '3' as address,
256
-        1 as building_type_id,
257
-        t.tagert_type as eventType,
258
-		t.create_date as visit_time
259
-        from ta_share t
260
-        left join ta_building_dynamic b on t.be_share = b.dynamic_id
261
-        where t.tagert_type = 'activity'
262
-        and t.person_id = #{personId} order by t.create_date desc limit 9999
263
-        ) t
264
-        group by t.target_id
265
-
266
-        union all
267
-
268
-        select * from (
269
-        select
270
-        t.be_share as target_id,
271
-        c.list_img as activity_img,
272
-        c.title as activity_name,
273
-        '1' as price,
274
-        '2' as building_name,
275
-        '3' as address,
276
-        1 as building_type_id,
277
-        t.tagert_type as eventType,
278
-		t.create_date as visit_time
279
-        from ta_share t
280
-        left join ta_help_activity c on t.be_share = c.help_activity_id
281
-        where t.tagert_type = 'help'
282
-        and t.person_id = #{personId} order by t.create_date desc limit 9999
283
-        ) t
284
-        group by t.target_id
285
-
286
-        union all
287
-
288
-        select * from (
289
-        select
290
-        t.be_share as target_id,
291
-        d.list_img as activity_img,
292
-        d.activity_name as activity_name,
293
-        '1' as price,
294
-        '2' as building_name,
295
-        '3' as address,
296
-        1 as building_type_id,
297
-        t.tagert_type as eventType,
298
-		t.create_date as visit_time
299
-        from ta_share t
300
-        left join ta_share_activity d on t.be_share = d.group_activity_id
301
-        where t.tagert_type = 'group'
302
-        and t.person_id = #{personId} order by t.create_date desc limit 9999
303
-        ) t
304
-		group by t.target_id
305
-
306
-        union all
307
-
308
-        select * from (
309
-        select
310
-        t.be_share as target_id,
311
-        e.news_img as activity_img,
312
-        e.news_name as activity_name,
313
-        '1' as price,
314
-        '2' as building_name,
315
-        '3' as address,
316
-        1 as building_type_id,
317
-        t.tagert_type as eventType,
318
-		t.create_date as visit_time
319
-        from ta_share t
320
-        left join ta_news e on t.be_share = e.news_id
321
-        where t.tagert_type = 'news'
322
-        and t.person_id = #{personId} order by t.create_date desc limit 9999
323
-        ) t
324
-        group by t.target_id
325
-
326
-        union all
327
-
328
-        select * from (
329
-            select
330
-            t.be_share as target_id,
331
-            f.share_img as activity_img,
332
-            f.`name` as activity_name,
333
-            '1' as price,
334
-            '2' as building_name,
335
-            '3' as address,
336
-            1 as building_type_id,
337
-			t.tagert_type as eventType,
338
-			t.create_date as visit_time
339
-            from ta_share t
340
-            left join ta_drainage f on t.be_share = f.drainage_id
341
-            where t.tagert_type = 'h5'
342
-            and t.person_id = #{personId} order by t.create_date desc limit 9999
343
-            ) t
344
-            group by t.target_id
345
-         union all
346
-
347
-        select * from (
348
-            select
349
-            t.be_share as target_id,
350
-            g.aerial_view_img as activity_img,
351
-            g.sales_batch_name as activity_name,
352
-            '1' as price,
353
-            '2' as building_name,
354
-            '3' as address,
355
-            1 as building_type_id,
356
-			left(t.tagert_type,5) as eventType,
357
-			t.create_date as visit_time
358
-            from ta_share t
359
-            left join ta_sales_batch g on t.be_share = g.sales_batch_id
360
-            where t.tagert_type like CONCAT('house' , '%')
361
-            and t.person_id = #{personId} order by t.create_date desc limit 9999
362
-            ) t
363
-            group by t.target_id
364
-
365
-			union all
366
-				select * from (
367
-					SELECT
368
-						t.be_share AS target_id,
369
-						g.list_img AS activity_img,
370
-						g.live_activity_title AS activity_name,
371
-						'1' AS price,
372
-						'2' AS building_name,
373
-						'3' AS address,
374
-						1 AS building_type_id,
375
-						LEFT ( t.tagert_type, 4 ) AS eventType,
376
-						t.create_date AS visit_time
377
-					FROM
378
-						ta_share t
379
-						LEFT JOIN ta_live_activity g ON t.be_share = g.live_activity_id
380
-					WHERE
381
-						t.tagert_type LIKE CONCAT( 'live', '%' )
382
-							AND t.person_id = #{personId}
383
-						ORDER BY
384
-							t.create_date DESC
385
-							LIMIT 9999
386
-					) t
387
-				group by t.target_id
388
-        ) t
389
-        order by t.visit_time desc
390
-    </select>
391
-
392
-    <select id="countShareNumByEventType" resultType="java.lang.Integer">
393
-        select count(DISTINCT t.person_id)  from ta_share_person_from t
394
-        left join ta_person a on t.person_id = a.person_id
395
-        where
396
-        (t.share_person = #{personId}
397
-        <if test="userId != null and userId != ''">
398
-            or t.share_person = #{userId}
399
-        </if>
400
-        )
401
-        and t.org_id = #{orgId}
402
-        and t.target_type = #{eventType}
403
-        and t.target_id = #{targetId}
404
-        and t.status = 1
405
-        and t.person_id != #{personId}
406
-        group by t.target_type
407
-    </select>
408
-
409
-    <select id="selectData" resultType="com.yunzhi.marketing.entity.TaPersonVisitRecord">
410
-		select t.share_person_id, t.target_id,
411
-		if(t.target_type = 'help' and t.event_type = 'activity', 'help', if(t.target_type = 'group' and t.event_type = 'activity' , 'group', t.event_type)) as target_type,
412
-		a.nickname, a.avatarurl FROM
413
-        ta_person_visit_record t
414
-        LEFT JOIN ta_person a ON t.share_person_id = a.person_id
415
-        LEFT JOIN ta_share_person_from b ON t.target_id = b.target_id  and t.event_type = b.target_type + '_share'
416
-        WHERE
417
-        (
418
-            ( t.consultant_id IS NOT NULL AND t.consultant_id != '' )
419
-            OR ( t.share_person_id IS NOT NULL AND t.share_person_id != '' )
420
-        )
421
-        AND t.person_id != t.share_person_id
422
-        AND t.`event` = 'detail'
423
-        AND ( t.share_person_id != b.share_person OR t.consultant_id != b.share_person )
424
-        GROUP BY
425
-        t.target_id, t.event_type;
426
-    </select>
427
-
428
-    <select id="selectTapersonFromShare" resultType="com.yunzhi.marketing.entity.TaPersonVisitRecord">
429
-        select t.share_person_id, if (t.consultant_id != '' and t.consultant_id is not null, 'Realty Consultant', 'customer') as person_type, t.person_id, b.target_type, t.target_id,t.org_id, t.building_id  From ta_person_visit_record t
430
-        left join ta_person a on t.share_person_id = a.person_id
431
-        LEFT JOIN ta_share_person_from b ON t.target_id = b.target_id  and t.event_type = b.target_type + '_share'
432
-        where
433
-        (
434
-            ( t.consultant_id IS NOT NULL AND t.consultant_id != '' )
435
-            OR ( t.share_person_id IS NOT NULL AND t.share_person_id != '' )
436
-            )
437
-            AND t.person_id != t.share_person_id
438
-            AND t.`event` = 'detail'
439
-            AND ( t.share_person_id != b.share_person OR t.consultant_id != b.share_person )
440
-        GROUP BY
441
-            t.target_id, t.event_type;
442
-    </select>
443
-
444
-    <select id="selectTodayVisitCount" resultType="java.lang.Integer">
445
-        SELECT
446
-        COUNT(1) as visit_count
447
-        FROM
448
-        ta_person_visit_record tp
449
-        where tp.org_id = #{orgId} AND
450
-        tp.event  = 'start'
451
-        AND DATE_FORMAT(tp.visit_time,'%Y-%m-%d') = DATE_FORMAT(#{nowDate},'%Y-%m-%d')
452
-    </select>
453
-
454
-
455
-</mapper>
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="com.yunzhi.marketing.mapper.TaPersonVisitRecordMapper">
4
+
5
+    <sql id="columnSql">
6
+        <trim suffixOverrides=",">
7
+            t.record_id,
8
+            t.person_id,
9
+            c.person_type,
10
+            t.visit_time,
11
+            t.leave_time,
12
+            t.visit_duration,
13
+            t.event,
14
+            t.data,
15
+            t.activity,
16
+            t.org_id,
17
+            t.building_id,
18
+            t.event_type,
19
+            t.target_id,
20
+            t.consultant_id,
21
+            t.share_person_id,
22
+        </trim>
23
+    </sql>
24
+
25
+    <select id="visitRecordByPersonId" resultType="com.yunzhi.marketing.entity.TaPersonVisitRecord">
26
+        select
27
+            t.* ,
28
+            b.parent_type_id from ta_person_visit_record t
29
+        left join td_biz_event_type b on t.event_type = b.type_id
30
+        where t.person_id = #{personId}
31
+        <if test="personBuildingList != null and personBuildingList.size > 0">
32
+            AND (b.parent_type_id = 'public' or t.building_id in
33
+            <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
34
+                #{personBuilding.buildingId}
35
+            </foreach>
36
+            )
37
+        </if>
38
+        <if test="buildingId != null and buildingId != ''">
39
+            AND (b.parent_type_id = 'public' or t.building_id = #{buildingId} )
40
+        </if>
41
+        order by t.visit_time desc
42
+    </select>
43
+
44
+    <select id="visitRecordByPersonIdNew" resultType="com.yunzhi.marketing.entity.TaPersonVisitRecord">
45
+        SELECT
46
+        t.*,
47
+        b.building_name
48
+        FROM
49
+        ta_person_visit_record t
50
+        LEFT JOIN ta_building b ON t.building_id = b.building_id
51
+        WHERE
52
+        t.person_id = #{personId}
53
+        ORDER BY
54
+        t.visit_time DESC
55
+    </select>
56
+
57
+    <select id="selectAll" resultType="com.yunzhi.marketing.entity.TaPersonVisitRecord">
58
+        SELECT
59
+            tpvr.record_id as recordId,
60
+            tpvr.person_id as personId,
61
+            tpvr.person_type as personType,
62
+            tpvr.building_id as buildingId,
63
+            tpvr.activity as activity,
64
+            tpvr.event as event,
65
+            tpvr.event_type as eventType,
66
+            tpvr.visit_duration as visitDuration,
67
+            (SELECT MIN(t.visit_time) FROM ta_person_visit_record t WHERE t.person_id = tpvr.person_id and t.event = tpvr.event and t.org_id = #{orgId} ) as visitTime,
68
+            (SELECT MAX(t.leave_time) FROM ta_person_visit_record t WHERE t.person_id = tpvr.person_id and t.event = tpvr.event and t.org_id = #{orgId} ) as leaveTime,
69
+            ifnull(tp.name, tp.nickname) as userName,
70
+            tbe.event_name as eventName,
71
+            COUNT(1) as accessCount
72
+        FROM
73
+            ta_person_visit_record tpvr
74
+            LEFT JOIN ta_person tp ON tpvr.person_id = tp.person_id
75
+            LEFT JOIN td_biz_event tbe on tpvr.event = tbe.event_code
76
+            <trim prefix="where" prefixOverrides="and | or">
77
+                tpvr.org_id = #{orgId}
78
+                and tp.org_id = #{orgId}
79
+                <if test="startDate != null and endDate != null">
80
+                    and tpvr.visit_time between #{startDate} and #{endDate}
81
+                </if>
82
+                <if test="buildingId != null and buildingId != ''">
83
+                    and tpvr.building_id = #{buildingId}
84
+                </if>
85
+                <if test="eventType != null and eventType != ''">
86
+                    and tpvr.event_type = #{eventType}
87
+                </if>
88
+                <if test="event != null and event != ''">
89
+                    and tpvr.event = #{event}
90
+                </if>
91
+                <if test="activity != null and activity != ''">
92
+                    and tpvr.activity = #{activity}
93
+                </if>
94
+            </trim>
95
+
96
+        GROUP BY tpvr.person_id, tpvr.event
97
+        ORDER BY 	accessCount DESC,tpvr.visit_time DESC
98
+    </select>
99
+    <select id="getPersonVisitRecordList" resultType="com.yunzhi.marketing.entity.TaPersonVisitRecord">
100
+        SELECT
101
+            t.*,
102
+            b.building_name
103
+        FROM
104
+            ta_person_visit_record t
105
+            LEFT JOIN ta_building b ON t.building_id = b.building_id
106
+        WHERE
107
+            t.person_id = #{personId}
108
+        ORDER BY
109
+            t.visit_time DESC
110
+    </select>
111
+
112
+    <select id="getDurationByPersonId" resultType="java.lang.Integer">
113
+        select SUM(visit_duration) from ta_person_visit_record where person_id = #{personId}
114
+    </select>
115
+
116
+    <select id="getFirstVisitTimeByPersonId" resultType="java.time.LocalDateTime">
117
+        select visit_time from ta_person_visit_record where person_id = #{personId} order by visit_time asc limit 1
118
+    </select>
119
+    <select id="getWxVisitRecordList" resultType="com.yunzhi.marketing.entity.TaPersonVisitRecord">
120
+        SELECT
121
+            t.* ,
122
+	        p.`name` as user_name,
123
+	        p.`nickname` as nickname,
124
+	        p.avatarurl,
125
+	        d.name as activity_name,
126
+	        d.create_date
127
+        FROM
128
+            ( SELECT * FROM ta_person_visit_record WHERE org_id = #{orgId} and event_type = #{eventType} AND consultant_id = #{userId} and person_id != #{personId} ORDER BY visit_time DESC LIMIT 999) t
129
+            left JOIN ta_person p on t.person_id = p.person_id
130
+            LEFT join ta_drainage d on t.target_id = d.drainage_id
131
+        GROUP BY
132
+            t.person_id
133
+        ORDER BY
134
+	        t.visit_time DESC
135
+    </select>
136
+
137
+    <select id="getWxActivityVisitRecordList" resultType="com.yunzhi.marketing.entity.TaPersonVisitRecord">
138
+        SELECT
139
+            t.share_from_id, t.share_person as consultant_id, t.share_person_type, t.person_id, t.target_type, t.target_id, t.create_date as visit_time, t.org_id ,t.building_id, t.status, t.is_first_time,
140
+	        p.`name` as user_name,
141
+	        p.`nickname` as nickname,
142
+	        p.avatarurl
143
+        FROM
144
+            ( SELECT * FROM ta_share_person_from WHERE org_id = #{orgId} and target_id = #{targetId} AND (share_person = #{userId} or share_person = #{personId}) and target_type = #{eventType} ORDER BY create_date DESC LIMIT 999) t
145
+            left JOIN ta_person p on t.person_id = p.person_id
146
+            where t.person_id != #{personId}
147
+        GROUP BY
148
+            t.person_id
149
+        ORDER BY
150
+	        t.create_date DESC
151
+    </select>
152
+
153
+
154
+    <select id="getWxVisitRecordActivityList" resultType="com.yunzhi.marketing.entity.TaPersonVisitRecord">
155
+            SELECT
156
+                t.*,
157
+                d.NAME AS activity_name,
158
+                d.create_date
159
+            FROM
160
+                ( SELECT * FROM ta_person_visit_record WHERE event_type = #{eventType} AND consultant_id = #{userId} AND person_id = #{personId} ORDER BY visit_time DESC ) t
161
+                LEFT JOIN ta_drainage d ON t.target_id = d.drainage_id
162
+            GROUP BY
163
+                t.target_id
164
+            ORDER BY
165
+	            t.visit_time DESC
166
+    </select>
167
+
168
+    <select id="getDrainageVisitRecord" resultType="com.yunzhi.marketing.entity.TaPersonVisitRecord">
169
+        select * from (
170
+            select
171
+            t.share_person as share_person_id,
172
+            t.person_id,
173
+            c.person_type,
174
+            t.create_date as visit_time,
175
+            t.target_type as event_type,
176
+            t.target_id as target_id,
177
+            b.name as drainageName,
178
+            d.building_name as buildingName,
179
+            tn.news_name as newsName,
180
+            tha.title as helpActivityName,
181
+            tsa.activity_name as groupActivityName,
182
+            tbd.title as activityName,
183
+            b.drainage_id
184
+            from ta_share_person_from t
185
+            left join ta_drainage b on t.target_id = b.drainage_id
186
+            left join ta_building d on t.target_id = d.building_id
187
+            left join ta_news tn on t.target_id = tn.news_id
188
+            left join ta_help_activity tha on t.target_id = tha.help_activity_id
189
+            left join ta_share_activity tsa on t.target_id = tsa.group_activity_id
190
+            left join ta_building_dynamic tbd on t.target_id = tbd.dynamic_id
191
+            left join ta_person c on t.org_id = c.org_id and (t.share_person = c.person_id or t.share_person = c.user_id)
192
+            where t.org_id = #{orgId}
193
+            and t.target_type in ('h5_share','group_share','help_share','news_share','dynamic_share','building_share')
194
+            <if test="eventType !=null and eventType != ''">
195
+                and t.target_type = #{eventType}
196
+            </if>
197
+            <if test="activityName !=null and activityName != ''">
198
+                and (
199
+                (b.name like concat('%',#{activityName},'%') and t.target_type = 'h5_share')or (d.name like concat('%',#{activityName},'%') and t.target_type = 'building_share') or (tn.news_name like concat('%',#{activityName},'%') and t.target_type = 'news_share')
200
+                or (tha.title like concat( '%', #{activityName}, '%' ) and t.target_type = 'help_share')  or (tsa.activity_name like concat('%',#{activityName},'%') and t.target_type = 'group_share') or (tbd.title like concat('%',#{activityName},'%') and t.target_type = 'dynamic_share')
201
+                )
202
+            </if>
203
+            <if test="shareName !=null and shareName != ''">
204
+                and c.nickname like concat('%',#{shareName},'%')
205
+            </if>
206
+            <if test="shareTel !=null and shareTel != ''">
207
+                and c.phone = #{shareTel}
208
+            </if>
209
+            <if test="personType == 'Realty Consultant'">
210
+                and c.person_type = 'Realty Consultant'
211
+            </if>
212
+            <if test="personType == 'customer'">
213
+                and c.person_type != 'Realty Consultant'
214
+            </if>
215
+            <if test="buildingId !=null and buildingId != ''">
216
+                and d.building_id = #{buildingId}
217
+            </if>
218
+            <if test="personBuildingList != null and personBuildingList.size > 0">
219
+                AND d.building_id in
220
+                <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
221
+                    #{personBuilding.buildingId}
222
+                </foreach>
223
+            </if>
224
+            order by t.create_date desc
225
+        ) t
226
+        group by t.person_id, t.target_id,t.event_type, t.share_person_id
227
+        order by t.visit_time desc
228
+    </select>
229
+
230
+    <select id="getConsultantShareInfoList" resultType="com.yunzhi.marketing.entity.TaConsultantInfo">
231
+        select * From (
232
+            select * from (
233
+                select
234
+                t.be_share as target_id,
235
+                a.url as activity_img,
236
+                a.building_name as activity_name,
237
+                a.building_name,
238
+                a.address,
239
+                a.price,
240
+                a.building_type_id,
241
+                t.tagert_type as eventType,
242
+				t.create_date as visit_time
243
+                from ta_share t
244
+                left join (select b.url, a.building_name,a.address,a.price,a.building_id,a.building_type_id from ta_building a left join ta_building_img b on a.building_id = b.building_id where b.img_type = 'list') a on t.be_share = a.building_id
245
+                where t.tagert_type = 'building'
246
+                and t.person_id = #{personId} order by t.create_date desc limit 9999
247
+            ) t
248
+            group by t.target_id
249
+
250
+        union all
251
+
252
+        select * from (
253
+        select
254
+        t.be_share as target_id,
255
+        b.list_img_url as activity_img,
256
+        b.title as activity_name,
257
+        '1' as price,
258
+        '2' as building_name,
259
+        '3' as address,
260
+        1 as building_type_id,
261
+        t.tagert_type as eventType,
262
+		t.create_date as visit_time
263
+        from ta_share t
264
+        left join ta_building_dynamic b on t.be_share = b.dynamic_id
265
+        where t.tagert_type = 'activity'
266
+        and t.person_id = #{personId} order by t.create_date desc limit 9999
267
+        ) t
268
+        group by t.target_id
269
+
270
+        union all
271
+
272
+        select * from (
273
+        select
274
+        t.be_share as target_id,
275
+        c.list_img as activity_img,
276
+        c.title as activity_name,
277
+        '1' as price,
278
+        '2' as building_name,
279
+        '3' as address,
280
+        1 as building_type_id,
281
+        t.tagert_type as eventType,
282
+		t.create_date as visit_time
283
+        from ta_share t
284
+        left join ta_help_activity c on t.be_share = c.help_activity_id
285
+        where t.tagert_type = 'help'
286
+        and t.person_id = #{personId} order by t.create_date desc limit 9999
287
+        ) t
288
+        group by t.target_id
289
+
290
+        union all
291
+
292
+        select * from (
293
+        select
294
+        t.be_share as target_id,
295
+        d.list_img as activity_img,
296
+        d.activity_name as activity_name,
297
+        '1' as price,
298
+        '2' as building_name,
299
+        '3' as address,
300
+        1 as building_type_id,
301
+        t.tagert_type as eventType,
302
+		t.create_date as visit_time
303
+        from ta_share t
304
+        left join ta_share_activity d on t.be_share = d.group_activity_id
305
+        where t.tagert_type = 'group'
306
+        and t.person_id = #{personId} order by t.create_date desc limit 9999
307
+        ) t
308
+		group by t.target_id
309
+
310
+        union all
311
+
312
+        select * from (
313
+        select
314
+        t.be_share as target_id,
315
+        e.news_img as activity_img,
316
+        e.news_name as activity_name,
317
+        '1' as price,
318
+        '2' as building_name,
319
+        '3' as address,
320
+        1 as building_type_id,
321
+        t.tagert_type as eventType,
322
+		t.create_date as visit_time
323
+        from ta_share t
324
+        left join ta_news e on t.be_share = e.news_id
325
+        where t.tagert_type = 'news'
326
+        and t.person_id = #{personId} order by t.create_date desc limit 9999
327
+        ) t
328
+        group by t.target_id
329
+
330
+        union all
331
+
332
+        select * from (
333
+            select
334
+            t.be_share as target_id,
335
+            f.share_img as activity_img,
336
+            f.`name` as activity_name,
337
+            '1' as price,
338
+            '2' as building_name,
339
+            '3' as address,
340
+            1 as building_type_id,
341
+			t.tagert_type as eventType,
342
+			t.create_date as visit_time
343
+            from ta_share t
344
+            left join ta_drainage f on t.be_share = f.drainage_id
345
+            where t.tagert_type = 'h5'
346
+            and t.person_id = #{personId} order by t.create_date desc limit 9999
347
+            ) t
348
+            group by t.target_id
349
+         union all
350
+
351
+        select * from (
352
+            select
353
+            t.be_share as target_id,
354
+            g.aerial_view_img as activity_img,
355
+            g.sales_batch_name as activity_name,
356
+            '1' as price,
357
+            '2' as building_name,
358
+            '3' as address,
359
+            1 as building_type_id,
360
+			left(t.tagert_type,5) as eventType,
361
+			t.create_date as visit_time
362
+            from ta_share t
363
+            left join ta_sales_batch g on t.be_share = g.sales_batch_id
364
+            where t.tagert_type like CONCAT('house' , '%')
365
+            and t.person_id = #{personId} order by t.create_date desc limit 9999
366
+            ) t
367
+            group by t.target_id
368
+
369
+			union all
370
+				select * from (
371
+					SELECT
372
+						t.be_share AS target_id,
373
+						g.list_img AS activity_img,
374
+						g.live_activity_title AS activity_name,
375
+						'1' AS price,
376
+						'2' AS building_name,
377
+						'3' AS address,
378
+						1 AS building_type_id,
379
+						LEFT ( t.tagert_type, 4 ) AS eventType,
380
+						t.create_date AS visit_time
381
+					FROM
382
+						ta_share t
383
+						LEFT JOIN ta_live_activity g ON t.be_share = g.live_activity_id
384
+					WHERE
385
+						t.tagert_type LIKE CONCAT( 'live', '%' )
386
+							AND t.person_id = #{personId}
387
+						ORDER BY
388
+							t.create_date DESC
389
+							LIMIT 9999
390
+					) t
391
+				group by t.target_id
392
+        ) t
393
+        order by t.visit_time desc
394
+    </select>
395
+
396
+    <select id="countShareNumByEventType" resultType="java.lang.Integer">
397
+        select count(DISTINCT t.person_id)  from ta_share_person_from t
398
+        left join ta_person a on t.person_id = a.person_id
399
+        where
400
+        (t.share_person = #{personId}
401
+        <if test="userId != null and userId != ''">
402
+            or t.share_person = #{userId}
403
+        </if>
404
+        )
405
+        and t.org_id = #{orgId}
406
+        and t.target_type = #{eventType}
407
+        and t.target_id = #{targetId}
408
+        and t.status = 1
409
+        and t.person_id != #{personId}
410
+        group by t.target_type
411
+    </select>
412
+
413
+    <select id="selectData" resultType="com.yunzhi.marketing.entity.TaPersonVisitRecord">
414
+		select t.share_person_id, t.target_id,
415
+		if(t.target_type = 'help' and t.event_type = 'activity', 'help', if(t.target_type = 'group' and t.event_type = 'activity' , 'group', t.event_type)) as target_type,
416
+		a.nickname, a.avatarurl FROM
417
+        ta_person_visit_record t
418
+        LEFT JOIN ta_person a ON t.share_person_id = a.person_id
419
+        LEFT JOIN ta_share_person_from b ON t.target_id = b.target_id  and t.event_type = b.target_type + '_share'
420
+        WHERE
421
+        (
422
+            ( t.consultant_id IS NOT NULL AND t.consultant_id != '' )
423
+            OR ( t.share_person_id IS NOT NULL AND t.share_person_id != '' )
424
+        )
425
+        AND t.person_id != t.share_person_id
426
+        AND t.`event` = 'detail'
427
+        AND ( t.share_person_id != b.share_person OR t.consultant_id != b.share_person )
428
+        GROUP BY
429
+        t.target_id, t.event_type;
430
+    </select>
431
+
432
+    <select id="selectTapersonFromShare" resultType="com.yunzhi.marketing.entity.TaPersonVisitRecord">
433
+        select t.share_person_id, if (t.consultant_id != '' and t.consultant_id is not null, 'Realty Consultant', 'customer') as person_type, t.person_id, b.target_type, t.target_id,t.org_id, t.building_id  From ta_person_visit_record t
434
+        left join ta_person a on t.share_person_id = a.person_id
435
+        LEFT JOIN ta_share_person_from b ON t.target_id = b.target_id  and t.event_type = b.target_type + '_share'
436
+        where
437
+        (
438
+            ( t.consultant_id IS NOT NULL AND t.consultant_id != '' )
439
+            OR ( t.share_person_id IS NOT NULL AND t.share_person_id != '' )
440
+            )
441
+            AND t.person_id != t.share_person_id
442
+            AND t.`event` = 'detail'
443
+            AND ( t.share_person_id != b.share_person OR t.consultant_id != b.share_person )
444
+        GROUP BY
445
+            t.target_id, t.event_type;
446
+    </select>
447
+
448
+    <select id="selectTodayVisitCount" resultType="java.lang.Integer">
449
+        SELECT
450
+        COUNT(1) as visit_count
451
+        FROM
452
+        ta_person_visit_record tp
453
+        where tp.org_id = #{orgId} AND
454
+        tp.event  = 'start'
455
+        AND DATE_FORMAT(tp.visit_time,'%Y-%m-%d') = DATE_FORMAT(#{nowDate},'%Y-%m-%d')
456
+    </select>
457
+
458
+
459
+</mapper>

+ 1
- 1
src/main/resources/mapper/TaRecommendCustomerMapper.xml Прегледај датотеку

@@ -89,7 +89,7 @@ FROM
89 89
         left join ta_channel_person tcp on a.person_id = tcp.person_id
90 90
         left join ta_channel tc on tc.channel_id = tcp.channel_id
91 91
         <where>
92
-            a.person_type in ('channel agent')
92
+            a.person_type in in ('channel agent', 'estate agent')
93 93
             and a.status >0
94 94
             <if test="name != null and name !=''">
95 95
                 and a.nickname = #{name}