TaPersonVisitRecordMapper.xml 17KB

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