TaChatMapper.xml 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.TaChatMapper">
  4. <select id="getChatHistory" resultType="com.huiju.estateagents.entity.TaChat">
  5. SELECT
  6. *
  7. FROM
  8. ta_chat t
  9. WHERE
  10. (
  11. t.send_person = #{from}
  12. AND t.receive_person = #{to}
  13. )
  14. OR (
  15. t.send_person = #{to}
  16. AND t.receive_person = #{from}
  17. )
  18. ORDER BY
  19. t.create_date DESC
  20. </select>
  21. <select id="getChatWith" resultType="com.huiju.estateagents.entity.TaChat">
  22. SELECT
  23. a.*
  24. FROM
  25. ta_chat a
  26. JOIN (
  27. SELECT DISTINCT
  28. (
  29. IF (
  30. t.send_person &gt; t.receive_person,
  31. CONCAT(
  32. t.send_person,
  33. t.receive_person
  34. ),
  35. CONCAT(
  36. t.receive_person,
  37. t.send_person
  38. )
  39. )
  40. ),
  41. max(t.chat_id) AS chat_id
  42. FROM
  43. ta_chat t
  44. WHERE
  45. t.send_person = #{person}
  46. OR t.receive_person = #{person}
  47. GROUP BY
  48. IF (
  49. t.send_person &gt; t.receive_person,
  50. CONCAT(
  51. t.send_person,
  52. t.receive_person
  53. ),
  54. CONCAT(
  55. t.receive_person,
  56. t.send_person
  57. )
  58. )
  59. ) b ON a.chat_id = b.chat_id
  60. ORDER BY a.chat_id desc
  61. </select>
  62. <select id="getUnReadMessage" resultType="Integer">
  63. SELECT
  64. count(1) AS total
  65. FROM
  66. ta_chat t
  67. WHERE
  68. (
  69. (
  70. t.send_person = #{from}
  71. AND t.receive_person = #{to}
  72. )
  73. OR (
  74. t.send_person = #{to}
  75. AND t.receive_person = #{from}
  76. )
  77. )
  78. AND IFNULL(t.is_read, 0) = 0
  79. </select>
  80. <select id="getAllUnReadMessage" resultType="Integer">
  81. SELECT
  82. count(1) AS total
  83. FROM
  84. ta_chat t
  85. WHERE
  86. t.receive_person = #{personId}
  87. AND IFNULL(t.is_read, 0) = 0
  88. </select>
  89. </mapper>