Commit 4526cd88 by 罗长华

新增创建群 解散群 加入群 离开群 群成员列表接口

parent 6ab229e5
package com.wecloud.im.controller;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSON;
import com.wecloud.im.param.group.CreateGroupParam;
import com.wecloud.im.param.group.DismissGroupParam;
import com.wecloud.im.param.group.JoinGroupParam;
import com.wecloud.im.param.group.LeaveGroupParam;
import com.wecloud.im.param.group.ListGroupMembersParam;
import com.wecloud.im.service.ImGroupService;
/**
* 群聊接口
* @Author luozh
* @Date 2022年05月10日 14:14
* @Version 1.0
*/
@AllArgsConstructor
@Slf4j
@RestController
@RequestMapping("/group")
public class ImGroupController {
private final ImGroupService groupService;
/**
* 创建群组
* @Author luozh
* @Date 2022年05月10日 02:16:19
* @Return
*/
@PostMapping("/createGroup")
public ApiResult<Long> createGroup(@RequestBody CreateGroupParam param) {
log.info("创建群组请求 参数: {}", JSON.toJSONString(param));
return null;
}
/**
* 解散群组
* @Author luozh
* @Date 2022年05月10日 02:16:19
* @Return
*/
@PostMapping("/dismissGroup")
public ApiResult<Boolean> dismissGroup(@RequestBody DismissGroupParam param) {
log.info("解散群组请求 参数: {}", JSON.toJSONString(param));
return null;
}
/**
* 加入群组
* @Author luozh
* @Date 2022年05月10日 02:16:19
* @Return
*/
@PostMapping("/joinGroup")
public ApiResult<Long> joinGroup(@RequestBody JoinGroupParam param) {
return null;
}
/**
* 离开群组
* @Author luozh
* @Date 2022年05月10日 02:16:19
* @Return
*/
@PostMapping("/leaveGroup")
public ApiResult<Long> leaveGroup(@RequestBody LeaveGroupParam param) {
log.info("离开群组请求 参数: {}", JSON.toJSONString(param));
return null;
}
/**
*
* @Author luozh
* @Date 2022年05月10日 02:16:19
* @Return
* @return
*/
@PostMapping("/listGroupMembers")
public ApiResult<List<String>> listGroupMembers(@RequestBody ListGroupMembersParam param) {
log.info("获取群组成员请求 参数: {}", JSON.toJSONString(param));
return ApiResult.ok(groupService.listGroupMembers(param.getGroupId()));
}
}
package com.wecloud.im.param.group;
import lombok.Data;
/**
* 创建群
* @Author luozh
* @Date 2022年05月10日 09:37
* @Version 1.0
*/
@Data
public class CreateGroupParam {
/**
* 群主id
*/
private String userId;
/**
* 群名
*/
private String groupName;
/**
* 群成员
*/
private String memberIds;
}
package com.wecloud.im.param.group;
import lombok.Data;
/**
* 解散群
* @Author luozh
* @Date 2022年05月10日 09:37
* @Version 1.0
*/
@Data
public class DismissGroupParam {
/**
* 操作解散群的用户 ID,可以为任何用户 ID ,非群组创建者也可以解散群组
*/
private String userId;
/**
* 要解散的群的群组 ID
*/
private String groupId;
}
package com.wecloud.im.param.group;
/**
* 加入群
* @Author luozh
* @Date 2022年05月10日 09:37
* @Version 1.0
*/
public class JoinGroupParam {
/**
* 要加入群的用户 ID
*/
private String userIds;
/**
* 要加入的群的群组 ID
*/
private String groupId;
}
package com.wecloud.im.param.group;
import lombok.Data;
/**
* 离开(踢出)群
* @Author luozh
* @Date 2022年05月10日 09:37
* @Version 1.0
*/
@Data
public class LeaveGroupParam {
/**
* 用户Id
*/
private String userIds;
/**
* 群组id
*/
private String groupId;
}
package com.wecloud.im.param.group;
import lombok.Data;
import javax.validation.constraints.NotBlank;
/**
* 查询群组成员
* @Author luozh
* @Date 2022年05月10日 09:37
* @Version 1.0
*/
@Data
public class ListGroupMembersParam {
/**
* 群id
*/
@NotBlank(message = "群id不能为空")
private String groupId;
}
......@@ -7,20 +7,15 @@ package com.wecloud.im.sdk.enums;
*/
public enum FriendSourceEnum {
/**
* 1 - 搜索
*/
// 名片
CARD("CARD", "名片"),
// 二维码
QR_CODE("QR_CODE", "二维码"),
// SEARCH 搜索
SEARCH("SEARCH", "搜索"),
/**
* 2 - 群聊
*/
GROUP("GROUP", "群聊"),
/**
* 3 - 名片
*/
CARD("CARD", "名片");
// 群聊
GROUP_CHAT("GROUP_CHAT", "群聊"),
;
FriendSourceEnum(String code, String desc) {
this.code = code;
......
package com.wecloud.im.service;
import java.util.List;
/**
* 群服务
* @Author luozh
* @Date 2022年05月10日 15:17
* @Version 1.0
*/
public interface ImGroupService {
/**
* 创建群组
* @Author luozh
* @Date 2022年05月10日 03:22:13
* @param groupOwnerUserId
* @param groupName
* @param memberIds
* @Return
*/
Long createGroup(String groupOwnerUserId, String groupName, List<String> memberIds);
/**
* 解散群组
* @Author luozh
* @Date 2022年05月10日 03:22:26
* @param userId
* @param groupId
* @Return
*/
Boolean dismissGroup(String userId, String groupId);
/**
* 加入群组
* @Author luozh
* @Date 2022年05月10日 03:22:35
* @param groupId
* @param userIds
* @Return
*/
Boolean joinGroup(String groupId, String userIds);
/**
* 离开群组
* @Author luozh
* @Date 2022年05月10日 03:22:44
* @param groupId
* @param userIds
* @Return
*/
Boolean leaveGroup(String groupId, String userIds);
/**
* 获取群成员列表
* @Author luozh
* @Date 2022年05月10日 03:23:09
* @param groupId
* @Return
*/
List<String> listGroupMembers(String groupId);
}
package com.wecloud.im.service.impl;
import io.geekidea.springbootplus.framework.common.exception.BusinessException;
import io.geekidea.springbootplus.framework.shiro.util.SecurityUtils;
import lombok.AllArgsConstructor;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.wecloud.im.entity.ImConversation;
import com.wecloud.im.entity.ImConversationMembers;
import com.wecloud.im.service.ImConversationMembersService;
import com.wecloud.im.service.ImConversationService;
import com.wecloud.im.service.ImGroupService;
/**
* 群服务
* @Author luozh
* @Date 2022年05月10日 15:23
* @Version 1.0
*/
@AllArgsConstructor
@Service
public class ImGroupServiceImpl implements ImGroupService {
/**
* 会话服务
*/
private final ImConversationService conversationService;
/**
* 会话成员服务
*/
private final ImConversationMembersService conversationMembersService;
@Override
public Long createGroup(String groupOwnerUserId, String groupName, List<String> memberIds) {
return null;
}
@Override
public Boolean dismissGroup(String userId, String groupId) {
return null;
}
@Override
public Boolean joinGroup(String groupId, String userIds) {
return null;
}
@Override
public Boolean leaveGroup(String groupId, String userIds) {
return null;
}
@Override
public List<String> listGroupMembers(String groupId) {
Long appId = SecurityUtils.getCurrentAppId();
// 获取会话
ImConversation conversation =
conversationService.getOne(Wrappers.<ImConversation>lambdaQuery()
.eq(ImConversation::getFkAppid, appId)
.eq(ImConversation::getId, groupId));
if (conversation == null) {
throw new BusinessException("群组不存在");
}
// 获取群成员
List<ImConversationMembers> membersList =
conversationMembersService.list(Wrappers.<ImConversationMembers>lambdaQuery().eq(ImConversationMembers::getFkConversationId, groupId));
return membersList.stream().map(ImConversationMembers::getClientId).collect(Collectors.toList());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment