| | |
| | | package com.ruoyi.utils.mqtt; |
| | | |
| | | import com.ruoyi.alarm.global.service.impl.GlobalAlarmServiceImpl; |
| | | import com.ruoyi.alarm.radar.service.ArdRadarService; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.utils.spring.SpringUtils; |
| | | import com.ruoyi.statistical.service.StatisticalService; |
| | | import com.ruoyi.storage.minio.service.IStorageMinioEventService; |
| | | import com.ruoyi.sy.domain.ArdSyCarLock; |
| | | import com.ruoyi.sy.domain.ArdSyCarRtu; |
| | | import com.ruoyi.sy.gps31.PositionContainer; |
| | | import com.ruoyi.sy.service.ArdSyCarLockService; |
| | | import com.ruoyi.sy.service.ArdSyCarRtuService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.eclipse.paho.client.mqttv3.*; |
| | | |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.Arrays; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @Description: mqtt回调处理类 |
| | |
| | | private MqttConnectOptions options; |
| | | private String topic; |
| | | private int qos; |
| | | //注入电子锁Bean |
| | | ArdSyCarRtuService carRtuService = SpringUtils.getBean(ArdSyCarRtuService.class); |
| | | ArdSyCarLockService carLockService = SpringUtils.getBean(ArdSyCarLockService.class); |
| | | |
| | | public MqttOnceCallback(MqttClient client, MqttConnectOptions options, String topic, int qos) { |
| | | this.client = client; |
| | |
| | | public void messageArrived(String topic, MqttMessage message) { |
| | | try { |
| | | // System.out.println("【车辆锁主题】:"+topic+"【车辆锁信息】:"+new String(message.getPayload(), StandardCharsets.UTF_8)); |
| | | //出来回调数据 |
| | | List<ArdSyCarLock> ardSyCarLocks = carLockService.data(new String(message.getPayload(), StandardCharsets.UTF_8)); |
| | | //存入集合 |
| | | Map<String,List<ArdSyCarLock>> map = PositionContainer.getTopicSubscribe(); |
| | | if(map==null){ |
| | | Map<String,List<ArdSyCarLock>> newMap = new HashMap<>(); |
| | | newMap.put("topic",ardSyCarLocks); |
| | | PositionContainer.setTopicSubscribe(newMap); |
| | | }else { |
| | | for(Map.Entry entry : map.entrySet()){ |
| | | String mapTopic = (String) entry.getKey(); |
| | | if(topic.equals(mapTopic)){ |
| | | map.remove(entry.getKey()); |
| | | } |
| | | Map<String,List<ArdSyCarLock>> newMap = new HashMap<>(); |
| | | newMap.put("topic",ardSyCarLocks); |
| | | PositionContainer.setTopicSubscribe(newMap); |
| | | } |
| | | } |
| | | log.debug(String.valueOf(map)); |
| | | } catch (Exception e) { |
| | | log.debug("车辆电磁锁处理mqtt消息异常:" + e); |
| | | } |