MessageMapper.xml 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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.kym.mapper.MessageMapper">
  4. <!-- 消息结果映射 -->
  5. <resultMap id="MessageResultMap" type="com.kym.entity.Message">
  6. <id column="id" property="id"/>
  7. <result column="company_id" property="companyId"/>
  8. <result column="title" property="title"/>
  9. <result column="content" property="content"/>
  10. <result column="type" property="type"/>
  11. <result column="sender_id" property="senderId"/>
  12. <result column="sender_name" property="senderName"/>
  13. <result column="receiver_id" property="receiverId"/>
  14. <result column="receiver_name" property="receiverName"/>
  15. <result column="status" property="status"/>
  16. <result column="read_time" property="readTime"/>
  17. <result column="biz_type" property="bizType"/>
  18. <result column="biz_id" property="bizId"/>
  19. <result column="priority" property="priority"/>
  20. <result column="is_push" property="isPush"/>
  21. <result column="create_time" property="createTime"/>
  22. <result column="update_time" property="updateTime"/>
  23. </resultMap>
  24. <!-- 分页查询消息列表 -->
  25. <select id="selectMessagePage" resultMap="MessageResultMap">
  26. SELECT * FROM t_message
  27. <where>
  28. status != 2
  29. <if test="params.receiverId != null">
  30. AND receiver_id = #{params.receiverId}
  31. </if>
  32. <if test="params.senderId != null">
  33. AND sender_id = #{params.senderId}
  34. </if>
  35. <if test="params.type != null">
  36. AND type = #{params.type}
  37. </if>
  38. <if test="params.status != null">
  39. AND status = #{params.status}
  40. </if>
  41. <if test="params.title != null and params.title != ''">
  42. AND title LIKE CONCAT('%', #{params.title}, '%')
  43. </if>
  44. <if test="params.priority != null">
  45. AND priority = #{params.priority}
  46. </if>
  47. </where>
  48. ORDER BY priority DESC, create_time DESC
  49. </select>
  50. <!-- 统计未读消息数量 -->
  51. <select id="countUnread" resultType="int">
  52. SELECT COUNT(*) FROM t_message
  53. WHERE receiver_id = #{receiverId}
  54. AND status = 0
  55. </select>
  56. <!-- 按类型统计未读消息数量 -->
  57. <select id="countUnreadByType" resultType="int">
  58. SELECT COUNT(*) FROM t_message
  59. WHERE receiver_id = #{receiverId}
  60. AND status = 0
  61. AND type = #{type}
  62. </select>
  63. <!-- 批量标记已读 -->
  64. <update id="batchMarkRead">
  65. UPDATE t_message
  66. SET status = 1, read_time = NOW()
  67. WHERE receiver_id = #{receiverId}
  68. AND status = 0
  69. <if test="type != null">
  70. AND type = #{type}
  71. </if>
  72. </update>
  73. </mapper>