提交代码7

This commit is contained in:
2026-03-06 17:58:39 +08:00
parent 83b97841ef
commit 47d40cf9d2
7 changed files with 161 additions and 161 deletions

View File

@ -38,18 +38,18 @@ public class BjqActiveReportingDeviceDataRule implements MqttMessageRule {
@Override @Override
public void execute(MqttRuleContext context) { public void execute(MqttRuleContext context) {
try { try {
// Object[] convertArr = context.getConvertArr(); Object[] convertArr = context.getConvertArr();
// // Latitude, longitude // Latitude, longitude
// //主灯档位,激光灯档位,电量百分比,充电状态,电池剩余续航时间 //主灯档位,激光灯档位,电量百分比,充电状态,电池剩余续航时间
// String mainLightMode = convertArr[1].toString(); String mainLightMode = convertArr[1].toString();
// String laserLightMode = convertArr[2].toString(); String laserLightMode = convertArr[2].toString();
// String batteryPercentage = convertArr[3].toString(); String batteryPercentage = convertArr[3].toString();
// String chargeState = convertArr[4].toString(); String chargeState = convertArr[4].toString();
// String batteryRemainingTime = convertArr[5].toString(); String batteryRemainingTime = convertArr[5].toString();
//
// // 发送设备状态和位置信息到Redis // 发送设备状态和位置信息到Redis
// asyncSendDeviceDataToRedisWithFuture(context.getDeviceImei(), mainLightMode, laserLightMode, asyncSendDeviceDataToRedisWithFuture(context.getDeviceImei(), mainLightMode, laserLightMode,
// batteryPercentage, chargeState, batteryRemainingTime); batteryPercentage, chargeState, batteryRemainingTime);
} catch (Exception e) { } catch (Exception e) {
log.error("处理上报数据命令时出错", e); log.error("处理上报数据命令时出错", e);
} }

View File

@ -44,37 +44,37 @@ public class BjqBootLogoRule implements MqttMessageRule {
public void execute(MqttRuleContext context) { public void execute(MqttRuleContext context) {
String functionAccess = FUNCTION_ACCESS_KEY + context.getDeviceImei(); String functionAccess = FUNCTION_ACCESS_KEY + context.getDeviceImei();
try { try {
// Byte val2 = (Byte) context.getConvertArr()[1]; Byte val2 = (Byte) context.getConvertArr()[1];
// if (val2 == 100) { if (val2 == 100) {
// RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.OK.getCode(), Duration.ofSeconds(20)); RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.OK.getCode(), Duration.ofSeconds(20));
// return; return;
// } }
//
// String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + context.getDeviceImei() +DEVICE_BOOT_LOGO_KEY_PREFIX); String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + context.getDeviceImei() +DEVICE_BOOT_LOGO_KEY_PREFIX);
// if (StringUtils.isEmpty(data)) { if (StringUtils.isEmpty(data)) {
// return; return;
// } }
//
// byte[] arr = ImageToCArrayConverter.convertStringToByteArray(data); byte[] arr = ImageToCArrayConverter.convertStringToByteArray(data);
// byte[] specificChunk = ImageToCArrayConverter.getChunk(arr, (val2 - 1), 512); byte[] specificChunk = ImageToCArrayConverter.getChunk(arr, (val2 - 1), 512);
// log.info("第{}块数据大小: {} 字节", val2, specificChunk.length); log.info("第{}块数据大小: {} 字节", val2, specificChunk.length);
//
// ArrayList<Integer> intData = new ArrayList<>(); ArrayList<Integer> intData = new ArrayList<>();
// intData.add(3); intData.add(3);
// intData.add((int) val2); intData.add((int) val2);
// ImageToCArrayConverter.buildArr(convertHexToDecimal(specificChunk), intData); ImageToCArrayConverter.buildArr(convertHexToDecimal(specificChunk), intData);
// intData.add(0); intData.add(0);
// intData.add(0); intData.add(0);
// intData.add(0); intData.add(0);
// intData.add(0); intData.add(0);
//
// Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
// map.put("instruct", intData); map.put("instruct", intData);
//
// mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + context.getDeviceImei(), 1, JsonUtils.toJsonString(map)); mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + context.getDeviceImei(), 1, JsonUtils.toJsonString(map));
// log.info("发送开机LOGO点阵数据到设备消息=>topic:{},payload:{}", log.info("发送开机LOGO点阵数据到设备消息=>topic:{},payload:{}",
// MqttConstants.GLOBAL_PUB_KEY + context.getDeviceImei(), MqttConstants.GLOBAL_PUB_KEY + context.getDeviceImei(),
// JsonUtils.toJsonString(map)); JsonUtils.toJsonString(map));
} catch (Exception e) { } catch (Exception e) {
log.error("处理开机LOGO时出错", e); log.error("处理开机LOGO时出错", e);

View File

@ -34,15 +34,15 @@ public class BjqLaserModeSettingsRule implements MqttMessageRule {
public void execute(MqttRuleContext context) { public void execute(MqttRuleContext context) {
String functionAccess = FUNCTION_ACCESS_KEY + context.getDeviceImei(); String functionAccess = FUNCTION_ACCESS_KEY + context.getDeviceImei();
try { try {
// Object[] convertArr = context.getConvertArr(); Object[] convertArr = context.getConvertArr();
//
// String mode = convertArr[1].toString(); String mode = convertArr[1].toString();
// if(StringUtils.isNotBlank(mode)){ if(StringUtils.isNotBlank(mode)){
// // 发送设备状态和位置信息到Redis // 发送设备状态和位置信息到Redis
// syncSendDeviceDataToRedisWithFuture(context.getDeviceImei(),mode); syncSendDeviceDataToRedisWithFuture(context.getDeviceImei(),mode);
// } }
//
// 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));

View File

@ -34,15 +34,15 @@ public class BjqLightBrightnessRule implements MqttMessageRule {
public void execute(MqttRuleContext context) { public void execute(MqttRuleContext context) {
String functionAccess = FUNCTION_ACCESS_KEY + context.getDeviceImei(); String functionAccess = FUNCTION_ACCESS_KEY + context.getDeviceImei();
try { try {
// Object[] convertArr = context.getConvertArr(); Object[] convertArr = context.getConvertArr();
//
// String convertValue = convertArr[1].toString(); String convertValue = convertArr[1].toString();
// // 将设备状态信息存储到Redis中 // 将设备状态信息存储到Redis中
// String deviceRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_KEY_PREFIX + context.getDeviceImei() + DEVICE_LIGHT_BRIGHTNESS_KEY_PREFIX; String deviceRedisKey = GlobalConstants.GLOBAL_REDIS_KEY+DeviceRedisKeyConstants.DEVICE_KEY_PREFIX + context.getDeviceImei() + DEVICE_LIGHT_BRIGHTNESS_KEY_PREFIX;
//
// // 存储到Redis // 存储到Redis
// RedisUtils.setCacheObject(deviceRedisKey, convertValue); RedisUtils.setCacheObject(deviceRedisKey, convertValue);
// RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.OK.getCode(), Duration.ofSeconds(20)); RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.OK.getCode(), Duration.ofSeconds(20));
} catch (Exception e) { } catch (Exception e) {
log.error("处理灯光亮度命令时出错", e); log.error("处理灯光亮度命令时出错", e);
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.FAILED.getCode(), Duration.ofSeconds(20)); RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.FAILED.getCode(), Duration.ofSeconds(20));

View File

@ -52,26 +52,26 @@ public class BjqLocationDataRule implements MqttMessageRule {
public void execute(MqttRuleContext context) { public void execute(MqttRuleContext context) {
String functionAccess = FUNCTION_ACCESS_KEY + context.getDeviceImei(); String functionAccess = FUNCTION_ACCESS_KEY + context.getDeviceImei();
try { try {
// Object[] convertArr = context.getConvertArr(); Object[] convertArr = context.getConvertArr();
// // Latitude, longitude // Latitude, longitude
// String latitude = convertArr[1].toString(); String latitude = convertArr[1].toString();
// String longitude = convertArr[2].toString(); String longitude = convertArr[2].toString();
// // 判断 latitude 和 longitude 是否都为 0 // 判断 latitude 和 longitude 是否都为 0
// if ("0".equals(latitude) && "0".equals(longitude)) { if ("0".equals(latitude) && "0".equals(longitude)) {
// log.info("位置信息为0不存储到Redis: device={}, lat={}, lon={}", context.getDeviceImei(), latitude, longitude); log.info("位置信息为0不存储到Redis: device={}, lat={}, lon={}", context.getDeviceImei(), latitude, longitude);
// return; return;
// } }
// // 异步发送经纬度到Redis // 异步发送经纬度到Redis
// asyncSendLocationToRedisWithFuture(context.getDeviceImei(), latitude, longitude); asyncSendLocationToRedisWithFuture(context.getDeviceImei(), latitude, longitude);
// // 异步保存数据 // 异步保存数据
// asyncSaveLocationToMySQLWithFuture(context.getDeviceImei(), latitude, longitude); asyncSaveLocationToMySQLWithFuture(context.getDeviceImei(), latitude, longitude);
//
// Map<String, Object> map = buildLocationDataMap(latitude, longitude); Map<String, Object> map = buildLocationDataMap(latitude, longitude);
// mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + context.getDeviceImei(), 1, JsonUtils.toJsonString(map)); mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + context.getDeviceImei(), 1, JsonUtils.toJsonString(map));
// log.info("发送定位数据到设备=>topic:{},payload:{}", log.info("发送定位数据到设备=>topic:{},payload:{}",
// MqttConstants.GLOBAL_PUB_KEY + context.getDeviceImei(), MqttConstants.GLOBAL_PUB_KEY + context.getDeviceImei(),
// JsonUtils.toJsonString(map)); JsonUtils.toJsonString(map));
// RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.OK.getCode(), Duration.ofSeconds(20)); RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.OK.getCode(), Duration.ofSeconds(20));
} catch (Exception e) { } catch (Exception e) {
log.error("处理定位数据命令时出错", e); log.error("处理定位数据命令时出错", e);
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.FAILED.getCode(), Duration.ofSeconds(20)); RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.FAILED.getCode(), Duration.ofSeconds(20));

View File

@ -52,45 +52,45 @@ public class BjqModeRule implements MqttMessageRule {
try { try {
log.info("处理灯光模式命令"); log.info("处理灯光模式命令");
log.info("MQTT消息负载字典{}", context.getPayloadDict()); log.info("MQTT消息负载字典{}", context.getPayloadDict());
// Object[] convertArr = context.getConvertArr(); Object[] convertArr = context.getConvertArr();
//
// String mainLightMode = convertArr[1].toString(); String mainLightMode = convertArr[1].toString();
// String batteryRemainingTime = convertArr[2].toString(); String batteryRemainingTime = convertArr[2].toString();
// if (StringUtils.isNotBlank(mainLightMode)) { if (StringUtils.isNotBlank(mainLightMode)) {
// log.info("设备离线mainLightMode{}", mainLightMode); log.info("设备离线mainLightMode{}", 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;
// RedisUtils.setCacheObject(deviceOnlineStatusRedisKey, "0"); RedisUtils.setCacheObject(deviceOnlineStatusRedisKey, "0");
//
// String sendMessageIng = GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + context.getDeviceImei() + ":messageSending"; String sendMessageIng = GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + context.getDeviceImei() + ":messageSending";
// String messageSendingValue = RedisUtils.getCacheObject(sendMessageIng); String messageSendingValue = RedisUtils.getCacheObject(sendMessageIng);
// if ("1".equals(messageSendingValue)) { if ("1".equals(messageSendingValue)) {
// // 设置为故障状态 // 设置为故障状态
// RedisUtils.setCacheObject(deviceOnlineStatusRedisKey, "2"); RedisUtils.setCacheObject(deviceOnlineStatusRedisKey, "2");
// UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>(); UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>();
// updateWrapper.eq("device_imei", context.getDeviceImei()); updateWrapper.eq("device_imei", context.getDeviceImei());
// updateWrapper.set("online_status", 2); updateWrapper.set("online_status", 2);
// deviceService.update(updateWrapper); deviceService.update(updateWrapper);
// RedisUtils.deleteObject(sendMessageIng); RedisUtils.deleteObject(sendMessageIng);
//
// // 解除告警 // 解除告警
// String deviceRedisKey = GlobalConstants.GLOBAL_REDIS_KEY + DeviceRedisKeyConstants.DEVICE_KEY_PREFIX + context.getDeviceImei() + DEVICE_ALARM_KEY_PREFIX; String deviceRedisKey = GlobalConstants.GLOBAL_REDIS_KEY + DeviceRedisKeyConstants.DEVICE_KEY_PREFIX + context.getDeviceImei() + DEVICE_ALARM_KEY_PREFIX;
// if (RedisUtils.getCacheObject(deviceRedisKey) != null) { if (RedisUtils.getCacheObject(deviceRedisKey) != null) {
// RedisUtils.deleteObject(deviceRedisKey); RedisUtils.deleteObject(deviceRedisKey);
// } }
// cancelAlarm(context.getDeviceImei()); cancelAlarm(context.getDeviceImei());
// } }
// } }
// // 发送设备状态和位置信息到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; String deviceRedisKey = GlobalConstants.GLOBAL_REDIS_KEY + DeviceRedisKeyConstants.DEVICE_KEY_PREFIX + context.getDeviceImei() + DEVICE_LIGHT_BRIGHTNESS_KEY_PREFIX;
//
// // 存储到Redis // 存储到Redis
// RedisUtils.setCacheObject(deviceRedisKey, batteryRemainingTime); 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) {
log.error("处理灯光模式命令时出错", e); log.error("处理灯光模式命令时出错", e);
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.FAILED.getCode(), Duration.ofSeconds(20)); RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.FAILED.getCode(), Duration.ofSeconds(20));

View File

@ -45,47 +45,47 @@ public class BjqSendMessageRule implements MqttMessageRule {
try { try {
// Byte val2 = (Byte) context.getConvertArr()[1]; // Byte val2 = (Byte) context.getConvertArr()[1];
// String val2Str = context.getConvertArr()[1].toString(); String val2Str = context.getConvertArr()[1].toString();
// int val2 = Integer.parseInt(val2Str); int val2 = Integer.parseInt(val2Str);
// System.out.println("收到设备信息命令:"+val2); System.out.println("收到设备信息命令:"+val2);
// if (val2 == 100) { if (val2 == 100) {
// RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.OK.getCode(), Duration.ofSeconds(20)); RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.OK.getCode(), Duration.ofSeconds(20));
// return; return;
// } }
//
// if(val2==200){ if(val2==200){
// String sendMessageIng = GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + context.getDeviceImei() + ":messageSending"; String sendMessageIng = GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + context.getDeviceImei() + ":messageSending";
// RedisUtils.deleteObject(sendMessageIng); RedisUtils.deleteObject(sendMessageIng);
// return; return;
// } }
//
//
// String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + context.getDeviceImei() + ":app_send_message_data"); String data = RedisUtils.getCacheObject(GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + context.getDeviceImei() + ":app_send_message_data");
// if (StringUtils.isEmpty(data)) { if (StringUtils.isEmpty(data)) {
// return; return;
// } }
//
// byte[] arr = ImageToCArrayConverter.convertStringToByteArray(data); byte[] arr = ImageToCArrayConverter.convertStringToByteArray(data);
// byte[] specificChunk = ImageToCArrayConverter.getChunk(arr, (val2 - 1), 512); byte[] specificChunk = ImageToCArrayConverter.getChunk(arr, (val2 - 1), 512);
// log.info("第{}块数据大小: {} 字节", val2, specificChunk.length); log.info("第{}块数据大小: {} 字节", val2, specificChunk.length);
//// System.out.println("第" + val2 + "块数据: " + Arrays.toString(specificChunk)); // System.out.println("第" + val2 + "块数据: " + Arrays.toString(specificChunk));
//
// ArrayList<Integer> intData = new ArrayList<>(); ArrayList<Integer> intData = new ArrayList<>();
// intData.add(6); intData.add(6);
// intData.add(val2); intData.add(val2);
// ImageToCArrayConverter.buildArr(convertHexToDecimal(specificChunk), intData); ImageToCArrayConverter.buildArr(convertHexToDecimal(specificChunk), intData);
// intData.add(0); intData.add(0);
// intData.add(0); intData.add(0);
// intData.add(0); intData.add(0);
// intData.add(0); intData.add(0);
//
// Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
// map.put("instruct", intData); map.put("instruct", intData);
//
// mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + context.getDeviceImei(), 1, JsonUtils.toJsonString(map)); mqttGateway.sendMsgToMqtt(MqttConstants.GLOBAL_PUB_KEY + context.getDeviceImei(), 1, JsonUtils.toJsonString(map));
// log.info("发送设备信息数据到设备消息=>topic:{},payload:{}", log.info("发送设备信息数据到设备消息=>topic:{},payload:{}",
// MqttConstants.GLOBAL_PUB_KEY + context.getDeviceImei(), MqttConstants.GLOBAL_PUB_KEY + context.getDeviceImei(),
// JsonUtils.toJsonString(map)); JsonUtils.toJsonString(map));
} catch (Exception e) { } catch (Exception e) {
log.error("处理发送设备信息时出错", e); log.error("处理发送设备信息时出错", e);