TaPersonVisitRecordMapper.xml 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. <select id="visitRecordByPersonId" resultType="com.huiju.estateagents.entity.TaPersonVisitRecord">
  5. select * from ta_person_visit_record
  6. where person_id = #{personId}
  7. order by visit_time desc
  8. </select>
  9. <select id="selectAll" resultType="com.huiju.estateagents.entity.TaPersonVisitRecord">
  10. SELECT
  11. tpvr.record_id as recordId,
  12. tpvr.person_id as personId,
  13. tpvr.person_type as personType,
  14. tpvr.building_id as buildingId,
  15. tpvr.activity as activity,
  16. tpvr.event as event,
  17. tpvr.event_type as eventType,
  18. tpvr.visit_duration as visitDuration,
  19. (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,
  20. (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,
  21. ifnull(tp.name, tp.nickname) as userName,
  22. tbe.event_name as eventName,
  23. COUNT(1) as accessCount
  24. FROM
  25. ta_person_visit_record tpvr
  26. LEFT JOIN ta_person tp ON tpvr.person_id = tp.person_id
  27. LEFT JOIN td_biz_event tbe on tpvr.event = tbe.event_code
  28. <trim prefix="where" prefixOverrides="and | or">
  29. tpvr.org_id = #{orgId}
  30. and tp.org_id = #{orgId}
  31. <if test="startDate != null and endDate != null">
  32. and tpvr.visit_time between #{startDate} and #{endDate}
  33. </if>
  34. <if test="buildingId != null and buildingId != ''">
  35. and tpvr.building_id = #{buildingId}
  36. </if>
  37. <if test="eventType != null and eventType != ''">
  38. and tpvr.event_type = #{eventType}
  39. </if>
  40. <if test="event != null and event != ''">
  41. and tpvr.event = #{event}
  42. </if>
  43. <if test="activity != null and activity != ''">
  44. and tpvr.activity = #{activity}
  45. </if>
  46. </trim>
  47. GROUP BY tpvr.person_id, tpvr.event
  48. ORDER BY accessCount DESC,tpvr.visit_time DESC
  49. </select>
  50. </mapper>