CREATE TABLE IF NOT EXISTS `safe_line_inspection_task` (
  `id` bigint NOT NULL AUTO_INCREMENT COMMENT '任务ID',
  `inspection_name` varchar(100) DEFAULT NULL COMMENT '巡检任务名称',
  `line_name` varchar(100) DEFAULT NULL COMMENT '线路名称',
  `inspection_project` varchar(1000) DEFAULT NULL COMMENT '巡检项目',
  `inspector_id` varchar(255) DEFAULT NULL COMMENT '巡检人ID，多个用逗号分隔',
  `frequency_type` varchar(20) DEFAULT NULL COMMENT '频率类型 DAILY/WEEKLY/MONTHLY',
  `frequency_detail` varchar(50) DEFAULT NULL COMMENT '频率详情：每日HH:mm；每周MON,HH:mm；每月DD,HH:mm',
  `next_execution_time` datetime DEFAULT NULL COMMENT '下次执行时间',
  `last_execution_time` datetime DEFAULT NULL COMMENT '最后执行时间',
  `is_enabled` tinyint DEFAULT '1' COMMENT '是否启用 0否 1是',
  `remark` varchar(500) DEFAULT NULL COMMENT '备注',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  `create_user` int DEFAULT NULL COMMENT '创建人ID',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `update_user` int DEFAULT NULL COMMENT '更新人ID',
  `tenant_id` bigint DEFAULT NULL COMMENT '租户ID',
  `dept_id` bigint DEFAULT NULL COMMENT '部门ID',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_safe_line_inspection_task_enabled` (`is_enabled`, `next_execution_time`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=DYNAMIC COMMENT='安全生产-线路定时巡检任务';

ALTER TABLE `safe_line_inspection`
  ADD COLUMN `schedule_task_id` bigint DEFAULT NULL COMMENT '定时巡检任务ID' AFTER `id`,
  ADD COLUMN `inspection_project` varchar(1000) DEFAULT NULL COMMENT '巡检项目' AFTER `inspection_type`,
  ADD KEY `idx_safe_line_inspection_schedule_task` (`schedule_task_id`) USING BTREE;

ALTER TABLE `safe_line_inspection`
  ADD COLUMN `inspection_result` varchar(20) DEFAULT NULL COMMENT '巡检结果：正常/异常' AFTER `status`,
  ADD COLUMN `actual_inspection_time` datetime DEFAULT NULL COMMENT '实际巡检时间' AFTER `inspection_result`,
  ADD COLUMN `hidden_id` int DEFAULT NULL COMMENT '关联隐患排查上报ID' AFTER `actual_inspection_time`,
  ADD KEY `idx_safe_line_inspection_hidden` (`hidden_id`) USING BTREE;

ALTER TABLE `safe_line_inspection_hazard`
  ADD COLUMN `safe_hidden_id` int DEFAULT NULL COMMENT '关联隐患排查上报ID' AFTER `record_id`,
  ADD COLUMN `rectify_deadline` date DEFAULT NULL COMMENT '整改期限' AFTER `rectify_user_id`,
  ADD KEY `idx_safe_line_inspection_hazard_hidden` (`safe_hidden_id`) USING BTREE;
