diff --git a/mallchat-common/src/main/java/com/abin/mallchat/common/user/dao/UserApplyDao.java b/mallchat-common/src/main/java/com/abin/mallchat/common/user/dao/UserApplyDao.java
index 2a82563..5def2ca 100644
--- a/mallchat-common/src/main/java/com/abin/mallchat/common/user/dao/UserApplyDao.java
+++ b/mallchat-common/src/main/java/com/abin/mallchat/common/user/dao/UserApplyDao.java
@@ -9,7 +9,11 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
+import java.util.List;
+
+import static com.abin.mallchat.common.user.domain.enums.ApplyReadStatusEnum.READ;
import static com.abin.mallchat.common.user.domain.enums.ApplyReadStatusEnum.UNREAD;
+import static com.abin.mallchat.common.user.domain.enums.ApplyStatusEnum.AGREE;
/**
*
@@ -36,7 +40,7 @@ public class UserApplyDao extends ServiceImpl {
.count();
}
- public IPage FriendApplyPage(Long uid, Page page) {
+ public IPage friendApplyPage(Long uid, Page page) {
return lambdaQuery()
.eq(UserApply::getTargetId, uid)
.eq(UserApply::getType, ApplyTypeEnum.ADD_FRIEND.getCode())
diff --git a/mallchat-common/src/main/java/com/abin/mallchat/common/user/dao/UserDao.java b/mallchat-common/src/main/java/com/abin/mallchat/common/user/dao/UserDao.java
index 659220c..0f4f7cb 100644
--- a/mallchat-common/src/main/java/com/abin/mallchat/common/user/dao/UserDao.java
+++ b/mallchat-common/src/main/java/com/abin/mallchat/common/user/dao/UserDao.java
@@ -53,4 +53,13 @@ public class UserDao extends ServiceImpl {
.list();
}
+
+ public List getUserList(List uids) {
+ return lambdaQuery()
+ .in(User::getId, uids)
+ .orderByDesc(User::getId)
+ .select(User::getId, User::getActiveStatus, User::getLastOptTime)
+ .list();
+
+ }
}
diff --git a/mallchat-common/src/main/java/com/abin/mallchat/common/user/dao/UserFriendDao.java b/mallchat-common/src/main/java/com/abin/mallchat/common/user/dao/UserFriendDao.java
index 0af3b41..68afa0f 100644
--- a/mallchat-common/src/main/java/com/abin/mallchat/common/user/dao/UserFriendDao.java
+++ b/mallchat-common/src/main/java/com/abin/mallchat/common/user/dao/UserFriendDao.java
@@ -1,10 +1,15 @@
package com.abin.mallchat.common.user.dao;
+import com.abin.mallchat.common.common.domain.vo.request.CursorPageBaseReq;
+import com.abin.mallchat.common.common.domain.vo.response.CursorPageBaseResp;
+import com.abin.mallchat.common.common.utils.CursorUtils;
import com.abin.mallchat.common.user.domain.entity.UserFriend;
import com.abin.mallchat.common.user.mapper.UserFriendMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
+import java.util.List;
+
/**
*
* 用户联系人表 服务实现类
@@ -27,4 +32,21 @@ public class UserFriendDao extends ServiceImpl {
.eq(UserFriend::getFriendUid, targetUid)
.one();
}
+
+ public CursorPageBaseResp getFriendPage(Long uid, CursorPageBaseReq cursorPageBaseReq) {
+ return CursorUtils.getCursorPageByMysql(this, cursorPageBaseReq,
+ wrapper -> wrapper.eq(UserFriend::getUid, uid), UserFriend::getId);
+ }
+
+ public List getUserFriend(Long uid, Long friendUid) {
+ return lambdaQuery()
+ .eq(UserFriend::getUid, uid)
+ .eq(UserFriend::getFriendUid, friendUid)
+ .or()
+ .eq(UserFriend::getFriendUid, uid)
+ .eq(UserFriend::getUid, friendUid)
+ .select(UserFriend::getId)
+ .list();
+ }
+
}
diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/service/adapter/MemberAdapter.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/service/adapter/MemberAdapter.java
index 9f88be3..e44695d 100644
--- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/service/adapter/MemberAdapter.java
+++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chat/service/adapter/MemberAdapter.java
@@ -1,6 +1,8 @@
package com.abin.mallchat.custom.chat.service.adapter;
import cn.hutool.core.lang.Pair;
+import com.abin.mallchat.common.user.domain.entity.User;
+import com.abin.mallchat.common.user.domain.entity.UserFriend;
import com.abin.mallchat.common.user.domain.enums.ChatActiveStatusEnum;
import com.abin.mallchat.common.user.service.cache.UserCache;
import com.abin.mallchat.custom.chat.domain.vo.response.ChatMemberResp;
@@ -10,6 +12,8 @@ import org.springframework.stereotype.Component;
import java.util.Date;
import java.util.List;
+import java.util.Map;
+import java.util.Objects;
import java.util.stream.Collectors;
/**
@@ -32,4 +36,18 @@ public class MemberAdapter {
return resp;
}).collect(Collectors.toList());
}
+
+ public static List buildMember(List list, List userList) {
+ Map userMap = userList.stream().collect(Collectors.toMap(User::getId, user -> user));
+ return list.stream().map(userFriend -> {
+ ChatMemberResp resp = new ChatMemberResp();
+ resp.setUid(userFriend.getFriendUid());
+ User user = userMap.get(userFriend.getFriendUid());
+ if (Objects.nonNull(user)) {
+ resp.setActiveStatus(user.getActiveStatus());
+ resp.setLastOptTime(user.getLastOptTime());
+ }
+ return resp;
+ }).collect(Collectors.toList());
+ }
}
diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/controller/FriendController.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/controller/FriendController.java
index e94288d..49a3f5e 100644
--- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/controller/FriendController.java
+++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/controller/FriendController.java
@@ -66,8 +66,8 @@ public class FriendController {
@DeleteMapping()
@ApiOperation("删除好友")
public ApiResult delete(@Valid @RequestBody FriendDeleteReq request) {
- //todo
Long uid = RequestHolder.get().getUid();
+ friendService.deleteFriend(uid, request.getTargetUid());
return ApiResult.success();
}
@@ -94,10 +94,9 @@ public class FriendController {
@PutMapping("/page")
@ApiOperation("联系人列表")
- public ApiResult> applyApprove(@Valid CursorPageBaseReq request) {
- //todo
+ public ApiResult> friendList(@Valid CursorPageBaseReq request) {
Long uid = RequestHolder.get().getUid();
- return ApiResult.success();
+ return ApiResult.success(friendService.friendList(uid, request));
}
}
diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/FriendService.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/FriendService.java
index 7502827..f6b85d9 100644
--- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/FriendService.java
+++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/FriendService.java
@@ -1,7 +1,10 @@
package com.abin.mallchat.custom.user.service;
+import com.abin.mallchat.common.common.domain.vo.request.CursorPageBaseReq;
import com.abin.mallchat.common.common.domain.vo.request.PageBaseReq;
+import com.abin.mallchat.common.common.domain.vo.response.CursorPageBaseResp;
import com.abin.mallchat.common.common.domain.vo.response.PageBaseResp;
+import com.abin.mallchat.custom.chat.domain.vo.response.ChatMemberResp;
import com.abin.mallchat.custom.user.domain.vo.request.friend.FriendApplyReq;
import com.abin.mallchat.custom.user.domain.vo.request.friend.FriendApproveReq;
import com.abin.mallchat.custom.user.domain.vo.request.friend.FriendCheckReq;
@@ -57,4 +60,14 @@ public interface FriendService {
* @param request 请求
*/
void applyApprove(Long uid, FriendApproveReq request);
+
+ /**
+ * 删除好友
+ *
+ * @param uid uid
+ * @param friendUid 朋友uid
+ */
+ void deleteFriend(Long uid, Long friendUid);
+
+ CursorPageBaseResp friendList(Long uid, CursorPageBaseReq request);
}
diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/FriendServiceImpl.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/FriendServiceImpl.java
index bc16a2e..7e90547 100644
--- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/FriendServiceImpl.java
+++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/service/impl/FriendServiceImpl.java
@@ -1,20 +1,25 @@
package com.abin.mallchat.custom.user.service.impl;
import cn.hutool.core.collection.CollectionUtil;
-import com.abin.mallchat.common.chat.dao.RoomFriendDao;
import com.abin.mallchat.common.chat.domain.entity.RoomFriend;
import com.abin.mallchat.common.chat.service.ContactService;
import com.abin.mallchat.common.chat.service.RoomService;
import com.abin.mallchat.common.common.annotation.RedissonLock;
+import com.abin.mallchat.common.common.domain.vo.request.CursorPageBaseReq;
import com.abin.mallchat.common.common.domain.vo.request.PageBaseReq;
+import com.abin.mallchat.common.common.domain.vo.response.CursorPageBaseResp;
import com.abin.mallchat.common.common.domain.vo.response.PageBaseResp;
import com.abin.mallchat.common.common.event.UserApplyEvent;
import com.abin.mallchat.common.common.utils.AssertUtil;
import com.abin.mallchat.common.user.dao.UserApplyDao;
+import com.abin.mallchat.common.user.dao.UserDao;
import com.abin.mallchat.common.user.dao.UserFriendDao;
+import com.abin.mallchat.common.user.domain.entity.User;
import com.abin.mallchat.common.user.domain.entity.UserApply;
import com.abin.mallchat.common.user.domain.entity.UserFriend;
+import com.abin.mallchat.custom.chat.domain.vo.response.ChatMemberResp;
import com.abin.mallchat.custom.chat.service.ChatService;
+import com.abin.mallchat.custom.chat.service.adapter.MemberAdapter;
import com.abin.mallchat.custom.chat.service.adapter.MessageAdapter;
import com.abin.mallchat.custom.user.domain.vo.request.friend.FriendApplyReq;
import com.abin.mallchat.custom.user.domain.vo.request.friend.FriendApproveReq;
@@ -23,7 +28,6 @@ import com.abin.mallchat.custom.user.domain.vo.response.friend.FriendApplyResp;
import com.abin.mallchat.custom.user.domain.vo.response.friend.FriendCheckResp;
import com.abin.mallchat.custom.user.domain.vo.response.friend.FriendUnreadResp;
import com.abin.mallchat.custom.user.service.FriendService;
-import com.abin.mallchat.custom.user.service.WebSocketService;
import com.abin.mallchat.custom.user.service.adapter.FriendAdapter;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.google.common.collect.Lists;
@@ -50,9 +54,6 @@ import static com.abin.mallchat.common.user.domain.enums.ApplyStatusEnum.AGREE;
@Service
public class FriendServiceImpl implements FriendService {
- @Autowired
- private WebSocketService webSocketService;
-
@Autowired
private UserFriendDao userFriendDao;
@Autowired
@@ -60,14 +61,15 @@ public class FriendServiceImpl implements FriendService {
@Autowired
private ApplicationEventPublisher applicationEventPublisher;
@Autowired
- private RoomFriendDao roomFriendDao;
- @Autowired
private RoomService roomService;
@Autowired
private ContactService contactService;
@Autowired
private ChatService chatService;
+ @Autowired
+ private UserDao userDao;
+
/**
* 检查
* 检查是否是自己好友
@@ -121,12 +123,14 @@ public class FriendServiceImpl implements FriendService {
*/
@Override
public PageBaseResp pageApplyFriend(Long uid, PageBaseReq request) {
- IPage userApplyIPage = userApplyDao.FriendApplyPage(uid, request.plusPage());
+ IPage userApplyIPage = userApplyDao.friendApplyPage(uid, request.plusPage());
if (CollectionUtil.isEmpty(userApplyIPage.getRecords())) {
return PageBaseResp.empty();
}
//将这些申请列表设为已读
- List applyIds = userApplyIPage.getRecords().stream().map(UserApply::getId).collect(Collectors.toList());
+ List applyIds = userApplyIPage.getRecords()
+ .stream().map(UserApply::getId)
+ .collect(Collectors.toList());
userApplyDao.readApples(uid, applyIds);
//返回消息
return PageBaseResp.init(userApplyIPage, FriendAdapter.buildFriendApplyList(userApplyIPage.getRecords()));
@@ -164,6 +168,33 @@ public class FriendServiceImpl implements FriendService {
chatService.sendMsg(MessageAdapter.buildAgreeMsg(roomFriend.getRoomId()), uid);
}
+ /**
+ * 删除好友
+ *
+ * @param uid uid
+ * @param friendUid 朋友uid
+ */
+ @Override
+ public void deleteFriend(Long uid, Long friendUid) {
+ List userFriends = userFriendDao.getUserFriend(uid, friendUid);
+ if (CollectionUtil.isEmpty(userFriends)) {
+ log.info("没有好友关系:{},{}", uid, friendUid);
+ return;
+ }
+ List friendRecordIds = userFriends.stream().map(UserFriend::getId).collect(Collectors.toList());
+ userFriendDao.removeByIds(friendRecordIds);
+ }
+
+ @Override
+ public CursorPageBaseResp friendList(Long uid, CursorPageBaseReq request) {
+ CursorPageBaseResp friendPage = userFriendDao.getFriendPage(uid, request);
+ List friendUids = friendPage.getList()
+ .stream().map(UserFriend::getFriendUid)
+ .collect(Collectors.toList());
+ List userList = userDao.getUserList(friendUids);
+ return CursorPageBaseResp.init(friendPage, MemberAdapter.buildMember(friendPage.getList(), userList));
+ }
+
private void createFriend(Long uid, Long targetUid) {
UserFriend userFriend1 = new UserFriend();
userFriend1.setUid(uid);
@@ -171,6 +202,7 @@ public class FriendServiceImpl implements FriendService {
UserFriend userFriend2 = new UserFriend();
userFriend2.setUid(targetUid);
userFriend2.setFriendUid(uid);
- userFriendDao.saveBatch(Lists.newArrayList(userFriend1, userFriend2))
+ userFriendDao.saveBatch(Lists.newArrayList(userFriend1, userFriend2));
}
+
}