Files
aiot-platform-cloud/sql/mysql/aiot_ops_inspection.sql
lzh e3882e1c2f fix(ops): code review 修复巡检模块6项问题
1. @Async 指定 ops-task-executor 线程池,避免使用默认线程池
2. 归属判定无工单/无标准时长时标记为 ATTRIBUTION_NORMAL(3),不再静默跳过
3. 补充 completionSeconds 字段语义注释和 standardDuration 单位转换说明
4. 整改工单默认时长 30 提取为 DEFAULT_RECTIFICATION_DURATION_MINUTES 常量
5. SQL 补充 idx_generated_order_id 和 idx_template_id 索引

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-05 20:40:36 +08:00

72 lines
4.2 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.

-- =============================================
-- 巡检模块表结构
-- =============================================
-- ----------------------------
-- 巡检检查项模板表
-- ----------------------------
DROP TABLE IF EXISTS `ops_inspection_template`;
CREATE TABLE `ops_inspection_template` (
`id` bigint NOT NULL COMMENT '模板ID',
`function_type` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '功能类型(关联 ops_bus_area.function_type',
`item_title` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '检查项标题',
`sort_order` int NOT NULL DEFAULT 0 COMMENT '排序序号',
`is_active` bit(1) NOT NULL DEFAULT b'1' COMMENT '是否启用',
`creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT '创建者',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci 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`),
KEY `idx_function_type` (`function_type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='巡检检查项模板';
-- ----------------------------
-- 巡检主记录表
-- ----------------------------
DROP TABLE IF EXISTS `ops_inspection_record`;
CREATE TABLE `ops_inspection_record` (
`id` bigint NOT NULL COMMENT '巡检记录ID',
`area_id` bigint NOT NULL COMMENT '区域ID',
`inspector_id` bigint NOT NULL COMMENT '巡检员用户ID',
`is_location_exception` tinyint NOT NULL DEFAULT 0 COMMENT '位置是否异常0正常 1异常',
`result_status` tinyint COMMENT '巡检结果0不合格 1合格',
`remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT '备注',
`last_order_id` bigint COMMENT '归属判定-上一个完成工单ID',
`stay_duration` int COMMENT '归属判定-保洁员停留时长(秒)',
`attribution_result` tinyint COMMENT '归属判定结果1个人责任 2突发状况 3正常',
`generated_order_id` bigint COMMENT '整改工单ID',
`creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT '创建者',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci 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`),
KEY `idx_area_id` (`area_id`),
KEY `idx_inspector_id` (`inspector_id`),
KEY `idx_generated_order_id` (`generated_order_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='巡检主记录';
-- ----------------------------
-- 巡检明细表
-- ----------------------------
DROP TABLE IF EXISTS `ops_inspection_record_item`;
CREATE TABLE `ops_inspection_record_item` (
`id` bigint NOT NULL COMMENT '明细ID',
`record_id` bigint NOT NULL COMMENT '巡检记录ID',
`template_id` bigint NOT NULL COMMENT '模板检查项ID',
`is_passed` bit(1) NOT NULL DEFAULT b'1' COMMENT '是否合格',
`remark` varchar(256) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT '备注',
`creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci COMMENT '创建者',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci 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`),
KEY `idx_record_id` (`record_id`),
KEY `idx_template_id` (`template_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='巡检明细';