20260110:

1、调试完全开放
This commit is contained in:
George 2026-01-10 16:00:41 +08:00
parent 753d859665
commit 241fcb0333
3 changed files with 16 additions and 136 deletions

View File

@ -2,7 +2,6 @@ package com.fastbee.iot.data.aspect;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.fastbee.common.constant.CacheConstants;
import com.fastbee.common.core.device.DeviceAndProtocol; import com.fastbee.common.core.device.DeviceAndProtocol;
import com.fastbee.common.core.mq.DeviceReportBo; import com.fastbee.common.core.mq.DeviceReportBo;
import com.fastbee.common.core.mq.message.DeviceData; import com.fastbee.common.core.mq.message.DeviceData;
@ -11,8 +10,6 @@ import com.fastbee.common.core.redis.RedisCache;
import com.fastbee.common.core.thingsModel.ThingsModelSimpleItem; import com.fastbee.common.core.thingsModel.ThingsModelSimpleItem;
import com.fastbee.common.enums.DeviceLogTypeEnum; import com.fastbee.common.enums.DeviceLogTypeEnum;
import com.fastbee.common.enums.TopicType; import com.fastbee.common.enums.TopicType;
import com.fastbee.common.utils.DateUtils;
import com.fastbee.common.utils.SecurityUtils;
import com.fastbee.common.utils.StringUtils; import com.fastbee.common.utils.StringUtils;
import com.fastbee.common.utils.gateway.mq.TopicsUtils; import com.fastbee.common.utils.gateway.mq.TopicsUtils;
import com.fastbee.iot.domain.*; import com.fastbee.iot.domain.*;
@ -60,23 +57,6 @@ import java.util.function.Function;
@Slf4j @Slf4j
public class DeviceDebugLogAspect { public class DeviceDebugLogAspect {
/**
* 日志值最大长度
*/
private static final int MAX_LOG_VALUE_LENGTH = 64;
/**
* 备注最大长度
*/
private static final int MAX_REMARK_LENGTH = 200;
/**
* 错误信息显示最大长度
*/
private static final int MAX_ERROR_MSG_DISPLAY_LENGTH = 50;
/**
* 其他模式
*/
private static final int MODE_OTHER = 3;
@Resource @Resource
private ILogService logService; private ILogService logService;
@ -220,11 +200,6 @@ public class DeviceDebugLogAspect {
return; return;
} }
// 检查用户是否在数据调试页面
if (!isUserInDebugPage(context.getSerialNumber())) {
return;
}
saveErrorLog(context); saveErrorLog(context);
} catch (Exception ex) { } catch (Exception ex) {
log.error("{}: {}", errorLogPrefix, ex.getMessage(), ex); log.error("{}: {}", errorLogPrefix, ex.getMessage(), ex);
@ -300,48 +275,7 @@ public class DeviceDebugLogAspect {
} }
@Resource @Resource
private IDeviceUserService deviceUserService; private IDeviceUserService deviceUserService;
/**
* 检查当前用户是否在数据调试页面
* @return true-在调试页面,false-不在调试页面
*/
private boolean isUserInDebugPage(String serialNumber) {
// 1、从Redis中获取用户ID
// 2、从SecurityContext中获取用户ID
// try {
// Long userId = SecurityUtils.getUserId();
// if (userId == null) {
// return false;
// }
// String cacheKey = CacheConstants.DEVICE_DEBUG_USER_KEY + userId;
// String flag = redisCache.getCacheObject(cacheKey);
// return "1".equals(flag);
// } catch (Exception e) {
// // 如果获取用户信息失败,默认不记录日志,避免影响正常功能
// log.debug("无法从SecurityContext获取用户ID(可能在异步线程中)");
// }
// 3、从数据库中获取用户ID
try {
// 获取设备信息
Device device = getDeviceBySerialNumber(serialNumber);
if (device == null || device.getTenantId() == null) {
return false;
}
String cacheKey = CacheConstants.DEVICE_DEBUG_USER_KEY + device.getTenantId();
String flag = redisCache.getCacheObject(cacheKey);
if ("1".equals(flag)) {
log.debug("检测到设备[{}]的关联用户[{}]开启了调试标志", serialNumber, device.getTenantId());
return true;
}
return false;
} catch (Exception e) {
log.warn("检查设备用户调试状态失败: {}, 设备编号: {}", e.getMessage(), serialNumber);
return false;
}
}
/** /**
* 检查设备是否已授权 * 检查设备是否已授权
@ -400,15 +334,6 @@ public class DeviceDebugLogAspect {
return; return;
} }
// 构建并保存设备日志
// DeviceLog deviceLog = buildDeviceLog(device, context);
// logService.saveDeviceLog(deviceLog);
// if (log.isDebugEnabled()) {
// log.debug("已保存错误日志到数据库 - 设备: {}, 错误类型: {}, 错误信息: {}",
// serialNumber, context.getIdentity(),
// StringUtils.substring(context.getErrorMsg(), 0, MAX_ERROR_MSG_DISPLAY_LENGTH));
// }
// 推送错误信息到前端页面 // 推送错误信息到前端页面
pushErrorToFrontend(serialNumber, productId, context); pushErrorToFrontend(serialNumber, productId, context);
} catch (Exception ex) { } catch (Exception ex) {
@ -428,30 +353,6 @@ public class DeviceDebugLogAspect {
} }
} }
/**
* 构建设备日志对象
*/
private DeviceLog buildDeviceLog(Device device, ErrorLogContext context) {
DeviceLog deviceLog = new DeviceLog();
deviceLog.setSerialNumber(context.getSerialNumber());
deviceLog.setDeviceId(device.getDeviceId());
deviceLog.setDeviceName(device.getDeviceName());
deviceLog.setLogType(context.getLogType());
deviceLog.setLogValue(StringUtils.substring(context.getSourceData(), 0, MAX_LOG_VALUE_LENGTH));
deviceLog.setRemark(StringUtils.substring(context.getErrorMsg(), 0, MAX_REMARK_LENGTH));
deviceLog.setIdentity(context.getIdentity());
deviceLog.setModelName(Objects.equals(context.getLogType(), DeviceLogTypeEnum.DATA_PARSE_ERROR.getType()) ?
"数据解析错误" : "指令发送错误");
deviceLog.setCreateTime(DateUtils.getNowDate());
deviceLog.setUserId(device.getTenantId());
deviceLog.setUserName(device.getTenantName());
deviceLog.setTenantId(device.getTenantId());
deviceLog.setTenantName(device.getTenantName());
deviceLog.setIsMonitor(0);
deviceLog.setMode(MODE_OTHER);
return deviceLog;
}
/** /**
* 推送错误信息到前端页面 * 推送错误信息到前端页面
*/ */

View File

@ -62,18 +62,18 @@ export function delPreferences(data) {
}); });
} }
// 开启设备调试日志记录 // 开启设备调试日志记录(先关闭)
export function enableDebugLog() { //export function enableDebugLog() {
return request({ // return request({
url: '/iot/device/debug/enable', // url: '/iot/device/debug/enable',
method: 'post', // method: 'post',
}); // });
} //}
//
// 关闭设备调试日志记录 //// 关闭设备调试日志记录
export function disableDebugLog() { //export function disableDebugLog() {
return request({ // return request({
url: '/iot/device/debug/disable', // url: '/iot/device/debug/disable',
method: 'post', // method: 'post',
}); // });
} //}

View File

@ -375,7 +375,7 @@
<script> <script>
import { hex2int, int2hex, copyText, formatDate, deepClone } from '@/utils/common'; import { hex2int, int2hex, copyText, formatDate, deepClone } from '@/utils/common';
import { encode, decode, messagePost, addPreferences, editPreferences, delPreferences, preferencesList, enableDebugLog, disableDebugLog } from '@/api/iot/mqttTest'; import { encode, decode, messagePost, addPreferences, editPreferences, delPreferences, preferencesList } from '@/api/iot/mqttTest';
export default { export default {
props: { props: {
device: { device: {
@ -910,22 +910,6 @@ export default {
}); });
} }
}, },
/**开启调试日志记录 */
async enableDebugLogging() {
try {
await enableDebugLog();
} catch (err) {
console.warn('开启调试日志记录失败:', err);
}
},
/**关闭调试日志记录 */
async disableDebugLogging() {
try {
await disableDebugLog();
} catch (err) {
console.warn('关闭调试日志记录失败:', err);
}
},
}, },
mounted() { mounted() {
this.resetCreateForm(); this.resetCreateForm();
@ -933,13 +917,8 @@ export default {
this.$busEvent.$off('updateData', this.handleUpdateData); this.$busEvent.$off('updateData', this.handleUpdateData);
// 绑定新的监听器 // 绑定新的监听器
this.$busEvent.$on('updateData', this.handleUpdateData); this.$busEvent.$on('updateData', this.handleUpdateData);
// 开启调试日志记录
this.enableDebugLogging();
}, },
beforeDestroy() { beforeDestroy() {
// 关闭调试日志记录
this.disableDebugLogging();
// 移除所有事件监听器 // 移除所有事件监听器
this.$busEvent.$off('updateData', this.handleUpdateData); this.$busEvent.$off('updateData', this.handleUpdateData);
this.$busEvent.$off('updateMqttMessage'); this.$busEvent.$off('updateMqttMessage');