335 lines
21 KiB
SQL
335 lines
21 KiB
SQL
-- ----------------------------
|
|
-- AR智能巡检平台 - 数据库表结构SQL
|
|
-- 适用于 MySQL 8.0+
|
|
-- 创建日期: 2025-01-13
|
|
-- ----------------------------
|
|
|
|
-- 设置字符集和排序规则
|
|
SET NAMES utf8mb4;
|
|
SET FOREIGN_KEY_CHECKS = 0;
|
|
|
|
-- ----------------------------
|
|
-- 表1: AR设备管理表
|
|
-- ----------------------------
|
|
DROP TABLE IF EXISTS `ar_device`;
|
|
CREATE TABLE `ar_device` (
|
|
`id` bigint(20) NOT NULL COMMENT '设备ID',
|
|
`tenant_id` varchar(20) DEFAULT '000000' COMMENT '租户编号',
|
|
`device_name` varchar(100) NOT NULL COMMENT '设备名称',
|
|
`device_no` varchar(50) NOT NULL COMMENT '设备编号',
|
|
`device_model` varchar(100) DEFAULT NULL COMMENT '设备型号',
|
|
`status` char(1) DEFAULT '0' COMMENT '状态(0启用 1停用)',
|
|
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
|
`del_flag` char(1) DEFAULT '0' COMMENT '删除标志(0存在 1删除)',
|
|
`create_dept` bigint(20) DEFAULT NULL COMMENT '创建部门',
|
|
`create_by` bigint(20) DEFAULT NULL COMMENT '创建者',
|
|
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
|
|
`update_by` bigint(20) DEFAULT NULL COMMENT '更新者',
|
|
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `uk_device_no` (`device_no`, `tenant_id`),
|
|
KEY `idx_tenant_id` (`tenant_id`),
|
|
KEY `idx_status` (`status`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='AR设备管理表';
|
|
|
|
-- ----------------------------
|
|
-- 表2: 巡检区域管理表
|
|
-- ----------------------------
|
|
DROP TABLE IF EXISTS `ar_region`;
|
|
CREATE TABLE `ar_region` (
|
|
`id` bigint(20) NOT NULL COMMENT '区域ID',
|
|
`tenant_id` varchar(20) DEFAULT '000000' COMMENT '租户编号',
|
|
`region_name` varchar(100) NOT NULL COMMENT '区域名称',
|
|
`region_code` varchar(50) NOT NULL COMMENT '区域编码',
|
|
`region_data` text DEFAULT NULL COMMENT '区域业务数据(JSON格式,预留)',
|
|
`status` char(1) DEFAULT '0' COMMENT '状态(0正常 1停用)',
|
|
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
|
`del_flag` char(1) DEFAULT '0' COMMENT '删除标志(0存在 1删除)',
|
|
`create_dept` bigint(20) DEFAULT NULL COMMENT '创建部门',
|
|
`create_by` bigint(20) DEFAULT NULL COMMENT '创建者',
|
|
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
|
|
`update_by` bigint(20) DEFAULT NULL COMMENT '更新者',
|
|
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `uk_region_code` (`region_code`, `tenant_id`),
|
|
KEY `idx_tenant_id` (`tenant_id`),
|
|
KEY `idx_status` (`status`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='巡检区域管理表';
|
|
|
|
-- ----------------------------
|
|
-- 表3: 巡检点位管理表
|
|
-- ----------------------------
|
|
DROP TABLE IF EXISTS `ar_point`;
|
|
CREATE TABLE `ar_point` (
|
|
`id` bigint(20) NOT NULL COMMENT '点位ID',
|
|
`tenant_id` varchar(20) DEFAULT '000000' COMMENT '租户编号',
|
|
`region_id` bigint(20) NOT NULL COMMENT '所属区域ID',
|
|
`point_name` varchar(100) NOT NULL COMMENT '点位名称',
|
|
`point_code` varchar(50) NOT NULL COMMENT '点位编码',
|
|
`position_data` text DEFAULT NULL COMMENT '点位业务数据(JSON格式,包含坐标、预设等)',
|
|
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
|
`del_flag` char(1) DEFAULT '0' COMMENT '删除标志(0存在 1删除)',
|
|
`create_dept` bigint(20) DEFAULT NULL COMMENT '创建部门',
|
|
`create_by` bigint(20) DEFAULT NULL COMMENT '创建者',
|
|
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
|
|
`update_by` bigint(20) DEFAULT NULL COMMENT '更新者',
|
|
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `uk_point_code` (`point_code`, `tenant_id`),
|
|
KEY `idx_region_id` (`region_id`),
|
|
KEY `idx_tenant_id` (`tenant_id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='巡检点位管理表';
|
|
|
|
-- ----------------------------
|
|
-- 表4: 巡检任务模板表
|
|
-- ----------------------------
|
|
DROP TABLE IF EXISTS `ar_task`;
|
|
CREATE TABLE `ar_task` (
|
|
`id` bigint(20) NOT NULL COMMENT '任务ID',
|
|
`tenant_id` varchar(20) DEFAULT '000000' COMMENT '租户编号',
|
|
`task_name` varchar(100) NOT NULL COMMENT '任务名称',
|
|
`task_code` varchar(50) NOT NULL COMMENT '任务编码',
|
|
`region_id` bigint(20) DEFAULT NULL COMMENT '关联区域ID',
|
|
`task_type` varchar(50) DEFAULT NULL COMMENT '任务类型',
|
|
`status` char(1) DEFAULT '0' COMMENT '状态(0正常 1停用)',
|
|
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
|
`del_flag` char(1) DEFAULT '0' COMMENT '删除标志(0存在 1删除)',
|
|
`create_dept` bigint(20) DEFAULT NULL COMMENT '创建部门',
|
|
`create_by` bigint(20) DEFAULT NULL COMMENT '创建者',
|
|
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
|
|
`update_by` bigint(20) DEFAULT NULL COMMENT '更新者',
|
|
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `uk_task_code` (`task_code`, `tenant_id`),
|
|
KEY `idx_region_id` (`region_id`),
|
|
KEY `idx_tenant_id` (`tenant_id`),
|
|
KEY `idx_task_type` (`task_type`),
|
|
KEY `idx_status` (`status`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='巡检任务模板表';
|
|
|
|
-- ----------------------------
|
|
-- 表5: 巡检步骤表(支持树形结构)
|
|
-- ----------------------------
|
|
DROP TABLE IF EXISTS `ar_step`;
|
|
CREATE TABLE `ar_step` (
|
|
`id` bigint(20) NOT NULL COMMENT '步骤ID',
|
|
`tenant_id` varchar(20) DEFAULT '000000' COMMENT '租户编号',
|
|
`task_id` bigint(20) NOT NULL COMMENT '所属任务ID',
|
|
`parent_id` bigint(20) DEFAULT 0 COMMENT '父步骤ID(0为顶级)',
|
|
`ancestors` varchar(500) DEFAULT '' COMMENT '祖级列表',
|
|
`step_name` varchar(100) NOT NULL COMMENT '步骤名称',
|
|
`step_content` text DEFAULT NULL COMMENT '步骤内容描述',
|
|
`content_voice` varchar(500) DEFAULT NULL COMMENT '步骤语音文本',
|
|
`order_num` int(11) DEFAULT 0 COMMENT '排序号',
|
|
`point_id` bigint(20) DEFAULT NULL COMMENT '关联点位ID',
|
|
`need_voice_read` char(1) DEFAULT '0' COMMENT '需要语音朗读(0否 1是)',
|
|
`need_voice_rephrase` char(1) DEFAULT '0' COMMENT '需要用户复述(0否 1是)',
|
|
`rephrase_content` text DEFAULT NULL COMMENT '复述提示文本',
|
|
`rephrase_voice` varchar(500) DEFAULT NULL COMMENT '复述语音文本',
|
|
`need_voice_confirm` char(1) DEFAULT '0' COMMENT '需要确认(0否 1是)',
|
|
`confirm_content` text DEFAULT NULL COMMENT '确认提示文本',
|
|
`confirm_voice` varchar(500) DEFAULT NULL COMMENT '确认语音文本',
|
|
`confirm_word` varchar(100) DEFAULT NULL COMMENT '确认词',
|
|
`need_ai` char(1) DEFAULT '0' COMMENT '需要AI识别(0否 1是)',
|
|
`ai_target_name` varchar(100) DEFAULT NULL COMMENT 'AI目标名称',
|
|
`ai_data` text DEFAULT NULL COMMENT 'AI配置数据(JSON格式,预留)',
|
|
`is_operation` char(1) DEFAULT '0' COMMENT '是否操作步骤(0否 1是)',
|
|
`is_leaf` char(1) DEFAULT '1' COMMENT '是否叶子节点(0否 1是)',
|
|
`del_flag` char(1) DEFAULT '0' COMMENT '删除标志(0存在 1删除)',
|
|
`create_dept` bigint(20) DEFAULT NULL COMMENT '创建部门',
|
|
`create_by` bigint(20) DEFAULT NULL COMMENT '创建者',
|
|
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
|
|
`update_by` bigint(20) DEFAULT NULL COMMENT '更新者',
|
|
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
|
|
PRIMARY KEY (`id`),
|
|
KEY `idx_task_id` (`task_id`),
|
|
KEY `idx_parent_id` (`parent_id`),
|
|
KEY `idx_point_id` (`point_id`),
|
|
KEY `idx_tenant_id` (`tenant_id`),
|
|
KEY `idx_order_num` (`order_num`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='巡检步骤表(支持树形结构)';
|
|
|
|
-- ----------------------------
|
|
-- 表6: 步骤媒体文件表
|
|
-- ----------------------------
|
|
DROP TABLE IF EXISTS `ar_step_media`;
|
|
CREATE TABLE `ar_step_media` (
|
|
`id` bigint(20) NOT NULL COMMENT '媒体ID',
|
|
`tenant_id` varchar(20) DEFAULT '000000' COMMENT '租户编号',
|
|
`step_record_id` bigint(20) NOT NULL COMMENT '步骤记录ID',
|
|
`media_type` varchar(50) NOT NULL COMMENT '媒体类型(image/video/audio)',
|
|
`file_url` varchar(500) NOT NULL COMMENT '文件URL',
|
|
`file_name` varchar(200) DEFAULT NULL COMMENT '文件名称',
|
|
`file_size` bigint(20) DEFAULT NULL COMMENT '文件大小(字节)',
|
|
`upload_time` datetime DEFAULT NULL COMMENT '上传时间',
|
|
`del_flag` char(1) DEFAULT '0' COMMENT '删除标志(0存在 1删除)',
|
|
`create_dept` bigint(20) DEFAULT NULL COMMENT '创建部门',
|
|
`create_by` bigint(20) DEFAULT NULL COMMENT '创建者',
|
|
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
|
|
`update_by` bigint(20) DEFAULT NULL COMMENT '更新者',
|
|
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
|
|
PRIMARY KEY (`id`),
|
|
KEY `idx_step_record_id` (`step_record_id`),
|
|
KEY `idx_media_type` (`media_type`),
|
|
KEY `idx_tenant_id` (`tenant_id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='步骤媒体文件表';
|
|
|
|
-- ----------------------------
|
|
-- 表7: 任务执行记录表
|
|
-- ----------------------------
|
|
DROP TABLE IF EXISTS `ar_execution`;
|
|
CREATE TABLE `ar_execution` (
|
|
`id` bigint(20) NOT NULL COMMENT '执行ID',
|
|
`tenant_id` varchar(20) DEFAULT '000000' COMMENT '租户编号',
|
|
`task_id` bigint(20) NOT NULL COMMENT '任务模板ID',
|
|
`execution_code` varchar(50) NOT NULL COMMENT '执行编号',
|
|
`region_id` bigint(20) DEFAULT NULL COMMENT '区域ID',
|
|
`device_id` bigint(20) DEFAULT NULL COMMENT '使用设备ID',
|
|
`operator_id` bigint(20) DEFAULT NULL COMMENT '操作人ID',
|
|
`operator_name` varchar(50) DEFAULT NULL COMMENT '操作人姓名',
|
|
`custodian_id` bigint(20) DEFAULT NULL COMMENT '监护人ID',
|
|
`custodian_name` varchar(50) DEFAULT NULL COMMENT '监护人姓名',
|
|
`sender_id` bigint(20) DEFAULT NULL COMMENT '发令人ID',
|
|
`sender_name` varchar(50) DEFAULT NULL COMMENT '发令人姓名',
|
|
`recipient_id` bigint(20) DEFAULT NULL COMMENT '收令人ID',
|
|
`recipient_name` varchar(50) DEFAULT NULL COMMENT '收令人姓名',
|
|
`commander_id` bigint(20) DEFAULT NULL COMMENT '值长ID',
|
|
`commander_name` varchar(50) DEFAULT NULL COMMENT '值长姓名',
|
|
`status` varchar(20) DEFAULT 'pending' COMMENT '状态(pending待执行/in_progress执行中/completed已完成/cancelled已取消)',
|
|
`start_time` datetime DEFAULT NULL COMMENT '开始时间',
|
|
`end_time` datetime DEFAULT NULL COMMENT '结束时间',
|
|
`total_steps` int(11) DEFAULT 0 COMMENT '总步骤数',
|
|
`completed_steps` int(11) DEFAULT 0 COMMENT '已完成步骤数',
|
|
`del_flag` char(1) DEFAULT '0' COMMENT '删除标志(0存在 1删除)',
|
|
`create_dept` bigint(20) DEFAULT NULL COMMENT '创建部门',
|
|
`create_by` bigint(20) DEFAULT NULL COMMENT '创建者',
|
|
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
|
|
`update_by` bigint(20) DEFAULT NULL COMMENT '更新者',
|
|
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `uk_execution_code` (`execution_code`, `tenant_id`),
|
|
KEY `idx_task_id` (`task_id`),
|
|
KEY `idx_region_id` (`region_id`),
|
|
KEY `idx_device_id` (`device_id`),
|
|
KEY `idx_status` (`status`),
|
|
KEY `idx_tenant_id` (`tenant_id`),
|
|
KEY `idx_create_time` (`create_time`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='任务执行记录表';
|
|
|
|
-- ----------------------------
|
|
-- 表8: 步骤执行记录表
|
|
-- ----------------------------
|
|
DROP TABLE IF EXISTS `ar_step_record`;
|
|
CREATE TABLE `ar_step_record` (
|
|
`id` bigint(20) NOT NULL COMMENT '记录ID',
|
|
`tenant_id` varchar(20) DEFAULT '000000' COMMENT '租户编号',
|
|
`execution_id` bigint(20) NOT NULL COMMENT '任务执行ID',
|
|
`step_id` bigint(20) NOT NULL COMMENT '步骤ID',
|
|
`status` varchar(20) DEFAULT 'pending' COMMENT '状态(pending待执行/completed已完成/skipped已跳过)',
|
|
`is_done` char(1) DEFAULT '0' COMMENT '是否完成(0否 1是)',
|
|
`start_time` datetime DEFAULT NULL COMMENT '开始时间',
|
|
`completion_time` datetime DEFAULT NULL COMMENT '完成时间',
|
|
`duration` int(11) DEFAULT 0 COMMENT '耗时(秒)',
|
|
`text_feedback` text DEFAULT NULL COMMENT '文本反馈',
|
|
`voice_text` text DEFAULT NULL COMMENT '语音识别文本',
|
|
`ai_result` text DEFAULT NULL COMMENT 'AI识别结果(JSON格式)',
|
|
`executor_id` bigint(20) DEFAULT NULL COMMENT '执行人ID',
|
|
`executor_name` varchar(50) DEFAULT NULL COMMENT '执行人姓名',
|
|
`del_flag` char(1) DEFAULT '0' COMMENT '删除标志(0存在 1删除)',
|
|
`create_dept` bigint(20) DEFAULT NULL COMMENT '创建部门',
|
|
`create_by` bigint(20) DEFAULT NULL COMMENT '创建者',
|
|
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
|
|
`update_by` bigint(20) DEFAULT NULL COMMENT '更新者',
|
|
`update_time` datetime DEFAULT NULL COMMENT '更新时间',
|
|
PRIMARY KEY (`id`),
|
|
KEY `idx_execution_id` (`execution_id`),
|
|
KEY `idx_step_id` (`step_id`),
|
|
KEY `idx_status` (`status`),
|
|
KEY `idx_tenant_id` (`tenant_id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='步骤执行记录表';
|
|
|
|
-- ----------------------------
|
|
-- 插入示例数据(可选)
|
|
-- ----------------------------
|
|
|
|
-- 示例设备数据
|
|
-- INSERT INTO ar_device VALUES(1, '000000', 'AR眼镜-001', 'DEV001', 'HoloLens 2', '0', 'AR智能眼镜设备', '0', 103, 1, sysdate(), null, null);
|
|
-- INSERT INTO ar_device VALUES(2, '000000', 'AR眼镜-002', 'DEV002', 'HoloLens 2', '0', 'AR智能眼镜设备', '0', 103, 1, sysdate(), null, null);
|
|
|
|
-- 示例区域数据
|
|
-- INSERT INTO ar_region VALUES(1, '000000', '主控室', 'REGION001', null, '0', '电厂主控室区域', '0', 103, 1, sysdate(), null, null);
|
|
-- INSERT INTO ar_region VALUES(2, '000000', '设备间', 'REGION002', null, '0', '设备机房区域', '0', 103, 1, sysdate(), null, null);
|
|
|
|
-- 示例点位数据
|
|
-- INSERT INTO ar_point VALUES(1, '000000', 1, '主控台', 'POINT001', null, '主控台点位', '0', 103, 1, sysdate(), null, null);
|
|
-- INSERT INTO ar_point VALUES(2, '000000', 1, '监控屏', 'POINT002', null, '监控屏点位', '0', 103, 1, sysdate(), null, null);
|
|
|
|
-- 示例任务模板数据
|
|
-- INSERT INTO ar_task VALUES(1, '000000', '日常巡检任务', 'TASK001', 1, 'daily', '0', '每日例行巡检任务', '0', 103, 1, sysdate(), null, null);
|
|
-- INSERT INTO ar_task VALUES(2, '000000', '设备检修任务', 'TASK002', 2, 'maintenance', '0', '设备定期检修任务', '0', 103, 1, sysdate(), null, null);
|
|
|
|
SET FOREIGN_KEY_CHECKS = 1;
|
|
|
|
-- ----------------------------
|
|
-- 说明
|
|
-- ----------------------------
|
|
-- 1. 本SQL文件适用于 MySQL 8.0+ 版本
|
|
-- 2. 所有表均支持多租户功能,通过 tenant_id 字段隔离
|
|
-- 3. 所有表均支持逻辑删除,通过 del_flag 字段标识
|
|
-- 4. 主键采用雪花ID算法,由应用程序生成,不使用数据库自增
|
|
-- 5. 所有表包含标准审计字段: create_dept, create_by, create_time, update_by, update_time
|
|
-- 6. ar_step 表支持树形结构,通过 parent_id 和 ancestors 字段实现
|
|
-- 7. JSON字段使用 text 类型存储,由 MyBatis-Plus 的 JacksonTypeHandler 处理
|
|
-- 8. 索引已根据业务查询场景优化配置
|
|
-- 9. 字符集使用 utf8mb4,支持emoji等特殊字符
|
|
-- 10. 排序规则使用 utf8mb4_unicode_ci,确保多语言支持
|
|
|
|
-- ----------------------------
|
|
-- 导入说明
|
|
-- ----------------------------
|
|
-- 执行方式1: 命令行导入
|
|
-- mysql -u root -p -D ry-vue < /path/to/ar-inspection-tables.sql
|
|
--
|
|
-- 执行方式2: MySQL客户端执行
|
|
-- mysql> use ry-vue;
|
|
-- mysql> source /path/to/ar-inspection-tables.sql;
|
|
--
|
|
-- 执行方式3: Navicat等GUI工具
|
|
-- 打开SQL文件后点击"运行"按钮执行
|
|
--
|
|
-- 注意事项:
|
|
-- - 请确保已创建数据库 ry-vue (或根据实际情况修改数据库名)
|
|
-- - 建议先在测试环境验证后再在生产环境执行
|
|
-- - 执行前请备份现有数据库
|
|
-- - 示例数据默认已注释,如需使用请取消注释
|
|
|
|
-- ----------------------------
|
|
-- 表关系说明
|
|
-- ----------------------------
|
|
-- ar_device (设备)
|
|
-- └── ar_execution (执行记录) - 通过 device_id 关联
|
|
--
|
|
-- ar_region (区域)
|
|
-- ├── ar_point (点位) - 通过 region_id 关联
|
|
-- ├── ar_task (任务模板) - 通过 region_id 关联
|
|
-- └── ar_execution (执行记录) - 通过 region_id 关联
|
|
--
|
|
-- ar_point (点位)
|
|
-- └── ar_step (巡检步骤) - 通过 point_id 关联
|
|
--
|
|
-- ar_task (任务模板)
|
|
-- ├── ar_step (巡检步骤) - 通过 task_id 关联
|
|
-- └── ar_execution (执行记录) - 通过 task_id 关联
|
|
--
|
|
-- ar_step (巡检步骤)
|
|
-- ├── ar_step (父子关系) - 通过 parent_id 关联(树形结构)
|
|
-- └── ar_step_record (步骤记录) - 通过 step_id 关联
|
|
--
|
|
-- ar_execution (执行记录)
|
|
-- └── ar_step_record (步骤记录) - 通过 execution_id 关联
|
|
--
|
|
-- ar_step_record (步骤记录)
|
|
-- └── ar_step_media (步骤媒体) - 通过 step_record_id 关联
|
|
|
|
-- 创建完成!
|