SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- 说明：本文件为「删表重建」全量脚本，仅适合空库/可丢数据环境。
-- 若库中已有旧结构 red_line_record（缺 sales_id 等列），请执行：
--   touch_red_line_alter_add_sales_and_subtype.sql
-- ----------------------------
-- Table structure for red_line_record
-- 触及红线记录：关联录音主表与分段，记录类型、阈值与当时文本
-- ----------------------------
DROP TABLE IF EXISTS `red_line_record`;
CREATE TABLE `red_line_record` (
  `id` char(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '主键，UUID',
  `tenant_id` varchar(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '租户ID',
  `sales_id` char(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '销售人员的id',
  `sales_name` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '销售人员的姓名',
  `sales_phone` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '销售人员的电话',
  `audio_management_id` char(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '音频主表ID（audio_management.id）',
  `audio_management_segments_id` char(36) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '音频分段表ID（audio_management_segments.id）',
  `red_line_type` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '触及的红线类型',
  `red_line_subtype` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '触及的红线的子类型',
  `check_threshold` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '检查时使用的阈值（数值、比例或规则描述等）',
  `reason_text` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL COMMENT '触发时对应的原始文本',
  `remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '备注',
  `create_time` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `update_time` datetime NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_tenant_id` (`tenant_id`) USING BTREE,
  KEY `idx_touch_red_line_audio_id` (`audio_management_id`) USING BTREE,
  KEY `idx_touch_red_line_segment_id` (`audio_management_segments_id`) USING BTREE,
  KEY `idx_touch_red_line_type` (`red_line_type`) USING BTREE,
  KEY `idx_red_line_subtype` (`red_line_subtype`) USING BTREE,
  KEY `idx_sales_id` (`sales_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='触及红线记录表' ROW_FORMAT=DYNAMIC;

SET FOREIGN_KEY_CHECKS = 1;



