| | |
| | | package org.jeecg.modules.dry.mqtt; |
| | | |
| | | import cn.hutool.core.thread.ThreadUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; |
| | | import org.eclipse.paho.client.mqttv3.MqttCallback; |
| | |
| | | import org.jeecg.common.util.RedisUtil; |
| | | import org.jeecg.modules.base.service.BaseCommonService; |
| | | import org.jeecg.modules.dry.api.EmqxApi; |
| | | import org.jeecg.modules.dry.service.IDryRealTimeDataService; |
| | | import org.jeecg.modules.dry.vo.RealTimeDataVo; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.context.annotation.Scope; |
| | |
| | | private BaseCommonService baseCommonService; |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | |
| | | @Autowired |
| | | private IDryRealTimeDataService realTimeDataService; |
| | | |
| | | |
| | | @Override |
| | |
| | | // 普通用户 |
| | | case "user": |
| | | System.err.println("user"); |
| | | parseUserCommand(topic, mqttMessage); |
| | | try { |
| | | parseUserCommand(topic, mqttMessage); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | break; |
| | | |
| | | } |
| | |
| | | if (messageJson.containsKey("timestamp")) { |
| | | messageJson.put("timestamp", DateUtils.zone2Str(messageJson.get("timestamp").toString())); |
| | | } |
| | | baseCommonService.addLog(message, CommonConstant.LOG_TYPE_MQTT, CommonConstant.OPERATE_MQTT_1); |
| | | // 实时数据上传太频繁且数据内容超过字段大小不记录日志 |
| | | if (!topic.equals(MqttConstant.TENANT_UP_PREFIX_REALTIME_DATA)){ |
| | | baseCommonService.addLog(message, CommonConstant.LOG_TYPE_MQTT, CommonConstant.OPERATE_MQTT_1); |
| | | } |
| | | |
| | | switch (topic) { |
| | | // 查询设备在线 |
| | | case MqttConstant.MOBILE_QUERY_EQU_STATU: |
| | |
| | | }); |
| | | break; |
| | | |
| | | // 接收设备实时数据 |
| | | case MqttConstant.TENANT_UP_PREFIX_REALTIME_DATA: |
| | | try { |
| | | RealTimeDataVo vo = JSON.parseObject(message, RealTimeDataVo.class); |
| | | realTimeDataService.realTimeDataHandle(vo); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | break; |
| | | |
| | | } |
| | | |
| | | } |