copy from src/main/java/com/whyc/webSocket/DevInfSocket.java
copy to src/main/java/com/whyc/webSocket/DevLithiumAlarmSocket.java
File was copied from src/main/java/com/whyc/webSocket/DevInfSocket.java |
| | |
| | | package com.whyc.webSocket; |
| | | |
| | | import com.whyc.config.WebSocketConfig; |
| | | import com.whyc.dto.DevInfDto; |
| | | import com.whyc.dto.DevA200AlarmDto; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.pojo.db_user.UserInf; |
| | | import com.whyc.service.DevInfService; |
| | | import com.whyc.service.DevLithiumAlarmDataService; |
| | | import com.whyc.util.ActionUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | * 设备实时连接信息 |
| | | */ |
| | | @Component |
| | | @ServerEndpoint(value = "/dinfSocket",encoders = WebSocketEncoder.class,configurator = WebSocketConfig.class) |
| | | public class DevInfSocket { |
| | | @ServerEndpoint(value = "/devLithiumAlarm",encoders = WebSocketEncoder.class,configurator = WebSocketConfig.class) |
| | | public class DevLithiumAlarmSocket { |
| | | private Session session; |
| | | |
| | | private Thread thread; |
| | | |
| | | private static DevInfService dinfService; |
| | | private static DevLithiumAlarmDataService service; |
| | | |
| | | private HttpSession httpSession; |
| | | |
| | |
| | | private volatile Map<Long,Boolean> threadFlagMap = new HashMap<>(); |
| | | |
| | | @Autowired |
| | | public void setDevInfService(DevInfService dinfService) { |
| | | DevInfSocket.dinfService = dinfService; |
| | | public void setService(DevLithiumAlarmDataService service) { |
| | | DevLithiumAlarmSocket.service = service; |
| | | } |
| | | |
| | | @OnOpen |
| | |
| | | } |
| | | @OnMessage |
| | | public void onMessage(Session session, String message) { |
| | | DevInfDto devInfDto = ActionUtil.getGson("yyyy-MM-dd").fromJson(message, DevInfDto.class); |
| | | DevA200AlarmDto dto = ActionUtil.getGson("yyyy-MM-dd HH:mm:ss").fromJson(message, DevA200AlarmDto.class); |
| | | UserInf user = (UserInf) this.httpSession.getAttribute("user"); |
| | | final int userId = user.getUid(); |
| | | //final int userId = 101; |
| | | thread = new Thread("Thread_DinfSocket") { |
| | | thread = new Thread("Thread_DevLithiumAlarmSocket") { |
| | | @Override |
| | | public void run() { |
| | | while (runFlag && !isInterrupted()) { |
| | | Thread thread = currentThread(); |
| | | threadFlagMap.put(thread.getId(), true); |
| | | try { |
| | | Response res=dinfService.getAllInf(userId, devInfDto); |
| | | Response res=service.getPage(userId, dto); |
| | | if (session.isOpen()) { |
| | | //推送信息 |
| | | synchronized (session) { |