QwMsgAuditMessageMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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.QwMsgAuditMessageMapper">
  6. <!-- 分表:上下文需含 corpId -->
  7. <sql id="physicalTableByCorpId">qw_msg_audit_message_${@com.fs.qw.shardingConfig.QwMsgAuditMessageSharding@shardIndex(corpId)}</sql>
  8. <resultMap type="QwMsgAuditMessage" id="QwMsgAuditMessageResult">
  9. <result property="id" column="id" />
  10. <result property="corpId" column="corp_id" />
  11. <result property="seq" column="seq" />
  12. <result property="msgId" column="msg_id" />
  13. <result property="msgTime" column="msg_time" />
  14. <result property="msgType" column="msg_type" />
  15. <result property="fromUser" column="from_user" />
  16. <result property="toList" column="to_list" />
  17. <result property="roomId" column="room_id" />
  18. <result property="conversationKey" column="conversation_key" />
  19. <result property="fromUserRole" column="from_user_role" />
  20. <result property="textContent" column="text_content" />
  21. <result property="mediaSdkfileid" column="media_sdkfileid" />
  22. <result property="mediaMd5sum" column="media_md5sum" />
  23. <result property="mediaSize" column="media_size" />
  24. <result property="mediaPlayLength" column="media_play_length" />
  25. <result property="mediaWidth" column="media_width" />
  26. <result property="mediaHeight" column="media_height" />
  27. <result property="mediaFileName" column="media_file_name" />
  28. <result property="mediaFileExt" column="media_file_ext" />
  29. <result property="mediaOssUrl" column="media_oss_url" />
  30. <result property="rawId" column="raw_id" />
  31. <result property="createTime" column="create_time" />
  32. </resultMap>
  33. <sql id="selectQwMsgAuditMessageVo">
  34. select id, corp_id, seq, msg_id, msg_time, msg_type, from_user, to_list, room_id, conversation_key, from_user_role, text_content, media_sdkfileid, media_md5sum, media_size, media_play_length, media_width, media_height, media_file_name, media_file_ext, media_oss_url, raw_id, create_time from
  35. </sql>
  36. <select id="selectQwMsgAuditMessageList" parameterType="QwMsgAuditMessage" resultMap="QwMsgAuditMessageResult">
  37. <include refid="selectQwMsgAuditMessageVo"/>
  38. <include refid="physicalTableByCorpId"/>
  39. <where>
  40. <if test="corpId != null and corpId != ''"> and corp_id = #{corpId}</if>
  41. <if test="seq != null "> and seq = #{seq}</if>
  42. <if test="msgId != null and msgId != ''"> and msg_id = #{msgId}</if>
  43. <if test="msgTime != null "> and msg_time = #{msgTime}</if>
  44. <if test="msgType != null and msgType != ''"> and msg_type = #{msgType}</if>
  45. <if test="fromUser != null and fromUser != ''"> and from_user = #{fromUser}</if>
  46. <if test="toList != null and toList != ''"> and to_list = #{toList}</if>
  47. <if test="roomId != null and roomId != ''"> and room_id = #{roomId}</if>
  48. <if test="conversationKey != null and conversationKey != ''"> and conversation_key = #{conversationKey}</if>
  49. <if test="fromUserRole != null "> and from_user_role = #{fromUserRole}</if>
  50. <if test="textContent != null and textContent != ''"> and text_content = #{textContent}</if>
  51. <if test="mediaSdkfileid != null and mediaSdkfileid != ''"> and media_sdkfileid = #{mediaSdkfileid}</if>
  52. <if test="mediaMd5sum != null and mediaMd5sum != ''"> and media_md5sum = #{mediaMd5sum}</if>
  53. <if test="mediaSize != null "> and media_size = #{mediaSize}</if>
  54. <if test="mediaPlayLength != null "> and media_play_length = #{mediaPlayLength}</if>
  55. <if test="mediaWidth != null "> and media_width = #{mediaWidth}</if>
  56. <if test="mediaHeight != null "> and media_height = #{mediaHeight}</if>
  57. <if test="mediaFileName != null and mediaFileName != ''"> and media_file_name like concat('%', #{mediaFileName}, '%')</if>
  58. <if test="mediaFileExt != null and mediaFileExt != ''"> and media_file_ext = #{mediaFileExt}</if>
  59. <if test="rawId != null "> and raw_id = #{rawId}</if>
  60. </where>
  61. order by msg_time desc
  62. </select>
  63. <select id="selectQwMsgAuditMessageById" resultMap="QwMsgAuditMessageResult">
  64. <include refid="selectQwMsgAuditMessageVo"/>
  65. qw_msg_audit_message_${shard}
  66. where id = #{id}
  67. </select>
  68. <insert id="insertQwMsgAuditMessage" parameterType="QwMsgAuditMessage" useGeneratedKeys="true" keyProperty="id">
  69. insert into
  70. <include refid="physicalTableByCorpId"/>
  71. <trim prefix="(" suffix=")" suffixOverrides=",">
  72. <if test="corpId != null and corpId != ''">corp_id,</if>
  73. <if test="seq != null">seq,</if>
  74. <if test="msgId != null">msg_id,</if>
  75. <if test="msgTime != null">msg_time,</if>
  76. <if test="msgType != null">msg_type,</if>
  77. <if test="fromUser != null">from_user,</if>
  78. <if test="toList != null">to_list,</if>
  79. <if test="roomId != null">room_id,</if>
  80. <if test="conversationKey != null">conversation_key,</if>
  81. <if test="fromUserRole != null">from_user_role,</if>
  82. <if test="textContent != null">text_content,</if>
  83. <if test="mediaSdkfileid != null">media_sdkfileid,</if>
  84. <if test="mediaMd5sum != null">media_md5sum,</if>
  85. <if test="mediaSize != null">media_size,</if>
  86. <if test="mediaPlayLength != null">media_play_length,</if>
  87. <if test="mediaWidth != null">media_width,</if>
  88. <if test="mediaHeight != null">media_height,</if>
  89. <if test="mediaFileName != null">media_file_name,</if>
  90. <if test="mediaFileExt != null">media_file_ext,</if>
  91. <if test="mediaOssUrl != null">media_oss_url,</if>
  92. <if test="rawId != null">raw_id,</if>
  93. <if test="createTime != null">create_time,</if>
  94. </trim>
  95. <trim prefix="values (" suffix=")" suffixOverrides=",">
  96. <if test="corpId != null and corpId != ''">#{corpId},</if>
  97. <if test="seq != null">#{seq},</if>
  98. <if test="msgId != null">#{msgId},</if>
  99. <if test="msgTime != null">#{msgTime},</if>
  100. <if test="msgType != null">#{msgType},</if>
  101. <if test="fromUser != null">#{fromUser},</if>
  102. <if test="toList != null">#{toList},</if>
  103. <if test="roomId != null">#{roomId},</if>
  104. <if test="conversationKey != null">#{conversationKey},</if>
  105. <if test="fromUserRole != null">#{fromUserRole},</if>
  106. <if test="textContent != null">#{textContent},</if>
  107. <if test="mediaSdkfileid != null">#{mediaSdkfileid},</if>
  108. <if test="mediaMd5sum != null">#{mediaMd5sum},</if>
  109. <if test="mediaSize != null">#{mediaSize},</if>
  110. <if test="mediaPlayLength != null">#{mediaPlayLength},</if>
  111. <if test="mediaWidth != null">#{mediaWidth},</if>
  112. <if test="mediaHeight != null">#{mediaHeight},</if>
  113. <if test="mediaFileName != null">#{mediaFileName},</if>
  114. <if test="mediaFileExt != null">#{mediaFileExt},</if>
  115. <if test="mediaOssUrl != null">#{mediaOssUrl},</if>
  116. <if test="rawId != null">#{rawId},</if>
  117. <if test="createTime != null">#{createTime},</if>
  118. </trim>
  119. </insert>
  120. <update id="updateQwMsgAuditMessage" parameterType="QwMsgAuditMessage">
  121. update
  122. <include refid="physicalTableByCorpId"/>
  123. <trim prefix="SET" suffixOverrides=",">
  124. <if test="corpId != null and corpId != ''">corp_id = #{corpId},</if>
  125. <if test="seq != null">seq = #{seq},</if>
  126. <if test="msgId != null">msg_id = #{msgId},</if>
  127. <if test="msgTime != null">msg_time = #{msgTime},</if>
  128. <if test="msgType != null">msg_type = #{msgType},</if>
  129. <if test="fromUser != null">from_user = #{fromUser},</if>
  130. <if test="toList != null">to_list = #{toList},</if>
  131. <if test="roomId != null">room_id = #{roomId},</if>
  132. <if test="conversationKey != null">conversation_key = #{conversationKey},</if>
  133. <if test="fromUserRole != null">from_user_role = #{fromUserRole},</if>
  134. <if test="textContent != null">text_content = #{textContent},</if>
  135. <if test="mediaSdkfileid != null">media_sdkfileid = #{mediaSdkfileid},</if>
  136. <if test="mediaMd5sum != null">media_md5sum = #{mediaMd5sum},</if>
  137. <if test="mediaSize != null">media_size = #{mediaSize},</if>
  138. <if test="mediaPlayLength != null">media_play_length = #{mediaPlayLength},</if>
  139. <if test="mediaWidth != null">media_width = #{mediaWidth},</if>
  140. <if test="mediaHeight != null">media_height = #{mediaHeight},</if>
  141. <if test="mediaFileName != null">media_file_name = #{mediaFileName},</if>
  142. <if test="mediaFileExt != null">media_file_ext = #{mediaFileExt},</if>
  143. <if test="mediaOssUrl != null">media_oss_url = #{mediaOssUrl},</if>
  144. <if test="rawId != null">raw_id = #{rawId},</if>
  145. <if test="createTime != null">create_time = #{createTime},</if>
  146. </trim>
  147. where id = #{id}
  148. </update>
  149. <delete id="deleteQwMsgAuditMessageById">
  150. delete from qw_msg_audit_message_${shard} where id = #{id}
  151. </delete>
  152. <delete id="deleteQwMsgAuditMessageByIdsInShard">
  153. delete from qw_msg_audit_message_${shard} where id in
  154. <foreach item="id" collection="ids" open="(" separator="," close=")">
  155. #{id}
  156. </foreach>
  157. </delete>
  158. <select id="selectByCorpIdAndSeq" resultMap="QwMsgAuditMessageResult">
  159. <include refid="selectQwMsgAuditMessageVo"/>
  160. <include refid="physicalTableByCorpId"/>
  161. where corp_id = #{corpId} and seq = #{seq} limit 1
  162. </select>
  163. <select id="selectMediaPendingOssUpload" resultMap="QwMsgAuditMessageResult">
  164. <include refid="selectQwMsgAuditMessageVo"/>
  165. <include refid="physicalTableByCorpId"/>
  166. where corp_id = #{corpId} and msg_type = #{msgType} and media_sdkfileid is not null and media_oss_url is null limit #{limit}
  167. </select>
  168. <!-- 单聊会话列表 -->
  169. <select id="selectSingleConversationList" resultType="com.fs.qw.dto.QwMsgAuditConversationDTO">
  170. SELECT m.conversation_key AS conversationKey,
  171. MAX(m.msg_time) AS lastMsgTime
  172. FROM
  173. qw_msg_audit_message_${@com.fs.qw.shardingConfig.QwMsgAuditMessageSharding@shardIndex(corpId)} m
  174. WHERE m.corp_id = #{corpId}
  175. AND (m.room_id IS NULL OR m.room_id = '')
  176. AND m.conversation_key IS NOT NULL
  177. AND m.conversation_key &lt;&gt; ''
  178. AND m.conversation_key LIKE CONCAT(#{corpId}, ':p2p:%')
  179. AND (
  180. m.from_user = #{qwUserId}
  181. OR (
  182. m.to_list IS NOT NULL AND m.to_list &lt;&gt; '' AND m.to_list &lt;&gt; '[]'
  183. AND JSON_CONTAINS(CAST(m.to_list AS JSON), JSON_QUOTE(#{qwUserId}), '$')
  184. )
  185. )
  186. GROUP BY m.conversation_key
  187. ORDER BY lastMsgTime DESC
  188. </select>
  189. </mapper>