好友相关后端

Change-Id: I4838ea80d0e9173d97c0afc60b4d8b4de926bf41
diff --git a/src/main/resources/mapper/xml/FriendsListMapper.xml b/src/main/resources/mapper/xml/FriendsListMapper.xml
new file mode 100644
index 0000000..3053fc2
--- /dev/null
+++ b/src/main/resources/mapper/xml/FriendsListMapper.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="com.pt5.pthouduan.mapper.FriendsListMapper">
+
+    <!-- 插入好友申请 -->
+    <insert id="insertFriendRequest" parameterType="com.pt5.pthouduan.entity.FriendsList">
+        INSERT INTO friendslist (relationid, friend1, friend2, requestTime, status)
+        VALUES (#{relationid}, #{friend1}, #{friend2}, #{requestTime}, #{status})
+    </insert>
+
+    <!-- 同意好友申请(更新 status) -->
+    <update id="updateFriendStatus">
+        UPDATE friendslist
+        SET status = #{status}
+        WHERE (friend1 = #{friend1} AND friend2 = #{friend2})
+           OR (friend1 = #{friend2} AND friend2 = #{friend1})
+    </update>
+
+    <!-- 删除好友关系(不区分 friend1 和 friend2) -->
+    <delete id="deleteByFriendPair">
+        DELETE FROM friendslist
+        WHERE (friend1 = #{friend1} AND friend2 = #{friend2})
+           OR (friend1 = #{friend2} AND friend2 = #{friend1})
+    </delete>
+
+    <!-- 查询某用户所有已通过好友 -->
+    <select id="selectAcceptedFriends" parameterType="long" resultType="com.pt5.pthouduan.entity.FriendsList">
+        SELECT * FROM friendslist
+        WHERE (friend1 = #{userid} OR friend2 = #{userid})
+          AND status = 'accepted'
+    </select>
+
+    <!-- 查询自己收到的好友请求(自己是 friend2 且 status = 'pending') -->
+    <select id="selectPendingRequests" parameterType="long" resultType="com.pt5.pthouduan.entity.FriendsList">
+        SELECT * FROM friendslist
+        WHERE friend2 = #{userid}
+          AND status = 'pending'
+        ORDER BY requestTime DESC
+    </select>
+
+</mapper>