QwSessionMapper.xml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.fs.qw.mapper.QwSessionMapper">
  6. <resultMap type="QwSession" id="QwSessionResult">
  7. <result property="sessionId" column="session_id" />
  8. <result property="chatId" column="chat_id" />
  9. <result property="qwExtWxId" column="qw_ext_wx_id" />
  10. <result property="qwExtId" column="qw_ext_id" />
  11. <result property="corpId" column="corp_id" />
  12. <result property="qwUserId" column="qw_user_id" />
  13. <result property="createTime" column="create_time" />
  14. <result property="updateTime" column="update_time" />
  15. <result property="status" column="status" />
  16. <result property="companyId" column="company_id" />
  17. <result property="userType" column="user_type" />
  18. <result property="nickName" column="nick_name" />
  19. <result property="avatar" column="avatar" />
  20. <result property="companyUserId" column="company_user_id" />
  21. <result property="isRoom" column="is_room" />
  22. <result property="firstLetter" column="first_letter" />
  23. <result property="lastMsgId" column="last_msg_id" />
  24. <result property="lastMsgType" column="last_msg_type" />
  25. <result property="lastSendTime" column="last_send_time" />
  26. <result property="lastContent" column="last_content" />
  27. </resultMap>
  28. <sql id="selectQwSessionVo">
  29. select session_id,qw_ext_wx_id, chat_id, qw_ext_id, corp_id, qw_user_id, create_time, update_time, status,
  30. company_id, user_type, nick_name, avatar, company_user_id, is_room, first_letter, last_msg_id,
  31. last_send_time,last_content, last_msg_type from qw_session
  32. </sql>
  33. <select id="selectQwSessionList" parameterType="QwSession" resultMap="QwSessionResult">
  34. <include refid="selectQwSessionVo"/>
  35. <where>
  36. <if test="chatId != null and chatId != ''"> and chat_id = #{chatId}</if>
  37. <if test="qwExtId != null "> and qw_ext_id = #{qwExtId}</if>
  38. <if test="corpId != null and corpId != ''"> and corp_id = #{corpId}</if>
  39. <if test="qwUserId != null and qwUserId != ''"> and qw_user_id = #{qwUserId}</if>
  40. <if test="status != null "> and status = #{status}</if>
  41. <if test="companyId != null "> and company_id = #{companyId}</if>
  42. <if test="userType != null "> and user_type = #{userType}</if>
  43. <if test="nickName != null and nickName != ''"> and nick_name like concat( #{nickName}, '%')</if>
  44. <if test="avatar != null and avatar != ''"> and avatar = #{avatar}</if>
  45. <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
  46. <if test="isRoom != null "> and is_room = #{isRoom}</if>
  47. <if test="firstLetter != null "> and first_letter = #{firstLetter}</if>
  48. <if test="lastMsgId != null "> and last_msg_id = #{lastMsgId}</if>
  49. <if test="lastMsgType != null "> and last_msg_type = #{lastMsgType}</if>
  50. <if test="lastSendTime != null "> and last_send_time = #{lastSendTime}</if>
  51. <if test="lastContent != null "> and last_content = #{lastContent}</if>
  52. </where>
  53. </select>
  54. <select id="selectQwSessionBySessionId" parameterType="Long" resultMap="QwSessionResult">
  55. <include refid="selectQwSessionVo"/>
  56. where session_id = #{sessionId}
  57. </select>
  58. <select id="selectQwConversationByMap" resultType="com.fs.qw.vo.QwContactListVO">
  59. select
  60. s.session_id as id,
  61. s.qw_ext_id as extId,
  62. s.avatar,
  63. s.session_id as conversationId,
  64. s.nick_name as displayName,
  65. ec.comment_status = 1 as isBlack,
  66. s.is_room as isGroup,
  67. (u.qw_repeat = 1 OR u.user_repeat = 1) as isRepeat,
  68. false as isPend,
  69. s.last_msg_id as msgId,
  70. s.last_msg_type as type,
  71. s.last_content as lastContent,
  72. s.last_send_time as lastSendTime,
  73. 0 as unread
  74. from qw_session s
  75. left join qw_external_contact ec on s.qw_ext_id = ec.id
  76. left join fs_user u on ec.fs_user_id = u.user_id
  77. where s.qw_user_id = #{params.qwUserId}
  78. <if test="params.removeBlack != null and params.removeBlack">
  79. and ec.comment_status = 0
  80. </if>
  81. <if test="params.removeRepeat != null and params.removeRepeat">
  82. and u.qw_repeat != 1 and u.user_repeat != 1
  83. </if>
  84. order by s.update_time desc
  85. </select>
  86. <insert id="insertQwSession" parameterType="QwSession" useGeneratedKeys="true" keyProperty="sessionId">
  87. insert into qw_session
  88. <trim prefix="(" suffix=")" suffixOverrides=",">
  89. <if test="chatId != null">chat_id,</if>
  90. <if test="qwExtId != null">qw_ext_id,</if>
  91. <if test="qwExtWxId != null">qw_ext_wx_id,</if>
  92. <if test="corpId != null">corp_id,</if>
  93. <if test="qwUserId != null">qw_user_id,</if>
  94. <if test="createTime != null">create_time,</if>
  95. <if test="updateTime != null">update_time,</if>
  96. <if test="status != null">status,</if>
  97. <if test="companyId != null">company_id,</if>
  98. <if test="userType != null">user_type,</if>
  99. <if test="nickName != null">nick_name,</if>
  100. <if test="avatar != null">avatar,</if>
  101. <if test="companyUserId != null">company_user_id,</if>
  102. <if test="isRoom != null">is_room,</if>
  103. <if test="firstLetter != null">first_letter,</if>
  104. <if test="lastMsgId != null">last_msg_id,</if>
  105. <if test="lastMsgType != null">last_msg_type,</if>
  106. <if test="lastSendTime != null">last_send_time,</if>
  107. <if test="lastContent != null">last_content,</if>
  108. </trim>
  109. <trim prefix="values (" suffix=")" suffixOverrides=",">
  110. <if test="chatId != null">#{chatId},</if>
  111. <if test="qwExtId != null">#{qwExtId},</if>
  112. <if test="qwExtWxId != null">#{qwExtWxId},</if>
  113. <if test="corpId != null">#{corpId},</if>
  114. <if test="qwUserId != null">#{qwUserId},</if>
  115. <if test="createTime != null">#{createTime},</if>
  116. <if test="updateTime != null">#{updateTime},</if>
  117. <if test="status != null">#{status},</if>
  118. <if test="companyId != null">#{companyId},</if>
  119. <if test="userType != null">#{userType},</if>
  120. <if test="nickName != null">#{nickName},</if>
  121. <if test="avatar != null">#{avatar},</if>
  122. <if test="companyUserId != null">#{companyUserId},</if>
  123. <if test="isRoom != null">#{isRoom},</if>
  124. <if test="firstLetter != null">#{firstLetter},</if>
  125. <if test="lastMsgId != null">#{lastMsgId},</if>
  126. <if test="lastMsgType != null">#{lastMsgType},</if>
  127. <if test="lastSendTime != null">#{lastSendTime},</if>
  128. <if test="lastContent != null">#{lastContent},</if>
  129. </trim>
  130. </insert>
  131. <update id="updateQwSession" parameterType="QwSession">
  132. update qw_session
  133. <trim prefix="SET" suffixOverrides=",">
  134. <if test="chatId != null">chat_id = #{chatId},</if>
  135. <if test="qwExtId != null">qw_ext_id = #{qwExtId},</if>
  136. <if test="qwExtWxId != null">qw_ext_wx_id = #{qwExtWxId},</if>
  137. <if test="corpId != null">corp_id = #{corpId},</if>
  138. <if test="qwUserId != null">qw_user_id = #{qwUserId},</if>
  139. <if test="createTime != null">create_time = #{createTime},</if>
  140. <if test="updateTime != null">update_time = #{updateTime},</if>
  141. <if test="status != null">status = #{status},</if>
  142. <if test="companyId != null">company_id = #{companyId},</if>
  143. <if test="userType != null">user_type = #{userType},</if>
  144. <if test="nickName != null">nick_name = #{nickName},</if>
  145. <if test="avatar != null">avatar = #{avatar},</if>
  146. <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
  147. <if test="isRoom != null">is_room = #{isRoom},</if>
  148. <if test="firstLetter != null">first_letter = #{firstLetter},</if>
  149. <if test="lastMsgId != null">last_msg_id = #{lastMsgId},</if>
  150. <if test="lastMsgType != null">last_msg_type = #{lastMsgType},</if>
  151. <if test="lastSendTime != null">last_send_time = #{lastSendTime},</if>
  152. <if test="lastContent != null">last_content = #{lastContent},</if>
  153. </trim>
  154. where session_id = #{sessionId}
  155. </update>
  156. <delete id="deleteQwSessionBySessionId" parameterType="Long">
  157. delete from qw_session where session_id = #{sessionId}
  158. </delete>
  159. <delete id="deleteQwSessionBySessionIds" parameterType="String">
  160. delete from qw_session where session_id in
  161. <foreach item="sessionId" collection="array" open="(" separator="," close=")">
  162. #{sessionId}
  163. </foreach>
  164. </delete>
  165. <select id="selectQwSessionByGroupChatId" resultType="com.fs.qw.domain.QwSession">
  166. select
  167. qs.*
  168. from qw_session qs
  169. inner join qw_group_chat qgc on qs.chat_id = qgc.chat_id
  170. where qgc.chat_id = #{groupChatId}
  171. </select>
  172. <select id="selectQwSessionByContactId" resultType="com.fs.qw.domain.QwSession">
  173. select
  174. qs.*
  175. from qw_session qs
  176. inner join qw_external_contact qec on qs.qw_ext_id = qec.id
  177. where qec.id = #{contactId}
  178. </select>
  179. </mapper>