123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416 |
- <?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.huiju.estateagents.mapper.TaPersonVisitRecordMapper">
-
- <sql id="columnSql">
- <trim suffixOverrides=",">
- t.record_id,
- t.person_id,
- c.person_type,
- t.visit_time,
- t.leave_time,
- t.visit_duration,
- t.event,
- t.data,
- t.activity,
- t.org_id,
- t.building_id,
- t.event_type,
- t.target_id,
- t.consultant_id,
- t.share_person_id,
- </trim>
- </sql>
-
- <select id="visitRecordByPersonId" resultType="com.huiju.estateagents.entity.TaPersonVisitRecord">
- select
- t.* ,
- b.parent_type_id from ta_person_visit_record t
- left join td_biz_event_type b on t.event_type = b.type_id
- where t.person_id = #{personId}
- <if test="personBuildingList != null and personBuildingList.size > 0">
- AND (b.parent_type_id = 'public' or t.building_id in
- <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
- #{personBuilding.buildingId}
- </foreach>
- )
- </if>
- <if test="buildingId != null and buildingId != ''">
- AND (b.parent_type_id = 'public' or t.building_id = #{buildingId} )
- </if>
- order by t.visit_time desc
- </select>
-
- <select id="selectAll" resultType="com.huiju.estateagents.entity.TaPersonVisitRecord">
- SELECT
- tpvr.record_id as recordId,
- tpvr.person_id as personId,
- tpvr.person_type as personType,
- tpvr.building_id as buildingId,
- tpvr.activity as activity,
- tpvr.event as event,
- tpvr.event_type as eventType,
- tpvr.visit_duration as visitDuration,
- (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,
- (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,
- ifnull(tp.name, tp.nickname) as userName,
- tbe.event_name as eventName,
- COUNT(1) as accessCount
- FROM
- ta_person_visit_record tpvr
- LEFT JOIN ta_person tp ON tpvr.person_id = tp.person_id
- LEFT JOIN td_biz_event tbe on tpvr.event = tbe.event_code
- <trim prefix="where" prefixOverrides="and | or">
- tpvr.org_id = #{orgId}
- and tp.org_id = #{orgId}
- <if test="startDate != null and endDate != null">
- and tpvr.visit_time between #{startDate} and #{endDate}
- </if>
- <if test="buildingId != null and buildingId != ''">
- and tpvr.building_id = #{buildingId}
- </if>
- <if test="eventType != null and eventType != ''">
- and tpvr.event_type = #{eventType}
- </if>
- <if test="event != null and event != ''">
- and tpvr.event = #{event}
- </if>
- <if test="activity != null and activity != ''">
- and tpvr.activity = #{activity}
- </if>
- </trim>
-
- GROUP BY tpvr.person_id, tpvr.event
- ORDER BY accessCount DESC,tpvr.visit_time DESC
- </select>
- <select id="getPersonVisitRecordList" resultType="com.huiju.estateagents.entity.TaPersonVisitRecord">
- SELECT
- t.*,
- b.building_name
- FROM
- ta_person_visit_record t
- LEFT JOIN ta_building b ON t.building_id = b.building_id
- WHERE
- t.person_id = #{personId}
- ORDER BY
- t.visit_time DESC
- </select>
-
- <select id="getDurationByPersonId" resultType="java.lang.Integer">
- select SUM(visit_duration) from ta_person_visit_record where person_id = #{personId}
- </select>
-
- <select id="getFirstVisitTimeByPersonId" resultType="java.time.LocalDateTime">
- select visit_time from ta_person_visit_record where person_id = #{personId} order by visit_time asc limit 1
- </select>
- <select id="getWxVisitRecordList" resultType="com.huiju.estateagents.entity.TaPersonVisitRecord">
- SELECT
- t.* ,
- p.`name` as user_name,
- p.`nickname` as nickname,
- p.avatarurl,
- d.name as activity_name,
- d.create_date
- FROM
- ( 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
- left JOIN ta_person p on t.person_id = p.person_id
- LEFT join ta_drainage d on t.target_id = d.drainage_id
- GROUP BY
- t.person_id
- ORDER BY
- t.visit_time DESC
- </select>
-
- <select id="getWxActivityVisitRecordList" resultType="com.huiju.estateagents.entity.TaPersonVisitRecord">
- SELECT
- 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 ,building_id, t.status, t.is_first_time,
- p.`name` as user_name,
- p.`nickname` as nickname,
- p.avatarurl
- FROM
- ( 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
- left JOIN ta_person p on t.person_id = p.person_id
- where t.person_id != #{personId}
- GROUP BY
- t.person_id
- ORDER BY
- t.create_date DESC
- </select>
-
-
- <select id="getWxVisitRecordActivityList" resultType="com.huiju.estateagents.entity.TaPersonVisitRecord">
- SELECT
- t.*,
- d.NAME AS activity_name,
- d.create_date
- FROM
- ( SELECT * FROM ta_person_visit_record WHERE event_type = #{eventType} AND consultant_id = #{userId} AND person_id = #{personId} ORDER BY visit_time DESC ) t
- LEFT JOIN ta_drainage d ON t.target_id = d.drainage_id
- GROUP BY
- t.target_id
- ORDER BY
- t.visit_time DESC
- </select>
-
- <select id="getDrainageVisitRecord" resultType="com.huiju.estateagents.entity.TaPersonVisitRecord">
- select * from (
- select
- t.share_person as share_person_id,
- t.person_id,
- c.person_type,
- t.create_date as visit_time,
- t.target_type as event_type,
- t.target_id as target_id,
- b.name as drainageName,
- d.building_name as buildingName,
- tn.news_name as newsName,
- tha.title as helpActivityName,
- tsa.activity_name as groupActivityName,
- tbd.title as activityName,
- b.drainage_id
- from ta_share_person_from t
- left join ta_drainage b on t.target_id = b.drainage_id
- left join ta_building d on t.target_id = d.building_id
- left join ta_news tn on t.target_id = tn.news_id
- left join ta_help_activity tha on t.target_id = tha.help_activity_id
- left join ta_share_activity tsa on t.target_id = tsa.group_activity_id
- left join ta_building_dynamic tbd on t.target_id = tbd.dynamic_id
- left join ta_person c on (t.share_person = c.person_id or t.share_person = c.user_id)
- where 1=1
- and t.target_type in ('h5_share','group_share','help_share','news_share','dynamic_share','building_share')
- <if test="orgId != null and orgId != ''">
- and c.org_id = #{orgId}
- </if>
- <if test="eventType !=null and eventType != ''">
- and t.target_type = #{eventType}
- </if>
- <if test="activityName !=null and activityName != ''">
- and (
- (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')
- 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')
- )
- </if>
- <if test="shareName !=null and shareName != ''">
- and c.nickname like concat('%',#{shareName},'%')
- </if>
- <if test="shareTel !=null and shareTel != ''">
- and c.phone = #{shareTel}
- </if>
- <if test="personType == 'Realty Consultant'">
- and c.person_type = 'Realty Consultant'
- </if>
- <if test="personType == 'customer'">
- and c.person_type != 'Realty Consultant'
- </if>
- <if test="buildingId !=null and buildingId != ''">
- and d.building_id = #{buildingId}
- </if>
- <if test="personBuildingList != null and personBuildingList.size > 0">
- AND d.building_id in
- <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
- #{personBuilding.buildingId}
- </foreach>
- </if>
- order by t.create_date desc
- ) t
- group by t.person_id, t.target_id,t.event_type, t.share_person_id
- order by t.visit_time desc
- </select>
-
- <select id="getConsultantShareInfoList" resultType="com.huiju.estateagents.entity.TaConsultantInfo">
- select * From (
- select * from (
- select
- t.be_share as target_id,
- a.url as activity_img,
- a.building_name as activity_name,
- a.building_name,
- a.address,
- a.price,
- a.building_type_id,
- t.tagert_type as eventType,
- t.create_date as visit_time
- from ta_share t
- 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
- where t.tagert_type = 'project'
- and t.person_id = #{personId} order by t.create_date desc limit 9999
- ) t
- group by t.target_id
-
- union all
-
- select * from (
- select
- t.be_share as target_id,
- b.list_img_url as activity_img,
- b.title as activity_name,
- '1' as price,
- '2' as building_name,
- '3' as address,
- 1 as building_type_id,
- t.tagert_type as eventType,
- t.create_date as visit_time
- from ta_share t
- left join ta_building_dynamic b on t.be_share = b.dynamic_id
- where t.tagert_type = 'activity'
- and t.person_id = #{personId} order by t.create_date desc limit 9999
- ) t
- group by t.target_id
-
- union all
-
- select * from (
- select
- t.be_share as target_id,
- c.list_img as activity_img,
- c.title as activity_name,
- '1' as price,
- '2' as building_name,
- '3' as address,
- 1 as building_type_id,
- t.tagert_type as eventType,
- t.create_date as visit_time
- from ta_share t
- left join ta_help_activity c on t.be_share = c.help_activity_id
- where t.tagert_type = 'help'
- and t.person_id = #{personId} order by t.create_date desc limit 9999
- ) t
- group by t.target_id
-
- union all
-
- select * from (
- select
- t.be_share as target_id,
- d.list_img as activity_img,
- d.activity_name as activity_name,
- '1' as price,
- '2' as building_name,
- '3' as address,
- 1 as building_type_id,
- t.tagert_type as eventType,
- t.create_date as visit_time
- from ta_share t
- left join ta_share_activity d on t.be_share = d.group_activity_id
- where t.tagert_type = 'group'
- and t.person_id = #{personId} order by t.create_date desc limit 9999
- ) t
- group by t.target_id
-
- union all
-
- select * from (
- select
- t.be_share as target_id,
- e.news_img as activity_img,
- e.news_name as activity_name,
- '1' as price,
- '2' as building_name,
- '3' as address,
- 1 as building_type_id,
- t.tagert_type as eventType,
- t.create_date as visit_time
- from ta_share t
- left join ta_news e on t.be_share = e.news_id
- where t.tagert_type = 'news'
- and t.person_id = #{personId} order by t.create_date desc limit 9999
- ) t
- group by t.target_id
-
- union all
-
- select * from (
- select
- t.be_share as target_id,
- f.share_img as activity_img,
- f.`name` as activity_name,
- '1' as price,
- '2' as building_name,
- '3' as address,
- 1 as building_type_id,
- t.tagert_type as eventType,
- t.create_date as visit_time
- from ta_share t
- left join ta_drainage f on t.be_share = f.drainage_id
- where t.tagert_type = 'h5'
- and t.person_id = #{personId} order by t.create_date desc limit 9999
- ) t
- group by t.target_id
- union all
-
- select * from (
- select
- t.be_share as target_id,
- g.aerial_view_img as activity_img,
- g.sales_batch_name as activity_name,
- '1' as price,
- '2' as building_name,
- '3' as address,
- 1 as building_type_id,
- left(t.tagert_type,5) as eventType,
- t.create_date as visit_time
- from ta_share t
- left join ta_sales_batch g on t.be_share = g.sales_batch_id
- where t.tagert_type like CONCAT('house' , '%')
- and t.person_id = #{personId} order by t.create_date desc limit 9999
- ) t
- group by t.target_id
-
- ) t
- order by t.visit_time desc
- </select>
-
- <select id="countShareNumByEventType" resultType="java.lang.Integer">
- select count(DISTINCT t.person_id) from ta_share_person_from t
- left join ta_person a on t.person_id = a.person_id
- where
- (t.share_person = #{userId}
- <if test="personId != null and personId != ''">
- or t.share_person = #{personId}
- </if>
- )
- and t.org_id = #{orgId}
- and t.target_type = #{eventType}
- and t.target_id = #{targetId}
- and t.status = 1
- and t.person_id != #{personId}
- group by t.target_type
- </select>
-
- <select id="selectData" resultType="com.huiju.estateagents.entity.TaPersonVisitRecord">
- select t.share_person_id, t.target_id,
- 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,
- a.nickname, a.avatarurl FROM
- ta_person_visit_record t
- LEFT JOIN ta_person a ON t.share_person_id = a.person_id
- LEFT JOIN ta_share_person_from b ON t.target_id = b.target_id and t.event_type = b.target_type + '_share'
- WHERE
- (
- ( t.consultant_id IS NOT NULL AND t.consultant_id != '' )
- OR ( t.share_person_id IS NOT NULL AND t.share_person_id != '' )
- )
- AND t.person_id != t.share_person_id
- AND t.`event` = 'detail'
- AND ( t.share_person_id != b.share_person OR t.consultant_id != b.share_person )
- GROUP BY
- t.target_id, t.event_type;
- </select>
-
- <select id="selectTapersonFromShare" resultType="com.huiju.estateagents.entity.TaPersonVisitRecord">
- 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
- left join ta_person a on t.share_person_id = a.person_id
- LEFT JOIN ta_share_person_from b ON t.target_id = b.target_id and t.event_type = b.target_type + '_share'
- where
- (
- ( t.consultant_id IS NOT NULL AND t.consultant_id != '' )
- OR ( t.share_person_id IS NOT NULL AND t.share_person_id != '' )
- )
- AND t.person_id != t.share_person_id
- AND t.`event` = 'detail'
- AND ( t.share_person_id != b.share_person OR t.consultant_id != b.share_person )
- GROUP BY
- t.target_id, t.event_type;
- </select>
-
-
- </mapper>
|