Browse Source

添加分组、标签、快捷回复、默认展示游客信息、所属地检查下

master
[yxf] 1 month ago
parent
commit
e703a76059
  1. 30
      im-platform/src/main/java/com/bx/implatform/controller/QuickReplyController.java
  2. 42
      im-platform/src/main/java/com/bx/implatform/controller/UserController.java
  3. 24
      im-platform/src/main/java/com/bx/implatform/entity/QuickReply.java
  4. 2
      im-platform/src/main/java/com/bx/implatform/entity/UserGroup.java
  5. 2
      im-platform/src/main/java/com/bx/implatform/entity/UserLabel.java
  6. 9
      im-platform/src/main/java/com/bx/implatform/mapper/QuickReplyMapper.java
  7. 8
      im-platform/src/main/java/com/bx/implatform/service/QuickReplyService.java
  8. 7
      im-platform/src/main/java/com/bx/implatform/service/UserGroupService.java
  9. 5
      im-platform/src/main/java/com/bx/implatform/service/UserLabelService.java
  10. 31
      im-platform/src/main/java/com/bx/implatform/service/UserService.java
  11. 49
      im-platform/src/main/java/com/bx/implatform/service/impl/QuickReplyServiceImpl.java
  12. 14
      im-platform/src/main/java/com/bx/implatform/service/impl/UserGroupServiceImpl.java
  13. 14
      im-platform/src/main/java/com/bx/implatform/service/impl/UserLabelServiceImpl.java
  14. 110
      im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java
  15. 16
      im-platform/src/main/java/com/bx/implatform/vo/QuickReplyVO.java
  16. 15
      im-platform/src/main/java/com/bx/implatform/vo/UserGroupVO.java
  17. 15
      im-platform/src/main/java/com/bx/implatform/vo/UserLabelVO.java
  18. 13
      im-platform/src/main/java/com/bx/implatform/vo/UserVO.java
  19. 612
      im-web/src/components/chat/ChatBox.vue

30
im-platform/src/main/java/com/bx/implatform/controller/QuickReplyController.java

@ -0,0 +1,30 @@
package com.bx.implatform.controller;
import com.bx.implatform.result.Result;
import com.bx.implatform.result.ResultUtils;
import com.bx.implatform.service.QuickReplyService;
import com.bx.implatform.vo.QuickReplyVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@Tag(name = "快捷回复")
@RestController
@RequestMapping("/quick/reply")
@RequiredArgsConstructor
public class QuickReplyController {
private final QuickReplyService quickReplyService;
@GetMapping("/list")
@Operation(summary = "获取快捷回复列表", description = "前端聊天页调用")
public Result<List<QuickReplyVO>> getList(@RequestParam Long userId) {
return ResultUtils.success(quickReplyService.getList(userId));
}
}

42
im-platform/src/main/java/com/bx/implatform/controller/UserController.java

@ -62,6 +62,47 @@ public class UserController {
return ResultUtils.success(userService.findUserById(id)); return ResultUtils.success(userService.findUserById(id));
} }
@PostMapping("/group/save")
@Operation(summary = "保存用户分组", description = "单个分组,保存到 group_ids 字段")
public Result<?> saveGroup(@RequestBody JSONObject jsonObject) {
Long userId = jsonObject.getLong("userId");
String groupId = jsonObject.getStr("groupIds"); // 前端传分组ID
if (ObjectUtil.isNull(userId) || ObjectUtil.isEmpty(groupId)) {
return ResultUtils.error(ResultCode.PROGRAM_ERROR, "参数不能为空");
}
userService.saveUserGroup(userId, groupId);
return ResultUtils.success();
}
@PostMapping("/label/save")
@Operation(summary = "保存用户标签")
public Result<?> saveLabel(@RequestBody JSONObject jsonObject) {
Long userId = jsonObject.getLong("userId");
String labelIds = jsonObject.getStr("labelIds");
// if (ObjectUtil.isNull(userId) || ObjectUtil.isEmpty(labelIds)) {
// return ResultUtils.error(ResultCode.PROGRAM_ERROR, "参数不能为空");
// }
userService.saveUserLabel(userId, labelIds);
return ResultUtils.success();
}
@GetMapping("/group/{id}")
@Operation(summary = "查询分组", description = "根据id查找分组")
public Result<UserVO> group(@NotNull @PathVariable("id") Long id) {
return ResultUtils.success(userService.getGroup(id));
}
@GetMapping("/label/{id}")
@Operation(summary = "重新分组", description = "根据id查找分组")
public Result<UserVO> label(@NotNull @PathVariable("id") Long id) {
return ResultUtils.success(userService.getLabe(id));
}
@PutMapping("/update") @PutMapping("/update")
@Operation(summary = "修改用户信息", description = "修改用户信息,仅允许修改登录用户信息") @Operation(summary = "修改用户信息", description = "修改用户信息,仅允许修改登录用户信息")
public Result update(@Valid @RequestBody UserVO vo) { public Result update(@Valid @RequestBody UserVO vo) {
@ -165,5 +206,6 @@ public class UserController {
return ResultUtils.success(vo); return ResultUtils.success(vo);
} }
} }

24
im-platform/src/main/java/com/bx/implatform/entity/QuickReply.java

@ -0,0 +1,24 @@
package com.bx.implatform.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.time.LocalDateTime;
@Data
@TableName("im_quick_reply")
public class QuickReply {
@TableId(type = IdType.AUTO)
private Long id;
private String uniqueToken;
private String replyName;
private Integer replyType;
private String replyTitle;
private String replyContent;
private String remark;
private LocalDateTime createdTime;
private LocalDateTime updatedTime;
private Long creatorId;
private Long updaterId;
}

2
im-platform/src/main/java/com/bx/implatform/entity/UserGroup.java

@ -20,6 +20,8 @@ public class UserGroup {
@TableId(type = IdType.AUTO) @TableId(type = IdType.AUTO)
private Long id; private Long id;
private String uniqueToken;
private String groupName; private String groupName;
} }

2
im-platform/src/main/java/com/bx/implatform/entity/UserLabel.java

@ -21,6 +21,8 @@ public class UserLabel {
@TableId(type = IdType.AUTO) @TableId(type = IdType.AUTO)
private Long id; private Long id;
private String uniqueToken;
private String labelName; private String labelName;
} }

9
im-platform/src/main/java/com/bx/implatform/mapper/QuickReplyMapper.java

@ -0,0 +1,9 @@
package com.bx.implatform.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bx.implatform.entity.QuickReply;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface QuickReplyMapper extends BaseMapper<QuickReply> {
}

8
im-platform/src/main/java/com/bx/implatform/service/QuickReplyService.java

@ -0,0 +1,8 @@
package com.bx.implatform.service;
import com.bx.implatform.vo.QuickReplyVO;
import java.util.List;
public interface QuickReplyService {
List<QuickReplyVO> getList(Long userId);
}

7
im-platform/src/main/java/com/bx/implatform/service/UserGroupService.java

@ -10,4 +10,11 @@ public interface UserGroupService extends IService<UserGroup> {
* 根据分组ID列表获取分组名称列表 * 根据分组ID列表获取分组名称列表
*/ */
List<String> getGroupNamesByIds(String groupIds); List<String> getGroupNamesByIds(String groupIds);
/**
* 获取token相同的分组
*/
List<UserGroup> getGroupList(String token);
} }

5
im-platform/src/main/java/com/bx/implatform/service/UserLabelService.java

@ -10,4 +10,9 @@ public interface UserLabelService extends IService<UserLabel> {
* 根据标签ID列表获取标签名称列表 * 根据标签ID列表获取标签名称列表
*/ */
List<String> getLabelNamesByIds(String labelIds); List<String> getLabelNamesByIds(String labelIds);
/**
* 获取token相同的标签
*/
List<UserLabel> getLabelList(String token);
} }

31
im-platform/src/main/java/com/bx/implatform/service/UserService.java

@ -74,6 +74,37 @@ public interface UserService extends IService<User> {
*/ */
UserVO findUserById(Long id); UserVO findUserById(Long id);
/**
* 根据用户id查询分组
*
* @param id 用户id
* @return 用户信息
*/
UserVO getGroup(Long id);
/**
* 根据用户id查询标签
*
* @param id 用户id
* @return 用户信息
*/
UserVO getLabe(Long id);
/**
* 保存用户分组
* @param userId 目标用户ID
* @param groupId 分组ID
*/
void saveUserGroup(Long userId, String groupId);
/**
* 保存用户标签
* @param userId 用户ID
* @param labelIds 标签ID逗号分隔
*/
void saveUserLabel(Long userId, String labelIds);
/** /**
* 根据用户昵称查询用户最多返回20条数据 * 根据用户昵称查询用户最多返回20条数据
* *

49
im-platform/src/main/java/com/bx/implatform/service/impl/QuickReplyServiceImpl.java

@ -0,0 +1,49 @@
package com.bx.implatform.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bx.implatform.entity.QuickReply;
import com.bx.implatform.entity.User;
import com.bx.implatform.mapper.QuickReplyMapper;
import com.bx.implatform.mapper.UserMapper;
import com.bx.implatform.service.QuickReplyService;
import com.bx.implatform.vo.QuickReplyVO;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
public class QuickReplyServiceImpl extends ServiceImpl<QuickReplyMapper, QuickReply> implements QuickReplyService {
private final UserMapper userMapper;
@Override
public List<QuickReplyVO> getList(Long userId) {
// 1. 根据前端传的 userId 查询用户
User user = userMapper.selectById(userId);
if (user == null) {
return List.of();
}
// 2. 拿到用户的 uniqueToken
String uniqueToken = user.getUniqueToken();
// 3. 匹配快捷回复
LambdaQueryWrapper<QuickReply> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(QuickReply::getUniqueToken, uniqueToken);
wrapper.orderByAsc(QuickReply::getCreatedTime);
List<QuickReply> list = this.list(wrapper);
// 4. 转VO返回
return list.stream().map(item -> {
QuickReplyVO vo = new QuickReplyVO();
BeanUtils.copyProperties(item, vo);
return vo;
}).collect(Collectors.toList());
}
}

14
im-platform/src/main/java/com/bx/implatform/service/impl/UserGroupServiceImpl.java

@ -43,4 +43,18 @@ public class UserGroupServiceImpl extends ServiceImpl<UserGroupMapper, UserGroup
.map(UserGroup::getGroupName) .map(UserGroup::getGroupName)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@Override
public List<UserGroup> getGroupList(String token) {
if (!StringUtils.hasText(token)) {
return Collections.emptyList();
}
// 查询与该token匹配的分组
LambdaQueryWrapper<UserGroup> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(UserGroup::getUniqueToken, token);
// 直接返回完整的UserGroup对象列表
return this.list(wrapper);
}
} }

14
im-platform/src/main/java/com/bx/implatform/service/impl/UserLabelServiceImpl.java

@ -2,6 +2,7 @@ package com.bx.implatform.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bx.implatform.entity.UserGroup;
import com.bx.implatform.entity.UserLabel; import com.bx.implatform.entity.UserLabel;
import com.bx.implatform.mapper.UserLabelMapper; import com.bx.implatform.mapper.UserLabelMapper;
import com.bx.implatform.service.UserLabelService; import com.bx.implatform.service.UserLabelService;
@ -43,4 +44,17 @@ public class UserLabelServiceImpl extends ServiceImpl<UserLabelMapper, UserLabel
.map(UserLabel::getLabelName) .map(UserLabel::getLabelName)
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
public List<UserLabel> getLabelList(String token) {
if (!StringUtils.hasText(token)) {
return Collections.emptyList();
}
// 查询与该token匹配的分组
LambdaQueryWrapper<UserLabel> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(UserLabel::getUniqueToken, token);
// 直接返回完整的UserLabel对象列表
return this.list(wrapper);
}
} }

110
im-platform/src/main/java/com/bx/implatform/service/impl/UserServiceImpl.java

@ -16,9 +16,7 @@ import com.bx.implatform.config.props.JwtProperties;
import com.bx.implatform.dto.LoginDTO; import com.bx.implatform.dto.LoginDTO;
import com.bx.implatform.dto.ModifyPwdDTO; import com.bx.implatform.dto.ModifyPwdDTO;
import com.bx.implatform.dto.RegisterDTO; import com.bx.implatform.dto.RegisterDTO;
import com.bx.implatform.entity.Friend; import com.bx.implatform.entity.*;
import com.bx.implatform.entity.GroupMember;
import com.bx.implatform.entity.User;
import com.bx.implatform.enums.ResultCode; import com.bx.implatform.enums.ResultCode;
import com.bx.implatform.exception.GlobalException; import com.bx.implatform.exception.GlobalException;
import com.bx.implatform.mapper.UserMapper; import com.bx.implatform.mapper.UserMapper;
@ -29,9 +27,7 @@ import com.bx.implatform.session.UserSession;
import com.bx.implatform.util.BeanUtils; import com.bx.implatform.util.BeanUtils;
import com.bx.implatform.util.IpUtils; import com.bx.implatform.util.IpUtils;
import com.bx.implatform.util.SensitiveFilterUtil; import com.bx.implatform.util.SensitiveFilterUtil;
import com.bx.implatform.vo.LoginVO; import com.bx.implatform.vo.*;
import com.bx.implatform.vo.OnlineTerminalVO;
import com.bx.implatform.vo.UserVO;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -61,6 +57,10 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
private UserLabelService userLabelService; private UserLabelService userLabelService;
@Autowired @Autowired
private UserGroupService UserGroupService; private UserGroupService UserGroupService;
private final UserGroupService userGroupService; // 注入 UserGroupService
// @Autowired
// private UserLabelService UserLabelService;
private final UserLabelService UserLabelService; // 注入 UserGroupService
// @Override // @Override
// public LoginVO login(LoginDTO dto) { // public LoginVO login(LoginDTO dto) {
@ -341,6 +341,104 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
return vo; return vo;
} }
@Override
public UserVO getGroup(Long id) {
User user = this.getById(id);
if (user == null) {
throw new GlobalException(ResultCode.PROGRAM_ERROR);
}
UserVO vo = BeanUtils.copyProperties(user, UserVO.class);
// 获取用户的分组信息并转换为VO
String token = user.getUniqueToken();
if (StringUtils.hasText(token)) {
List<UserGroup> groups = userGroupService.getGroupList(token);
// 转换为UserGroupVO
List<UserGroupVO> groupVOList = groups.stream()
.map(g -> new UserGroupVO(g.getId(), g.getGroupName()))
.collect(Collectors.toList());
vo.setGroupList(groupVOList);
// 设置分组名称列表
List<String> groupNames = groups.stream()
.map(UserGroup::getGroupName)
.collect(Collectors.toList());
} else {
vo.setGroupList(new ArrayList<>());
}
return vo;
}
@Override
public UserVO getLabe(Long id) {
User user = this.getById(id);
if (user == null) {
throw new GlobalException(ResultCode.PROGRAM_ERROR);
}
UserVO vo = BeanUtils.copyProperties(user, UserVO.class);
// 获取用户的分组信息并转换为VO
String token = user.getUniqueToken();
if (StringUtils.hasText(token)) {
List<UserLabel> label = UserLabelService.getLabelList(token);
// 转换为UserGroupVO
List<UserLabelVO> labelVOList = label.stream()
.map(g -> new UserLabelVO(g.getId(), g.getLabelName()))
.collect(Collectors.toList());
vo.setLabelList(labelVOList);
// 设置标签名称列表
List<String> labelNames = label.stream()
.map(UserLabel::getLabelName)
.collect(Collectors.toList());
} else {
vo.setLabelList(new ArrayList<>());
}
return vo;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void saveUserGroup(Long userId, String groupId) {
// 获取目标用户
User targetUser = this.getById(userId);
if (ObjectUtil.isNull(targetUser)) {
throw new GlobalException(ResultCode.PROGRAM_ERROR);
}
// 设置分组ID
targetUser.setGroupIds(groupId);
// 更新用户信息到数据库
boolean updated = this.updateById(targetUser);
if (!updated) {
throw new GlobalException(ResultCode.PROGRAM_ERROR, "更新用户分组失败");
}
log.info("用户 {} 的分组已更新为: {}", userId, groupId);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void saveUserLabel(Long userId, String labelIds) {
User user = this.getById(userId);
log.info("用户 {} 的分组已更新为: {}", userId, labelIds);
if (ObjectUtil.isNull(user)) {
throw new GlobalException(ResultCode.PROGRAM_ERROR, "用户不存在");
}
// 保存标签ID串
user.setLabelIds(labelIds);
this.updateById(user);
log.info("用户{}标签保存成功: {}", userId, labelIds);
}
@Override @Override
public List<UserVO> findUserByName(String name) { public List<UserVO> findUserByName(String name) {
LambdaQueryWrapper<User> queryWrapper = Wrappers.lambdaQuery(); LambdaQueryWrapper<User> queryWrapper = Wrappers.lambdaQuery();

16
im-platform/src/main/java/com/bx/implatform/vo/QuickReplyVO.java

@ -0,0 +1,16 @@
package com.bx.implatform.vo;
import lombok.Data;
import java.time.LocalDateTime;
@Data
public class QuickReplyVO {
private Long id;
private String uniqueToken;
private String replyName;
private Integer replyType; // 0文本 1图片
private String replyTitle;
private String replyContent;
private String remark;
private LocalDateTime createdTime;
}

15
im-platform/src/main/java/com/bx/implatform/vo/UserGroupVO.java

@ -0,0 +1,15 @@
package com.bx.implatform.vo;
import lombok.Data;
@Data
public class UserGroupVO {
private Long id;
private String groupName;
// 构造方法
public UserGroupVO(Long id, String groupName) {
this.id = id;
this.groupName = groupName;
}
}

15
im-platform/src/main/java/com/bx/implatform/vo/UserLabelVO.java

@ -0,0 +1,15 @@
package com.bx.implatform.vo;
import lombok.Data;
@Data
public class UserLabelVO {
private Long id;
private String labelName;
// 构造方法
public UserLabelVO(Long id, String labelName) {
this.id = id;
this.labelName = labelName;
}
}

13
im-platform/src/main/java/com/bx/implatform/vo/UserVO.java

@ -1,5 +1,6 @@
package com.bx.implatform.vo; package com.bx.implatform.vo;
import com.bx.implatform.entity.UserGroup;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
@ -15,6 +16,9 @@ public class UserVO {
@Schema(description = "id") @Schema(description = "id")
private Long id; private Long id;
@Schema(description = "代理标识token")
private String uniqueToken;
@NotEmpty(message = "用户名不能为空") @NotEmpty(message = "用户名不能为空")
@Length(max = 20, message = "用户名不能大于20字符") @Length(max = 20, message = "用户名不能大于20字符")
@Schema(description = "用户名") @Schema(description = "用户名")
@ -65,4 +69,13 @@ public class UserVO {
@Schema(description = "分组名称列表") @Schema(description = "分组名称列表")
private List<String> groupNames; private List<String> groupNames;
// @Schema(description = "所有分组名称")
// private List<String> groupNameList;
// 修改为完整的UserGroup列表
private List<UserGroupVO> groupList; // 完整的分组信息列表
// 修改为完整的UserGroup列表
private List<UserLabelVO> labelList; // 完整的分组信息列表
} }

612
im-web/src/components/chat/ChatBox.vue

File diff suppressed because it is too large
Loading…
Cancel
Save