forked from dyf/fys-Multi-tenant
修改灯光上报状态
This commit is contained in:
@ -1,5 +1,9 @@
|
|||||||
package com.fuyuanshen.global.mqtt.base;
|
package com.fuyuanshen.global.mqtt.base;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.core.task.TaskExecutor;
|
||||||
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
@ -11,7 +15,10 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class MqttRuleEngine {
|
public class MqttRuleEngine {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@Qualifier("threadPoolTaskExecutor")
|
||||||
|
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
||||||
|
|
||||||
private final LinkedHashMap<String, MqttMessageRule> rulesMap = new LinkedHashMap<>();
|
private final LinkedHashMap<String, MqttMessageRule> rulesMap = new LinkedHashMap<>();
|
||||||
public MqttRuleEngine(List<MqttMessageRule> rules) {
|
public MqttRuleEngine(List<MqttMessageRule> rules) {
|
||||||
@ -30,7 +37,7 @@ public class MqttRuleEngine {
|
|||||||
int commandType = context.getCommandType();
|
int commandType = context.getCommandType();
|
||||||
MqttMessageRule mqttMessageRule = rulesMap.get("Light_"+commandType);
|
MqttMessageRule mqttMessageRule = rulesMap.get("Light_"+commandType);
|
||||||
if (mqttMessageRule != null) {
|
if (mqttMessageRule != null) {
|
||||||
mqttMessageRule.execute(context);
|
threadPoolTaskExecutor.execute(() -> mqttMessageRule.execute(context));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ public class BjqLaserModeSettingsRule implements MqttMessageRule {
|
|||||||
|
|
||||||
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.OK.getCode(), Duration.ofSeconds(30));
|
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.OK.getCode(), Duration.ofSeconds(30));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("处理灯光模式命令时出错", e);
|
log.error("处理激光模式命令时出错", e);
|
||||||
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.FAILED.getCode(), Duration.ofSeconds(30));
|
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.FAILED.getCode(), Duration.ofSeconds(30));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,7 @@ import java.time.Duration;
|
|||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
|
||||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_KEY_PREFIX;
|
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.*;
|
||||||
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.DEVICE_LIGHT_MODE_KEY_PREFIX;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 灯光模式订阅设备回传消息
|
* 灯光模式订阅设备回传消息
|
||||||
@ -39,6 +38,7 @@ public class BjqModeRule implements MqttMessageRule {
|
|||||||
Object[] convertArr = context.getConvertArr();
|
Object[] convertArr = context.getConvertArr();
|
||||||
|
|
||||||
String mainLightMode = convertArr[1].toString();
|
String mainLightMode = convertArr[1].toString();
|
||||||
|
String batteryRemainingTime = convertArr[2].toString();
|
||||||
if(StringUtils.isNotBlank(mainLightMode)){
|
if(StringUtils.isNotBlank(mainLightMode)){
|
||||||
if("0".equals(mainLightMode)){
|
if("0".equals(mainLightMode)){
|
||||||
String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ context.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX ;
|
String deviceOnlineStatusRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX+ context.getDeviceImei() + DeviceRedisKeyConstants.DEVICE_ONLINE_STATUS_KEY_PREFIX ;
|
||||||
@ -46,6 +46,10 @@ public class BjqModeRule implements MqttMessageRule {
|
|||||||
}
|
}
|
||||||
// 发送设备状态和位置信息到Redis
|
// 发送设备状态和位置信息到Redis
|
||||||
syncSendDeviceDataToRedisWithFuture(context.getDeviceImei(),mainLightMode);
|
syncSendDeviceDataToRedisWithFuture(context.getDeviceImei(),mainLightMode);
|
||||||
|
String deviceRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_KEY_PREFIX + context.getDeviceImei() + DEVICE_LIGHT_BRIGHTNESS_KEY_PREFIX;
|
||||||
|
|
||||||
|
// 存储到Redis
|
||||||
|
RedisUtils.setCacheObject(deviceRedisKey, batteryRemainingTime);
|
||||||
}
|
}
|
||||||
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.OK.getCode(), Duration.ofSeconds(20));
|
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.OK.getCode(), Duration.ofSeconds(20));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -232,7 +232,7 @@ xss:
|
|||||||
# 如使用JDK21请直接使用虚拟线程 不要开启此配置
|
# 如使用JDK21请直接使用虚拟线程 不要开启此配置
|
||||||
thread-pool:
|
thread-pool:
|
||||||
# 是否开启线程池
|
# 是否开启线程池
|
||||||
enabled: false
|
enabled: true
|
||||||
# 队列最大长度
|
# 队列最大长度
|
||||||
queueCapacity: 128
|
queueCapacity: 128
|
||||||
# 线程池维护线程所允许的空闲时间
|
# 线程池维护线程所允许的空闲时间
|
||||||
|
Reference in New Issue
Block a user