-- =====================================================================
-- FIGS 教育管理模块 - 升级脚本 v3 (家长约谈)
-- 增量脚本, 在 schema_upgrade_v2_alert.sql 之后执行
-- 功能: 老师教学过程中与家长的约谈记录(方式/内容/结论/跟进/附件)
-- =====================================================================

SET NAMES utf8mb4;

-- -----------------------------------------------------------------
-- 1. 家长约谈记录表 edu_parent_interview
-- -----------------------------------------------------------------
DROP TABLE IF EXISTS `edu_parent_interview`;
CREATE TABLE `edu_parent_interview` (
  `id`               bigint        NOT NULL                COMMENT '主键',
  `tenant_id`        varchar(20)   DEFAULT '000000'        COMMENT '租户ID',
  `student_id`       bigint        NOT NULL                COMMENT '学生ID',
  `parent_id`        bigint        DEFAULT NULL            COMMENT '家长ID(关联 edu_student_parent)',
  `interview_time`   datetime      NOT NULL                COMMENT '约谈时间',
  `method`           varchar(16)   NOT NULL                COMMENT '约谈方式 ONSITE=面谈 PHONE=电话 WECHAT=微信 VIDEO=视频',
  `location`         varchar(128)  DEFAULT NULL            COMMENT '约谈地点',
  `interviewer_id`   bigint        DEFAULT NULL            COMMENT '发起人/约谈人(系统登录用户ID)',
  `topic`            varchar(255)  DEFAULT NULL            COMMENT '谈话主题',
  `content`          text          DEFAULT NULL            COMMENT '内容纪要',
  `student_status`   varchar(500)  DEFAULT NULL            COMMENT '学生近况',
  `result`           varchar(16)   DEFAULT NULL            COMMENT '约谈结论 CONTINUE=维持 ADJUST=调班 MAKEUP=补课 RENEWAL=续签 TRANSFER=转课 OTHER=其他',
  `conclusion`       varchar(1000) DEFAULT NULL            COMMENT '达成结论',
  `next_action`      varchar(500)  DEFAULT NULL            COMMENT '下一步行动项',
  `next_follow_time` datetime      DEFAULT NULL            COMMENT '下次跟进时间',
  `follow_status`    char(1)       DEFAULT '0'             COMMENT '跟进状态 0=待跟进 1=已跟进 2=无需跟进',
  `attachments`      varchar(500)  DEFAULT NULL            COMMENT '附件 ossId 串(逗号分隔)',
  `del_flag`         char(1)       DEFAULT '0'             COMMENT '删除标志 0=存在 1=删除',
  `create_dept`      bigint        DEFAULT NULL            COMMENT '创建部门',
  `create_by`        bigint        DEFAULT NULL            COMMENT '创建者',
  `create_time`      datetime      DEFAULT NULL            COMMENT '创建时间',
  `update_by`        bigint        DEFAULT NULL            COMMENT '更新者',
  `update_time`      datetime      DEFAULT NULL            COMMENT '更新时间',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_tenant_student` (`tenant_id`,`student_id`,`interview_time`) USING BTREE,
  KEY `idx_tenant_follow` (`tenant_id`,`follow_status`,`next_follow_time`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='家长约谈记录';

-- -----------------------------------------------------------------
-- 2. 字典: 约谈方式 / 约谈结论 / 跟进状态
--    幂等: 先删后插 (edu_dict.id 不自增, 从131起)
-- -----------------------------------------------------------------
DELETE FROM `edu_dict` WHERE id BETWEEN 131 AND 145;
INSERT INTO `edu_dict`(`id`,`tenant_id`,`dict_type`,`dict_label`,`dict_value`,`sort_order`,`color`,`status`,`remark`,`create_by`,`create_time`) VALUES
(131,'000000','edu_interview_method','面谈','ONSITE',1,'primary','0',NULL,1,NOW()),
(132,'000000','edu_interview_method','电话','PHONE',2,'success','0',NULL,1,NOW()),
(133,'000000','edu_interview_method','微信','WECHAT',3,'info','0',NULL,1,NOW()),
(134,'000000','edu_interview_method','视频','VIDEO',4,'warning','0',NULL,1,NOW()),
(135,'000000','edu_interview_result','维持','CONTINUE',1,'info','0',NULL,1,NOW()),
(136,'000000','edu_interview_result','调班','ADJUST',2,'warning','0',NULL,1,NOW()),
(137,'000000','edu_interview_result','补课','MAKEUP',3,'primary','0',NULL,1,NOW()),
(138,'000000','edu_interview_result','续签','RENEWAL',4,'success','0',NULL,1,NOW()),
(139,'000000','edu_interview_result','转课','TRANSFER',5,'danger','0',NULL,1,NOW()),
(140,'000000','edu_interview_result','其他','OTHER',6,'info','0',NULL,1,NOW()),
(141,'000000','edu_follow_status','待跟进','0',1,'warning','0',NULL,1,NOW()),
(142,'000000','edu_follow_status','已跟进','1',2,'success','0',NULL,1,NOW()),
(143,'000000','edu_follow_status','无需跟进','2',3,'info','0',NULL,1,NOW());

-- -----------------------------------------------------------------
-- 3. 菜单: 家长约谈 (教务管理2000下, 菜单2100)
-- -----------------------------------------------------------------
DELETE FROM `sys_menu` WHERE menu_id IN (2100, 2110, 2111, 2112, 2113, 2114, 2115);
INSERT INTO `sys_menu`(`menu_id`,`menu_name`,`parent_id`,`order_num`,`path`,`component`,`query_param`,`is_frame`,`is_cache`,`menu_type`,`visible`,`status`,`perms`,`icon`,`create_dept`,`create_by`,`create_time`,`remark`) VALUES
(2100,'家长约谈',2000,7,'interview','edu/interview/index',NULL,1,0,'C','0','0','edu:interview:list','phone',NULL,1,NOW(),'家长约谈记录管理'),
(2110,'约谈查询',2100,1,'#','',NULL,1,0,'F','0','0','edu:interview:query','#',NULL,1,NOW(),''),
(2111,'约谈新增',2100,2,'#','',NULL,1,0,'F','0','0','edu:interview:add','#',NULL,1,NOW(),''),
(2112,'约谈修改',2100,3,'#','',NULL,1,0,'F','0','0','edu:interview:edit','#',NULL,1,NOW(),''),
(2113,'约谈删除',2100,4,'#','',NULL,1,0,'F','0','0','edu:interview:remove','#',NULL,1,NOW(),''),
(2114,'约谈导出',2100,5,'#','',NULL,1,0,'F','0','0','edu:interview:export','#',NULL,1,NOW(),''),
(2115,'约谈跟进',2100,6,'#','',NULL,1,0,'F','0','0','edu:interview:follow','#',NULL,1,NOW(),'');
