admin/update_device_status_fields.sql
lvfengfree 2e28ad1472 feat: 拆分设备状态为AMT状态和Agent状态
- 数据库:添加 amt_status 和 agent_status 字段
- 后端:Device 实体类和 DeviceDTO 添加新状态字段
- 后端:DeviceService 添加状态检测和更新方法
- 后端:添加 AmtStatusCheckTask 定时任务(每30秒检测一次)
- 前端:设备列表页面拆分状态列显示
- 前端:统计卡片显示 AMT 和 Agent 在线/离线数量
- 网络扫描:自动设置 AMT 状态为在线
- 文档:添加 DEVICE_STATUS_SPLIT.md 和 AMT_REALTIME_STATUS.md
2026-03-01 19:18:32 +08:00

50 lines
1.7 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 更新设备表,添加 AMT 状态和 Agent 状态字段(安全版本)
-- 1. 检查并添加 amt_status 字段(如果不存在)
SET @col_exists = 0;
SELECT COUNT(*) INTO @col_exists
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = 'soybean_admin'
AND TABLE_NAME = 'sys_device'
AND COLUMN_NAME = 'amt_status';
SET @sql = IF(@col_exists = 0,
'ALTER TABLE sys_device ADD COLUMN amt_status VARCHAR(20) DEFAULT ''offline'' COMMENT ''AMT状态: online-在线, offline-离线''',
'SELECT ''amt_status column already exists'' AS message');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- 2. 检查并添加 agent_status 字段(如果不存在)
SET @col_exists = 0;
SELECT COUNT(*) INTO @col_exists
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = 'soybean_admin'
AND TABLE_NAME = 'sys_device'
AND COLUMN_NAME = 'agent_status';
SET @sql = IF(@col_exists = 0,
'ALTER TABLE sys_device ADD COLUMN agent_status VARCHAR(20) DEFAULT ''offline'' COMMENT ''Agent状态: online-在线, offline-离线''',
'SELECT ''agent_status column already exists'' AS message');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- 3. 将原有的 status 字段数据迁移到 amt_status仅当 amt_status 为 NULL 或 'offline' 时)
UPDATE sys_device
SET amt_status = CASE
WHEN status IN ('online', 'offline') THEN status
ELSE 'offline'
END
WHERE amt_status IS NULL OR amt_status = 'offline';
-- 4. 确保所有设备都有 agent_status默认为离线
UPDATE sys_device
SET agent_status = 'offline'
WHERE agent_status IS NULL;
-- 5. 查看更新后的数据
SELECT id, device_name, status, amt_status, agent_status, ip_address
FROM sys_device
LIMIT 10;