From 7cbb7a70344309684ef7bdab4603b06b07e61efb Mon Sep 17 00:00:00 2001 From: kaiyu <404897439@qq.com> Date: Wed, 30 Sep 2020 16:08:23 +0800 Subject: [PATCH] 传输参数排序 --- src/main/java/com/moral/webSocketServer/BSTestWebsocketServer.java | 48 ++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/moral/webSocketServer/BSTestWebsocketServer.java b/src/main/java/com/moral/webSocketServer/BSTestWebsocketServer.java index 570884f..198f26a 100644 --- a/src/main/java/com/moral/webSocketServer/BSTestWebsocketServer.java +++ b/src/main/java/com/moral/webSocketServer/BSTestWebsocketServer.java @@ -18,6 +18,7 @@ import javax.websocket.server.ServerEndpoint; import java.io.IOException; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -25,6 +26,13 @@ @Slf4j @ServerEndpoint("/web/testWebSocket/{param}") @Component +/** +* @Description: ���������������websocket + * @Param: + * @return: + * @Author: ������������ + * @Date: 2020/9/30 + */ public class BSTestWebsocketServer { public static DeviceService deviceService; @@ -99,16 +107,23 @@ channel.queueBind(queue, exchange, routingKey); } + //������������,��������������������� channel.basicQos(1);//��������������������������� channel.basicConsume(queue, false, new DefaultConsumer(channel) { @Override public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { + //������MQ������������������������������������������������������������ Map message = (Map) JSON.parse((String) JSON.parse(new String(body))); sendWindInfo(message); + + //���������������������������������������mac���������������������������������mac������������ if(mac!=null&&(!mac.equals(0))) - sendDeviceInfo(message); + sendDeviceInfo(message,deviceList); + + //������������ channel.basicAck(envelope.getDeliveryTag(), false); + //������socket������������������ if (!webSocketMap.containsKey(accountId)) { RabbitMQUtils.closeConnectionChannel(connection, channel); @@ -132,7 +147,6 @@ @OnMessage public void onMessage(String message, Session session) { if (!ObjectUtils.isEmpty(message)) { - System.out.println(message); Map<String, Object> map = JSON.parseObject(message); this.mac = (String) map.get("mac"); } @@ -154,7 +168,13 @@ } } - //��������������������� + /** + * @Description: ���������������������socket��������������������������������� + * @Param: [param] + * @return: void + * @Author: ��������� + * @Date: 2020/9/30 + */ private void sendWindInfo(Map<String, Object> param) { try { Map<String, Object> map = new HashMap<>(); @@ -168,11 +188,18 @@ } } - //������mac������device������ - private void sendDeviceInfo(Map<String, Object> param) { + /** + * @Description: ������������mac������accountid���������������������mac������������������ + * @Param: [param] + * @return: void + * @Author: ��������� + * @Date: 2020/9/30 + */ + private void sendDeviceInfo(Map<String, Object> param,List<Device> deviceList) { String deviceMac = (String) param.get("mac"); if (mac.equals(deviceMac)) { try { + Map<String,Object> sortMap = new LinkedHashMap<>(); Map<String, Object> map = new HashMap<>(); param.forEach((key, value) -> { Sensor sensor = sensors.get(key); @@ -183,7 +210,16 @@ }); String mac = (String) param.get("mac"); map.put("mac", mac); - sendMessage(JSON.toJSONString(map)); + map.put("flag",1); + for (Device device : deviceList) { + if(mac.equals(device.getMac())){ + sortMap.put("������",device.getName()); + sortMap.put("������",device.getAddress()); + sortMap.putAll(map); + break; + } + } + sendMessage(JSON.toJSONString(sortMap)); } catch (IOException e) { log.error("������mac������������������������"); } -- Gitblit v1.8.0