TaPersonVisitRecordMapper.xml 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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 * from ta_person_visit_record
  25. where person_id = #{personId}
  26. order by visit_time desc
  27. </select>
  28. <select id="selectAll" resultType="com.huiju.estateagents.entity.TaPersonVisitRecord">
  29. SELECT
  30. tpvr.record_id as recordId,
  31. tpvr.person_id as personId,
  32. tpvr.person_type as personType,
  33. tpvr.building_id as buildingId,
  34. tpvr.activity as activity,
  35. tpvr.event as event,
  36. tpvr.event_type as eventType,
  37. tpvr.visit_duration as visitDuration,
  38. (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,
  39. (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,
  40. ifnull(tp.name, tp.nickname) as userName,
  41. tbe.event_name as eventName,
  42. COUNT(1) as accessCount
  43. FROM
  44. ta_person_visit_record tpvr
  45. LEFT JOIN ta_person tp ON tpvr.person_id = tp.person_id
  46. LEFT JOIN td_biz_event tbe on tpvr.event = tbe.event_code
  47. <trim prefix="where" prefixOverrides="and | or">
  48. tpvr.org_id = #{orgId}
  49. and tp.org_id = #{orgId}
  50. <if test="startDate != null and endDate != null">
  51. and tpvr.visit_time between #{startDate} and #{endDate}
  52. </if>
  53. <if test="buildingId != null and buildingId != ''">
  54. and tpvr.building_id = #{buildingId}
  55. </if>
  56. <if test="eventType != null and eventType != ''">
  57. and tpvr.event_type = #{eventType}
  58. </if>
  59. <if test="event != null and event != ''">
  60. and tpvr.event = #{event}
  61. </if>
  62. <if test="activity != null and activity != ''">
  63. and tpvr.activity = #{activity}
  64. </if>
  65. </trim>
  66. GROUP BY tpvr.person_id, tpvr.event
  67. ORDER BY accessCount DESC,tpvr.visit_time DESC
  68. </select>
  69. <select id="getPersonVisitRecordList" resultType="com.huiju.estateagents.entity.TaPersonVisitRecord">
  70. SELECT
  71. t.*,
  72. b.building_name
  73. FROM
  74. ta_person_visit_record t
  75. LEFT JOIN ta_building b ON t.building_id = b.building_id
  76. WHERE
  77. t.person_id = #{personId}
  78. ORDER BY
  79. t.visit_time DESC
  80. </select>
  81. <select id="getDurationByPersonId" resultType="java.lang.Integer">
  82. select SUM(visit_duration) from ta_person_visit_record where person_id = #{personId}
  83. </select>
  84. <select id="getFirstVisitTimeByPersonId" resultType="java.time.LocalDateTime">
  85. select visit_time from ta_person_visit_record where person_id = #{personId} order by visit_time asc limit 1
  86. </select>
  87. <select id="getWxVisitRecordList" resultType="com.huiju.estateagents.entity.TaPersonVisitRecord">
  88. SELECT
  89. t.* ,
  90. p.`name` as user_name,
  91. p.`nickname` as nickname,
  92. p.avatarurl,
  93. d.name as activity_name,
  94. d.create_date
  95. FROM
  96. ( 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
  97. left JOIN ta_person p on t.person_id = p.person_id
  98. LEFT join ta_drainage d on t.target_id = d.drainage_id
  99. GROUP BY
  100. t.person_id
  101. ORDER BY
  102. t.visit_time DESC
  103. </select>
  104. <select id="getWxActivityVisitRecordList" resultType="com.huiju.estateagents.entity.TaPersonVisitRecord">
  105. SELECT
  106. t.* ,
  107. p.`name` as user_name,
  108. p.`nickname` as nickname,
  109. p.avatarurl
  110. FROM
  111. ( SELECT * FROM ta_person_visit_record WHERE org_id = #{orgId} and target_id = #{targetId} AND consultant_id = #{userId} and person_id != #{personId} and event_type = #{eventType} ORDER BY visit_time DESC LIMIT 999) t
  112. left JOIN ta_person p on t.person_id = p.person_id
  113. GROUP BY
  114. t.person_id
  115. ORDER BY
  116. t.visit_time DESC
  117. </select>
  118. <select id="getWxVisitRecordActivityList" resultType="com.huiju.estateagents.entity.TaPersonVisitRecord">
  119. SELECT
  120. t.*,
  121. d.NAME AS activity_name,
  122. d.create_date
  123. FROM
  124. ( SELECT * FROM ta_person_visit_record WHERE event_type = #{eventType} AND consultant_id = #{userId} AND person_id = #{personId} ORDER BY visit_time DESC ) t
  125. LEFT JOIN ta_drainage d ON t.target_id = d.drainage_id
  126. GROUP BY
  127. t.target_id
  128. ORDER BY
  129. t.visit_time DESC
  130. </select>
  131. <select id="getDrainageVisitRecord" resultType="com.huiju.estateagents.entity.TaPersonVisitRecord">
  132. select * from (
  133. select
  134. <include refid="columnSql"></include>,
  135. b.name as drainageName,
  136. d.building_name as buildingName,
  137. tn.news_name as newsName,
  138. tha.title as helpActivityName,
  139. tsa.activity_name as groupActivityName,
  140. tbd.title as activityName,
  141. b.drainage_id
  142. from ta_person_visit_record t
  143. left join ta_drainage b on t.target_id = b.drainage_id
  144. left join ta_building d on t.target_id = d.building_id
  145. left join ta_news tn on t.target_id = tn.news_id
  146. left join ta_help_activity tha on t.target_id = tha.help_activity_id
  147. left join ta_share_activity tsa on t.target_id = tsa.group_activity_id
  148. left join ta_building_dynamic tbd on t.target_id = tbd.dynamic_id
  149. left join ta_person c on t.share_person_id = c.person_id
  150. where
  151. t.share_person_id != t.person_id and t.share_person_id is not null and t.share_person_id != ''
  152. <if test="orgId != null and orgId != ''">
  153. and t.org_id = #{orgId}
  154. </if>
  155. <if test="eventType !=null and eventType != ''">
  156. and t.event_type = #{eventType}
  157. </if>
  158. <if test="activityName !=null and activityName != ''">
  159. and (
  160. (b.name like concat('%',#{activityName},'%') and t.event_type = 'h5')or (d.name like concat('%',#{activityName},'%') and t.event_type = 'building') or (tn.news_name like concat('%',#{activityName},'%') and t.event_type = 'news')
  161. or (tha.title like concat( '%', #{activityName}, '%' ) and t.event_type = 'help') or (tsa.activity_name like concat('%',#{activityName},'%') and t.event_type = 'group') or (tbd.title like concat('%',#{activityName},'%') and t.event_type = 'activity')
  162. )
  163. </if>
  164. <if test="shareName !=null and shareName != ''">
  165. and c.nickname like concat('%',#{shareName},'%')
  166. </if>
  167. <if test="shareTel !=null and shareTel != ''">
  168. and c.phone = #{shareTel}
  169. </if>
  170. <if test="personType == 'Realty Consultant'">
  171. and t.consultant_id is not null and t.consultant_id != ''
  172. </if>
  173. <if test="personType == 'customer'">
  174. and t.consultant_id is null
  175. </if>
  176. <if test="buildingId !=null and buildingId != ''">
  177. and t.building_id = #{buildingId}
  178. </if>
  179. <if test="personBuildingList != null and personBuildingList.size > 0">
  180. AND t.building_id in
  181. <foreach collection="personBuildingList" item="personBuilding" open="(" close=")" separator=",">
  182. #{personBuilding.buildingId}
  183. </foreach>
  184. </if>
  185. order by t.visit_time desc
  186. ) t
  187. group by t.person_id, t.share_person_id,t.target_id,t.event_type
  188. order by t.visit_time desc
  189. </select>
  190. <select id="getConsultantShareInfoList" resultType="com.huiju.estateagents.entity.TaConsultantInfo">
  191. select * From (
  192. select * from (
  193. select
  194. t.target_id,
  195. a.url as activity_img,
  196. a.building_name as activity_name,
  197. a.building_name,
  198. a.address,
  199. a.price,
  200. t.event_type,
  201. t.visit_time
  202. from ta_person_visit_record t
  203. left join (select b.url, a.building_name,a.address,a.price,a.building_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.target_id = a.building_id
  204. where t.event_type = 'building'
  205. and t.consultant_id = #{userId}
  206. and t.org_id = #{orgId}
  207. and t.`event` = 'share' order by t.visit_time desc limit 9999
  208. ) t
  209. group by t.target_id
  210. union all
  211. select * from (
  212. select
  213. t.target_id,
  214. b.list_img_url as activity_img,
  215. b.title as activity_name,
  216. '1' as price,
  217. '2' as building_name,
  218. '3' as address,
  219. t.event_type,
  220. t.visit_time
  221. from ta_person_visit_record t
  222. left join ta_building_dynamic b on t.target_id = b.dynamic_id
  223. where t.event_type = 'activity'
  224. and t.consultant_id = #{userId}
  225. and t.org_id = #{orgId}
  226. and t.`event` = 'share' order by t.visit_time desc limit 9999
  227. ) t
  228. group by t.target_id
  229. union all
  230. select * from (
  231. select
  232. t.target_id,
  233. c.list_img as activity_img,
  234. c.title as activity_name,
  235. '1' as price,
  236. '2' as building_name,
  237. '3' as address,
  238. t.event_type,
  239. t.visit_time
  240. from ta_person_visit_record t
  241. left join ta_help_activity c on t.target_id = c.help_activity_id
  242. where t.event_type = 'help'
  243. and t.consultant_id = #{userId}
  244. and t.org_id = #{orgId}
  245. and t.`event` = 'share' order by t.visit_time desc limit 9999
  246. ) t
  247. group by t.target_id
  248. union all
  249. select * from (
  250. select
  251. t.target_id,
  252. d.list_img as activity_img,
  253. d.activity_name as activity_name,
  254. '1' as price,
  255. '2' as building_name,
  256. '3' as address,
  257. t.event_type,
  258. t.visit_time
  259. from ta_person_visit_record t
  260. left join ta_share_activity d on t.target_id = d.group_activity_id
  261. where t.event_type = 'group'
  262. and t.consultant_id = #{userId}
  263. and t.org_id = #{orgId}
  264. and t.`event` = 'share'
  265. group by t.target_id order by t.visit_time desc limit 9999
  266. ) t
  267. union all
  268. select * from (
  269. select
  270. t.target_id,
  271. e.news_img as activity_img,
  272. e.news_name as activity_name,
  273. '1' as price,
  274. '2' as building_name,
  275. '3' as address,
  276. t.event_type,
  277. t.visit_time
  278. from ta_person_visit_record t
  279. left join ta_news e on t.target_id = e.news_id
  280. where t.event_type = 'news'
  281. and t.consultant_id = #{userId}
  282. and t.org_id = #{orgId}
  283. and t.`event` = 'share' order by t.visit_time desc limit 9999
  284. ) t
  285. group by t.target_id
  286. union all
  287. select * from (
  288. select
  289. t.target_id,
  290. f.share_img as activity_img,
  291. f.`name` as activity_name,
  292. '1' as price,
  293. '2' as building_name,
  294. '3' as address,
  295. t.event_type,
  296. t.visit_time
  297. from ta_person_visit_record t
  298. left join ta_drainage f on t.target_id = f.drainage_id
  299. where t.event_type = 'h5'
  300. and t.consultant_id = #{userId}
  301. and t.org_id = #{orgId}
  302. and t.`event` = 'share' order by t.visit_time desc limit 9999
  303. ) t
  304. group by t.target_id
  305. ) t
  306. order by t.visit_time desc
  307. </select>
  308. <select id="countShareNumByEventType" resultType="java.lang.Integer">
  309. select count(DISTINCT t.person_id) from ta_person_visit_record t
  310. where
  311. t.consultant_id = #{userId}
  312. and t.org_id = #{orgId}
  313. and t.event_type = #{eventType}
  314. and t.target_id = #{targetId}
  315. and t.person_id != t.share_person_id
  316. group by t.event_type
  317. </select>
  318. </mapper>