消费改造
This commit is contained in:
@@ -9,7 +9,7 @@ public class CacheConstants
|
|||||||
/**
|
/**
|
||||||
* 设备心跳缓存key
|
* 设备心跳缓存key
|
||||||
*/
|
*/
|
||||||
public static final String EQUIPMENT_HEARTBEAT = "equipment:heartbeat:";
|
public static final String EQUIPMENT_HEARTBEAT = "xf:heartbeat:";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设备心跳缓存过期时间
|
* 设备心跳缓存过期时间
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
package org.dromara.mica.mqtt.server.listener;
|
|
||||||
|
|
||||||
import cn.hutool.http.HttpUtil;
|
|
||||||
import com.alibaba.fastjson2.JSON;
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.dromara.mica.mqtt.core.annotation.MqttServerFunction;
|
|
||||||
import org.dromara.mica.mqtt.server.constant.CacheConstants;
|
|
||||||
import org.dromara.mica.mqtt.server.enums.FlagEnums;
|
|
||||||
import org.dromara.mica.mqtt.server.pojo.WhiteListOperatorPO;
|
|
||||||
import org.dromara.mica.mqtt.server.redis.RedisService;
|
|
||||||
import org.dromara.mica.mqtt.server.utils.AESUtil;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
|
||||||
import org.tio.utils.hutool.StrUtil;
|
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 消息监听器
|
|
||||||
*
|
|
||||||
* @author wsq
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@Service
|
|
||||||
public class CarMessageListener {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
RedisService redisService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 心跳
|
|
||||||
* @param topic
|
|
||||||
* @param topicVars
|
|
||||||
* @param message
|
|
||||||
*/
|
|
||||||
@MqttServerFunction("${sn}")
|
|
||||||
public void onKeepAliveMessage(String topic, Map<String, String> topicVars, byte[] message) {
|
|
||||||
String sn = topicVars.get("sn");
|
|
||||||
log.info("接收到来自客户端 [{}] 的心跳消息 -> Topic: {}, TopicVars: {}, Message: {}", sn, topic,topicVars,new String(message, StandardCharsets.UTF_8));
|
|
||||||
|
|
||||||
// 更新客户端的最后心跳
|
|
||||||
redisService.setCacheObject(CacheConstants.EQUIPMENT_HEARTBEAT + sn, FlagEnums.ONLINE.getCode(), CacheConstants.OFFLINE_THRESHOLD, TimeUnit.MILLISECONDS);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
package org.dromara.mica.mqtt.server.listener;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.http.HttpUtil;
|
||||||
|
import com.alibaba.fastjson2.JSON;
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.dromara.mica.mqtt.core.annotation.MqttServerFunction;
|
||||||
|
import org.dromara.mica.mqtt.server.constant.CacheConstants;
|
||||||
|
import org.dromara.mica.mqtt.server.enums.FlagEnums;
|
||||||
|
import org.dromara.mica.mqtt.server.pojo.WhiteListOperatorPO;
|
||||||
|
import org.dromara.mica.mqtt.server.redis.RedisService;
|
||||||
|
import org.dromara.mica.mqtt.server.utils.AESUtil;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息监听器
|
||||||
|
*
|
||||||
|
* @author wsq
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class xfMessageListener {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
RedisService redisService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 餐盘机8
|
||||||
|
* @param topic
|
||||||
|
* @param topicVars
|
||||||
|
* @param message
|
||||||
|
*/
|
||||||
|
@MqttServerFunction("${sn}/8")
|
||||||
|
public void onKeepAliveMessage8(String topic, Map<String, String> topicVars, byte[] message) {
|
||||||
|
String sn = topicVars.get("sn");
|
||||||
|
String s = new String(message, StandardCharsets.UTF_8);
|
||||||
|
log.info("接收到来自客户端 [{}] 的心跳消息 -> sn: {}, Message: {}", topic, sn, s);
|
||||||
|
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(s);
|
||||||
|
if (jsonObject != null && jsonObject.containsKey("IoState") && StrUtil.isNotBlank(jsonObject.getString("IoState"))) {
|
||||||
|
redisService.setCacheObject(CacheConstants.EQUIPMENT_HEARTBEAT + "8", jsonObject.getString("IoState"), CacheConstants.OFFLINE_THRESHOLD, TimeUnit.MILLISECONDS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 餐盘机9
|
||||||
|
* @param topic
|
||||||
|
* @param topicVars
|
||||||
|
* @param message
|
||||||
|
*/
|
||||||
|
@MqttServerFunction("${sn}/9")
|
||||||
|
public void onKeepAliveMessage9(String topic, Map<String, String> topicVars, byte[] message) {
|
||||||
|
String sn = topicVars.get("sn");
|
||||||
|
String s = new String(message, StandardCharsets.UTF_8);
|
||||||
|
log.info("接收到来自客户端 [{}] 的心跳消息 -> sn: {}, Message: {}", topic, sn, s);
|
||||||
|
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(s);
|
||||||
|
if (jsonObject != null && jsonObject.containsKey("IoState") && StrUtil.isNotBlank(jsonObject.getString("IoState"))) {
|
||||||
|
redisService.setCacheObject(CacheConstants.EQUIPMENT_HEARTBEAT + "9", jsonObject.getString("IoState"), CacheConstants.OFFLINE_THRESHOLD, TimeUnit.MILLISECONDS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -20,7 +20,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class HeartbeatOnLineTask {
|
public class xfHeartbeatOnLineTask {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
RedisService redisService;
|
RedisService redisService;
|
||||||
@@ -28,7 +28,7 @@ public class HeartbeatOnLineTask {
|
|||||||
@Autowired
|
@Autowired
|
||||||
IEquipmentService equipmentService;
|
IEquipmentService equipmentService;
|
||||||
|
|
||||||
@Scheduled(fixedRate = 10 * 1000)
|
// @Scheduled(fixedRate = 10 * 1000)
|
||||||
public void run() {
|
public void run() {
|
||||||
log.info("===========心跳检测=============");
|
log.info("===========心跳检测=============");
|
||||||
//缓存中有该设备心跳key
|
//缓存中有该设备心跳key
|
||||||
@@ -1,28 +1,13 @@
|
|||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
#xa
|
url: jdbc:mysql://192.168.19.3:3306/taihe_cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||||
# url: jdbc:mysql://127.0.0.1:3306/xa_cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
|
||||||
# username: root
|
|
||||||
# password: Xahg2024.
|
|
||||||
#jl
|
|
||||||
# url: jdbc:mysql://127.0.0.1:3306/jl_cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
|
||||||
# username: root
|
|
||||||
# password: JL202509jj
|
|
||||||
#td
|
|
||||||
# url: jdbc:mysql://127.0.0.1:3306/td_cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
|
||||||
# username: root
|
|
||||||
# password: td@JJ2024
|
|
||||||
#zr
|
|
||||||
url: jdbc:mysql://192.168.155.42:3306/zr_cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
|
||||||
username: root
|
username: root
|
||||||
password: zr202407.J
|
password: thXF2024.
|
||||||
data:
|
data:
|
||||||
redis:
|
redis:
|
||||||
#zr
|
#zr
|
||||||
host: 192.168.155.42
|
host: 127.0.0.1
|
||||||
#xa、jl、td
|
|
||||||
# host: 127.0.0.1
|
|
||||||
port: 6379
|
port: 6379
|
||||||
password:
|
password:
|
||||||
database: 1
|
database: 0
|
||||||
|
|||||||
Reference in New Issue
Block a user