-
Notifications
You must be signed in to change notification settings - Fork 932
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
242 additions
and
12 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
mallchat-chat-server/src/main/java/com/abin/mallchat/common/chat/constant/GroupConst.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.abin.mallchat.common.chat.constant; | ||
|
||
/** | ||
* @Author Kkuil | ||
* @Date 2023/10/24 16:06 | ||
* @Description 群常量 | ||
*/ | ||
public class GroupConst { | ||
|
||
/** | ||
* 最大群管理员数量 | ||
*/ | ||
public static final int MAX_MANAGE_COUNT = 3; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...hat-server/src/main/java/com/abin/mallchat/common/chat/domain/vo/request/AdminAddReq.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.abin.mallchat.common.chat.domain.vo.request; | ||
|
||
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 AdminAddReq { | ||
@NotNull | ||
@ApiModelProperty("房间号") | ||
private Long roomId; | ||
|
||
@NotNull | ||
@Size(min = 1, max = 3) | ||
@ApiModelProperty("需要添加管理的列表") | ||
private List<Long> uidList; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...rver/src/main/java/com/abin/mallchat/common/chat/service/impl/GroupMemberServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.abin.mallchat.common.chat.service.impl; | ||
|
||
import com.abin.mallchat.common.chat.dao.GroupMemberDao; | ||
import com.abin.mallchat.common.chat.dao.RoomGroupDao; | ||
import com.abin.mallchat.common.chat.domain.entity.RoomGroup; | ||
import com.abin.mallchat.common.chat.domain.vo.request.AdminAddReq; | ||
import com.abin.mallchat.common.chat.service.IGroupMemberService; | ||
import com.abin.mallchat.common.common.exception.GroupErrorEnum; | ||
import com.abin.mallchat.common.common.utils.AssertUtil; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.HashSet; | ||
import java.util.List; | ||
|
||
import static com.abin.mallchat.common.chat.constant.GroupConst.MAX_MANAGE_COUNT; | ||
|
||
/** | ||
* @Author Kkuil | ||
* @Date 2023/10/24 15:45 | ||
* @Description 群成员服务类 | ||
*/ | ||
@Service | ||
public class GroupMemberServiceImpl implements IGroupMemberService { | ||
|
||
@Autowired | ||
private GroupMemberDao groupMemberDao; | ||
|
||
@Autowired | ||
private RoomGroupDao roomGroupDao; | ||
|
||
/** | ||
* 增加管理员 | ||
* | ||
* @param uid 用户ID | ||
* @param request 请求信息 | ||
*/ | ||
@Override | ||
public void addAdmin(Long uid, AdminAddReq request) { | ||
// 1. 判断群聊是否存在 | ||
RoomGroup roomGroup = roomGroupDao.getByRoomId(request.getRoomId()); | ||
AssertUtil.isNotEmpty(roomGroup, GroupErrorEnum.GROUP_NOT_EXIST); | ||
|
||
// 2. 判断该用户是否是群主 | ||
Boolean isLord = groupMemberDao.isLord(roomGroup.getId(), uid); | ||
AssertUtil.isTrue(isLord, GroupErrorEnum.NOT_ALLOWED_OPERATION); | ||
|
||
// 3. 判断群成员是否在群中 | ||
Boolean isGroupShip = groupMemberDao.isGroupShip(roomGroup.getRoomId(), request.getUidList()); | ||
AssertUtil.isTrue(isGroupShip, GroupErrorEnum.USER_NOT_IN_GROUP); | ||
|
||
// 4. 判断管理员数量是否达到上限 | ||
// 4.1 查询现有管理员数量 | ||
List<Long> manageUidList = groupMemberDao.getManageUidList(roomGroup.getId()); | ||
// 4.2 去重 | ||
HashSet<Long> manageUidSet = new HashSet<>(manageUidList); | ||
manageUidSet.addAll(request.getUidList()); | ||
AssertUtil.isFalse(manageUidSet.size() > MAX_MANAGE_COUNT, GroupErrorEnum.MANAGE_COUNT_EXCEED); | ||
|
||
// 5. 增加管理员 | ||
groupMemberDao.addAdmin(roomGroup.getId(), request.getUidList()); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...t-chat-server/src/main/java/com/abin/mallchat/common/common/exception/GroupErrorEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |