Skip to content

Commit

Permalink
Merge pull request zongzibinbin#151 from Kkuil/main
Browse files Browse the repository at this point in the history
feat: 新增撤销管理员与退群功能
  • Loading branch information
zongzibinbin authored Nov 6, 2023
2 parents 2d4ba05 + 62611be commit d7de7fa
Show file tree
Hide file tree
Showing 22 changed files with 365 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@


import com.abin.mallchat.common.chat.domain.vo.request.*;
import com.abin.mallchat.common.chat.domain.vo.request.admin.AdminAddReq;
import com.abin.mallchat.common.chat.domain.vo.request.admin.AdminRevokeReq;
import com.abin.mallchat.common.chat.domain.vo.request.member.MemberAddReq;
import com.abin.mallchat.common.chat.domain.vo.request.member.MemberDelReq;
import com.abin.mallchat.common.chat.domain.vo.request.member.MemberExitReq;
import com.abin.mallchat.common.chat.domain.vo.request.member.MemberReq;
import com.abin.mallchat.common.chat.domain.vo.response.ChatMemberListResp;
import com.abin.mallchat.common.chat.domain.vo.response.MemberResp;
import com.abin.mallchat.common.chat.service.IGroupMemberService;
Expand Down Expand Up @@ -66,6 +72,14 @@ public ApiResult<Void> delMember(@Valid @RequestBody MemberDelReq request) {
return ApiResult.success();
}

@DeleteMapping("/group/member/exit")
@ApiOperation("退出群聊")
public ApiResult<Boolean> exitGroup(@Valid @RequestBody MemberExitReq request) {
Long uid = RequestHolder.get().getUid();
groupMemberService.exitGroup(uid, request);
return ApiResult.success();
}

@PostMapping("/group")
@ApiOperation("新增群组")
public ApiResult<IdRespVO> addGroup(@Valid @RequestBody GroupAddReq request) {
Expand All @@ -89,4 +103,12 @@ public ApiResult<Boolean> addAdmin(@Valid @RequestBody AdminAddReq request) {
groupMemberService.addAdmin(uid, request);
return ApiResult.success();
}

@DeleteMapping("/group/admin")
@ApiOperation("撤销管理员")
public ApiResult<Boolean> revokeAdmin(@Valid @RequestBody AdminRevokeReq request) {
Long uid = RequestHolder.get().getUid();
groupMemberService.revokeAdmin(uid, request);
return ApiResult.success();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
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.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -33,7 +36,7 @@ public Contact get(Long uid, Long roomId) {
public Integer getReadCount(Message message) {
return lambdaQuery()
.eq(Contact::getRoomId, message.getRoomId())
.ne(Contact::getUid, message.getFromUid())//不需要查询出自己
.ne(Contact::getUid, message.getFromUid())// 不需要查询出自己
.ge(Contact::getReadTime, message.getCreateTime())
.count();
}
Expand All @@ -54,16 +57,16 @@ public Integer getUnReadCount(Message message) {
public CursorPageBaseResp<Contact> getReadPage(Message message, CursorPageBaseReq cursorPageBaseReq) {
return CursorUtils.getCursorPageByMysql(this, cursorPageBaseReq, wrapper -> {
wrapper.eq(Contact::getRoomId, message.getRoomId());
wrapper.ne(Contact::getUid, message.getFromUid());//不需要查询出自己
wrapper.ge(Contact::getReadTime, message.getCreateTime());//已读时间大于等于消息发送时间
wrapper.ne(Contact::getUid, message.getFromUid());// 不需要查询出自己
wrapper.ge(Contact::getReadTime, message.getCreateTime());// 已读时间大于等于消息发送时间
}, Contact::getReadTime);
}

public CursorPageBaseResp<Contact> getUnReadPage(Message message, CursorPageBaseReq cursorPageBaseReq) {
return CursorUtils.getCursorPageByMysql(this, cursorPageBaseReq, wrapper -> {
wrapper.eq(Contact::getRoomId, message.getRoomId());
wrapper.ne(Contact::getUid, message.getFromUid());//不需要查询出自己
wrapper.lt(Contact::getReadTime, message.getCreateTime());//已读时间小于消息发送时间
wrapper.ne(Contact::getUid, message.getFromUid());// 不需要查询出自己
wrapper.lt(Contact::getReadTime, message.getCreateTime());// 已读时间小于消息发送时间
}, Contact::getReadTime);
}

Expand All @@ -89,4 +92,16 @@ public List<Contact> getByRoomIds(List<Long> roomIds, Long uid) {
public void refreshOrCreateActiveTime(Long roomId, List<Long> memberUidList, Long msgId, Date activeTime) {
baseMapper.refreshOrCreateActiveTime(roomId, memberUidList, msgId, activeTime);
}

/**
* 根据房间ID删除会话
*
* @param roomId 房间ID
* @return 是否删除成功
*/
public Boolean removeByRoomId(Long roomId) {
LambdaQueryWrapper<Contact> wrapper = new QueryWrapper<Contact>().lambda()
.eq(Contact::getRoomId, roomId);
return this.remove(wrapper);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.abin.mallchat.common.chat.dao;

import cn.hutool.core.util.ObjectUtil;
import com.abin.mallchat.common.chat.domain.entity.Contact;
import com.abin.mallchat.common.chat.domain.entity.GroupMember;
import com.abin.mallchat.common.chat.domain.enums.GroupRoleEnum;
import com.abin.mallchat.common.chat.mapper.GroupMemberMapper;
import com.abin.mallchat.common.chat.service.cache.GroupMemberCache;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
Expand Down Expand Up @@ -144,7 +148,7 @@ public List<Long> getManageUidList(Long id) {
/**
* 增加管理员
*
* @param id 群主ID
* @param id 群组ID
* @param uidList 用户列表
*/
public void addAdmin(Long id, List<Long> uidList) {
Expand All @@ -154,4 +158,31 @@ public void addAdmin(Long id, List<Long> uidList) {
.set(GroupMember::getRole, GroupRoleEnum.MANAGER.getType());
this.update(wrapper);
}

/**
* 撤销管理员
*
* @param id 群组ID
* @param uidList 用户列表
*/
public void revokeAdmin(Long id, List<Long> uidList) {
LambdaUpdateWrapper<GroupMember> wrapper = new UpdateWrapper<GroupMember>().lambda()
.eq(GroupMember::getGroupId, id)
.in(GroupMember::getUid, uidList)
.set(GroupMember::getRole, GroupRoleEnum.MEMBER.getType());
this.update(wrapper);
}

/**
* 根据群组ID删除群成员
*
* @param groupId 群组ID
* @return 是否删除成功
*/
public Boolean removeByGroupId(Long groupId) {
LambdaQueryWrapper<GroupMember> wrapper = new QueryWrapper<GroupMember>()
.lambda()
.eq(GroupMember::getGroupId, groupId);
return this.remove(wrapper);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.abin.mallchat.common.chat.dao;

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;
import com.abin.mallchat.common.chat.mapper.MessageMapper;
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.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
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;

Expand Down Expand Up @@ -63,4 +68,17 @@ public Integer getUnReadCount(Long roomId, Date readTime) {
.gt(Objects.nonNull(readTime), Message::getCreateTime, readTime)
.count();
}

/**
* 根据房间ID逻辑删除消息
*
* @param roomId 房间ID
* @return 是否删除成功
*/
public Boolean removeByRoomId(Long roomId) {
LambdaUpdateWrapper<Message> wrapper = new UpdateWrapper<Message>().lambda()
.eq(Message::getRoomId, roomId)
.set(Message::getStatus, MessageStatusEnum.DELETE.getStatus());
return this.update(wrapper);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.abin.mallchat.common.chat.domain.vo.request;
package com.abin.mallchat.common.chat.domain.vo.request.admin;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.abin.mallchat.common.chat.domain.vo.request.admin;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.List;

/**
* @Author Kkuil
* @Date 2023/10/24 12:46
* @Description 撤销管理员请求信息
*/
@Data
public class AdminRevokeReq {
@NotNull
@ApiModelProperty("房间号")
private Long roomId;

@NotNull
@Size(min = 1, max = 3)
@ApiModelProperty("需要撤销管理的列表")
private List<Long> uidList;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.abin.mallchat.common.chat.domain.vo.request;
package com.abin.mallchat.common.chat.domain.vo.request.member;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.abin.mallchat.common.chat.domain.vo.request;
package com.abin.mallchat.common.chat.domain.vo.request.member;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.abin.mallchat.common.chat.domain.vo.request.member;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotNull;

/**
* @Author Kkuil
* @Date 2023/10/30 11:49
* @Description 退出群聊
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class MemberExitReq {
@NotNull
@ApiModelProperty("会话id")
private Long roomId;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.abin.mallchat.common.chat.domain.vo.request;
package com.abin.mallchat.common.chat.domain.vo.request.member;

import com.abin.mallchat.common.common.domain.vo.request.CursorPageBaseReq;
import io.swagger.annotations.ApiModelProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import com.abin.mallchat.common.chat.domain.dto.MsgReadInfoDTO;
import com.abin.mallchat.common.chat.domain.entity.Message;
import com.abin.mallchat.common.chat.domain.vo.request.*;
import com.abin.mallchat.common.chat.domain.vo.request.member.MemberReq;
import com.abin.mallchat.common.chat.domain.vo.response.ChatMemberListResp;
import com.abin.mallchat.common.chat.domain.vo.response.ChatMemberStatisticResp;
import com.abin.mallchat.common.chat.domain.vo.response.ChatMessageReadResp;
import com.abin.mallchat.common.chat.domain.vo.response.ChatMessageResp;
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.user.domain.vo.response.ws.ChatMemberResp;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.abin.mallchat.common.chat.service;

import com.abin.mallchat.common.chat.domain.entity.GroupMember;
import com.abin.mallchat.common.chat.domain.vo.request.AdminAddReq;
import com.baomidou.mybatisplus.extension.service.IService;
import com.abin.mallchat.common.chat.domain.vo.request.admin.AdminAddReq;
import com.abin.mallchat.common.chat.domain.vo.request.admin.AdminRevokeReq;
import com.abin.mallchat.common.chat.domain.vo.request.member.MemberExitReq;

/**
* <p>
Expand All @@ -20,4 +20,14 @@ public interface IGroupMemberService {
* @param request 请求信息
*/
void addAdmin(Long uid, AdminAddReq request);

/**
* 撤销管理员
*
* @param uid 用户ID
* @param request 请求信息
*/
void revokeAdmin(Long uid, AdminRevokeReq request);

void exitGroup(Long uid, MemberExitReq request);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.abin.mallchat.common.chat.service;

import com.abin.mallchat.common.chat.domain.vo.request.*;
import com.abin.mallchat.common.chat.domain.vo.request.member.MemberAddReq;
import com.abin.mallchat.common.chat.domain.vo.request.member.MemberDelReq;
import com.abin.mallchat.common.chat.domain.vo.request.member.MemberReq;
import com.abin.mallchat.common.chat.domain.vo.response.ChatMemberListResp;
import com.abin.mallchat.common.chat.domain.vo.response.ChatRoomResp;
import com.abin.mallchat.common.chat.domain.vo.response.MemberResp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.abin.mallchat.common.chat.domain.enums.MessageMarkActTypeEnum;
import com.abin.mallchat.common.chat.domain.enums.MessageTypeEnum;
import com.abin.mallchat.common.chat.domain.vo.request.*;
import com.abin.mallchat.common.chat.domain.vo.request.member.MemberReq;
import com.abin.mallchat.common.chat.domain.vo.response.ChatMemberListResp;
import com.abin.mallchat.common.chat.domain.vo.response.ChatMemberStatisticResp;
import com.abin.mallchat.common.chat.domain.vo.response.ChatMessageReadResp;
Expand Down Expand Up @@ -41,7 +42,6 @@
import com.abin.mallchat.common.user.domain.vo.response.ws.ChatMemberResp;
import com.abin.mallchat.common.user.service.IRoleService;
import com.abin.mallchat.common.user.service.cache.UserCache;
import com.abin.mallchat.transaction.service.MQProducer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -52,7 +52,6 @@

import javax.annotation.Nullable;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
Expand Down
Loading

0 comments on commit d7de7fa

Please sign in to comment.