TaPersonVisitRecordMapper.xml 13KB

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