| | |
| | | package com.ltkj.web.websocket; |
| | | |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ltkj.common.core.domain.model.LoginUser; |
| | | import com.ltkj.hosp.domain.SysNoticeUser; |
| | | import com.ltkj.hosp.service.SysNoticeUserService; |
| | | import com.ltkj.system.domain.SysNotice; |
| | | import com.ltkj.system.service.ISysNoticeService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.socket.CloseStatus; |
| | | import org.springframework.web.socket.TextMessage; |
| | |
| | | import redis.clients.jedis.util.SafeEncoder; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.stream.Collectors; |
| | |
| | | @Slf4j |
| | | @Component |
| | | public class WebSockerManager extends TextWebSocketHandler { |
| | | |
| | | @Autowired |
| | | private SysNoticeUserService noticeUserService; |
| | | @Autowired |
| | | private ISysNoticeService noticeService; |
| | | |
| | | public final ConcurrentHashMap<String, ClientSessionInfo> userSessions = new ConcurrentHashMap<>(); |
| | | private static final ConcurrentHashMap<String, WebSocketClientInfo> sessions = new ConcurrentHashMap<>(); |
| | |
| | | userSessions.put(String.valueOf(clientInfo.getUid()), sessionInfo); |
| | | session.sendMessage(new TextMessage("连接成功")); |
| | | log.info("[WebSocket] 在线列表UserIds\n{}",JSONUtil.toJsonStr(new ArrayList<>(userSessions.keySet()))); |
| | | LambdaQueryWrapper<SysNoticeUser> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(SysNoticeUser::getUserId,clientInfo.getUid()); |
| | | wrapper.eq(SysNoticeUser::getIsRead,0); |
| | | List<SysNoticeUser> list = noticeUserService.list(wrapper); |
| | | if (list != null && !list.isEmpty()){ |
| | | List<Long> noticeIds = list.stream().map(SysNoticeUser::getNoticeId).collect(Collectors.toList()); |
| | | for (Long noticeId : noticeIds) { |
| | | session.sendMessage(new TextMessage(JSONUtil.toJsonStr(noticeService.getById(noticeId)))); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |