ImRoomMapper.xml 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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.nb.im.mapper.ImRoomMapper">
  4. <resultMap id="imRoomResult" type="com.nb.im.service.dto.ImRoomResult">
  5. <result column="id" property="id"/>
  6. <result column="assist_id" property="assistId"/>
  7. <result column="patient_id" property="patientId"/>
  8. <result column="patient_code" property="patientCode"/>
  9. <result column="patient_name" property="patientName"/>
  10. <result column="patient_age" property="patientAge"/>
  11. <result column="patient_sex" property="patientSex"/>
  12. <result column="manage_type" property="manageType"/>
  13. <result column="status" property="status"/>
  14. <result column="sponsor_type" property="sponsorType"/>
  15. <result column="total_count" property="totalCount"/>
  16. <result column="last_msg_time" property="lastMsgTime"/>
  17. <result column="payload" property="payload"/>
  18. <result column="operation_type" property="operationType"/>
  19. <result column="msg_type" property="msgType"/>
  20. <result column="patient_name_ps" property="patientNamePs"/>
  21. <result column="doctorNickname" property="doctorNickname"/>
  22. <result column="doctorId" property="doctorId"/>
  23. <result column="assist_avatar" property="assistAvatar"/>
  24. <result column="doctor_avatar" property="doctorAvatar"/>
  25. <result column="create_time" property="createTime"/>
  26. <result column="update_time" property="updateTime"/>
  27. </resultMap>
  28. <select id="queryPageNoneMsgBlurry" resultMap="imRoomResult">
  29. select
  30. r.id as id,
  31. r.patient_code as patient_code,
  32. r.patient_age as patient_age,
  33. r.patient_name_ps as patient_name_ps,
  34. r.patient_name as patient_name,
  35. r.patient_sex as patient_sex,
  36. r.manage_type as manage_type,
  37. r.`status` as status,
  38. r.last_msg_time as last_msg_time,
  39. r.sponsor_type as sponsor_type,
  40. r.total_count as total_count,
  41. r.create_time as create_time,
  42. r.update_time as update_time,
  43. r.doctor_avatar as doctor_avatar,
  44. r.assist_avatar as assist_avatar,
  45. r.assist_id as assist_id,
  46. r.patient_id as patient_id,
  47. <if test="query.assistId != null">
  48. ru.nickname as doctorNickname,
  49. ru.user_id as doctorId,
  50. </if>
  51. rm.payload as payload,
  52. rm.msg_type as msg_type,
  53. rm.operation_type as operation_type
  54. from
  55. (select * from im_room
  56. <where>
  57. <if test="query.doctorId != null">
  58. and doctor_id=#{query.doctorId}
  59. </if>
  60. <if test="query.patientInfo != null">
  61. and (patient_code like concat('%',#{query.patientInfo},'%') or patient_name like concat('%',#{query.patientInfo},'%') )
  62. </if>
  63. <if test="query.manageType != null">
  64. and manage_type=#{query.manageType}
  65. </if>
  66. <if test="query.patientId != null">
  67. and patient_id=#{query.patientId}
  68. </if>
  69. <if test="query.assistId != null">
  70. and assist_id=#{query.assistId}
  71. </if>
  72. <if test="query.status != null and query.status.size > 0">
  73. and status in
  74. <foreach item="st" index="index" collection="query.status" open="(" separator="," close=")">
  75. #{st, jdbcType=VARCHAR}
  76. </foreach>
  77. </if>
  78. </where>
  79. ) as r
  80. left join (select * from im_msg) as rm
  81. on rm.id=r.last_msg_id
  82. <if test="query.assistId != null">
  83. left join (select * from im_room_user where
  84. user_id != #{query.assistId}
  85. ) as ru
  86. on ru.im_room_id=r.id
  87. </if>
  88. <where>
  89. <if test="query.successTime != null">
  90. and (r.success_time &gt; #{query.successTime}
  91. or r.create_time &gt; #{query.successTime})
  92. </if>
  93. </where>
  94. order by last_msg_time desc
  95. </select>
  96. <select id="queryPageMsgBlurry" resultMap="imRoomResult">
  97. -- todo
  98. </select>
  99. <select id="maxSort" resultType="java.lang.Long">
  100. SELECT
  101. MAX( sort )
  102. FROM
  103. im_msg
  104. GROUP BY
  105. room_id
  106. HAVING
  107. room_id = #{roomId};
  108. </select>
  109. <select id="queryDoctorRecentList" resultMap="imRoomResult">
  110. select
  111. r.id as id,
  112. r.patient_code as patient_code,
  113. r.patient_age as patient_age,
  114. r.patient_name_ps as patient_name_ps,
  115. r.patient_name as patient_name,
  116. r.patient_sex as patient_sex,
  117. r.manage_type as manage_type,
  118. r.`status` as status,
  119. r.last_msg_time as last_msg_time,
  120. r.sponsor_type as sponsor_type,
  121. r.total_count as total_count,
  122. r.create_time as create_time,
  123. r.update_time as update_time,
  124. r.doctor_avatar as doctor_avatar,
  125. r.assist_avatar as assist_avatar,
  126. r.assist_id as assist_id,
  127. r.patient_id as patient_id,
  128. rm.payload as payload,
  129. rm.msg_type as msg_type,
  130. rm.operation_type as operation_type
  131. from
  132. (select * from im_room
  133. <where>
  134. <if test="query.doctorId != null">
  135. and doctor_id=#{query.doctorId}
  136. </if>
  137. <if test="query.patientInfo != null">
  138. and (patient_code like concat('%',#{query.patientInfo},'%') or patient_name like concat('%',#{query.patientInfo},'%') )
  139. </if>
  140. <if test="query.manageType != null">
  141. and manage_type=#{query.manageType}
  142. </if>
  143. <if test="query.patientId != null">
  144. and patient_id=#{query.patientId}
  145. </if>
  146. </where>
  147. ) as r
  148. join (select MAX(id) as id,doctor_id,patient_id,assist_id from im_room group by doctor_id,patient_id,assist_id) as ir2 on r.id=ir2.id
  149. left join (select * from im_msg) as rm
  150. on rm.id=r.last_msg_id
  151. <where>
  152. <if test="query.successTime != null">
  153. and (r.success_time &gt; #{query.successTime}
  154. or r.create_time &gt; #{query.successTime})
  155. </if>
  156. </where>
  157. order by doctor_top desc , case when (status =1) then 0 else 1 end desc ,create_time desc
  158. </select>
  159. </mapper>