Files
cattleTransportation/tradeCattle/add_iot_device_table.sql
2025-10-23 17:28:06 +08:00

45 lines
2.4 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.

-- 创建IoT设备数据表
CREATE TABLE IF NOT EXISTS `iot_device_data` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`device_id` varchar(50) NOT NULL COMMENT '设备ID',
`device_type` int(11) NOT NULL COMMENT '设备类型1-主机2-耳标4-项圈',
`device_name` varchar(50) NOT NULL COMMENT '设备名称',
`voltage` decimal(5,3) DEFAULT NULL COMMENT '电压值',
`battery_percentage` int(11) DEFAULT NULL COMMENT '电量百分比',
`temperature` decimal(5,2) DEFAULT NULL COMMENT '温度',
`steps` bigint(20) DEFAULT NULL COMMENT '步数',
`signal_strength` varchar(20) DEFAULT NULL COMMENT '信号强度',
`rsrp` varchar(20) DEFAULT NULL COMMENT 'RSRP信号强度',
`gps_state` varchar(20) DEFAULT NULL COMMENT 'GPS状态',
`latitude` varchar(20) DEFAULT NULL COMMENT '纬度',
`longitude` varchar(20) DEFAULT NULL COMMENT '经度',
`altitude` varchar(20) DEFAULT NULL COMMENT '海拔',
`same_day_steps` int(11) DEFAULT NULL COMMENT '当日步数',
`status` int(11) DEFAULT NULL COMMENT '设备状态',
`version` varchar(20) DEFAULT NULL COMMENT '设备版本',
`uptime` datetime DEFAULT NULL COMMENT '更新时间',
`organ_id` varchar(20) DEFAULT NULL COMMENT '机构ID',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_device_id` (`device_id`),
KEY `idx_device_type` (`device_type`),
KEY `idx_organ_id` (`organ_id`),
KEY `idx_uptime` (`uptime`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='IoT设备数据表';
-- 创建数据同步日志表
CREATE TABLE IF NOT EXISTS `iot_sync_log` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`sync_type` varchar(20) NOT NULL COMMENT '同步类型AUTO-自动MANUAL-手动',
`sync_status` varchar(20) NOT NULL COMMENT '同步状态SUCCESS-成功FAILED-失败',
`total_count` int(11) DEFAULT 0 COMMENT '总数据量',
`success_count` int(11) DEFAULT 0 COMMENT '成功数量',
`failed_count` int(11) DEFAULT 0 COMMENT '失败数量',
`error_message` text COMMENT '错误信息',
`sync_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '同步时间',
PRIMARY KEY (`id`),
KEY `idx_sync_time` (`sync_time`),
KEY `idx_sync_status` (`sync_status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='IoT数据同步日志表';