From 915e9c8c892499d8d7851d3572b35db1ce4be465 Mon Sep 17 00:00:00 2001 From: limeng Date: Sun, 23 Jul 2023 00:32:05 +0800 Subject: [PATCH 1/2] =?UTF-8?q?sql=E8=BF=81=E7=A7=BB=E6=8C=81=E4=B9=85?= =?UTF-8?q?=E5=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/user/dao/UserApplyDao.java | 43 +++++++++++++++ .../common/user/dao/UserFriendDao.java | 12 +++++ .../vo/response/friend/FriendApplyResp.java | 2 + .../user/service/impl/FriendServiceImpl.java | 52 ++++++------------- 4 files changed, 74 insertions(+), 35 deletions(-) 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 0beacd6..51ed985 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 @@ -3,9 +3,16 @@ package com.abin.mallchat.common.user.dao; import com.abin.mallchat.common.user.domain.entity.UserApply; import com.abin.mallchat.common.user.mapper.UserApplyMapper; import com.abin.mallchat.common.user.service.IUserApplyService; +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; +import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; 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.UNREAD; +import static com.abin.mallchat.common.user.domain.enums.ApplyStatusEnum.AGREE; + /** *

* 用户申请表 服务实现类 @@ -17,4 +24,40 @@ import org.springframework.stereotype.Service; @Service public class UserApplyDao extends ServiceImpl implements IUserApplyService { + public UserApply queryUserApply(Long uid, Long targetUid) { + LambdaQueryChainWrapper wrapper = lambdaQuery() + .eq(UserApply::getUid, uid) + .eq(UserApply::getTargetId, targetUid); + return getOne(wrapper); + } + + public void insert(UserApply userApply) { + save(userApply); + } + + public List queryUserApplyList(Long uid) { + LambdaQueryChainWrapper wrapper = lambdaQuery() + .eq(UserApply::getUid, uid) + .or() + .eq(UserApply::getTargetId, uid); + return list(wrapper); + } + + public Integer unreadCount(Long uid) { + LambdaQueryChainWrapper wrapper = lambdaQuery() + .eq(UserApply::getTargetId, uid) + .eq(UserApply::getReadStatus, UNREAD.getCode()); + return count(wrapper); + } + + public UserApply queryUserApplyById(Long applyId) { + return getById(applyId); + } + + public void agreeUserApply(Long applyId) { + LambdaUpdateChainWrapper updateWrapper = lambdaUpdate() + .set(UserApply::getStatus, AGREE.getCode()) + .eq(UserApply::getId, applyId); + update(updateWrapper); + } } 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 5921882..1807360 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 @@ -3,9 +3,12 @@ package com.abin.mallchat.common.user.dao; import com.abin.mallchat.common.user.domain.entity.UserFriend; import com.abin.mallchat.common.user.mapper.UserFriendMapper; import com.abin.mallchat.common.user.service.IUserFriendService; +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.stereotype.Service; +import java.util.List; + /** *

* 用户联系人表 服务实现类 @@ -17,4 +20,13 @@ import org.springframework.stereotype.Service; @Service public class UserFriendDao extends ServiceImpl implements IUserFriendService { + public List queryUserFriend(Long uid, List friendUidList) { + LambdaQueryChainWrapper wrapper = lambdaQuery() + .eq(UserFriend::getUid, uid).in(UserFriend::getFriendUid, friendUidList); + return list(wrapper); + } + + public void insertBatch(List userFriends) { + saveBatch(userFriends); + } } diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/domain/vo/response/friend/FriendApplyResp.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/domain/vo/response/friend/FriendApplyResp.java index ed2bedb..460bf8c 100644 --- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/domain/vo/response/friend/FriendApplyResp.java +++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/user/domain/vo/response/friend/FriendApplyResp.java @@ -17,6 +17,8 @@ import lombok.NoArgsConstructor; @AllArgsConstructor @NoArgsConstructor public class FriendApplyResp { + @ApiModelProperty("申请id") + private Long applyId; @ApiModelProperty("申请人uid") private Long uid; 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 5c5343b..15f0669 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 @@ -2,10 +2,10 @@ package com.abin.mallchat.custom.user.service.impl; import com.abin.mallchat.common.common.domain.vo.request.PageBaseReq; import com.abin.mallchat.common.common.domain.vo.response.PageBaseResp; +import com.abin.mallchat.common.user.dao.UserApplyDao; +import com.abin.mallchat.common.user.dao.UserFriendDao; import com.abin.mallchat.common.user.domain.entity.UserApply; import com.abin.mallchat.common.user.domain.entity.UserFriend; -import com.abin.mallchat.common.user.service.IUserApplyService; -import com.abin.mallchat.common.user.service.IUserFriendService; 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; @@ -17,8 +17,6 @@ import com.abin.mallchat.custom.user.domain.vo.response.ws.WSApplyMessage; import com.abin.mallchat.custom.user.service.FriendService; import com.abin.mallchat.custom.user.service.WebSocketService; import com.abin.mallchat.custom.user.service.adapter.WSAdapter; -import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; -import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; import com.google.common.collect.Lists; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -43,16 +41,15 @@ import static com.abin.mallchat.common.user.domain.enums.ApplyTypeEnum.ADD_FRIEN @Slf4j @Service public class FriendServiceImpl implements FriendService { - - @Resource - private IUserFriendService friendService; - - @Resource - private IUserApplyService applyService; - @Resource private WebSocketService webSocketService; + @Resource + private UserFriendDao userFriendDao; + + @Resource + private UserApplyDao userApplyDao; + /** * 检查 * 检查是否是自己好友 @@ -63,10 +60,7 @@ public class FriendServiceImpl implements FriendService { */ @Override public FriendCheckResp check(Long uid, FriendCheckReq request) { - LambdaQueryChainWrapper wrapper = friendService.lambdaQuery(); - wrapper.eq(UserFriend::getUid, uid) - .in(UserFriend::getFriendUid, request.getUidList()); - List friendList = friendService.list(wrapper); + List friendList = userFriendDao.queryUserFriend(uid, request.getUidList()); Map friendMap = friendList.stream().collect(Collectors.toMap(UserFriend::getFriendUid, friend -> friend)); List friendCheckList = request.getUidList().stream().map(friendUid -> { FriendCheckResp.FriendCheck friendCheck = new FriendCheckResp.FriendCheck(); @@ -84,10 +78,7 @@ public class FriendServiceImpl implements FriendService { */ @Override public void apply(Long uid, FriendApplyReq request) { - LambdaQueryChainWrapper wrapper = applyService.lambdaQuery(); - wrapper.eq(UserApply::getUid, uid) - .eq(UserApply::getTargetId, request.getTargetUid()); - UserApply userApply = applyService.getOne(wrapper); + UserApply userApply = userApplyDao.queryUserApply(uid, request.getTargetUid()); if (Objects.nonNull(userApply)) { log.info("已有好友申请记录,uid:{}, targetId:{}", uid, request.getTargetUid()); return; @@ -99,7 +90,7 @@ public class FriendServiceImpl implements FriendService { userApplyNew.setTargetId(request.getTargetUid()); userApplyNew.setStatus(WAIT_APPROVAL.getCode()); userApplyNew.setReadStatus(UNREAD.getCode()); - applyService.save(userApplyNew); + userApplyDao.insert(userApplyNew); WSApplyMessage applyMessage = MessageAdapter.buildApplyResp(userApplyNew); webSocketService.sendToFriend(WSAdapter.buildApplySend(applyMessage), request.getTargetUid()); @@ -114,13 +105,10 @@ public class FriendServiceImpl implements FriendService { @Override public PageBaseResp pageApplyFriend(Long uid, PageBaseReq request) { // todo 分页 - LambdaQueryChainWrapper wrapper = applyService.lambdaQuery(); - wrapper.eq(UserApply::getUid, uid) - .or() - .eq(UserApply::getTargetId, uid); - List userApplyList = applyService.list(wrapper); + List userApplyList = userApplyDao.queryUserApplyList(uid); List friendApplyResps = userApplyList.stream().map(userApply -> { FriendApplyResp friendApplyResp = new FriendApplyResp(); + friendApplyResp.setApplyId(userApply.getId()); friendApplyResp.setUid(userApply.getUid()); friendApplyResp.setType(userApply.getType()); friendApplyResp.setMsg(userApply.getMsg()); @@ -139,16 +127,13 @@ public class FriendServiceImpl implements FriendService { */ @Override public FriendUnreadResp unread(Long uid) { - LambdaQueryChainWrapper wrapper = applyService.lambdaQuery(); - wrapper.eq(UserApply::getTargetId, uid) - .eq(UserApply::getReadStatus, UNREAD.getCode()); - return new FriendUnreadResp(applyService.count(wrapper)); + return new FriendUnreadResp(userApplyDao.unreadCount(uid)); } @Override @Transactional public void applyApprove(FriendApproveReq request) { - UserApply userApply = applyService.getById(request.getApplyId()); + UserApply userApply = userApplyDao.queryUserApplyById(request.getApplyId()); if (Objects.isNull(userApply)) { log.error("不存在申请记录:{}", request.getApplyId()); return; @@ -157,16 +142,13 @@ public class FriendServiceImpl implements FriendService { log.error("已同意好友申请:{}", request.getApplyId()); return; } - LambdaUpdateChainWrapper updateWrapper = applyService.lambdaUpdate(); - updateWrapper.set(UserApply::getStatus, AGREE.getCode()) - .eq(UserApply::getId, request.getApplyId()); - applyService.update(updateWrapper); + userApplyDao.agreeUserApply(request.getApplyId()); UserFriend userFriend1 = new UserFriend(); userFriend1.setUid(userApply.getUid()); userFriend1.setFriendUid(userApply.getTargetId()); UserFriend userFriend2 = new UserFriend(); userFriend2.setUid(userApply.getTargetId()); userFriend2.setFriendUid(userApply.getUid()); - friendService.saveBatch(Lists.newArrayList(userFriend1, userFriend2)); + userFriendDao.insertBatch(Lists.newArrayList(userFriend1, userFriend2)); } } From 7cb64f039b59246b52dc23befc8759fe2d315568 Mon Sep 17 00:00:00 2001 From: limeng Date: Sun, 23 Jul 2023 12:36:19 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=A5=BD=E5=8F=8B?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=92=8C=E8=81=94=E7=B3=BB=E4=BA=BA=E5=88=97?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/user/dao/UserApplyDao.java | 6 ++- .../mallchat/common/user/dao/UserDao.java | 9 ++++ .../common/user/dao/UserFriendDao.java | 22 ++++++++ .../chat/service/adapter/MemberAdapter.java | 18 +++++++ .../user/controller/FriendController.java | 7 ++- .../custom/user/service/FriendService.java | 13 +++++ .../user/service/impl/FriendServiceImpl.java | 52 +++++++++++++++---- 7 files changed, 112 insertions(+), 15 deletions(-) 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)); } + }