yangys
2024-04-04 ed4a5236bab800094be4a8378f5098eebe3de6ac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.qianwen.smartman.modules.notify.websocket;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketSession;
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.qianwen.core.jwt.JwtUtil;
import com.qianwen.core.secure.utils.AuthUtil;
import com.qianwen.core.websocket.config.WebSocketMessageSender;
import com.qianwen.core.websocket.handler.JsonMessageHandler;
import com.qianwen.smartman.modules.notify.entity.NotifySystem;
import com.qianwen.smartman.modules.notify.service.INotifySystemService;
 
import io.jsonwebtoken.Claims;
 
@Component
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/notify/websocket/InternalMessageDataJsonMessageHandler.class */
public class InternalMessageDataJsonMessageHandler implements JsonMessageHandler<InternalMessageRequestJsonWebSocketMessage> {
    private static final Logger log = LoggerFactory.getLogger(InternalMessageDataJsonMessageHandler.class);
    private INotifySystemService notifySystemService;
 
 
    public InternalMessageDataJsonMessageHandler(final INotifySystemService notifySystemService) {
        this.notifySystemService = notifySystemService;
    }
 
    public void handle(WebSocketSession session, InternalMessageRequestJsonWebSocketMessage message) {
        try {
            String uri = session.getUri().getQuery();
            Claims claims = AuthUtil.parseJWT(JwtUtil.getToken(uri.substring(uri.lastIndexOf("=") + 1)));
            long unNotificationCount = this.notifySystemService.count(Wrappers.<NotifySystem>lambdaQuery()
                    .ne(NotifySystem::getStatus, 1)
                    .eq(NotifySystem::getNotifyUser, claims.get("user_id")));
            /*
            long unNotificationCount = this.notifySystemService.count((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().ne((v0) -> {
                return v0.getStatus();
            }, 1)).eq((v0) -> {
                return v0.getNotifyUser();
            }, claims.get("user_id")));*/
            InternalMessageResponseJsonWebSocketMessage internalMessageResponseJsonWebSocketMessage = new InternalMessageResponseJsonWebSocketMessage();
            internalMessageResponseJsonWebSocketMessage.setHaveUnread(unNotificationCount > 0);
            WebSocketMessageSender.send(session, internalMessageResponseJsonWebSocketMessage);
        } catch (Exception e) {
            log.error("消息通知websocket连接异常,异常信息为", e);
        }
    }
 
    public String type() {
        return "internalMessageData";
    }
 
    public Class<InternalMessageRequestJsonWebSocketMessage> getMessageClass() {
        return InternalMessageRequestJsonWebSocketMessage.class;
    }
}