feat: 新增添加管理员功能

This commit is contained in:
Kkuil
2023-10-24 16:50:30 +08:00
parent d29b43d4c0
commit 5065105e2b
12 changed files with 261 additions and 42 deletions

View File

@@ -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);
}
}

View File

@@ -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;

View File

@@ -13,4 +13,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/
public interface IGroupMemberService extends IService<GroupMember> {
}

View File

@@ -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;
}
}

View File

@@ -1,40 +1,39 @@
#todo ????????????
##################mysql??##################
mallchat.mysql.ip=127.0.0.1
mallchat.mysql.port=3306
mallchat.mysql.ip=101.33.251.36
mallchat.mysql.port=3307
mallchat.mysql.db=mallchat
mallchat.mysql.username=root
mallchat.mysql.password=123456
mallchat.mysql.password=123321@
##################redis??##################
mallchat.redis.host=127.0.0.1
mallchat.redis.port=6379
mallchat.redis.password=123456
mallchat.redis.host=101.33.251.36
mallchat.redis.port=6378
mallchat.redis.password=123321@
##################jwt##################
mallchat.jwt.secret=dsfsdfsdfsdfsd
##################???????##################
mallchat.wx.callback=http://limeng-test.nat300.top/
mallchat.wx.appId=wx6cb0974bff30cce0
mallchat.wx.secret=072c615d9704d2e9bf0a048407928258
##################???????(????)##################
mallchat.wx.callback=http://709dj99328.goho.co:14042
mallchat.wx.appId=wx53f618ad95af90b4
mallchat.wx.secret=5f17417b434f5442ace0a101c38d5dda
# ??????Token?
mallchat.wx.token=sdfsf
# ??????EncodingAESKey?
mallchat.wx.aesKey=sha1
mallchat.wx.token=dssdfsdfs
# ??????EncodingAESKey????????????
mallchat.wx.aesKey=TPn0rewrkQL1E2t
##################OSS??##################
oss.enabled=true
oss.type=minio
oss.endpoint=http://localhost:9000
oss.access-key=BEZ213
oss.secret-key=Ii4vCMIXuFe241dsfEZ8e7RXI2342342kV
oss.bucketName=default
oss.type= minio
oss.endpoint=http://101.33.251.36:9002
oss.access-key=cWAjkmXd9BL9XWlf
oss.secret-key=JZSOH7NLZJ7qmM8OEV0L4Cj49nJAa0Z1
oss.bucketName=mallchat
##################rocketmq##################
rocketmq.name-server=127.0.0.1:9876
rocketmq.access-key=root
rocketmq.secret-key=123456
##################gpt??##################
rocketmq.name-server=101.33.251.36:9876
rocketmq.access-key=mallchat
rocketmq.secret-key=12345678
##################gpt??(????)##################
mallchat.chatgpt.use=false
mallchat.chatgpt.uid=10001
mallchat.chatgpt.key=sk-wvWM0xGcxFfsddfsgxixbXK5tHovM
mallchat.chatgpt.proxyUrl=https://123.cc
mallchat.chatgpt.key=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
mallchat.chatgpt.proxyUrl=https://test.mallchat.top/v1/completions
mallchat.chatglm2.use=false
mallchat.chatglm2.url=http://v32134.cc
mallchat.chatglm2.url=http://vaso.ntap1.cc
mallchat.chatglm2.uid=10002