Merge branch 'dyf-device' into 6170

This commit is contained in:
2025-12-26 16:22:00 +08:00
12 changed files with 19 additions and 31 deletions

View File

@ -15,11 +15,14 @@ import org.springframework.messaging.MessageHandler;
@Configuration
@Slf4j
public class MqttOutboundConfiguration {
@Autowired
private MqttPropertiesConfig mqttPropertiesConfig;
@Autowired
private MqttPahoClientFactory mqttPahoClientFactory;
// 消息通道
@Bean
public MessageChannel mqttOutboundChannel(){

View File

@ -1,6 +1,7 @@
package com.fuyuanshen.global.mqtt.constants;
public class DeviceRedisKeyConstants {
public static final String DEVICE_KEY_PREFIX = "device:";
// 设备上报状态
public static final String DEVICE_STATUS_KEY_PREFIX = ":status";
@ -52,4 +53,5 @@ public class DeviceRedisKeyConstants {
* 告警信息
*/
public static final String DEVICE_ALARM_MESSAGE_KEY_PREFIX = ":alarmMessage";
}

View File

@ -36,7 +36,6 @@ public class LightingCommandTypeConstants {
*/
public static final String SEND_MESSAGE = "Light_6";
/**
* 报警模式
*/

View File

@ -57,12 +57,12 @@ public class BjqAlarmRule implements MqttMessageRule {
if (StringUtils.isNotBlank(convertValue)) {
// 将设备状态信息存储到Redis中
String deviceRedisKey = GlobalConstants.GLOBAL_REDIS_KEY + DeviceRedisKeyConstants.DEVICE_KEY_PREFIX + context.getDeviceImei() + DEVICE_ALARM_KEY_PREFIX;
String sendMessageIng = GLOBAL_REDIS_KEY+ DEVICE_KEY_PREFIX + context.getDeviceImei() + ":messageSending";
String sendMessageIng = GLOBAL_REDIS_KEY + DEVICE_KEY_PREFIX + context.getDeviceImei() + ":messageSending";
if ("1".equals(convertValue)) {
RedisUtils.setCacheObject(sendMessageIng, "1", Duration.ofDays(1));
// 存储到Redis
RedisUtils.setCacheObject(deviceRedisKey, "1");
}else if ("0".equals(convertValue)){
} else if ("0".equals(convertValue)) {
RedisUtils.deleteObject(sendMessageIng);
RedisUtils.deleteObject(deviceRedisKey);
}

View File

@ -71,5 +71,4 @@ public class BjqLaserModeSettingsRule implements MqttMessageRule {
}
}

View File

@ -45,6 +45,7 @@ public class BjqModeRule implements MqttMessageRule {
return LightingCommandTypeConstants.LIGHT_MODE;
}
@Override
public void execute(MqttRuleContext context) {
String functionAccess = FUNCTION_ACCESS_KEY + context.getDeviceImei();

View File

@ -1,32 +1,18 @@
package com.fuyuanshen.global.mqtt.rule.bjq;
import com.alibaba.fastjson2.JSONObject;
import com.fuyuanshen.common.core.constant.GlobalConstants;
import com.fuyuanshen.common.core.utils.StringUtils;
import com.fuyuanshen.common.json.utils.JsonUtils;
import com.fuyuanshen.common.redis.utils.RedisUtils;
import com.fuyuanshen.equipment.utils.map.GetAddressFromLatUtil;
import com.fuyuanshen.equipment.utils.map.LngLonUtil;
import com.fuyuanshen.global.mqtt.base.MqttMessageRule;
import com.fuyuanshen.global.mqtt.base.MqttRuleContext;
import com.fuyuanshen.global.mqtt.config.MqttGateway;
import com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants;
import com.fuyuanshen.global.mqtt.constants.LightingCommandTypeConstants;
import com.fuyuanshen.global.mqtt.constants.MqttConstants;
import com.fuyuanshen.global.mqtt.listener.domain.FunctionAccessStatus;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.time.Duration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import static com.fuyuanshen.common.core.constant.GlobalConstants.FUNCTION_ACCESS_KEY;
import static com.fuyuanshen.global.mqtt.constants.DeviceRedisKeyConstants.*;
/**
* 定位数据命令处理
@ -55,4 +41,5 @@ public class BjqPersonnelInfoDataRule implements MqttMessageRule {
RedisUtils.setCacheObject(functionAccess, FunctionAccessStatus.FAILED.getCode(), Duration.ofSeconds(30));
}
}
}

View File

@ -27,11 +27,12 @@ public class MqttMessageConsumer {
@Autowired
private DeviceMapper deviceMapper;
// 创建两个线程池:一个用于消息获取,一个用于业务处理
private ExecutorService messageConsumerPool = Executors.newFixedThreadPool(3);
private ExecutorService messageProcessorPool = Executors.newFixedThreadPool(10);
// 初始化方法,启动消息监听
@PostConstruct
public void start() {
@ -130,4 +131,5 @@ public class MqttMessageConsumer {
log.error("业务处理线程 {} 处理消息时发生错误: {}", threadName, message, e);
}
}
}

View File

@ -22,6 +22,8 @@ public class OnlineStatusTask {
@Autowired
private DeviceMapper deviceMapper;
// 使用cron表达式每分钟的第0秒执行
@Scheduled(cron = "0 */3 * * * ?")
public void cronTask() {
@ -37,4 +39,5 @@ public class OnlineStatusTask {
}
});
}
}

View File

@ -98,6 +98,7 @@ public class DeviceControlCenterController extends BaseController {
return R.ok(appDeviceService.getDeviceInfo(deviceMac));
}
/**
* 指令下发记录
*/
@ -106,6 +107,7 @@ public class DeviceControlCenterController extends BaseController {
return appDeviceService.getInstructionRecord(dto, pageQuery);
}
/**
* 导出
*/

View File

@ -79,7 +79,6 @@ public class DeviceTypeController {
public R<DeviceType> getCommunicationMode(@Parameter(name = "设备类型ID", required = true) Long id) {
DeviceType communicationMode = deviceTypeService.getCommunicationMode(id);
return R.ok(communicationMode);
}
}

View File

@ -224,22 +224,13 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeMapper, DeviceT
throw new RuntimeException("设备类型不存在");
}
if (!deviceType.getTypeName().equals(resources.getTypeName())) {
int count = deviceMapper.countByDeviceTypeId(deviceType.getId());
if (count > 0) {
throw new RuntimeException("该设备类型下已有绑定设备,无法修改设备类型名称!!!");
throw new RuntimeException("该设备类型下已有设备,无法修改设备类型名称!!!");
}
}
// List<Device> devices = deviceMapper.selectList(new QueryWrapper<Device>()
// .eq("device_type", deviceTypeGrants.getDeviceTypeId()));
// if (CollectionUtil.isNotEmpty(devices)) {
// throw new RuntimeException("该设备类型已绑定设备,无法修改!!!");
// }
// 校验设备类型名称
DeviceType dt = deviceTypeMapper.selectOne(new QueryWrapper<DeviceType>().eq("type_name", resources.getTypeName()));
if (dt != null && !dt.getId().equals(deviceType.getId())) {