ChatMsgMapper.xml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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.doc.chat.mapper.ChatMsgMapper">
  6. <resultMap type="ChatMsg" id="ChatMsgResult">
  7. <result property="msgId" column="MSG_ID"/>
  8. <result property="fromId" column="FROM_ID"/>
  9. <result property="toId" column="TO_ID"/>
  10. <result property="isRead" column="IS_READ"/>
  11. <result property="msgType" column="MSG_TYPE"/>
  12. <result property="content" column="CONTENT"/>
  13. <result property="idIndex" column="ID_INDEX"/>
  14. <result property="createTime" column="CREATE_TIME"/>
  15. </resultMap>
  16. <sql id="selectChatMsgVo">
  17. select MSG_ID,
  18. FROM_ID,
  19. TO_ID,
  20. MSG_TYPE,
  21. CONTENT,
  22. IS_READ,
  23. ID_INDEX,
  24. CREATE_TIME
  25. from chat_msg
  26. </sql>
  27. <select id="selectChatMsgList" parameterType="ChatMsg" resultMap="ChatMsgResult">
  28. <include refid="selectChatMsgVo"/>
  29. <where>
  30. <if test="fromId != null ">and FROM_ID = #{fromId}</if>
  31. <if test="toId != null ">and TO_ID = #{toId}</if>
  32. <if test="isRead != null ">and IS_READ = #{isRead}</if>
  33. <if test="msgType != null and msgType != ''">and MSG_TYPE = #{msgType}</if>
  34. <if test="content != null and content != ''">and CONTENT = #{content}</if>
  35. <if test="idIndex != null and idIndex != ''">and ID_INDEX = #{idIndex}</if>
  36. <if test="createTime != null ">and CREATE_TIME = #{createTime}</if>
  37. </where>
  38. </select>
  39. <select id="selectChatMsgByMsgId" parameterType="Long" resultMap="ChatMsgResult">
  40. <include refid="selectChatMsgVo"/>
  41. where MSG_ID = #{msgId}
  42. </select>
  43. <select id="selectFriendList" resultType="com.doc.chat.domain.ChatMsg">
  44. <include refid="selectChatMsgVo"/>
  45. where msg_id in (SELECT MAX(msg_id) msg_id
  46. FROM chat_msg
  47. WHERE from_id = #{userId} OR to_id = #{userId}
  48. GROUP BY id_index)
  49. ORDER BY create_time desc,msg_id desc
  50. </select>
  51. <select id="selectRecordList" resultType="com.doc.chat.domain.ChatMsg">
  52. <include refid="selectChatMsgVo"/>
  53. where id_index=#{idIndex}
  54. order by CREATE_TIME desc
  55. </select>
  56. <insert id="insertChatMsg" parameterType="ChatMsg" useGeneratedKeys="true" keyProperty="msgId">
  57. insert into chat_msg
  58. <trim prefix="(" suffix=")" suffixOverrides=",">
  59. <if test="fromId != null">FROM_ID,</if>
  60. <if test="toId != null">TO_ID,</if>
  61. <if test="isRead != null">IS_READ,</if>
  62. <if test="msgType != null">MSG_TYPE,</if>
  63. <if test="content != null">CONTENT,</if>
  64. <if test="idIndex != null">ID_INDEX,</if>
  65. <if test="createTime != null">CREATE_TIME,</if>
  66. </trim>
  67. <trim prefix="values (" suffix=")" suffixOverrides=",">
  68. <if test="fromId != null">#{fromId},</if>
  69. <if test="toId != null">#{toId},</if>
  70. <if test="isRead != null">#{isRead},</if>
  71. <if test="msgType != null">#{msgType},</if>
  72. <if test="content != null">#{content},</if>
  73. <if test="idIndex != null">#{idIndex},</if>
  74. <if test="createTime != null">#{createTime},</if>
  75. </trim>
  76. </insert>
  77. <update id="updateChatMsg" parameterType="ChatMsg">
  78. update chat_msg
  79. <trim prefix="SET" suffixOverrides=",">
  80. <if test="fromId != null">FROM_ID = #{fromId},</if>
  81. <if test="toId != null">TO_ID = #{toId},</if>
  82. <if test="isRead != null">IS_READ=#{isRead},</if>
  83. <if test="msgType != null">MSG_TYPE = #{msgType},</if>
  84. <if test="content != null">CONTENT = #{content},</if>
  85. <if test="idIndex != null">ID_INDEX = #{idIndex},</if>
  86. <if test="createTime != null">CREATE_TIME = #{createTime},</if>
  87. </trim>
  88. where MSG_ID = #{msgId}
  89. </update>
  90. <delete id="deleteChatMsgByMsgId" parameterType="Long">
  91. delete
  92. from chat_msg
  93. where MSG_ID = #{msgId}
  94. </delete>
  95. <delete id="deleteChatMsgByMsgIds" parameterType="String">
  96. delete from chat_msg where MSG_ID in
  97. <foreach item="msgId" collection="array" open="(" separator="," close=")">
  98. #{msgId}
  99. </foreach>
  100. </delete>
  101. </mapper>