QwConversationMessageMapper.xml 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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.fs.qw.mapper.QwConversationMessageMapper">
  4. <resultMap id="BaseResultMap" type="com.fs.qw.domain.QwConversationMessage">
  5. <id column="id" property="id"/>
  6. <result column="corp_id" property="corpId"/>
  7. <result column="msgid" property="msgid"/>
  8. <result column="sender_type" property="senderType"/>
  9. <result column="sender_id" property="senderId"/>
  10. <result column="chatid" property="chatid"/>
  11. <result column="msgtype" property="msgtype"/>
  12. <result column="send_time" property="sendTime"/>
  13. <result column="encrypted_secret_key" property="encryptedSecretKey"/>
  14. <result column="secret_key" property="secretKey"/>
  15. <result column="public_key_ver" property="publicKeyVer"/>
  16. <result column="extra_info" property="extraInfo"/>
  17. <result column="create_time" property="createTime"/>
  18. <result column="update_time" property="updateTime"/>
  19. </resultMap>
  20. <sql id="Base_Column_List">
  21. SELECT id, corp_id, msgid, sender_type, sender_id, chatid, msgtype, send_time,
  22. encrypted_secret_key, secret_key, public_key_ver, extra_info, create_time, update_time
  23. FROM qw_conversation_message
  24. </sql>
  25. <!-- 插入 -->
  26. <insert id="insert" useGeneratedKeys="true" keyProperty="id">
  27. INSERT INTO qw_conversation_message
  28. <trim prefix="(" suffix=")" suffixOverrides=",">
  29. <if test="corpId != null">corp_id,</if>
  30. <if test="msgid != null">msgid,</if>
  31. <if test="senderType != null">sender_type,</if>
  32. <if test="senderId != null">sender_id,</if>
  33. <if test="chatid != null">chatid,</if>
  34. <if test="msgtype != null">msgtype,</if>
  35. <if test="sendTime != null">send_time,</if>
  36. <if test="encryptedSecretKey != null">encrypted_secret_key,</if>
  37. <if test="secretKey != null">secret_key,</if>
  38. <if test="publicKeyVer != null">public_key_ver,</if>
  39. <if test="extraInfo != null">extra_info,</if>
  40. create_time, update_time
  41. </trim>
  42. <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
  43. <if test="corpId != null">#{corpId},</if>
  44. <if test="msgid != null">#{msgid},</if>
  45. <if test="senderType != null">#{senderType},</if>
  46. <if test="senderId != null">#{senderId},</if>
  47. <if test="chatid != null">#{chatid},</if>
  48. <if test="msgtype != null">#{msgtype},</if>
  49. <if test="sendTime != null">#{sendTime},</if>
  50. <if test="encryptedSecretKey != null">#{encryptedSecretKey},</if>
  51. <if test="secretKey != null">#{secretKey},</if>
  52. <if test="publicKeyVer != null">#{publicKeyVer},</if>
  53. <if test="extraInfo != null">#{extraInfo},</if>
  54. NOW(), NOW()
  55. </trim>
  56. </insert>
  57. <!-- 根据主键删除 -->
  58. <delete id="deleteById">
  59. DELETE FROM qw_conversation_message WHERE id = #{id}
  60. </delete>
  61. <!-- 根据企业+msgid删除 -->
  62. <delete id="deleteByMsgid">
  63. DELETE FROM qw_conversation_message WHERE corp_id = #{corpId} AND msgid = #{msgid}
  64. </delete>
  65. <!-- 更新(根据主键) -->
  66. <update id="updateById" parameterType="com.fs.qw.domain.QwConversationMessage">
  67. UPDATE qw_conversation_message
  68. <set>
  69. <if test="encryptedSecretKey != null">encrypted_secret_key = #{encryptedSecretKey},</if>
  70. <if test="secretKey != null">secret_key = #{secretKey},</if>
  71. <if test="publicKeyVer != null">public_key_ver = #{publicKeyVer},</if>
  72. <if test="extraInfo != null">extra_info = #{extraInfo},</if>
  73. update_time = NOW()
  74. </set>
  75. WHERE id = #{id}
  76. </update>
  77. <!-- 根据主键查询 -->
  78. <select id="selectById" resultMap="BaseResultMap">
  79. <include refid="Base_Column_List"/> WHERE id = #{id}
  80. </select>
  81. <!-- 根据企业+msgid查询 -->
  82. <select id="selectByCorpIdAndMsgid" resultMap="BaseResultMap">
  83. <include refid="Base_Column_List"/>
  84. WHERE corp_id = #{corpId} AND msgid = #{msgid}
  85. </select>
  86. <!-- 检查是否存在 -->
  87. <select id="existsByCorpIdAndMsgid" resultType="int">
  88. SELECT COUNT(1) FROM qw_conversation_message
  89. WHERE corp_id = #{corpId} AND msgid = #{msgid}
  90. </select>
  91. <!-- 查询两个参与者之间的消息(通过参与者表关联) -->
  92. <select id="selectMessagesBetweenUsers" resultMap="BaseResultMap">
  93. SELECT DISTINCT
  94. m.id, m.corp_id, m.msgid, m.sender_type, m.sender_id, m.chatid, m.msgtype, m.send_time,
  95. m.encrypted_secret_key, m.secret_key, m.public_key_ver, m.extra_info, m.create_time, m.update_time
  96. FROM qw_conversation_message m
  97. INNER JOIN qw_conversation_participant p1 ON m.msgid = p1.msgid AND m.corp_id = p1.corp_id
  98. INNER JOIN qw_conversation_participant p2 ON m.msgid = p2.msgid AND m.corp_id = p2.corp_id
  99. WHERE m.corp_id = #{corpId}
  100. AND p1.user_type = 1 AND p1.user_id = #{staffUserId}
  101. AND p2.user_type = 2 AND p2.user_id = #{customerId}
  102. ORDER BY m.send_time ASC
  103. <if test="limit != null and limit > 0">LIMIT #{limit}</if>
  104. </select>
  105. <!-- 条件分页查询(按时间范围) -->
  106. <select id="selectListByCondition" resultMap="BaseResultMap">
  107. <include refid="Base_Column_List"/>
  108. WHERE corp_id = #{corpId}
  109. <if test="startTime != null">AND send_time >= #{startTime}</if>
  110. <if test="endTime != null">AND send_time &lt;= #{endTime}</if>
  111. ORDER BY send_time DESC
  112. <if test="offset != null and limit != null">LIMIT #{offset}, #{limit}</if>
  113. </select>
  114. <select id="selectByMsgIds" resultType="com.fs.qw.domain.QwConversationMessage">
  115. <include refid="Base_Column_List"/>
  116. WHERE corp_id = #{corpId}
  117. AND msgid IN
  118. <foreach collection="msgIds" item="msgid" open="(" separator="," close=")">
  119. #{msgid}
  120. </foreach>
  121. </select>
  122. </mapper>