ym923 | 8cced1d | 2025-06-09 09:50:53 +0800 | [diff] [blame^] | 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 | |
| 6 | <mapper namespace="com.pt5.pthouduan.mapper.FriendsListMapper"> |
| 7 | |
| 8 | <!-- 插入好友申请 --> |
| 9 | <insert id="insertFriendRequest" parameterType="com.pt5.pthouduan.entity.FriendsList"> |
| 10 | INSERT INTO friendslist (relationid, friend1, friend2, requestTime, status) |
| 11 | VALUES (#{relationid}, #{friend1}, #{friend2}, #{requestTime}, #{status}) |
| 12 | </insert> |
| 13 | |
| 14 | <!-- 同意好友申请(更新 status) --> |
| 15 | <update id="updateFriendStatus"> |
| 16 | UPDATE friendslist |
| 17 | SET status = #{status} |
| 18 | WHERE (friend1 = #{friend1} AND friend2 = #{friend2}) |
| 19 | OR (friend1 = #{friend2} AND friend2 = #{friend1}) |
| 20 | </update> |
| 21 | |
| 22 | <!-- 删除好友关系(不区分 friend1 和 friend2) --> |
| 23 | <delete id="deleteByFriendPair"> |
| 24 | DELETE FROM friendslist |
| 25 | WHERE (friend1 = #{friend1} AND friend2 = #{friend2}) |
| 26 | OR (friend1 = #{friend2} AND friend2 = #{friend1}) |
| 27 | </delete> |
| 28 | |
| 29 | <!-- 查询某用户所有已通过好友 --> |
| 30 | <select id="selectAcceptedFriends" parameterType="long" resultType="com.pt5.pthouduan.entity.FriendsList"> |
| 31 | SELECT * FROM friendslist |
| 32 | WHERE (friend1 = #{userid} OR friend2 = #{userid}) |
| 33 | AND status = 'accepted' |
| 34 | </select> |
| 35 | |
| 36 | <!-- 查询自己收到的好友请求(自己是 friend2 且 status = 'pending') --> |
| 37 | <select id="selectPendingRequests" parameterType="long" resultType="com.pt5.pthouduan.entity.FriendsList"> |
| 38 | SELECT * FROM friendslist |
| 39 | WHERE friend2 = #{userid} |
| 40 | AND status = 'pending' |
| 41 | ORDER BY requestTime DESC |
| 42 | </select> |
| 43 | |
| 44 | </mapper> |