干燥机配套车间生产管理系统/云平台服务端
bsw215583320
2024-11-01 e2a02c09b9d087a49ae5dd9f70856967390237de
jeecg-module-dry/jeecg-module-dry-biz/src/main/java/org/jeecg/modules/dry/mqtt/MqttSampleCallback.java
@@ -1,6 +1,7 @@
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;
@@ -11,6 +12,8 @@
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;
@@ -29,6 +32,9 @@
  private BaseCommonService baseCommonService;
  @Autowired
  private RedisUtil redisUtil;
  @Autowired
  private IDryRealTimeDataService realTimeDataService;
  @Override
@@ -84,7 +90,12 @@
      // 普通用户
      case "user":
        System.err.println("user");
        try {
        parseUserCommand(topic, mqttMessage);
        } catch (Exception e) {
          e.printStackTrace();
        }
        break;
    }
@@ -111,7 +122,11 @@
    if (messageJson.containsKey("timestamp")) {
      messageJson.put("timestamp", DateUtils.zone2Str(messageJson.get("timestamp").toString()));
    }
    // 实时数据上传太频繁且数据内容超过字段大小不记录日志
    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:
@@ -149,6 +164,17 @@
        });
        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;
    }
  }