update:优化智控台参数名称

This commit is contained in:
hrz
2025-09-10 17:38:29 +08:00
parent eee907b1a2
commit ef02a01439
5 changed files with 26 additions and 35 deletions
@@ -9,6 +9,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TimeZone; import java.util.TimeZone;
import java.util.UUID; import java.util.UUID;
import javax.crypto.Mac; import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.SecretKeySpec;
@@ -37,6 +38,7 @@ import xiaozhi.common.user.UserDetail;
import xiaozhi.common.utils.ConvertUtils; import xiaozhi.common.utils.ConvertUtils;
import xiaozhi.common.utils.DateUtils; import xiaozhi.common.utils.DateUtils;
import xiaozhi.modules.device.dao.DeviceDao; import xiaozhi.modules.device.dao.DeviceDao;
import xiaozhi.modules.device.dto.DeviceManualAddDTO;
import xiaozhi.modules.device.dto.DevicePageUserDTO; import xiaozhi.modules.device.dto.DevicePageUserDTO;
import xiaozhi.modules.device.dto.DeviceReportReqDTO; import xiaozhi.modules.device.dto.DeviceReportReqDTO;
import xiaozhi.modules.device.dto.DeviceReportRespDTO; import xiaozhi.modules.device.dto.DeviceReportRespDTO;
@@ -48,7 +50,6 @@ import xiaozhi.modules.device.vo.UserShowDeviceListVO;
import xiaozhi.modules.security.user.SecurityUser; import xiaozhi.modules.security.user.SecurityUser;
import xiaozhi.modules.sys.service.SysParamsService; import xiaozhi.modules.sys.service.SysParamsService;
import xiaozhi.modules.sys.service.SysUserUtilService; import xiaozhi.modules.sys.service.SysUserUtilService;
import xiaozhi.modules.device.dto.DeviceManualAddDTO;
@Slf4j @Slf4j
@Service @Service
@@ -183,7 +184,7 @@ public class DeviceServiceImpl extends BaseServiceImpl<DeviceDao, DeviceEntity>
// 添加MQTT UDP配置 // 添加MQTT UDP配置
// 从系统参数获取MQTT Gateway地址,仅在配置有效时使用 // 从系统参数获取MQTT Gateway地址,仅在配置有效时使用
String mqttUdpConfig = sysParamsService.getValue(Constant.SERVER_MQTT_GATEWAY, false); String mqttUdpConfig = sysParamsService.getValue(Constant.SERVER_MQTT_GATEWAY, false);
if(mqttUdpConfig != null && !mqttUdpConfig.equals("null") && !mqttUdpConfig.isEmpty() && deviceById != null) { if (mqttUdpConfig != null && !mqttUdpConfig.equals("null") && !mqttUdpConfig.isEmpty() && deviceById != null) {
try { try {
DeviceReportRespDTO.MQTT mqtt = buildMqttConfig(macAddress, clientId, deviceById); DeviceReportRespDTO.MQTT mqtt = buildMqttConfig(macAddress, clientId, deviceById);
if (mqtt != null) { if (mqtt != null) {
@@ -459,7 +460,8 @@ public class DeviceServiceImpl extends BaseServiceImpl<DeviceDao, DeviceEntity>
/** /**
* 生成MQTT密码签名 * 生成MQTT密码签名
* @param content 签名内容 (clientId + '|' + username) *
* @param content 签名内容 (clientId + '|' + username)
* @param secretKey 密钥 * @param secretKey 密钥
* @return Base64编码的HMAC-SHA256签名 * @return Base64编码的HMAC-SHA256签名
*/ */
@@ -473,19 +475,16 @@ public class DeviceServiceImpl extends BaseServiceImpl<DeviceDao, DeviceEntity>
/** /**
* 构建MQTT配置信息 * 构建MQTT配置信息
*
* @param macAddress MAC地址 * @param macAddress MAC地址
* @param clientId 客户端ID (UUID) * @param clientId 客户端ID (UUID)
* @param device 设备信息 * @param device 设备信息
* @return MQTT配置对象 * @return MQTT配置对象
*/ */
private DeviceReportRespDTO.MQTT buildMqttConfig(String macAddress, String clientId, DeviceEntity device) throws Exception { private DeviceReportRespDTO.MQTT buildMqttConfig(String macAddress, String clientId, DeviceEntity device)
throws Exception {
// 从环境变量或系统参数获取签名密钥 // 从环境变量或系统参数获取签名密钥
String signatureKey = System.getenv("MQTT_SIGNATURE_KEY"); String signatureKey = sysParamsService.getValue("server.mqtt_signature_key", false);
if (StringUtils.isBlank(signatureKey)) {
// 如果环境变量没有,尝试从系统参数获取
signatureKey = sysParamsService.getValue("mqtt.signature_key", false);
}
if (StringUtils.isBlank(signatureKey)) { if (StringUtils.isBlank(signatureKey)) {
log.warn("缺少MQTT_SIGNATURE_KEY,跳过MQTT配置生成"); log.warn("缺少MQTT_SIGNATURE_KEY,跳过MQTT配置生成");
return null; return null;
@@ -500,7 +499,8 @@ public class DeviceServiceImpl extends BaseServiceImpl<DeviceDao, DeviceEntity>
Map<String, String> userData = new HashMap<>(); Map<String, String> userData = new HashMap<>();
// 尝试获取客户端IP // 尝试获取客户端IP
try { try {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder
.getRequestAttributes();
if (attributes != null) { if (attributes != null) {
HttpServletRequest request = attributes.getRequest(); HttpServletRequest request = attributes.getRequest();
String clientIp = request.getRemoteAddr(); String clientIp = request.getRemoteAddr();
@@ -1,7 +0,0 @@
delete from `sys_params` where id = 108;
delete from `sys_params` where param_code = 'server.mqtt_gateway';
INSERT INTO `sys_params` (id, param_code, param_value, value_type, param_type, remark) VALUES (108, 'server.mqtt_gateway', 'null', 'string', 1, 'mqtt gateway 配置');
delete from `sys_params` where param_code = 'server.udp_gateway';
INSERT INTO `sys_params` (id, param_code, param_value, value_type, param_type, remark) VALUES (109, 'server.udp_gateway', 'null', 'string', 1, 'udp gateway 配置');
@@ -0,0 +1,8 @@
delete from `sys_params` where param_code = 'server.mqtt_gateway';
INSERT INTO `sys_params` (id, param_code, param_value, value_type, param_type, remark) VALUES (116, 'server.mqtt_gateway', 'null', 'string', 1, 'mqtt gateway 配置');
delete from `sys_params` where param_code = 'server.mqtt_signature_key';
INSERT INTO `sys_params` (id, param_code, param_value, value_type, param_type, remark) VALUES (117, 'server.mqtt_signature_key', 'null', 'string', 1, 'mqtt 密钥 配置');
delete from `sys_params` where param_code = 'server.udp_gateway';
INSERT INTO `sys_params` (id, param_code, param_value, value_type, param_type, remark) VALUES (118, 'server.udp_gateway', 'null', 'string', 1, 'udp gateway 配置');
@@ -1,2 +0,0 @@
delete from `sys_params` where param_code = 'mqtt.signature_key';
INSERT INTO `sys_params` (id, param_code, param_value, value_type, param_type, remark) VALUES (120, 'mqtt.signature_key', 'null', 'string', 1, 'mqtt 密钥 配置');
@@ -305,17 +305,9 @@ databaseChangeLog:
path: classpath:db/changelog/202508131557.sql path: classpath:db/changelog/202508131557.sql
- changeSet: - changeSet:
id: 202509080921 id: 202509080922
author: fan author: fyb
changes: changes:
- sqlFile: - sqlFile:
encoding: utf8 encoding: utf8
path: classpath:db/changelog/202509080921.sql path: classpath:db/changelog/202509080922.sql
- changeSet:
id: 202509080927
author: fan
changes:
- sqlFile:
encoding: utf8
path: classpath:db/changelog/202509080927.sql