| | |
| | | package com.whyc.webSocket; |
| | | |
| | | import com.whyc.config.WebSocketConfig; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.dto.paramter.AlarmPar; |
| | | import com.whyc.service.BattalarmDataService; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.servlet.http.HttpSession; |
| | | import javax.websocket.*; |
| | | import javax.websocket.server.ServerEndpoint; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | @Component |
| | | @ServerEndpoint(value = "/battAlarmData",encoders = WebSocketEncoder.class) |
| | | @ServerEndpoint(value = "/battAlarmData", encoders = WebSocketEncoder.class, configurator = WebSocketConfig.class) |
| | | public class BattAlarmDataSocket { |
| | | private volatile Thread thread; |
| | | |
| | | private static final int executeTime = 10000; |
| | | |
| | | private volatile boolean runFlag=true; |
| | | private volatile boolean runFlag = true; |
| | | |
| | | private volatile Map<String,Thread> threadMap = new HashMap<>(); |
| | | private volatile Map<String, Thread> threadMap = new HashMap<>(); |
| | | |
| | | private volatile Map<Long,Boolean> threadFlagMap = new HashMap<>(); |
| | | private volatile Map<Long, Boolean> threadFlagMap = new HashMap<>(); |
| | | |
| | | private static BattalarmDataService service; |
| | | |
| | | private Session session; |
| | | |
| | | private HttpSession httpSession; |
| | | |
| | | private String lang; |
| | | |
| | | @Autowired |
| | | public void setService(BattalarmDataService service){ |
| | | public void setService(BattalarmDataService service) { |
| | | BattAlarmDataSocket.service = service; |
| | | } |
| | | |
| | | @OnOpen |
| | | public void onOpen(Session session){ |
| | | this.session=session; |
| | | public void onOpen(Session session, EndpointConfig config) { |
| | | this.session = session; |
| | | this.httpSession = (HttpSession) config.getUserProperties().get("httpSession"); |
| | | this.lang = (String) this.httpSession.getAttribute("lang"); |
| | | } |
| | | |
| | | @OnMessage |
| | | public synchronized void onMessage(Session session, String message){ |
| | | public synchronized void onMessage(Session session, String message) { |
| | | AlarmPar alarmPar = ActionUtil.getGson().fromJson(message, AlarmPar.class); |
| | | thread = new Thread("Thread_battAlarmData") { |
| | | @Override |
| | | public void run() { |
| | | while (runFlag&&!isInterrupted()) { |
| | | while (runFlag && !isInterrupted()) { |
| | | Thread thread = currentThread(); |
| | | threadFlagMap.put(thread.getId(),true); |
| | | threadFlagMap.put(thread.getId(), true); |
| | | try { |
| | | Map<String, Response> res = new HashMap<>(); |
| | | //查询已确认信息 |
| | | alarmPar.setAlmIsConfirmed(1); |
| | | Response confirmedAlarms = service.serchByConditionOfWebSocket(alarmPar); |
| | | Response confirmedAlarms = service.serchByConditionOfWebSocket(alarmPar, lang); |
| | | res.put("confirmedAlarms", confirmedAlarms); |
| | | alarmPar.setAlmIsConfirmed(0); |
| | | Response unconfirmedAlarms = service.serchByConditionOfWebSocket(alarmPar); |
| | | Response unconfirmedAlarms = service.serchByConditionOfWebSocket(alarmPar, lang); |
| | | res.put("unconfirmedAlarms", unconfirmedAlarms); |
| | | //查询分级告警的个数 |
| | | Response levelRes = service.serchByLevel(alarmPar.getUId()); |