-- =====================================================
--  智能会议纪要 (Smart Meeting Minutes)
--  - 弃用 oa_meeting_project，改为绑定 sys_oa_project.project_id
--  - 主持人/参会/待办负责人 统一存 user_id
--  - 待办在保存时可同步生成 sys_oa_task
-- =====================================================

-- 清理上一版（如有）
DROP TABLE IF EXISTS `oa_meeting_project`;

-- ---------------- 会议纪要 ----------------
DROP TABLE IF EXISTS `oa_meeting_minutes`;
CREATE TABLE `oa_meeting_minutes` (
  `id`                  bigint(20)     NOT NULL AUTO_INCREMENT             COMMENT '主键ID',
  `meeting_code`        varchar(32)    NOT NULL                            COMMENT '会议编号 MT-yyyyMMddHHmmss',
  `meeting_date`        date           NOT NULL                            COMMENT '会议日期',
  `project_id`          bigint(20)     DEFAULT NULL                        COMMENT '关联 sys_oa_project.project_id',
  `meeting_type`        varchar(20)    DEFAULT 'other'                     COMMENT '类型 tech/project/client/weekly/other',
  `subject`             varchar(500)   NOT NULL                            COMMENT '会议主题',
  `location`            varchar(255)   DEFAULT NULL                        COMMENT '会议地点',
  `host_user_id`        bigint(20)     DEFAULT NULL                        COMMENT '主持人 sys_user.user_id',
  `attendee_user_ids`   varchar(1000)  DEFAULT NULL                        COMMENT '参会人员 user_id 列表（逗号分隔）',
  `topic`               text                                               COMMENT '会议议题',
  `discussion`          text                                               COMMENT '讨论内容',
  `decision`            text                                               COMMENT '决议事项',
  `tasks_json`          text                                               COMMENT '待办 JSON：[{assigneeUserId,content,deadline,status,taskId}]',
  `sync_task`           tinyint(1)     DEFAULT 1                           COMMENT '是否将待办同步为 OA 任务',
  `create_by`           varchar(64)    DEFAULT NULL,
  `create_time`         datetime       DEFAULT CURRENT_TIMESTAMP,
  `update_by`           varchar(64)    DEFAULT NULL,
  `update_time`         datetime       DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `del_flag`            char(1)        DEFAULT '0'                         COMMENT '删除标志：0正常 1删除',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_meeting_code` (`meeting_code`, `del_flag`),
  KEY `idx_date` (`meeting_date`),
  KEY `idx_project` (`project_id`),
  KEY `idx_type` (`meeting_type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='会议纪要';

-- ---------------- 字典：会议类型 ----------------
INSERT IGNORE INTO `sys_dict_type` (`dict_name`, `dict_type`, `status`, `create_by`, `create_time`, `remark`)
VALUES ('会议类型', 'oa_meeting_type', '0', 'admin', NOW(), '智能会议纪要-会议类型');

INSERT IGNORE INTO `sys_dict_data`
  (`dict_sort`, `dict_label`, `dict_value`, `dict_type`, `css_class`, `list_class`, `is_default`, `status`, `create_by`, `create_time`, `remark`)
VALUES
  (1, '技术评审', 'tech',    'oa_meeting_type', '', 'info',    'N', '0', 'admin', NOW(), ''),
  (2, '项目推进', 'project', 'oa_meeting_type', '', 'primary', 'N', '0', 'admin', NOW(), ''),
  (3, '客户沟通', 'client',  'oa_meeting_type', '', 'warning', 'N', '0', 'admin', NOW(), ''),
  (4, '周例会',   'weekly',  'oa_meeting_type', '', 'success', 'N', '0', 'admin', NOW(), ''),
  (5, '其他',     'other',   'oa_meeting_type', '', '',        'Y', '0', 'admin', NOW(), '');

-- ---------------- 字典：待办状态 ----------------
INSERT IGNORE INTO `sys_dict_type` (`dict_name`, `dict_type`, `status`, `create_by`, `create_time`, `remark`)
VALUES ('会议待办状态', 'oa_meeting_task_status', '0', 'admin', NOW(), '智能会议纪要-待办状态');

INSERT IGNORE INTO `sys_dict_data`
  (`dict_sort`, `dict_label`, `dict_value`, `dict_type`, `css_class`, `list_class`, `is_default`, `status`, `create_by`, `create_time`, `remark`)
VALUES
  (1, '待办',   'pending',  'oa_meeting_task_status', '', 'info',    'Y', '0', 'admin', NOW(), ''),
  (2, '进行中', 'progress', 'oa_meeting_task_status', '', 'primary', 'N', '0', 'admin', NOW(), ''),
  (3, '已完成', 'done',     'oa_meeting_task_status', '', 'success', 'N', '0', 'admin', NOW(), '');
