完成历史信息查询,并且可以通过内容模糊查询,通过时间查询,通过消息类型查询

This commit is contained in:
KilLze
2026-01-06 04:18:30 +08:00
parent 2a9acb946e
commit c0969406b3
9 changed files with 210 additions and 15 deletions

View File

@@ -31,4 +31,30 @@
)
</insert>
<!-- 根据两个用户ID及可选条件查询聊天记录 (按发送时间倒序) - PageHelper 会自动处理分页 -->
<select id="selectByUsersAndConditions" resultType="com.bao.dating.pojo.entity.ChatRecords">
SELECT
chat_id, sender_user_id, receiver_user_id, message_content, message_type,
read_status, read_time, send_time, message_status, created_at, updated_at
FROM chat_records
WHERE (
(sender_user_id = #{currentUserId} AND receiver_user_id = #{targetUserId})
OR (sender_user_id = #{targetUserId} AND receiver_user_id = #{currentUserId})
)
AND message_status = 1
<!-- 动态条件 -->
<if test="messageContent != null and messageContent != ''">
AND message_content LIKE CONCAT('%', #{messageContent}, '%')
</if>
<if test="startTime != null">
AND send_time >= #{startTime}
</if>
<if test="endTime != null">
AND send_time &lt;= #{endTime}
</if>
<if test="messageType != null">
AND message_type = #{messageType}
</if>
ORDER BY send_time DESC
</select>
</mapper>