09-12-netty优化
This commit is contained in:
		| @ -155,8 +155,10 @@ public class ChatServerHandler extends SimpleChannelInboundHandler<TextWebSocket | ||||
|                 message.put("type", "3"); | ||||
|                 message.put("unReadCount", roomCounts); | ||||
|                 log.info("发送所有未读消息:{}",message); | ||||
|                 if(!roomCounts.isEmpty()) { | ||||
|                     sendMessage(ctx, message.toJSONString()); | ||||
|                 } | ||||
|             } | ||||
|             //认证完成后开始构建系统消息房间   判断是否有系统消息房间 没有则增加 | ||||
|             if (!isHaveSystemRoom){ | ||||
|                 ChatGroup chatGroup = new ChatGroup(); | ||||
| @ -277,7 +279,7 @@ public class ChatServerHandler extends SimpleChannelInboundHandler<TextWebSocket | ||||
|                                 temp.put(value,userRoomCountMap.get(value)); | ||||
|                             } | ||||
|                         }); | ||||
|                         jsonObject.put("unReadCount", JsonUtils.toJsonString(temp)); | ||||
|                         jsonObject.put("unReadCount", temp); | ||||
|                         //给每个通道发送对应消息 | ||||
|                         for (ChannelHandlerContext handlerContext : channelHandlerContexts) { | ||||
|                             sendMessage(handlerContext, jsonObject.toString()); | ||||
|  | ||||
| @ -4,7 +4,10 @@ package org.dromara.websocket.controller; | ||||
| import cn.dev33.satoken.annotation.SaCheckPermission; | ||||
| import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||||
| import org.dromara.common.core.domain.R; | ||||
| import org.dromara.common.mybatis.core.page.PageQuery; | ||||
| import org.dromara.common.mybatis.core.page.TableDataInfo; | ||||
| import org.dromara.common.satoken.utils.LoginHelper; | ||||
| import org.dromara.system.domain.bo.SysUserBo; | ||||
| import org.dromara.system.domain.vo.SysUserVo; | ||||
| import org.dromara.system.service.impl.SysUserServiceImpl; | ||||
| import org.dromara.websocket.domain.ChatFriendship; | ||||
| @ -129,17 +132,18 @@ public class ChatFriendshipController { | ||||
|      */ | ||||
| //    @SaCheckPermission("chatGroup:chatFriendship:getList") | ||||
|     @GetMapping("/getList") | ||||
|     public R<List<SysUserVo>> getList(){ | ||||
|         Long userId = LoginHelper.getLoginUser().getUserId(); | ||||
|         LambdaQueryWrapper<ChatFriendship> lambdaQueryWrapper = new LambdaQueryWrapper<>(); | ||||
|         lambdaQueryWrapper.eq(ChatFriendship::getOurSide,userId); | ||||
|         List<ChatFriendship> list = chatFriendshipService.list(lambdaQueryWrapper); | ||||
|  | ||||
|         List<SysUserVo> sysUserVos = new ArrayList<>(); | ||||
|         for (ChatFriendship chatFriendship : list) { | ||||
|             sysUserVos.add(sysUserService.selectUserById(chatFriendship.getOtherSide())); | ||||
|         } | ||||
|         return R.ok(sysUserVos); | ||||
|     public TableDataInfo<SysUserVo> getList(SysUserBo bo, PageQuery pageQuery){ | ||||
| //        Long userId = LoginHelper.getLoginUser().getUserId(); | ||||
| //        LambdaQueryWrapper<ChatFriendship> lambdaQueryWrapper = new LambdaQueryWrapper<>(); | ||||
| //        lambdaQueryWrapper.eq(ChatFriendship::getOurSide, userId); | ||||
| //        List<ChatFriendship> list = chatFriendshipService.list(lambdaQueryWrapper); | ||||
| // | ||||
| //        List<SysUserVo> sysUserVos = new ArrayList<>(); | ||||
| //        for (ChatFriendship chatFriendship : list) { | ||||
| //            sysUserVos.add(sysUserService.selectUserById(chatFriendship.getOtherSide())); | ||||
| //        } | ||||
| //        return R.ok(sysUserVos); | ||||
|         return chatFriendshipService.getAppUserList(bo,pageQuery); | ||||
|     } | ||||
|  | ||||
| } | ||||
|  | ||||
| @ -1,11 +1,92 @@ | ||||
| package org.dromara.websocket.service.Impl; | ||||
|  | ||||
| import cn.hutool.core.collection.CollUtil; | ||||
| import cn.hutool.core.convert.Convert; | ||||
| import cn.hutool.core.util.ObjectUtil; | ||||
| import com.baomidou.mybatisplus.core.conditions.Wrapper; | ||||
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | ||||
| import com.baomidou.mybatisplus.core.toolkit.Wrappers; | ||||
| import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | ||||
| import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | ||||
| import jakarta.annotation.Resource; | ||||
| import org.dromara.common.core.constant.SystemConstants; | ||||
| import org.dromara.common.core.utils.StreamUtils; | ||||
| import org.dromara.common.core.utils.StringUtils; | ||||
| import org.dromara.common.mybatis.core.page.PageQuery; | ||||
| import org.dromara.common.mybatis.core.page.TableDataInfo; | ||||
| import org.dromara.system.domain.SysDept; | ||||
| import org.dromara.system.domain.SysUser; | ||||
| import org.dromara.system.domain.SysUserFile; | ||||
| import org.dromara.system.domain.bo.SysUserBo; | ||||
| import org.dromara.system.domain.vo.SysUserVo; | ||||
| import org.dromara.system.mapper.SysDeptMapper; | ||||
| import org.dromara.system.mapper.SysUserMapper; | ||||
| import org.dromara.system.service.ISysUserFileService; | ||||
| import org.dromara.system.service.impl.SysUserServiceImpl; | ||||
| import org.dromara.websocket.domain.ChatFriendship; | ||||
| import org.dromara.websocket.mapper.ChatFriendshipMapper; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Service; | ||||
|  | ||||
| import java.util.List; | ||||
| import java.util.Map; | ||||
| import java.util.stream.Collectors; | ||||
|  | ||||
| @Service | ||||
| public class ChatFriendshipServiceImpl extends ServiceImpl<ChatFriendshipMapper, ChatFriendship> { | ||||
|  | ||||
|     @Autowired | ||||
|     private SysDeptMapper deptMapper; | ||||
|     @Autowired | ||||
|     private SysUserMapper sysUserMapper; | ||||
|     @Autowired | ||||
|     private ISysUserFileService userFileService; | ||||
|  | ||||
|     public TableDataInfo<SysUserVo> getAppUserList(SysUserBo user, PageQuery pageQuery){ | ||||
|         Page<SysUserVo> page = sysUserMapper.selectPageUserList(pageQuery.build(), this.buildQueryWrapper(user)); | ||||
|         List<SysUserVo> userVoList = page.getRecords(); | ||||
|         List<Long> userIdList = userVoList.stream().map(SysUserVo::getUserId).toList(); | ||||
|         if (CollUtil.isNotEmpty(userIdList)) { | ||||
|             List<SysUserFile> userFileList = userFileService.lambdaQuery() | ||||
|                 .in(SysUserFile::getUserId, userIdList) | ||||
|                 .list(); | ||||
|             Map<Long, List<SysUserFile>> userFileMap = userFileList.stream().collect(Collectors.groupingBy(SysUserFile::getUserId)); | ||||
|             userVoList.forEach(userVo -> { | ||||
|                 Long userId = userVo.getUserId(); | ||||
|                 if (userFileMap.containsKey(userId)) { | ||||
|                     List<SysUserFile> fileList = userFileMap.get(userId); | ||||
|                     String fileIdStr = fileList.stream() | ||||
|                         .map(file -> String.valueOf(file.getFileId())) | ||||
|                         .collect(Collectors.joining(",")); | ||||
|                     userVo.setFilePath(fileIdStr); | ||||
|                 } | ||||
|             }); | ||||
|             page.setRecords(userVoList); | ||||
|         } | ||||
|         return TableDataInfo.build(page); | ||||
|     } | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|     private Wrapper<SysUser> buildQueryWrapper(SysUserBo user) { | ||||
|         Map<String, Object> params = user.getParams(); | ||||
|         QueryWrapper<SysUser> wrapper = Wrappers.query(); | ||||
|         wrapper.eq("u.del_flag", SystemConstants.NORMAL) | ||||
|             .eq(ObjectUtil.isNotNull(user.getUserId()), "u.user_id", user.getUserId()) | ||||
|             .like(StringUtils.isNotBlank(user.getNickName()), "u.nick_name", user.getNickName()) | ||||
|             .like(StringUtils.isNotBlank(user.getUserName()), "u.user_name", user.getUserName()) | ||||
|             .eq(StringUtils.isNotBlank(user.getStatus()), "u.status", user.getStatus()) | ||||
|             .like(StringUtils.isNotBlank(user.getPhonenumber()), "u.phonenumber", user.getPhonenumber()) | ||||
|             .between(params.get("beginTime") != null && params.get("endTime") != null, "u.create_time", params.get("beginTime"), params.get("endTime")) | ||||
|             .eq(ObjectUtil.isNotNull(user.getDeptId()),"u.dept_id", user.getDeptId()) | ||||
|             .orderByAsc("u.user_id"); | ||||
|         if (StringUtils.isNotBlank(user.getExcludeUserIds())) { | ||||
|             wrapper.notIn("u.user_id", StringUtils.splitTo(user.getExcludeUserIds(), Convert::toLong)); | ||||
|         } | ||||
|         return wrapper; | ||||
|     } | ||||
|  | ||||
|  | ||||
|  | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user