123456789101112131415161718192021222324252627282930313233343536373839404142 |
- package com.fjhx.event;
- import com.alibaba.fastjson.JSONObject;
- import com.fjhx.service.WebSocketServer;
- import com.fjhx.utils.Assert;
- import lombok.Getter;
- import org.springframework.context.ApplicationEvent;
- /**
- * webStock接收消息事件
- */
- @Getter
- public class WebSocketOnMessageEvent extends ApplicationEvent {
- private final String userId;
- private final String message;
- public WebSocketOnMessageEvent(WebSocketServer source, String userId, String message) {
- super(source);
- this.userId = userId;
- this.message = message;
- }
- @Override
- public WebSocketServer getSource() {
- return (WebSocketServer) super.getSource();
- }
- public JSONObject getMessageObj() {
- return JSONObject.parseObject(message);
- }
- /**
- * 消息类型
- */
- public Integer getType() {
- Integer type = getMessageObj().getInteger("type");
- Assert.notEmpty(type, "消息类型不能为空");
- return type;
- }
- }
|