|
@@ -1,16 +1,21 @@
|
|
|
package org.jeecg.modules.largeScreen.component;
|
|
|
|
|
|
+import org.jeecg.modules.itdmOpenDaping.entity.ItdmDaping;
|
|
|
+import org.jeecg.modules.itdmOpenDaping.mapper.ItdmDapingMapper;
|
|
|
import org.jeecg.modules.largeScreen.config.CronTaskRegistrar;
|
|
|
import org.jeecg.modules.largeScreen.task.DemoTask2;
|
|
|
import org.jeecg.modules.largeScreen.task.SchedulingRunnable;
|
|
|
import org.jeecg.modules.largeScreen.util.EncoderClassListVo;
|
|
|
import org.jeecg.modules.largeScreen.util.SpringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
+import javax.annotation.Resource;
|
|
|
import javax.websocket.*;
|
|
|
import javax.websocket.server.ServerEndpoint;
|
|
|
import java.io.IOException;
|
|
|
-import java.util.Arrays;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.concurrent.CopyOnWriteArraySet;
|
|
|
|
|
@@ -18,17 +23,27 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|
|
* @ServerEndpoint 注解是一个类层次的注解,它的功能主要是将目前的类定义成一个websocket服务器端,
|
|
|
* 注解的值将被用于监听用户连接的终端访问URL地址,客户端可以通过这个URL来连接到WebSocket服务器端
|
|
|
*/
|
|
|
+
|
|
|
@Component
|
|
|
@ServerEndpoint(value = "/itdmWebsocket/list2", encoders = {EncoderClassListVo.class})
|
|
|
public class WebSocketServer2 {
|
|
|
|
|
|
+// @Resource
|
|
|
+// private ItdmDapingMapper dapingMapper;
|
|
|
+// @Autowired
|
|
|
+// public static WebSocketServer2 testUtils;
|
|
|
+//
|
|
|
+// @PostConstruct
|
|
|
+// public void init(){
|
|
|
+// testUtils = this;
|
|
|
+// }
|
|
|
+
|
|
|
//静态变量,用来记录当前在线连接数。应该把它设计成线程安全的。
|
|
|
private static int onlineCount = 0;
|
|
|
|
|
|
//concurrent包的线程安全Set,用来存放每个客户端对应的WebSocketServer对象。若要实现服务端与单一客户端通信的话,可以使用Map来存放,其中Key可以为用户标识
|
|
|
private static CopyOnWriteArraySet<WebSocketServer2> webSocketSet = new CopyOnWriteArraySet<WebSocketServer2>();
|
|
|
|
|
|
-
|
|
|
private static ConcurrentHashMap<String, SchedulingRunnable> webSocketSet1 = new ConcurrentHashMap<String, SchedulingRunnable>();
|
|
|
// private static String cabid = "";
|
|
|
//与某个客户端的连接会话,需要通过它来给客户端发送数据
|
|
@@ -54,8 +69,8 @@ public class WebSocketServer2 {
|
|
|
webSocketSet.add(this);
|
|
|
|
|
|
sendUser(this.getDemoTask2().chushihua(), session);
|
|
|
-
|
|
|
SchedulingRunnable task = new SchedulingRunnable("demoTask2", "taskWithParamsList", session);
|
|
|
+
|
|
|
addOnlineCount();//在线数加1
|
|
|
this.getCronTaskRegistrar().addCronTask(task, "0/30 * * * * ?");//30秒传一次数据
|
|
|
webSocketSet1.put(session.getId(), task);
|
|
@@ -79,7 +94,26 @@ public class WebSocketServer2 {
|
|
|
@OnMessage
|
|
|
public void onMessage(String message, Session session) throws IOException, EncodeException {
|
|
|
|
|
|
- System.out.println("来自客户端的消息:" + message);
|
|
|
+ System.out.println("来自客户端的消息2:" + message);
|
|
|
+ if(message.equals("打开大屏")){
|
|
|
+
|
|
|
+ List<Map<String,Object>> list = new ArrayList<>();//清空原来的数据
|
|
|
+
|
|
|
+ ItdmDaping daping = new ItdmDaping();
|
|
|
+ daping.setId(1);
|
|
|
+ daping.setDakaidaping(1);
|
|
|
+
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("data",daping.getDakaidaping()); //打开大屏
|
|
|
+ map.put("name","打开大屏");
|
|
|
+ list.add(map);
|
|
|
+
|
|
|
+ sendAll(list);
|
|
|
+// ItdmDaping daping = new ItdmDaping();
|
|
|
+// daping.setId(1);
|
|
|
+// daping.setDakaidaping(1);
|
|
|
+// testUtils.dapingMapper.updateById(daping);
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|