mirror of
https://github.com/zongzibinbin/MallChat.git
synced 2026-03-14 14:13:42 +08:00
feat: 新增添加管理员功能
This commit is contained in:
@@ -1,20 +1,24 @@
|
||||
package com.abin.mallchat.common.chat.dao;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
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.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import io.swagger.models.auth.In;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.abin.mallchat.common.chat.domain.enums.GroupRoleEnum.ADMIN_LIST;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 群成员表 服务实现类
|
||||
@@ -58,6 +62,7 @@ public class GroupMemberDao extends ServiceImpl<GroupMemberMapper, GroupMember>
|
||||
List<GroupMember> list = lambdaQuery()
|
||||
.eq(GroupMember::getGroupId, groupId)
|
||||
.in(GroupMember::getUid, uidList)
|
||||
.in(GroupMember::getRole, ADMIN_LIST)
|
||||
.select(GroupMember::getUid, GroupMember::getRole)
|
||||
.list();
|
||||
return list.stream().collect(Collectors.toMap(GroupMember::getUid, GroupMember::getRole));
|
||||
@@ -88,4 +93,49 @@ public class GroupMemberDao extends ServiceImpl<GroupMemberMapper, GroupMember>
|
||||
List<Long> memberUidList = groupMemberCache.getMemberUidList(roomId);
|
||||
return memberUidList.containsAll(uidList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否是群主
|
||||
*
|
||||
* @param id 群组ID
|
||||
* @param uid 用户ID
|
||||
* @return 是否是群主
|
||||
*/
|
||||
public Boolean isLord(Long id, Long uid) {
|
||||
GroupMember groupMember = this.lambdaQuery()
|
||||
.eq(GroupMember::getGroupId, id)
|
||||
.eq(GroupMember::getUid, uid)
|
||||
.one();
|
||||
return ObjectUtil.isNotNull(groupMember);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取管理员uid列表
|
||||
*
|
||||
* @param id 群主ID
|
||||
* @return 管理员uid列表
|
||||
*/
|
||||
public List<Long> getManageUidList(Long id) {
|
||||
return this.lambdaQuery()
|
||||
.eq(GroupMember::getGroupId, id)
|
||||
.eq(GroupMember::getRole, GroupRoleEnum.MANAGER.getType())
|
||||
.list()
|
||||
.stream()
|
||||
.map(GroupMember::getUid)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加管理员
|
||||
*
|
||||
* @param id 群主ID
|
||||
* @param uidList 用户列表
|
||||
*/
|
||||
public void addAdmin(Long id, List<Long> uidList) {
|
||||
LambdaUpdateWrapper<GroupMember> wrapper = new UpdateWrapper<GroupMember>().lambda()
|
||||
.eq(GroupMember::getGroupId, id)
|
||||
.in(GroupMember::getUid, uidList)
|
||||
.set(GroupMember::getRole, GroupRoleEnum.MANAGER.getType());
|
||||
this.update(wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -23,6 +24,8 @@ public enum GroupRoleEnum {
|
||||
|
||||
private final Integer type;
|
||||
private final String desc;
|
||||
|
||||
public static final List<Integer> ADMIN_LIST = Arrays.asList(GroupRoleEnum.LEADER.getType(), GroupRoleEnum.MANAGER.getType());
|
||||
|
||||
private static Map<Integer, GroupRoleEnum> cache;
|
||||
|
||||
|
||||
@@ -13,4 +13,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
*/
|
||||
public interface IGroupMemberService extends IService<GroupMember> {
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.abin.mallchat.common.common.exception;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @Author Kkuil
|
||||
* @Date 2023/10/24 15:50
|
||||
* @Description 群异常码
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum GroupErrorEnum implements ErrorEnum {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
GROUP_NOT_EXIST(9001, "该群不存在~"),
|
||||
NOT_ALLOWED_OPERATION(9002, "您无权操作~"),
|
||||
MANAGE_COUNT_EXCEED(9003, "群管理员数量达到上限,请先删除后再操作~"),
|
||||
USER_NOT_IN_GROUP(9004, "非法操作,用户不存在群聊中~"),
|
||||
;
|
||||
private final Integer code;
|
||||
private final String msg;
|
||||
|
||||
@Override
|
||||
public Integer getErrorCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getErrorMsg() {
|
||||
return this.msg;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user