25 changed files with 889 additions and 27 deletions
@ -0,0 +1,58 @@ |
|||
package com.lx.implatform.controller; |
|||
|
|||
|
|||
import com.lx.common.result.Result; |
|||
import com.lx.common.result.ResultUtils; |
|||
import com.lx.implatform.service.IGroupService; |
|||
import com.lx.implatform.vo.GroupInviteVO; |
|||
import com.lx.implatform.vo.GroupVO; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import javax.validation.Valid; |
|||
import javax.validation.constraints.NotEmpty; |
|||
import javax.validation.constraints.NotNull; |
|||
import java.util.List; |
|||
|
|||
|
|||
@RestController |
|||
@RequestMapping("/group") |
|||
public class GroupController { |
|||
|
|||
@Autowired |
|||
private IGroupService groupService; |
|||
|
|||
@ApiOperation(value = "创建群聊",notes="创建群聊") |
|||
@PostMapping("/create") |
|||
public Result<GroupVO> createGroup(@NotEmpty(message = "群名不能为空") @RequestParam String groupName){ |
|||
return ResultUtils.success(groupService.createGroup(groupName)); |
|||
} |
|||
|
|||
@ApiOperation(value = "修改群聊信息",notes="修改群聊信息") |
|||
@PutMapping("/modify") |
|||
public Result<GroupVO> modifyGroup(@Valid @RequestBody GroupVO vo){ |
|||
return ResultUtils.success(groupService.modifyGroup(vo)); |
|||
} |
|||
|
|||
@ApiOperation(value = "修改群聊信息",notes="修改群聊信息") |
|||
@DeleteMapping("/delete/{groupId}") |
|||
public Result<GroupVO> deleteGroup(@NotNull(message = "群聊id不能为空") @PathVariable Long groupId){ |
|||
groupService.deleteGroup(groupId); |
|||
return ResultUtils.success(); |
|||
} |
|||
|
|||
@ApiOperation(value = "查询群聊列表",notes="查询群聊列表") |
|||
@GetMapping("/list") |
|||
public Result<List<GroupVO>> findGroups(){ |
|||
return ResultUtils.success(groupService.findGroups()); |
|||
} |
|||
|
|||
@ApiOperation(value = "邀请进群",notes="邀请好友进群") |
|||
@PostMapping("/invite") |
|||
public Result invite(@Valid @RequestBody GroupInviteVO vo){ |
|||
groupService.invite(vo); |
|||
return ResultUtils.success(); |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,14 @@ |
|||
package com.lx.implatform.controller; |
|||
|
|||
|
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
|
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
|
|||
@RestController |
|||
@RequestMapping("/group/message") |
|||
public class GroupMessageController { |
|||
|
|||
} |
|||
|
|||
@ -0,0 +1,83 @@ |
|||
package com.lx.implatform.entity; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import com.baomidou.mybatisplus.annotation.IdType; |
|||
import com.baomidou.mybatisplus.extension.activerecord.Model; |
|||
|
|||
import java.util.Date; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.Version; |
|||
import com.baomidou.mybatisplus.annotation.TableId; |
|||
import com.baomidou.mybatisplus.annotation.TableField; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
|
|||
/** |
|||
* 群 |
|||
* @author blue |
|||
* @since 2022-10-31 |
|||
*/ |
|||
@Data |
|||
@EqualsAndHashCode(callSuper = false) |
|||
@TableName("group") |
|||
public class Group extends Model<Group> { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** |
|||
* id |
|||
*/ |
|||
@TableId(value = "id", type = IdType.AUTO) |
|||
private Long id; |
|||
|
|||
/** |
|||
* 群名字 |
|||
*/ |
|||
private String name; |
|||
|
|||
/** |
|||
* 群主id |
|||
*/ |
|||
@TableField("owner_id") |
|||
private Long ownerId; |
|||
|
|||
/** |
|||
* 头像 |
|||
*/ |
|||
@TableField("head_image") |
|||
private String headImage; |
|||
|
|||
/** |
|||
* 头像缩略图 |
|||
*/ |
|||
@TableField("head_image_thumb") |
|||
private String headImageThumb; |
|||
|
|||
/** |
|||
* 群公告 |
|||
*/ |
|||
@TableField("notice") |
|||
private String notice; |
|||
|
|||
/** |
|||
* 群备注 |
|||
*/ |
|||
@TableField("remark") |
|||
private String remark; |
|||
|
|||
/** |
|||
* 创建时间 |
|||
*/ |
|||
@TableField("created_time") |
|||
private Date createdTime; |
|||
|
|||
|
|||
@Override |
|||
protected Serializable pkVal() { |
|||
return this.id; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,83 @@ |
|||
package com.lx.implatform.entity; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import com.baomidou.mybatisplus.annotation.IdType; |
|||
import com.baomidou.mybatisplus.extension.activerecord.Model; |
|||
|
|||
import java.util.Date; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.Version; |
|||
import com.baomidou.mybatisplus.annotation.TableId; |
|||
import com.baomidou.mybatisplus.annotation.TableField; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
|
|||
/** |
|||
* <p> |
|||
* 群成员 |
|||
* </p> |
|||
* |
|||
* @author blue |
|||
* @since 2022-10-31 |
|||
*/ |
|||
@Data |
|||
@EqualsAndHashCode(callSuper = false) |
|||
@TableName("group_member") |
|||
public class GroupMember extends Model<GroupMember> { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** |
|||
* id |
|||
*/ |
|||
@TableId(value = "id", type = IdType.AUTO) |
|||
private Long id; |
|||
|
|||
/** |
|||
* 群id |
|||
*/ |
|||
@TableField("group_id") |
|||
private Long groupId; |
|||
|
|||
/** |
|||
* 用户id |
|||
*/ |
|||
@TableField("user_id") |
|||
private Long userId; |
|||
|
|||
/** |
|||
* 群内显示名称 |
|||
*/ |
|||
@TableField("user_id") |
|||
private String aliasName; |
|||
|
|||
/** |
|||
* 头像 |
|||
*/ |
|||
@TableField("head_image") |
|||
private String headImage; |
|||
|
|||
|
|||
|
|||
/** |
|||
* 备注 |
|||
*/ |
|||
@TableField("remarks") |
|||
private String remarks; |
|||
|
|||
/** |
|||
* 创建时间 |
|||
*/ |
|||
@TableField("created_time") |
|||
private Date createdTime; |
|||
|
|||
|
|||
@Override |
|||
protected Serializable pkVal() { |
|||
return this.id; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,75 @@ |
|||
package com.lx.implatform.entity; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import com.baomidou.mybatisplus.annotation.IdType; |
|||
import com.baomidou.mybatisplus.extension.activerecord.Model; |
|||
|
|||
import java.util.Date; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.Version; |
|||
import com.baomidou.mybatisplus.annotation.TableId; |
|||
import com.baomidou.mybatisplus.annotation.TableField; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
|
|||
/** |
|||
* <p> |
|||
* 群消息 |
|||
* </p> |
|||
* |
|||
* @author blue |
|||
* @since 2022-10-31 |
|||
*/ |
|||
@Data |
|||
@EqualsAndHashCode(callSuper = false) |
|||
@TableName("group_message") |
|||
public class GroupMessage extends Model<GroupMessage> { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** |
|||
* id |
|||
*/ |
|||
@TableId(value = "id", type = IdType.AUTO) |
|||
private Long id; |
|||
|
|||
/** |
|||
* 群id |
|||
*/ |
|||
@TableField("group_id") |
|||
private Long groupId; |
|||
|
|||
/** |
|||
* 发送用户id |
|||
*/ |
|||
@TableField("send_user_id") |
|||
private Long sendUserId; |
|||
|
|||
/** |
|||
* 发送内容 |
|||
*/ |
|||
@TableField("content") |
|||
private String content; |
|||
|
|||
/** |
|||
* 消息类型 0:文字 1:图片 2:文件 |
|||
*/ |
|||
@TableField("type") |
|||
private Boolean type; |
|||
|
|||
/** |
|||
* 发送时间 |
|||
*/ |
|||
@TableField("send_time") |
|||
private Date sendTime; |
|||
|
|||
|
|||
@Override |
|||
protected Serializable pkVal() { |
|||
return this.id; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,69 @@ |
|||
package com.lx.implatform.entity; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import com.baomidou.mybatisplus.annotation.IdType; |
|||
import com.baomidou.mybatisplus.extension.activerecord.Model; |
|||
|
|||
import java.util.Date; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.Version; |
|||
import com.baomidou.mybatisplus.annotation.TableId; |
|||
import com.baomidou.mybatisplus.annotation.TableField; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
|
|||
/** |
|||
* <p> |
|||
* 群消息读取位置 |
|||
* </p> |
|||
* |
|||
* @author blue |
|||
* @since 2022-10-31 |
|||
*/ |
|||
@Data |
|||
@EqualsAndHashCode(callSuper = false) |
|||
@TableName("group_message_read_pos") |
|||
public class GroupMessageReadPos extends Model<GroupMessageReadPos> { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** |
|||
* id |
|||
*/ |
|||
@TableId(value = "id", type = IdType.AUTO) |
|||
private Long id; |
|||
|
|||
/** |
|||
* 群id |
|||
*/ |
|||
@TableField("group_id") |
|||
private Long groupId; |
|||
|
|||
/** |
|||
* 用户id |
|||
*/ |
|||
@TableField("user_id") |
|||
private Long userId; |
|||
|
|||
/** |
|||
* 已读取消息的最大消息id |
|||
*/ |
|||
@TableField("read_pos") |
|||
private Long readPos; |
|||
|
|||
/** |
|||
* 最后读取时间 |
|||
*/ |
|||
@TableField("last_read_time") |
|||
private Date lastReadTime; |
|||
|
|||
|
|||
@Override |
|||
protected Serializable pkVal() { |
|||
return this.id; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
package com.lx.implatform.mapper; |
|||
|
|||
import com.lx.implatform.entity.Group; |
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
|
|||
/** |
|||
* <p> |
|||
* 群 Mapper 接口 |
|||
* </p> |
|||
* |
|||
* @author blue |
|||
* @since 2022-10-31 |
|||
*/ |
|||
public interface GroupMapper extends BaseMapper<Group> { |
|||
|
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
package com.lx.implatform.mapper; |
|||
|
|||
import com.lx.implatform.entity.GroupMember; |
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
|
|||
/** |
|||
* <p> |
|||
* 群成员 Mapper 接口 |
|||
* </p> |
|||
* |
|||
* @author blue |
|||
* @since 2022-10-31 |
|||
*/ |
|||
public interface GroupMemberMapper extends BaseMapper<GroupMember> { |
|||
|
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
package com.lx.implatform.mapper; |
|||
|
|||
import com.lx.implatform.entity.GroupMessage; |
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
|
|||
/** |
|||
* <p> |
|||
* 群消息 Mapper 接口 |
|||
* </p> |
|||
* |
|||
* @author blue |
|||
* @since 2022-10-31 |
|||
*/ |
|||
public interface GroupMessageMapper extends BaseMapper<GroupMessage> { |
|||
|
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
package com.lx.implatform.mapper; |
|||
|
|||
import com.lx.implatform.entity.GroupMessageReadPos; |
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
|
|||
/** |
|||
* <p> |
|||
* 群消息读取位置 Mapper 接口 |
|||
* </p> |
|||
* |
|||
* @author blue |
|||
* @since 2022-10-31 |
|||
*/ |
|||
public interface GroupMessageReadPosMapper extends BaseMapper<GroupMessageReadPos> { |
|||
|
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
package com.lx.implatform.service; |
|||
|
|||
import com.lx.implatform.entity.GroupMember; |
|||
import com.baomidou.mybatisplus.extension.service.IService; |
|||
|
|||
/** |
|||
* <p> |
|||
* 群成员 服务类 |
|||
* </p> |
|||
* |
|||
* @author blue |
|||
* @since 2022-10-31 |
|||
*/ |
|||
public interface IGroupMemberService extends IService<GroupMember> { |
|||
|
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
package com.lx.implatform.service; |
|||
|
|||
import com.lx.implatform.entity.GroupMessageReadPos; |
|||
import com.baomidou.mybatisplus.extension.service.IService; |
|||
|
|||
/** |
|||
* <p> |
|||
* 群消息读取位置 服务类 |
|||
* </p> |
|||
* |
|||
* @author blue |
|||
* @since 2022-10-31 |
|||
*/ |
|||
public interface IGroupMessageReadPosService extends IService<GroupMessageReadPos> { |
|||
|
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
package com.lx.implatform.service; |
|||
|
|||
import com.lx.implatform.entity.GroupMessage; |
|||
import com.baomidou.mybatisplus.extension.service.IService; |
|||
|
|||
/** |
|||
* <p> |
|||
* 群消息 服务类 |
|||
* </p> |
|||
* |
|||
* @author blue |
|||
* @since 2022-10-31 |
|||
*/ |
|||
public interface IGroupMessageService extends IService<GroupMessage> { |
|||
|
|||
} |
|||
@ -0,0 +1,30 @@ |
|||
package com.lx.implatform.service; |
|||
|
|||
import com.lx.implatform.entity.Group; |
|||
import com.baomidou.mybatisplus.extension.service.IService; |
|||
import com.lx.implatform.vo.GroupInviteVO; |
|||
import com.lx.implatform.vo.GroupVO; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* <p> |
|||
* 群 服务类 |
|||
* </p> |
|||
* |
|||
* @author blue |
|||
* @since 2022-10-31 |
|||
*/ |
|||
public interface IGroupService extends IService<Group> { |
|||
|
|||
|
|||
GroupVO createGroup(String groupName); |
|||
|
|||
GroupVO modifyGroup(GroupVO vo); |
|||
|
|||
void deleteGroup(Long groupId); |
|||
|
|||
List<GroupVO> findGroups(); |
|||
|
|||
void invite(GroupInviteVO vo); |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
package com.lx.implatform.service.impl; |
|||
|
|||
import com.lx.implatform.entity.GroupMember; |
|||
import com.lx.implatform.mapper.GroupMemberMapper; |
|||
import com.lx.implatform.service.IGroupMemberService; |
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
/** |
|||
* <p> |
|||
* 群成员 服务实现类 |
|||
* </p> |
|||
* |
|||
* @author blue |
|||
* @since 2022-10-31 |
|||
*/ |
|||
@Service |
|||
public class GroupMemberServiceImpl extends ServiceImpl<GroupMemberMapper, GroupMember> implements IGroupMemberService { |
|||
|
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
package com.lx.implatform.service.impl; |
|||
|
|||
import com.lx.implatform.entity.GroupMessageReadPos; |
|||
import com.lx.implatform.mapper.GroupMessageReadPosMapper; |
|||
import com.lx.implatform.service.IGroupMessageReadPosService; |
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
/** |
|||
* <p> |
|||
* 群消息读取位置 服务实现类 |
|||
* </p> |
|||
* |
|||
* @author blue |
|||
* @since 2022-10-31 |
|||
*/ |
|||
@Service |
|||
public class GroupMessageReadPosServiceImpl extends ServiceImpl<GroupMessageReadPosMapper, GroupMessageReadPos> implements IGroupMessageReadPosService { |
|||
|
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
package com.lx.implatform.service.impl; |
|||
|
|||
import com.lx.implatform.entity.GroupMessage; |
|||
import com.lx.implatform.mapper.GroupMessageMapper; |
|||
import com.lx.implatform.service.IGroupMessageService; |
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
/** |
|||
* <p> |
|||
* 群消息 服务实现类 |
|||
* </p> |
|||
* |
|||
* @author blue |
|||
* @since 2022-10-31 |
|||
*/ |
|||
@Service |
|||
public class GroupMessageServiceImpl extends ServiceImpl<GroupMessageMapper, GroupMessage> implements IGroupMessageService { |
|||
|
|||
} |
|||
@ -0,0 +1,177 @@ |
|||
package com.lx.implatform.service.impl; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import com.lx.common.enums.ResultCode; |
|||
import com.lx.common.util.BeanUtils; |
|||
import com.lx.implatform.entity.Friends; |
|||
import com.lx.implatform.entity.Group; |
|||
import com.lx.implatform.entity.GroupMember; |
|||
import com.lx.implatform.entity.User; |
|||
import com.lx.implatform.exception.GlobalException; |
|||
import com.lx.implatform.mapper.GroupMapper; |
|||
import com.lx.implatform.service.IFriendsService; |
|||
import com.lx.implatform.service.IGroupMemberService; |
|||
import com.lx.implatform.service.IGroupService; |
|||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|||
import com.lx.implatform.service.IUserService; |
|||
import com.lx.implatform.session.SessionContext; |
|||
import com.lx.implatform.session.UserSession; |
|||
import com.lx.implatform.vo.GroupInviteVO; |
|||
import com.lx.implatform.vo.GroupVO; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
|
|||
import java.util.List; |
|||
import java.util.stream.Collectors; |
|||
|
|||
|
|||
@Service |
|||
public class GroupServiceImpl extends ServiceImpl<GroupMapper, Group> implements IGroupService { |
|||
|
|||
@Autowired |
|||
private IUserService userService; |
|||
|
|||
@Autowired |
|||
private IGroupMemberService groupMemberService; |
|||
|
|||
@Autowired |
|||
private IFriendsService friendsService; |
|||
|
|||
/** |
|||
* 创建新群聊 |
|||
* |
|||
* @return GroupVO |
|||
* @Param groupName 群聊名称 |
|||
**/ |
|||
@Transactional |
|||
@Override |
|||
public GroupVO createGroup(String groupName) { |
|||
UserSession session = SessionContext.getSession(); |
|||
User user = userService.getById(session.getId()); |
|||
// 保存群组数据
|
|||
Group group = new Group(); |
|||
group.setName(groupName); |
|||
group.setOwnerId(user.getId()); |
|||
group.setHeadImage(user.getHeadImage()); |
|||
group.setHeadImageThumb(user.getHeadImageThumb()); |
|||
this.save(group); |
|||
// 把群主加入群
|
|||
GroupMember groupMember = new GroupMember(); |
|||
groupMember.setGroupId(group.getId()); |
|||
groupMember.setUserId(user.getId()); |
|||
groupMember.setAliasName(user.getNickName()); |
|||
groupMember.setHeadImage(user.getHeadImageThumb()); |
|||
groupMemberService.save(groupMember); |
|||
GroupVO vo = BeanUtils.copyProperties(group, GroupVO.class); |
|||
return vo; |
|||
} |
|||
|
|||
/** |
|||
* 修改群聊信息 |
|||
* |
|||
* @Param GroupVO 群聊信息 |
|||
* @return GroupVO |
|||
**/ |
|||
@Override |
|||
public GroupVO modifyGroup(GroupVO vo) { |
|||
UserSession session = SessionContext.getSession(); |
|||
// 校验是不是群主,只有群主能改信息
|
|||
Group group = this.getById(vo.getId()); |
|||
if(group.getOwnerId() != session.getId()){ |
|||
throw new GlobalException(ResultCode.PROGRAM_ERROR,"您不是群主,不可修改群信息"); |
|||
} |
|||
// 保存群信息
|
|||
group = BeanUtils.copyProperties(vo,Group.class); |
|||
this.save(group); |
|||
return vo; |
|||
} |
|||
|
|||
/** |
|||
* 删除群聊 |
|||
* |
|||
* @Param groupId 群聊id |
|||
* @return void |
|||
**/ |
|||
@Transactional |
|||
@Override |
|||
public void deleteGroup(Long groupId) { |
|||
UserSession session = SessionContext.getSession(); |
|||
Group group = this.getById(groupId); |
|||
if(group == null){ |
|||
throw new GlobalException(ResultCode.PROGRAM_ERROR,"群组不存在"); |
|||
} |
|||
if(group.getOwnerId() != session.getId()){ |
|||
throw new GlobalException(ResultCode.PROGRAM_ERROR,"只有群主才有权限解除群聊"); |
|||
} |
|||
// 删除群数据
|
|||
this.removeById(groupId); |
|||
// 删除成员数据
|
|||
QueryWrapper<GroupMember> wrapper = new QueryWrapper(); |
|||
wrapper.lambda().eq(GroupMember::getGroupId,groupId); |
|||
groupMemberService.remove(wrapper); |
|||
} |
|||
|
|||
/** |
|||
* 查询当前用户的所有群聊 |
|||
* |
|||
* @return List<GroupVO> |
|||
**/ |
|||
@Override |
|||
public List<GroupVO> findGroups() { |
|||
UserSession session = SessionContext.getSession(); |
|||
// 查询当前用户的群id列表
|
|||
QueryWrapper<GroupMember> memberWrapper = new QueryWrapper(); |
|||
memberWrapper.lambda().eq(GroupMember::getUserId, session.getId()); |
|||
List<GroupMember> groupMembers = groupMemberService.list(memberWrapper); |
|||
// 拉取群信息
|
|||
List<Long> ids = groupMembers.stream().map((gm -> gm.getGroupId())).collect(Collectors.toList()); |
|||
QueryWrapper<Group> groupWrapper = new QueryWrapper(); |
|||
groupWrapper.lambda().in(Group::getId, ids); |
|||
List<Group> groups = this.list(groupWrapper); |
|||
// 转vo
|
|||
List<GroupVO> vos = groups.stream().map(g -> { |
|||
GroupVO vo = BeanUtils.copyProperties(g, GroupVO.class); |
|||
return vo; |
|||
}).collect(Collectors.toList()); |
|||
return vos; |
|||
} |
|||
|
|||
/** |
|||
* 邀请好友进群 |
|||
* |
|||
* @return |
|||
* @Param GroupInviteVO 群id、好友id列表 |
|||
**/ |
|||
@Override |
|||
public void invite(GroupInviteVO vo) { |
|||
UserSession session = SessionContext.getSession(); |
|||
// 已经在群里面用户,不可重复加入
|
|||
QueryWrapper<GroupMember> wrapper = new QueryWrapper(); |
|||
wrapper.lambda().eq(GroupMember::getId, vo.getGroupId()) |
|||
.in(GroupMember::getUserId, vo.getFriendIds()); |
|||
if(groupMemberService.count(wrapper)>0){ |
|||
throw new GlobalException(ResultCode.PROGRAM_ERROR, "部分用户已经在群中,邀请失败"); |
|||
} |
|||
// 找出好友信息
|
|||
List<Friends> friends = friendsService.findFriendsByUserId(session.getId()); |
|||
List<Friends> friendsList = vo.getFriendIds().stream().map(id -> |
|||
friends.stream().filter(f -> f.getFriendId().equals(id)).findFirst().get()).collect(Collectors.toList()); |
|||
if (friendsList.size() != vo.getFriendIds().size()) { |
|||
throw new GlobalException(ResultCode.PROGRAM_ERROR, "部分用户不是您的好友,邀请失败"); |
|||
} |
|||
// 批量保存成员数据
|
|||
List<GroupMember> groupMembers = friendsList.stream() |
|||
.map(f -> { |
|||
GroupMember groupMember = new GroupMember(); |
|||
groupMember.setGroupId(vo.getGroupId()); |
|||
groupMember.setUserId(f.getFriendId()); |
|||
groupMember.setAliasName(f.getFriendNickName()); |
|||
groupMember.setHeadImage(f.getFriendHeadImage()); |
|||
return groupMember; |
|||
}).collect(Collectors.toList()); |
|||
if(!groupMembers.isEmpty()) { |
|||
groupMemberService.saveBatch(groupMembers); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
package com.lx.implatform.vo; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
|||
import javax.validation.constraints.NotEmpty; |
|||
import javax.validation.constraints.NotNull; |
|||
import java.util.List; |
|||
|
|||
@Data |
|||
@ApiModel("邀请好友进群请求VO") |
|||
public class GroupInviteVO { |
|||
|
|||
@NotNull(message = "群id不可为空") |
|||
@ApiModelProperty(value = "群id") |
|||
private Long groupId; |
|||
|
|||
@NotEmpty(message = "群id不可为空") |
|||
@ApiModelProperty(value = "好友id列表不可为空") |
|||
private List<Long> friendIds; |
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
package com.lx.implatform.vo; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.IdType; |
|||
import com.baomidou.mybatisplus.annotation.TableField; |
|||
import com.baomidou.mybatisplus.annotation.TableId; |
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
|
|||
import javax.validation.constraints.NotEmpty; |
|||
import javax.validation.constraints.NotNull; |
|||
import java.util.Date; |
|||
|
|||
@Data |
|||
@ApiModel("群信息VO") |
|||
public class GroupVO { |
|||
|
|||
@NotNull(message = "群id不可为空") |
|||
@ApiModelProperty(value = "群id") |
|||
private Long id; |
|||
|
|||
@NotEmpty(message = "群名称不可为空") |
|||
@ApiModelProperty(value = "群名称") |
|||
private String name; |
|||
|
|||
@NotEmpty(message = "群主id不可为空") |
|||
@ApiModelProperty(value = "群主id") |
|||
private Long ownerId; |
|||
|
|||
@ApiModelProperty(value = "头像") |
|||
private String headImage; |
|||
|
|||
@ApiModelProperty(value = "头像缩略图") |
|||
private String headImageThumb; |
|||
|
|||
@ApiModelProperty(value = "群公告") |
|||
private String notice; |
|||
|
|||
@ApiModelProperty(value = "群备注") |
|||
private String remark; |
|||
|
|||
|
|||
} |
|||
Loading…
Reference in new issue