diff --git a/.gitignore b/.gitignore index fe372340..f40b493d 100644 --- a/.gitignore +++ b/.gitignore @@ -72,3 +72,6 @@ mybatis-generator-config.xml ChannelBizRankClient.java ChannelBizBrandWallClient.java /*/rebel.xml + +# yml +*.yml diff --git a/mallchat-chat-server/src/main/java/com/abin/mallchat/common/chat/dao/ContactDao.java b/mallchat-chat-server/src/main/java/com/abin/mallchat/common/chat/dao/ContactDao.java index ff144f2d..1b3374fa 100644 --- a/mallchat-chat-server/src/main/java/com/abin/mallchat/common/chat/dao/ContactDao.java +++ b/mallchat-chat-server/src/main/java/com/abin/mallchat/common/chat/dao/ContactDao.java @@ -1,5 +1,6 @@ package com.abin.mallchat.common.chat.dao; +import cn.hutool.core.collection.CollectionUtil; import com.abin.mallchat.common.chat.domain.entity.Contact; import com.abin.mallchat.common.chat.domain.entity.Message; import com.abin.mallchat.common.chat.mapper.ContactMapper; @@ -96,12 +97,17 @@ public void refreshOrCreateActiveTime(Long roomId, List memberUidList, Lon /** * 根据房间ID删除会话 * - * @param roomId 房间ID + * @param roomId 房间ID + * @param uidList 群成员列表 * @return 是否删除成功 */ - public Boolean removeByRoomId(Long roomId) { - LambdaQueryWrapper wrapper = new QueryWrapper().lambda() - .eq(Contact::getRoomId, roomId); - return this.remove(wrapper); + public Boolean removeByRoomId(Long roomId, List uidList) { + if (CollectionUtil.isNotEmpty(uidList)) { + LambdaQueryWrapper wrapper = new QueryWrapper().lambda() + .eq(Contact::getRoomId, roomId) + .in(Contact::getUid, uidList); + return this.remove(wrapper); + } + return false; } } diff --git a/mallchat-chat-server/src/main/java/com/abin/mallchat/common/chat/dao/GroupMemberDao.java b/mallchat-chat-server/src/main/java/com/abin/mallchat/common/chat/dao/GroupMemberDao.java index 5c04cb44..1f7175d7 100644 --- a/mallchat-chat-server/src/main/java/com/abin/mallchat/common/chat/dao/GroupMemberDao.java +++ b/mallchat-chat-server/src/main/java/com/abin/mallchat/common/chat/dao/GroupMemberDao.java @@ -1,5 +1,6 @@ package com.abin.mallchat.common.chat.dao; +import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.ObjectUtil; import com.abin.mallchat.common.chat.domain.entity.Contact; import com.abin.mallchat.common.chat.domain.entity.GroupMember; @@ -177,12 +178,17 @@ public void revokeAdmin(Long id, List uidList) { * 根据群组ID删除群成员 * * @param groupId 群组ID + * @param uidList 群成员列表 * @return 是否删除成功 */ - public Boolean removeByGroupId(Long groupId) { - LambdaQueryWrapper wrapper = new QueryWrapper() - .lambda() - .eq(GroupMember::getGroupId, groupId); - return this.remove(wrapper); + public Boolean removeByGroupId(Long groupId, List uidList) { + if (CollectionUtil.isNotEmpty(uidList)) { + LambdaQueryWrapper wrapper = new QueryWrapper() + .lambda() + .eq(GroupMember::getGroupId, groupId) + .in(GroupMember::getUid, uidList); + return this.remove(wrapper); + } + return false; } } diff --git a/mallchat-chat-server/src/main/java/com/abin/mallchat/common/chat/dao/MessageDao.java b/mallchat-chat-server/src/main/java/com/abin/mallchat/common/chat/dao/MessageDao.java index 05880456..c1d31068 100644 --- a/mallchat-chat-server/src/main/java/com/abin/mallchat/common/chat/dao/MessageDao.java +++ b/mallchat-chat-server/src/main/java/com/abin/mallchat/common/chat/dao/MessageDao.java @@ -1,5 +1,6 @@ package com.abin.mallchat.common.chat.dao; +import cn.hutool.core.collection.CollectionUtil; import com.abin.mallchat.common.chat.domain.entity.Contact; import com.abin.mallchat.common.chat.domain.entity.Message; import com.abin.mallchat.common.chat.domain.enums.MessageStatusEnum; @@ -15,6 +16,7 @@ import org.springframework.stereotype.Service; import java.util.Date; +import java.util.List; import java.util.Objects; /** @@ -72,13 +74,18 @@ public Integer getUnReadCount(Long roomId, Date readTime) { /** * 根据房间ID逻辑删除消息 * - * @param roomId 房间ID + * @param roomId 房间ID + * @param uidList 群成员列表 * @return 是否删除成功 */ - public Boolean removeByRoomId(Long roomId) { - LambdaUpdateWrapper wrapper = new UpdateWrapper().lambda() - .eq(Message::getRoomId, roomId) - .set(Message::getStatus, MessageStatusEnum.DELETE.getStatus()); - return this.update(wrapper); + public Boolean removeByRoomId(Long roomId, List uidList) { + if (CollectionUtil.isNotEmpty(uidList)) { + LambdaUpdateWrapper wrapper = new UpdateWrapper().lambda() + .eq(Message::getRoomId, roomId) + .in(Message::getFromUid, uidList) + .set(Message::getStatus, MessageStatusEnum.DELETE.getStatus()); + return this.update(wrapper); + } + return false; } } diff --git a/mallchat-chat-server/src/main/java/com/abin/mallchat/common/chat/service/IGroupMemberService.java b/mallchat-chat-server/src/main/java/com/abin/mallchat/common/chat/service/IGroupMemberService.java index 5e8ba976..2dc072ed 100644 --- a/mallchat-chat-server/src/main/java/com/abin/mallchat/common/chat/service/IGroupMemberService.java +++ b/mallchat-chat-server/src/main/java/com/abin/mallchat/common/chat/service/IGroupMemberService.java @@ -29,5 +29,11 @@ public interface IGroupMemberService { */ void revokeAdmin(Long uid, AdminRevokeReq request); + /** + * 退出群聊 + * + * @param uid 用户ID + * @param request 请求信息 + */ void exitGroup(Long uid, MemberExitReq request); } diff --git a/mallchat-chat-server/src/main/java/com/abin/mallchat/common/chat/service/impl/GroupMemberServiceImpl.java b/mallchat-chat-server/src/main/java/com/abin/mallchat/common/chat/service/impl/GroupMemberServiceImpl.java index d94a4e7e..2f45ca69 100644 --- a/mallchat-chat-server/src/main/java/com/abin/mallchat/common/chat/service/impl/GroupMemberServiceImpl.java +++ b/mallchat-chat-server/src/main/java/com/abin/mallchat/common/chat/service/impl/GroupMemberServiceImpl.java @@ -139,19 +139,23 @@ public void exitGroup(Long uid, MemberExitReq request) { boolean isDelRoom = roomDao.removeById(roomId); AssertUtil.isTrue(isDelRoom, CommonErrorEnum.SYSTEM_ERROR); // 4.2 删除会话 - Boolean isDelContact = contactDao.removeByRoomId(roomId); + Boolean isDelContact = contactDao.removeByRoomId(roomId, Collections.EMPTY_LIST); AssertUtil.isTrue(isDelContact, CommonErrorEnum.SYSTEM_ERROR); // 4.3 删除群成员 - Boolean isDelGroupMember = groupMemberDao.removeByGroupId(roomGroup.getId()); + Boolean isDelGroupMember = groupMemberDao.removeByGroupId(roomGroup.getId(), Collections.EMPTY_LIST); AssertUtil.isTrue(isDelGroupMember, CommonErrorEnum.SYSTEM_ERROR); // 4.4 删除消息记录 (逻辑删除) - Boolean isDelMessage = messageDao.removeByRoomId(roomId); + Boolean isDelMessage = messageDao.removeByRoomId(roomId, Collections.EMPTY_LIST); AssertUtil.isTrue(isDelMessage, CommonErrorEnum.SYSTEM_ERROR); // TODO 这里也可以告知群成员 群聊已被删除的消息 } else { - // 4.5 删除成员 - groupMemberDao.removeById(uid); - // 发送移除事件告知群成员 + // 4.5 删除会话 + Boolean isDelContact = contactDao.removeByRoomId(roomId, Collections.singletonList(uid)); + AssertUtil.isTrue(isDelContact, CommonErrorEnum.SYSTEM_ERROR); + // 4.6 删除群成员 + Boolean isDelGroupMember = groupMemberDao.removeByGroupId(roomGroup.getId(), Collections.singletonList(uid)); + AssertUtil.isTrue(isDelGroupMember, CommonErrorEnum.SYSTEM_ERROR); + // 4.7 发送移除事件告知群成员 List memberUidList = groupMemberCache.getMemberUidList(roomGroup.getRoomId()); WSBaseResp ws = MemberAdapter.buildMemberRemoveWS(roomGroup.getRoomId(), uid); pushService.sendPushMsg(ws, memberUidList);