SpringBoot+WebSocket实现即时通讯(三)

前言

紧接着上文《SpringBoot+WebSocket实现即时通讯(二)》

本博客姊妹篇

  • SpringBoot+WebSocket实现即时通讯(一)
  • SpringBoot+WebSocket实现即时通讯(二)
  • SpringBoot+WebSocket实现即时通讯(三)
  • SpringBoot+WebSocket实现即时通讯(四)

一、功能描述

  • 用户管理:业务自己实现,暂从数据库添加
  • 好友管理:添加好友、删除好友、修改备注、好友列表等
  • 群组管理:新建群、解散群、编辑群、变更群主、拉人进群、踢出群等
  • 聊天模式:私聊、群聊
  • 消息类型:系统、文本、语音、图片、视频
  • 聊天管理:删除聊天、置顶聊天、查看聊天记录等

二、好友、群组功能实现

2.1 好友

mapper

package com.qiangesoft.im.mapper;import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qiangesoft.im.entity.ImFriend;/*** <p>* 好友 Mapper 接口* </p>** @author qiangesoft* @date 2024-02-07*/
public interface ImFriendMapper extends BaseMapper<ImFriend> {}

service

package com.qiangesoft.im.service;import com.baomidou.mybatisplus.extension.service.IService;
import com.qiangesoft.im.entity.ImFriend;
import com.qiangesoft.im.pojo.dto.ImFriendDTO;
import com.qiangesoft.im.pojo.vo.ImFriendVO;import java.util.List;/*** <p>* 好友 服务类* </p>** @author qiangesoft* @date 2024-02-07*/
public interface IImFriendService extends IService<ImFriend> {/*** 添加好友** @param friendDTO*/void addFriend(ImFriendDTO friendDTO);/*** 删除好友** @param id*/void removeFriend(Long id);/*** 编辑好友信息** @param id* @param friendDTO*/void updateFriend(Long id, ImFriendDTO friendDTO);/*** 好友列表** @param keyword* @return*/List<ImFriendVO> listFriend(String keyword);/*** 好友详情** @param id* @return*/ImFriendVO getFriendInfo(Long id);
}
package com.qiangesoft.im.service.impl;import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qiangesoft.im.auth.UserUtil;
import com.qiangesoft.im.entity.ImFriend;
import com.qiangesoft.im.exception.ServiceException;
import com.qiangesoft.im.mapper.ImFriendMapper;
import com.qiangesoft.im.pojo.dto.ImFriendDTO;
import com.qiangesoft.im.pojo.vo.ImFriendVO;
import com.qiangesoft.im.pojo.vo.SysUserVo;
import com.qiangesoft.im.service.IImFriendService;
import com.qiangesoft.im.service.ISysUserService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;/*** <p>* 好友 服务实现类* </p>** @author qiangesoft* @date 2024-02-07*/
@RequiredArgsConstructor
@Service
public class ImFriendServiceImpl extends ServiceImpl<ImFriendMapper, ImFriend> implements IImFriendService {private final ISysUserService sysUserService;@Transactional(rollbackFor = RuntimeException.class)@Overridepublic void addFriend(ImFriendDTO friendDTO) {Long userId = UserUtil.getUserId();Long friendUserId = friendDTO.getFriendUserId();if (userId.equals(friendUserId)) {throw new ServiceException("不能添加自己!");}LambdaQueryWrapper<ImFriend> queryWrapper = new LambdaQueryWrapper<>();queryWrapper.eq(ImFriend::getUserId, userId).eq(ImFriend::getFriendUserId, friendUserId).eq(ImFriend::getDelFlag, false);Long count = baseMapper.selectCount(queryWrapper);if (count > 0) {throw new ServiceException("已添加过好友!");}ImFriend friend = new ImFriend();friend.setUserId(userId);friend.setFriendUserId(friendDTO.getFriendUserId());friend.setRemark(friendDTO.getRemark());friend.setDelFlag(false);baseMapper.insert(friend);}@Overridepublic void removeFriend(Long id) {LambdaUpdateWrapper<ImFriend> updateWrapper = new LambdaUpdateWrapper<>();updateWrapper.eq(ImFriend::getId, id).set(ImFriend::getDelFlag, true);baseMapper.update(null, updateWrapper);}@Overridepublic void updateFriend(Long id, ImFriendDTO friendDTO) {LambdaUpdateWrapper<ImFriend> updateWrapper = new LambdaUpdateWrapper<>();updateWrapper.eq(ImFriend::getId, id).set(ImFriend::getRemark, friendDTO.getRemark());baseMapper.update(null, updateWrapper);}@Overridepublic List<ImFriendVO> listFriend(String keyword) {LambdaQueryWrapper<ImFriend> queryWrapper = new LambdaQueryWrapper<>();queryWrapper.like(StringUtils.isNotBlank(keyword), ImFriend::getRemark, keyword).eq(ImFriend::getDelFlag, false);List<ImFriend> friendList = baseMapper.selectList(queryWrapper);List<ImFriendVO> friendVOList = new ArrayList<>();if (CollectionUtils.isEmpty(friendList)) {return friendVOList;}List<Long> userIdList = friendList.stream().map(ImFriend::getFriendUserId).collect(Collectors.toList());Map<Long, SysUserVo> sysUserVoMap = sysUserService.listByIds(userIdList).stream().map(SysUserVo::fromEntity).collect(Collectors.toMap(SysUserVo::getId, sysUserVo -> sysUserVo));for (ImFriend friend : friendList) {ImFriendVO friendVO = new ImFriendVO();friendVO.setId(friend.getId());friendVO.setFriendUser(sysUserVoMap.get(friend.getFriendUserId()));friendVO.setRemark(friend.getRemark());friendVOList.add(friendVO);}return friendVOList;}@Overridepublic ImFriendVO getFriendInfo(Long id) {LambdaQueryWrapper<ImFriend> queryWrapper = new LambdaQueryWrapper<>();queryWrapper.eq(ImFriend::getId, id).eq(ImFriend::getDelFlag, false);ImFriend friend = baseMapper.selectOne(queryWrapper);if (friend == null) {throw new ServiceException("未添加为好友!");}SysUserVo sysUserVo = SysUserVo.fromEntity(sysUserService.getById(friend.getFriendUserId()));ImFriendVO friendVO = new ImFriendVO();friendVO.setId(friend.getId());friendVO.setFriendUser(sysUserVo);friendVO.setRemark(friend.getRemark());return friendVO;}
}

controller

package com.qiangesoft.im.controller;import com.qiangesoft.im.pojo.dto.ImFriendDTO;
import com.qiangesoft.im.pojo.vo.ImFriendVO;
import com.qiangesoft.im.pojo.vo.ResultInfo;
import com.qiangesoft.im.service.IImFriendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;import java.util.List;/*** <p>* 好友 前端控制器* </p>** @author qiangesoft* @date 2024-02-07*/
@Api(tags = "好友")
@RequiredArgsConstructor
@RestController
@RequestMapping("/im/friend")
public class ImFriendController {private final IImFriendService friendService;@PostMapping@ApiOperation(value = "添加好友")public ResultInfo<Void> addFriend(@RequestBody ImFriendDTO friendDTO) {friendService.addFriend(friendDTO);return ResultInfo.ok();}@DeleteMapping("/{id}")@ApiOperation(value = "删除好友")public ResultInfo<Void> removeFriend(@PathVariable Long id) {friendService.removeFriend(id);return ResultInfo.ok();}@PutMapping("/{id}")@ApiOperation(value = "编辑好友")public ResultInfo<Void> updateFriend(@PathVariable Long id, @RequestBody ImFriendDTO friendDTO) {friendService.updateFriend(id, friendDTO);return ResultInfo.ok();}@GetMapping@ApiOperation(value = "好友列表")public ResultInfo<List<ImFriendVO>> listFriend(String keyword) {return ResultInfo.ok(friendService.listFriend(keyword));}@GetMapping("/{id}")@ApiOperation(value = "好友详情")public ResultInfo<ImFriendVO> getFriendInfo(@PathVariable Long id) {return ResultInfo.ok(friendService.getFriendInfo(id));}}

2.2 群组

mapper

package com.qiangesoft.im.mapper;import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qiangesoft.im.entity.ImGroup;/*** <p>* 群组 Mapper 接口* </p>** @author qiangesoft* @date 2024-02-07*/
public interface ImGroupMapper extends BaseMapper<ImGroup> {}
package com.qiangesoft.im.mapper;import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qiangesoft.im.entity.ImGroupUser;/*** <p>* 群成员 Mapper 接口* </p>** @author qiangesoft* @date 2024-02-07*/
public interface ImGroupUserMapper extends BaseMapper<ImGroupUser> {}
package com.qiangesoft.im.service;import com.baomidou.mybatisplus.extension.service.IService;
import com.qiangesoft.im.entity.ImGroup;
import com.qiangesoft.im.pojo.dto.ImGroupDTO;
import com.qiangesoft.im.pojo.dto.ImGroupMasterDTO;
import com.qiangesoft.im.pojo.vo.ImGroupInfoVO;
import com.qiangesoft.im.pojo.vo.ImGroupVO;import java.util.List;/*** <p>* 群组 服务类* </p>** @author qiangesoft* @date 2024-02-07*/
public interface IImGroupService extends IService<ImGroup> {/*** 建群** @param groupDTO*/void addGroup(ImGroupDTO groupDTO);/*** 解散群** @param id*/void removeGroup(Long id);/*** 编辑群** @param id* @param groupDTO*/void updateGroup(Long id, ImGroupDTO groupDTO);/*** 群列表** @param keyword* @return*/List<ImGroupVO> listGroup(String keyword);/*** 群详情** @param id* @return*/ImGroupInfoVO getGroupInfo(Long id);/*** 变更群主** @param groupMasterDTO*/void updateMaster(ImGroupMasterDTO groupMasterDTO);/*** 校验群组** @param id* @return*/ImGroup validateGroup(Long id);
}
package com.qiangesoft.im.service;import com.baomidou.mybatisplus.extension.service.IService;
import com.qiangesoft.im.entity.ImGroupUser;
import com.qiangesoft.im.pojo.dto.ImGroupUserDTO;
import com.qiangesoft.im.pojo.vo.SysUserVo;import java.util.List;/*** <p>* 群成员 服务类* </p>** @author qiangesoft* @date 2024-02-07*/
public interface IImGroupUserService extends IService<ImGroupUser> {/*** 添加群成员** @param groupUserDTO*/void addGroupUser(ImGroupUserDTO groupUserDTO);/*** 删除群成员** @param groupUserDTO*/void removeGroupUser(ImGroupUserDTO groupUserDTO);/*** 群成员列表** @param id* @return*/List<SysUserVo> listGroupUser(Long id);}
package com.qiangesoft.im.service.impl;import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qiangesoft.im.auth.UserUtil;
import com.qiangesoft.im.entity.ImGroup;
import com.qiangesoft.im.entity.ImGroupUser;
import com.qiangesoft.im.entity.SysUser;
import com.qiangesoft.im.exception.ServiceException;
import com.qiangesoft.im.mapper.ImGroupMapper;
import com.qiangesoft.im.pojo.dto.ImGroupDTO;
import com.qiangesoft.im.pojo.dto.ImGroupMasterDTO;
import com.qiangesoft.im.pojo.vo.ImGroupInfoVO;
import com.qiangesoft.im.pojo.vo.ImGroupVO;
import com.qiangesoft.im.pojo.vo.SysUserVo;
import com.qiangesoft.im.service.IImGroupService;
import com.qiangesoft.im.service.IImGroupUserService;
import com.qiangesoft.im.service.ISysUserService;
import com.qiangesoft.im.util.IdSplitUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;/*** <p>* 群组 服务实现类* </p>** @author qiangesoft* @date 2024-02-07*/
@Service
public class ImGroupServiceImpl extends ServiceImpl<ImGroupMapper, ImGroup> implements IImGroupService {@Autowiredprivate IImGroupUserService groupUserService;@Autowiredprivate ISysUserService sysUserService;@Transactional(rollbackFor = RuntimeException.class)@Overridepublic void addGroup(ImGroupDTO groupDTO) {Long userId = UserUtil.getUserId();ImGroup group = new ImGroup();group.setName(groupDTO.getName());group.setAvatar(groupDTO.getAvatar());group.setMaster(userId);group.setManager(IdSplitUtil.listToStr(groupDTO.getManager()));group.setNotice(groupDTO.getNotice());group.setRemark(groupDTO.getRemark());group.setDelFlag(false);baseMapper.insert(group);// 群成员List<ImGroupUser> groupUserList = new ArrayList<>();List<Long> memberIdList = groupDTO.getMemberIdList();if (!memberIdList.contains(userId)) {memberIdList.add(userId);}for (Long memberId : memberIdList) {ImGroupUser groupUser = new ImGroupUser();groupUser.setGroupId(group.getId());groupUser.setUserId(memberId);groupUser.setDelFlag(false);groupUserList.add(groupUser);}groupUserService.saveBatch(groupUserList);}@Overridepublic void removeGroup(Long id) {LambdaUpdateWrapper<ImGroup> updateWrapper = new LambdaUpdateWrapper<>();updateWrapper.eq(ImGroup::getId, id).set(ImGroup::getDelFlag, true);baseMapper.update(null, updateWrapper);}@Overridepublic void updateGroup(Long id, ImGroupDTO groupDTO) {ImGroup group = this.validateGroup(id);if (group.getDelFlag()) {throw new ServiceException("群组已解散!");}group.setName(groupDTO.getName());group.setAvatar(groupDTO.getAvatar());group.setManager(IdSplitUtil.listToStr(groupDTO.getManager()));group.setNotice(groupDTO.getNotice());group.setRemark(groupDTO.getRemark());baseMapper.updateById(group);}@Overridepublic List<ImGroupVO> listGroup(String keyword) {LambdaQueryWrapper<ImGroup> queryWrapper = new LambdaQueryWrapper<>();queryWrapper.like(StringUtils.isNotBlank(keyword), ImGroup::getRemark, keyword).eq(ImGroup::getDelFlag, false);List<ImGroup> groupList = baseMapper.selectList(queryWrapper);List<ImGroupVO> groupVOList = new ArrayList<>();if (CollectionUtils.isEmpty(groupList)) {return groupVOList;}for (ImGroup group : groupList) {ImGroupVO groupVO = new ImGroupVO();groupVO.setId(group.getId());groupVO.setName(group.getName());groupVO.setAvatar(group.getAvatar());groupVO.setRemark(group.getRemark());groupVO.setCreateTime(group.getCreateTime().getTime());groupVOList.add(groupVO);}return groupVOList;}@Overridepublic ImGroupInfoVO getGroupInfo(Long id) {ImGroup group = this.validateGroup(id);ImGroupInfoVO vo = new ImGroupInfoVO();vo.setId(group.getId());vo.setName(group.getName());vo.setAvatar(group.getAvatar());vo.setNotice(group.getNotice());vo.setRemark(group.getRemark());vo.setCreateTime(group.getCreateTime().getTime());// 群主Long masterId = group.getMaster();if (masterId != null) {SysUser master = sysUserService.getById(masterId);if (master != null) {SysUserVo masterVo = SysUserVo.fromEntity(master);vo.setMaster(masterVo);}}// 群管理String manager = group.getManager();List<Long> managerIdList = IdSplitUtil.strToList(manager);if (!CollectionUtils.isEmpty(managerIdList)) {List<SysUserVo> managerUserList = sysUserService.listByIds(managerIdList).stream().map(SysUserVo::fromEntity).collect(Collectors.toList());vo.setManagerList(managerUserList);}// 群成员List<SysUserVo> userVoList = new ArrayList<>();LambdaQueryWrapper<ImGroupUser> queryWrapper = new LambdaQueryWrapper<>();queryWrapper.eq(ImGroupUser::getGroupId, id).eq(ImGroupUser::getDelFlag, false);List<ImGroupUser> groupUserList = groupUserService.list(queryWrapper);if (CollectionUtils.isEmpty(groupUserList)) {vo.setMemberList(userVoList);return vo;}List<Long> userIdList = groupUserList.stream().map(ImGroupUser::getUserId).collect(Collectors.toList());Map<Long, SysUserVo> sysUserVOMap = sysUserService.listByIds(userIdList).stream().map(SysUserVo::fromEntity).collect(Collectors.toMap(SysUserVo::getId, sysUserVo -> sysUserVo));for (ImGroupUser groupUser : groupUserList) {SysUserVo sysUserVo = sysUserVOMap.get(groupUser.getUserId());if (sysUserVo != null) {userVoList.add(sysUserVo);}}vo.setMemberList(userVoList);return vo;}@Overridepublic void updateMaster(ImGroupMasterDTO groupMasterDTO) {Long id = groupMasterDTO.getId();ImGroup group = this.validateGroup(id);if (group.getDelFlag()) {throw new ServiceException("群组已解散!");}LambdaUpdateWrapper<ImGroup> updateWrapper = new LambdaUpdateWrapper<>();updateWrapper.eq(ImGroup::getId, id).set(ImGroup::getMaster, groupMasterDTO.getMaster());baseMapper.update(null, updateWrapper);}@Overridepublic ImGroup validateGroup(Long id) {ImGroup group = baseMapper.selectById(id);if (group == null) {throw new ServiceException("群组不存在");}return group;}
}
package com.qiangesoft.im.service.impl;import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qiangesoft.im.auth.UserUtil;
import com.qiangesoft.im.entity.ImGroup;
import com.qiangesoft.im.entity.ImGroupUser;
import com.qiangesoft.im.exception.ServiceException;
import com.qiangesoft.im.mapper.ImGroupUserMapper;
import com.qiangesoft.im.pojo.dto.ImGroupUserDTO;
import com.qiangesoft.im.pojo.vo.SysUserVo;
import com.qiangesoft.im.service.IImGroupService;
import com.qiangesoft.im.service.IImGroupUserService;
import com.qiangesoft.im.service.ISysUserService;
import com.qiangesoft.im.util.IdSplitUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;/*** <p>* 群成员 服务实现类* </p>** @author qiangesoft* @date 2024-02-07*/
@Service
public class ImGroupUserServiceImpl extends ServiceImpl<ImGroupUserMapper, ImGroupUser> implements IImGroupUserService {@Autowiredprivate ISysUserService sysUserService;@Lazy@Autowiredprivate IImGroupService groupService;@Transactional(rollbackFor = RuntimeException.class)@Overridepublic void addGroupUser(ImGroupUserDTO groupUserDTO) {Long groupId = groupUserDTO.getGroupId();ImGroup group = groupService.validateGroup(groupId);if (group.getDelFlag()) {throw new ServiceException("群组已解散!");}Long userId = UserUtil.getUserId();List<Long> managerIdList = IdSplitUtil.strToList(group.getManager());if (group.getMaster().equals(userId)) {throw new ServiceException("无添加好友权限!");} else {if (!managerIdList.contains(userId)) {throw new ServiceException("无添加好友权限!");}}List<Long> memberIdList = groupUserDTO.getMemberIdList();if (memberIdList.contains(userId)) {throw new ServiceException("你是群主,不可添加!");}LambdaQueryWrapper<ImGroupUser> queryWrapper = new LambdaQueryWrapper<>();queryWrapper.eq(ImGroupUser::getGroupId, groupId).eq(ImGroupUser::getDelFlag, false);List<Long> existMemberIdList = baseMapper.selectList(queryWrapper).stream().map(ImGroupUser::getUserId).collect(Collectors.toList());List<Long> notExistMemberIdList = memberIdList.stream().filter(e -> !existMemberIdList.contains(e)).collect(Collectors.toList());List<ImGroupUser> groupUserList = new ArrayList<>();for (Long memberId : notExistMemberIdList) {ImGroupUser groupUser = new ImGroupUser();groupUser.setGroupId(groupId);groupUser.setUserId(memberId);groupUser.setDelFlag(false);groupUserList.add(groupUser);}this.saveBatch(groupUserList);}@Transactional(rollbackFor = RuntimeException.class)@Overridepublic void removeGroupUser(ImGroupUserDTO groupUserDTO) {Long groupId = groupUserDTO.getGroupId();ImGroup group = groupService.validateGroup(groupId);if (group.getDelFlag()) {throw new ServiceException("群组已解散!");}Long userId = UserUtil.getUserId();List<Long> managerIdList = IdSplitUtil.strToList(group.getManager());if (group.getMaster().equals(userId)) {throw new ServiceException("无移除好友权限!");} else {if (!managerIdList.contains(userId)) {throw new ServiceException("无移除好友权限!");}}List<Long> memberIdList = groupUserDTO.getMemberIdList();if (memberIdList.contains(userId)) {throw new ServiceException("不能移除自己!");}LambdaUpdateWrapper<ImGroupUser> updateWrapper = new LambdaUpdateWrapper<>();updateWrapper.eq(ImGroupUser::getGroupId, groupId).in(ImGroupUser::getUserId, memberIdList).set(ImGroupUser::getDelFlag, true);baseMapper.update(null, updateWrapper);// 去除管理员权限List<Long> collect = managerIdList.stream().filter(e -> !memberIdList.contains(e)).collect(Collectors.toList());LambdaUpdateWrapper<ImGroup> updateWrapper1 = new LambdaUpdateWrapper<>();updateWrapper1.eq(ImGroup::getId, groupId).set(ImGroup::getManager, IdSplitUtil.listToStr(collect));groupService.update(updateWrapper1);}@Overridepublic List<SysUserVo> listGroupUser(Long id) {groupService.validateGroup(id);List<SysUserVo> userVoList = new ArrayList<>();LambdaQueryWrapper<ImGroupUser> queryWrapper = new LambdaQueryWrapper<>();queryWrapper.eq(ImGroupUser::getGroupId, id).eq(ImGroupUser::getDelFlag, false);List<ImGroupUser> groupUserList = baseMapper.selectList(queryWrapper);if (CollectionUtils.isEmpty(groupUserList)) {return userVoList;}List<Long> userIdList = groupUserList.stream().map(ImGroupUser::getUserId).collect(Collectors.toList());Map<Long, SysUserVo> sysUserVOMap = sysUserService.listByIds(userIdList).stream().map(SysUserVo::fromEntity).collect(Collectors.toMap(SysUserVo::getId, sysUserVo -> sysUserVo));for (ImGroupUser groupUser : groupUserList) {SysUserVo sysUserVo = sysUserVOMap.get(groupUser.getUserId());if (sysUserVo != null) {userVoList.add(sysUserVo);}}return userVoList;}
}

controller

package com.qiangesoft.im.controller;import com.qiangesoft.im.pojo.dto.ImGroupDTO;
import com.qiangesoft.im.pojo.dto.ImGroupMasterDTO;
import com.qiangesoft.im.pojo.vo.ImGroupInfoVO;
import com.qiangesoft.im.pojo.vo.ImGroupVO;
import com.qiangesoft.im.pojo.vo.ResultInfo;
import com.qiangesoft.im.service.IImGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;import java.util.List;/*** <p>* 群组 前端控制器* </p>** @author qiangesoft* @date 2024-02-07*/
@Api(tags = "群组")
@RestController
@RequestMapping("/im/group")
public class ImGroupController {@Autowiredprivate IImGroupService groupService;@PostMapping@ApiOperation(value = "建群")public ResultInfo<Void> addGroup(@RequestBody ImGroupDTO groupDTO) {groupService.addGroup(groupDTO);return ResultInfo.ok();}@DeleteMapping("/{id}")@ApiOperation(value = "解散群")public ResultInfo<Void> removeGroup(@PathVariable Long id) {groupService.removeGroup(id);return ResultInfo.ok();}@PutMapping("/{id}")@ApiOperation(value = "编辑群")public ResultInfo<Void> updateGroup(@PathVariable Long id, @RequestBody ImGroupDTO groupDTO) {groupService.updateGroup(id, groupDTO);return ResultInfo.ok();}@GetMapping@ApiOperation(value = "群列表")public ResultInfo<List<ImGroupVO>> listGroup(String keyword) {return ResultInfo.ok(groupService.listGroup(keyword));}@GetMapping("/{id}")@ApiOperation(value = "群详情")public ResultInfo<ImGroupInfoVO> getGroupInfo(@PathVariable Long id) {return ResultInfo.ok(groupService.getGroupInfo(id));}@GetMapping("/updateMaster")@ApiOperation(value = "变更群主")public ResultInfo<Void> updateMaster(@RequestBody ImGroupMasterDTO groupMasterDTO) {groupService.updateMaster(groupMasterDTO);return ResultInfo.ok();}
}
package com.qiangesoft.im.controller;import com.qiangesoft.im.pojo.dto.ImGroupUserDTO;
import com.qiangesoft.im.pojo.vo.ResultInfo;
import com.qiangesoft.im.pojo.vo.SysUserVo;
import com.qiangesoft.im.service.IImGroupUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;import java.util.List;/*** <p>* 群成员 前端控制器* </p>** @author qiangesoft* @date 2024-02-07*/
@Api(tags = "群成员")
@RestController
@RequestMapping("/im/groupUser")
public class ImGroupUserController {@Autowiredprivate IImGroupUserService groupUserService;@PostMapping@ApiOperation(value = "添加群成员")public ResultInfo<Void> addGroupUser(@RequestBody ImGroupUserDTO groupUserDTO) {groupUserService.addGroupUser(groupUserDTO);return ResultInfo.ok();}@DeleteMapping@ApiOperation(value = "删除群成员")public ResultInfo<Void> removeGroupUser(@RequestBody ImGroupUserDTO groupUserDTO) {groupUserService.removeGroupUser(groupUserDTO);return ResultInfo.ok();}@GetMapping("/{id}")@ApiOperation(value = "群成员列表")public ResultInfo<List<SysUserVo>> listGroupUser(@PathVariable Long id) {return ResultInfo.ok(groupUserService.listGroupUser(id));}}

三、源码地址

源码地址:https://gitee.com/qiangesoft/boot-business/tree/master/boot-business-im

后续内容见下章

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/694257.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【Vulkan Tutorials 01】【环境搭建】三角形例子

Development Environment&#xff08;开发环境&#xff09; 1. 安装Vulkan SDK 官网 2. 安装cmake和minGW 2.1 cmake 官网 双击可执行文件&#xff0c;然后直接安装&#xff0c;注意环境变量选择设置&#xff0c;否则需要自己操作。 2.2 minGW 官网 下载如下图所示&am…

2.21数据与结构算法学习日记(最小生成树prim算法)

目录 最小生成树prim 最小生成树算法是一种用来在一个加权连通图中找到最小生成树的算法。最小生成树是一个包含图中所有顶点的树&#xff0c;其总权值最小。 prim算法 洛谷题目示例 P3366 【模板】最小生成树 题目描述 输入格式 输出格式 输入输出样例 说明/提示 题…

K8s ingress-nginx根据请求目录不同将请求转发到不同应用

K8s ingress-nginx根据请求目录不同将请求转发到不同应用 1. 起因 有小伙伴做实验想要实现以下需求: 输入www.pana.com/app1访问app1的svc 输入www.pana.com/app2访问app2的svc 2. 实验 2.1 Dockerfile 先准备Dockerfile FROM nginx:1.20ADD index.html /usr/share/ngin…

还迷糊事务的并发问题以及隔离级别?

还迷糊事务的并发问题以及隔离级别&#xff1f; 事务并发问题 MySQL 服务端是允许多个客户端连接的&#xff0c;这意味着 MySQL 会出现同时处理多个事务的情况。 那么在同时处理多个事务的时候&#xff0c;就可能出现脏读&#xff08;dirty read&#xff09;、不可重复读&am…

Linux常见指令(二)

目录 常见指令 1.1more指令 1.2less指令 1.3tail指令 1.4时间相关的指令 1.5Cal指令 1.6find指令 1.7grep指令 1.8zip/unzip指令 1.9tar指令&#xff08;重要&#xff09; 1.10bc指令 常见指令 1.1more指令 语法 &#xff1a; more [ 选项 ][ 文件 ] 功能 &#xf…

力扣代码学习日记五

Problem: 283. 移动零 文章目录 思路解题方法复杂度代码 思路 给定一个数组 nums&#xff0c;编写一个函数将所有 0 移动到数组的末尾&#xff0c;同时保持非零元素的相对顺序。 请注意 &#xff0c;必须在不复制数组的情况下原地对数组进行操作。 示例 1: 输入: nums [0,…

269.【华为OD机试真题】解密犯罪时间(深度优先搜索(DFS)-JavaPythonC++JS实现)

🚀点击这里可直接跳转到本专栏,可查阅顶置最新的华为OD机试宝典~ 本专栏所有题目均包含优质解题思路,高质量解题代码(Java&Python&C++&JS分别实现),详细代码讲解,助你深入学习,深度掌握! 文章目录 一. 题目二.解题思路三.题解代码Python题解代码JAVA题解…

Windows认证基础知识

Windows凭据 1.SSPI SSPI(Security Support Provider Interface,安全支持提供程序接口)是Windows操作系统中用于执行各种安全相关操作的公用API.SSPI的功能比较全面&#xff0c;可以用来获得身份验证、信息完整性校验、信息隐私保护等集成的安全服务。它是众多安全支持提供程…

华清远见作业第四十天——Qt(第二天)

思维导图&#xff1a; 编程&#xff1a; 使用手动连接&#xff0c;将登录框中的取消按钮使用qt4版本的连接到自定义的槽函数中&#xff0c;在自定义的槽函数中调用关闭函数 将登录按钮使用qt5版本的连接到自定义的槽函数中&#xff0c;在槽函数中判断ui界面上输入的账号是否为…

等级保护是什么,为什么要做等级保护

一、 什么是等级保护&#xff1a; 等级保护是一种信息安全管理方法&#xff0c;用于对不同级别的信息和信息系统进行分类、评估和保护。它涉及将信息系统和信息按照其重要性和敏感性分级别&#xff0c;然后根据等级要求实施相应的安全措施&#xff0c;以确保信息的保密性、完整…

碳化硅晶片C面和硅面详解

SiC是一种Si元素和C元素以1:1比例形成的二元化合物&#xff0c;即百分之五十的硅&#xff08;Si&#xff09;和百分之五十的碳&#xff08;C&#xff09;&#xff0c;其基本结构单元为 Si-C 四面体。 举个例子&#xff0c;Si原子直径大&#xff0c;相当于苹果&#xff0c;C原子…

EasyRecovery支持恢复多种类型的文件包括文档、表格、图片、音频、视频等

EasyRecovery易恢复是一款来自美国的数据恢复软件&#xff0c;已有35年&#xff08;或38年&#xff09;的历史。它支持不同存储介质的数据恢复&#xff0c;包括电脑系统硬盘、移动硬盘等&#xff0c;并针对不同的数据丢失原因提供了相应的恢复方案。 EasyRecovery易恢复是一款…

开源模型应用落地-工具使用篇-向量数据库(三)

一、前言 通过学习"开源模型应用落地"系列文章&#xff0c;我们成功地建立了一个完整可实施的AI交付流程。现在&#xff0c;我们要引入向量数据库&#xff0c;作为我们AI服务的二级缓存。本文将详细介绍如何使用Milvus Lite来为我们的AI服务部署一个前置缓存。 二、术…

CSS中伪元素和伪类的区别和作用?

伪元素&#xff1a;在内容元素的前后插入额外的元素或样式&#xff0c;但是这些元素实际上并不在文档中生成。它们只在外部显示可见&#xff0c;但不会在文档的源代码中找到它们&#xff0c;因此&#xff0c;称为“伪”元素。例如&#xff1a; p::before {content:"第一章…

曝光一下不发年终奖的企业

原文连接&#xff1a; 曝光一下不发年终奖的企业 今日热帖&#xff0c;看到网上发布的一篇帖子&#xff1a;请曝光一下不发年终奖的企业&#xff01; 结果留言上百条&#xff0c;除了私企&#xff0c;还有很多国企&#xff0c;银行等。而且还有一些我们认为应该很赚钱的企业&a…

记一次重大的问题解决

问题的模样 我们是需要的操作两个git仓库的的三个分支&#xff08;此处第一个仓库简称&#xff1a;A&#xff08;负责程序的第一层进入&#xff09;&#xff0c;第二个简称B&#xff08;负责业务的执行&#xff09;&#xff09; 大致就是A的代码引用了B&#xff0c;B的代码引…

opengl 学习着色器

一.GLSL 着色器是使用一种叫GLSL的类C语言写成的。GLSL着色器编码顺序&#xff1a;声明版本》定义输入输出》uniform》main函数。每个着色器的入口点是main函数&#xff0c;在main函数中我们处理所有的输入变量&#xff0c;并将结果输出到输出变量中。如下图&#xff1a; #ver…

Java之反射:Class类、调用构造方法、访问字段、访问方法

反射 什么是反射&#xff1a; ​ 反射是Java语法的一种高级特性&#xff0c;在“运行期间”对Java的类型信息进行检查&#xff0c;操作处理。例如&#xff1a;加载JDBC驱动类&#xff0c;Mybatis动态处理resultType&#xff0c;Spring根据配置创建Bean对象等使用场景都用反射…

CVE-2024-24565 CrateDB数据库任意文件读取漏洞

目录 前言 简介 ​编辑 环境搭建 漏洞复现 前言 本次介绍的漏洞不同与以往&#xff0c; 本次洞更多是适用于利用数据库提权。 利用数据库的导入导出数据的功能&#xff0c;我们往往可以将内部的一些敏感文件如/etc/passwd导入到数据库进行查看。也可以将数据导入到一些特…

SpringBoot + Thymeleaf打造VIP视频源解析网站

第一步&#xff1a;创建一个SpringBoot项目 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency><dependency><groupId>org.springframework.bo…