| | |
| | | package com.ycl.jxkg.server; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.google.gson.JsonObject; |
| | | import com.ycl.jxkg.domain.entity.Message; |
| | | import com.ycl.jxkg.domain.query.WebSocketQuery; |
| | | import com.ycl.jxkg.enums.WebsocketCommendEnum; |
| | | import com.ycl.jxkg.service.EducationResourceService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.servlet.http.HttpSession; |
| | | import javax.websocket.OnClose; |
| | | import javax.websocket.OnMessage; |
| | | import javax.websocket.OnOpen; |
| | |
| | | @ServerEndpoint("/websocket/{userId}") |
| | | public class WebsocketServer { |
| | | |
| | | @Autowired |
| | | private EducationResourceService educationResourceService; |
| | | /** |
| | | * 线程安全的无序的集合 |
| | | */ |
| | |
| | | |
| | | @OnMessage |
| | | public void onMessage(String message) { |
| | | WebSocketQuery webSocketQuery = JSONObject.parseObject(message, WebSocketQuery.class); |
| | | String commend = webSocketQuery.getCommend(); |
| | | Integer userId = webSocketQuery.getId(); |
| | | if(WebsocketCommendEnum.RECORD_STUDY_TIME.getCommend().equals(commend)){ |
| | | educationResourceService.recordTime(userId); |
| | | } |
| | | log.info("【WebSocket消息】收到客户端消息:" + message); |
| | | } |
| | | |