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;
|
}
|
}
|