私信一个人可以称作对一个人进行私信:
id
from_id(发送者,1表系统,否则用户)
to_id(接受者)
status(状态,0表未读,1表已读)
conversation_id(会话id,可以使用发送者id和接收者id拼起来,小的在前)
content(内容)
查询查询一个人所有会话的最后一条数据:
select <include refid="selectFields"></include>
from message
where id in (
select max(id) from message
where status != 2
and from_id != 1
and (from_id = #{userId} or to_id = #{userId})
group by conversation_id
)
order by id desc
limit #{offset}, #{limit}
查询两个会话的全部数据:
select <include refid="selectFields"></include>
from message
where status != 2
and from_id != 1
and conversation_id = #{conversationId}
order by id desc
limit #{offset}, #{limit}
查询未读消息数量:
select count(id)
from message
where status = 0
and from_id != 1
and to_id = #{userId}
<if test="conversationId!=null">
and conversation_id = #{conversationId}
</if>
更新一批id设置成已读:
update message set status = #{status}
where id in
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
插入一条私信:
insert into message(<include refid="insertFields"></include>)
values(#{fromId},#{toId},#{conversationId},#{content},#{status},#{createTime})