/*
 Navicat Premium Dump SQL

 Source Server         : 腾讯云-124.221.55.225
 Source Server Type    : MySQL
 Source Server Version : 80044 (8.0.44)
 Source Host           : 124.221.55.225:3306
 Source Schema         : aiot-platform

 Target Server Type    : MySQL
 Target Server Version : 80044 (8.0.44)
 File Encoding         : 65001

 Date: 17/01/2026 15:01:11
*/

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for ops_bus_area
-- ----------------------------
DROP TABLE IF EXISTS `ops_bus_area`;
CREATE TABLE `ops_bus_area`  (
  `id` bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '区域ID，主键',
  `parent_id` bigint UNSIGNED NULL DEFAULT NULL COMMENT '父级区域ID，用于构建区域树',
  `parent_path` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '父级路径（如：1/2/3，便于查询所有子区域）',
  `area_name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '区域名称',
  `area_code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '区域业务编码（可选，全局唯一）',
  `area_type` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '区域层级类型（PARK=园区/BUILDING=楼栋/FLOOR=楼层/FUNCTION=功能区域）',
  `function_type` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '功能类型（MALE_TOILET=男卫/FEMALE_TOILET=女卫/PUBLIC=公共区/ELEVATOR=电梯厅等）',
  `floor_no` int NULL DEFAULT NULL COMMENT '楼层号（如：2、-1）',
  `cleaning_frequency` int NULL DEFAULT 1 COMMENT '保洁频率（次/天）',
  `standard_duration` int NULL DEFAULT NULL COMMENT '标准保洁时长（分钟）',
  `area_level` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '区域等级（HIGH=高优先级/MEDIUM=中/LOW=低）',
  `is_active` bit(1) NOT NULL DEFAULT b'1' COMMENT '是否启用',
  `sort` int NOT NULL DEFAULT 0 COMMENT '显示排序',
  `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '创建者',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '更新者',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
  `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `uk_area_code`(`area_code` ASC, `deleted` ASC) USING BTREE,
  INDEX `idx_parent_id`(`parent_id` ASC) USING BTREE,
  INDEX `idx_area_type`(`area_type` ASC) USING BTREE,
  INDEX `idx_floor_no`(`floor_no` ASC) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '业务区域' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for ops_order
-- ----------------------------
DROP TABLE IF EXISTS `ops_order`;
CREATE TABLE `ops_order`  (
  `id` bigint NOT NULL COMMENT '工单ID',
  `order_code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '工单编号（WO202501040001）',
  `order_type` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '工单类型（CLEAN=保洁/REPAIR=维修/SECURITY=安保/SERVICE=客服）',
  `source_type` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '来源（TRAFFIC=流量触发/INSPECTION=巡检发现/MANUAL=手动创建/SCHEDULE=定时排班）',
  `title` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '工单标题',
  `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT '工单描述/详情',
  `priority` tinyint NOT NULL DEFAULT 2 COMMENT '优先级（0=P0紧急 1=P1重要 2=P2普通）',
  `status` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'PENDING' COMMENT '工单状态（PENDING待分配/ASSIGNED已分配/ARRIVED已到岗/PAUSED已暂停/COMPLETED已完成/CANCELLED已取消）',
  `area_id` bigint NULL DEFAULT NULL COMMENT '区域ID',
  `location` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '具体位置描述（冗余，便于查询）',
  `urgent_reason` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '加急原因',
  `assignee_id` bigint NULL DEFAULT NULL COMMENT '当前执行人ID',
  `inspector_id` bigint NULL DEFAULT NULL COMMENT '巡检员ID（发起人）',
  `start_time` datetime NULL DEFAULT NULL COMMENT '工单开始时间（ARRIVED状态时间）',
  `end_time` datetime NULL DEFAULT NULL COMMENT '工单结束时间（COMPLETED状态时间）',
  `inspector_accept_time` datetime NULL DEFAULT NULL COMMENT '巡检员验收时间',
  `quality_score` tinyint NULL DEFAULT NULL COMMENT '验收评分（1-5星）',
  `quality_comment` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '���收评语',
  `response_seconds` int NULL DEFAULT NULL COMMENT '响应耗时（秒，派单到接单）',
  `completion_seconds` int NULL DEFAULT NULL COMMENT '完成耗时（秒，接单到完成）',
  `flow_instance_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT 'Flowable流程实例ID（预留）',
  `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '创建者',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '更新者',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
  `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `uk_order_code`(`order_code` ASC, `deleted` ASC) USING BTREE,
  INDEX `idx_order_type`(`order_type` ASC) USING BTREE,
  INDEX `idx_status`(`status` ASC) USING BTREE,
  INDEX `idx_priority`(`priority` ASC) USING BTREE,
  INDEX `idx_assignee`(`assignee_id` ASC) USING BTREE,
  INDEX `idx_area`(`area_id` ASC) USING BTREE,
  INDEX `idx_create_time`(`create_time` ASC) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '通用工单' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for ops_order_clean_ext
-- ----------------------------
DROP TABLE IF EXISTS `ops_order_clean_ext`;
CREATE TABLE `ops_order_clean_ext`  (
  `id` bigint NOT NULL COMMENT '主键',
  `ops_order_id` bigint NOT NULL COMMENT '工单ID',
  `is_auto` tinyint NULL DEFAULT 1 COMMENT '是否自动工单（1=自动 0=手动）',
  `expected_duration` int NULL DEFAULT NULL COMMENT '预计作业时长（分钟）',
  `arrived_time` datetime NULL DEFAULT NULL COMMENT '实际到岗时间',
  `completed_time` datetime NULL DEFAULT NULL COMMENT '实际完成时间',
  `pause_start_time` datetime NULL DEFAULT NULL COMMENT '暂停开始时间',
  `pause_end_time` datetime NULL DEFAULT NULL COMMENT '暂停结束时间',
  `total_pause_seconds` int NULL DEFAULT 0 COMMENT '累计暂停时长（秒）',
  `cleaning_type` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '保洁类型（ROUTINE=日常/DEEP=深度/SPOT=点状/EMERGENCY=应急）',
  `difficulty_level` tinyint NULL DEFAULT NULL COMMENT '难度等级（1-5级）',
  `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '创建者',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '更新者',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
  `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `uk_ops_order_id`(`ops_order_id` ASC, `deleted` ASC) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '保洁工单扩展' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for ops_order_clean_log
-- ----------------------------
DROP TABLE IF EXISTS `ops_order_clean_log`;
CREATE TABLE `ops_order_clean_log`  (
  `id` bigint NOT NULL COMMENT '日志ID',
  `event_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '事件发生时间',
  `event_level` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'INFO' COMMENT '日志级别（INFO=信息/WARN=警告/ERROR=错误）',
  `event_domain` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '领域（RULE=规则引擎/DISPATCH=调度/BADGE=工牌/BEACON=信标/SYSTEM=系统）',
  `event_type` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '事件类型',
  `ops_order_id` bigint NULL DEFAULT NULL COMMENT '关联工单ID',
  `area_id` bigint NULL DEFAULT NULL COMMENT '区域ID',
  `cleaner_id` bigint NULL DEFAULT NULL COMMENT '保洁员ID',
  `device_id` bigint NULL DEFAULT NULL COMMENT '设备ID（工牌/信标）',
  `event_message` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '可读日志内容',
  `event_payload` json NULL COMMENT '结构化上下文',
  `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '创建者',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '更新者',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
  `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_event_time`(`event_time` ASC) USING BTREE,
  INDEX `idx_ops_order_id`(`ops_order_id` ASC) USING BTREE,
  INDEX `idx_cleaner_id`(`cleaner_id` ASC) USING BTREE,
  INDEX `idx_event_domain_type`(`event_domain` ASC, `event_type` ASC) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '保洁业务日志' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for ops_order_dispatch
-- ----------------------------
DROP TABLE IF EXISTS `ops_order_dispatch`;
CREATE TABLE `ops_order_dispatch`  (
  `id` bigint NOT NULL COMMENT '派单ID',
  `ops_order_id` bigint NOT NULL COMMENT '工单ID',
  `user_id` bigint NOT NULL COMMENT '保洁员用户ID',
  `priority` tinyint NULL DEFAULT NULL COMMENT '优先级（0=P0紧急 1=P1重要 2=P2普通）',
  `dispatch_mode` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '派单模式（NORMAL=普通/SILENT=静默/URGENT=紧急插队）',
  `dispatch_reason` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '派单原因（AUTO=自动派单/INSPECT_URGE=巡检催办/MANUAL=手动指派）',
  `dispatch_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '派单时间',
  `accepted_time` datetime NULL DEFAULT NULL COMMENT '接单时间',
  `response_seconds` int NULL DEFAULT NULL COMMENT '响应耗时（秒）',
  `device_id` bigint NULL DEFAULT NULL COMMENT '工牌设备ID',
  `device_response_time` datetime NULL DEFAULT NULL COMMENT '工牌响应时间（播报/震动）',
  `notification_method` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '通知方式（VOICE_ONLY=仅语音/VIBRATE_ONLY=仅震动/BOTH=语音+震动）',
  `event_message` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '可读日志内容',
  `event_payload` json NULL COMMENT '结构化上下文',
  `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '创建者',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '更新者',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
  `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_ops_order_id`(`ops_order_id` ASC) USING BTREE,
  INDEX `idx_user_id`(`user_id` ASC) USING BTREE,
  INDEX `idx_dispatch_time`(`dispatch_time` ASC) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '工单分派决策' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for ops_order_event
-- ----------------------------
DROP TABLE IF EXISTS `ops_order_event`;
CREATE TABLE `ops_order_event`  (
  `id` bigint NOT NULL COMMENT '事件ID',
  `ops_order_id` bigint NOT NULL COMMENT '工单ID',
  `from_status` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '原状态',
  `to_status` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '新状态',
  `event_type` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '事件类型（CREATE/ASSIGN/ACCEPT/ARRIVE/PAUSE/RESUME/COMPLETE/CANCEL）',
  `operator_type` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'SYSTEM' COMMENT '操作人类型（SYSTEM=系统/CLEANER=保洁员/INSPECTOR=巡检员）',
  `operator_id` bigint NULL DEFAULT NULL COMMENT '操作人ID',
  `operator_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '操作人姓名（冗余）',
  `event_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '发生时间',
  `remark` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '说明',
  `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '创建者',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '更新者',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
  `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_ops_order_id`(`ops_order_id` ASC) USING BTREE,
  INDEX `idx_event_time`(`event_time` ASC) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = 'FSM 事件流' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for ops_order_queue
-- ----------------------------
DROP TABLE IF EXISTS `ops_order_queue`;
CREATE TABLE `ops_order_queue`  (
  `id` bigint NOT NULL COMMENT '队列ID',
  `user_id` bigint NOT NULL COMMENT '保洁员用户ID',
  `ops_order_id` bigint NOT NULL COMMENT '工单ID',
  `queue_index` int NOT NULL COMMENT '队列顺序（1表示最高优先级）',
  `priority` tinyint NOT NULL DEFAULT 2 COMMENT '优先级（0=P0紧急 1=P1重要 2=P2普通）',
  `queue_status` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'WAITING' COMMENT '队列状态（WAITING=等待中/EXECUTING=执行中/PAUSED=已暂停/CANCELLED=已取消）',
  `enqueue_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '入队时间',
  `dequeue_time` datetime NULL DEFAULT NULL COMMENT '出队时间（工单开始执行）',
  `paused_duration` int NULL DEFAULT 0 COMMENT '累计暂停时长（���）',
  `device_id` bigint NULL DEFAULT NULL COMMENT '工牌设备ID',
  `event_message` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '可读日志内容',
  `event_payload` json NULL COMMENT '结构化上下文',
  `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '创建者',
  `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '更新者',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
  `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `uk_user_order`(`user_id` ASC, `ops_order_id` ASC, `deleted` ASC) USING BTREE,
  INDEX `idx_user_priority`(`user_id` ASC, `priority` ASC, `queue_status` ASC) USING BTREE,
  INDEX `idx_enqueue_time`(`enqueue_time` ASC) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '工单排队队列' ROW_FORMAT = Dynamic;

SET FOREIGN_KEY_CHECKS = 1;
