-- code字典表
DROP TABLE IF EXISTS `t_code_dictionaries`;
CREATE TABLE `t_code_dictionaries` (
  `id` bigint(20) NOT NULL,
  `code` varchar(20) DEFAULT '' COMMENT '类型code',
  `name` varchar(200) DEFAULT '' COMMENT '名称',
  `parent_code` varchar(20) DEFAULT '' COMMENT '上级code',
  `level` tinyint(1) unsigned DEFAULT 0 COMMENT '层级数',
  `sort` int(11) DEFAULT 0 COMMENT '顺序',
  `remark` varchar(500) DEFAULT '' COMMENT '备注',

  `operator` bigint(20) DEFAULT 0 COMMENT '操作人id',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `rec_status` tinyint(1) unsigned DEFAULT 0 COMMENT '状态，0正常 1禁用 2删除',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `code_parent_index` (`parent_code`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Code字典表';


-- 试题表表
DROP TABLE IF EXISTS `t_question`;
CREATE TABLE `t_question` (
  `id` bigint(20) NOT NULL,
  `question` varchar(500) DEFAULT '' COMMENT ' 题目',
  `code` varchar(20) DEFAULT '' COMMENT '试题所属的code',
  `sort` int(11) DEFAULT 0 COMMENT '排序',
  `type` tinyint(3) unsigned DEFAULT 1 COMMENT '1单行文本,2多行文本,3单选,4多选,5下拉菜单,6日期,7图片(文件)',
  `relevance_option_id` bigint(20) DEFAULT 0 COMMENT '关联选项ID 默认0不关联',
  `remark` varchar(500) CHARACTER SET utf8 DEFAULT '' COMMENT ' 备注 ',

  `operator` bigint(20) DEFAULT 0 COMMENT '操作人id',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `rec_status` tinyint(1) unsigned DEFAULT 0 COMMENT '状态，0正常 1禁用 2删除',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `question_code_index` (`code`,`sort`) USING BTREE,
  KEY `question_relevance_index` (`relevance_option_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='模板信息表';

  
-- 选项表
DROP TABLE IF EXISTS `t_question_option`;
CREATE TABLE `t_question_option` (
  `id` bigint(20) NOT NULL,
  `question_id` bigint(20) DEFAULT 0 COMMENT ' 试题ID',
  `sort` int(11) DEFAULT 1 COMMENT ' 排序 ',
  `show_value` varchar(512) DEFAULT '' COMMENT '显示值',
  `submit_value` varchar(512) DEFAULT '' COMMENT '提交值',
  `after_operation` tinyint(1) unsigned DEFAULT 0 COMMENT '选择之后的操作 0无 1单行文本 2多行文本 3关联其他题目',

  `operator` bigint(20) DEFAULT 0 COMMENT '操作人id',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `rec_status` tinyint(1) unsigned DEFAULT 0 COMMENT '状态，0正常 1禁用 2删除',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `option_question_index` (`question_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='选项表';



-- 知识产权表
DROP TABLE IF EXISTS `t_intellectual_property`;
CREATE TABLE `t_intellectual_property` (
  `id` bigint(20) NOT NULL,
  `experiment_id` bigint(20) DEFAULT 0 COMMENT '课题id',
  `type` tinyint(1) unsigned DEFAULT 0 COMMENT '类型 0专利 1论文 2软著',
  `time` bigint(20) DEFAULT 0 COMMENT '时间',

  `operator` bigint(20) DEFAULT 0 COMMENT '操作人id',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `update_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `rec_status` tinyint(1) unsigned DEFAULT 0 COMMENT '状态 0正常 1禁用 2删除',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='知识产权表';

-- 答题记录表
DROP TABLE IF EXISTS `t_experiment_question_record`;
CREATE TABLE `t_experiment_question_record` (
  `id` bigint(20) NOT NULL,
  `experiment_id` bigint(20) DEFAULT 0 COMMENT '课题id/知识产权id',
  `questions_id` bigint(20) DEFAULT 0 COMMENT '试题id',
  `contents` varchar(512) DEFAULT '' COMMENT '内容',
  `submit_id` bigint(20) DEFAULT 0 COMMENT '提交人id（机构成员id）',

  `operator` bigint(20) DEFAULT 0 COMMENT '操作人id',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `update_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `rec_status` tinyint(1) unsigned DEFAULT 0 COMMENT '状态 0正常 1禁用 2删除',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `experiment_index` (`experiment_id`) USING BTREE,
  KEY `questions_id_contents_index` (`questions_id`,`contents`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='答题记录表';


-- 课题表--课题，子课题，实验 共用一张表
DROP TABLE IF EXISTS `t_experiment`;
CREATE TABLE `t_experiment` (
  `id` bigint(20) NOT NULL,
  `name` varchar(512) DEFAULT '' COMMENT '名称',
  `type` tinyint(1) unsigned DEFAULT 0 COMMENT '类型 0课题 1子课题 2实验',
  `member_id` bigint(20) DEFAULT 0 COMMENT '负责人id（机构成员id）',
  `start_time` bigint(20) DEFAULT 0 COMMENT '开始时间',
  `end_time` bigint(20) DEFAULT 0 COMMENT '结束时间',
  `remark` varchar(512) DEFAULT '' COMMENT '内容备注（实验里的目标）',
  `project_id` bigint(20) DEFAULT 0 COMMENT '项目id',
  `parent_id` bigint(20) DEFAULT 0 COMMENT '上级课题id',

  `operator` bigint(20) DEFAULT 0 COMMENT '操作人id',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `update_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `rec_status` tinyint(1) unsigned DEFAULT 0 COMMENT '状态 0正常 1禁用 2删除',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `member_index` (`member_id`) USING BTREE,
  KEY `parent_index` (`parent_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='课题表';


-- 计划任务书
DROP TABLE IF EXISTS `t_plan_task`;
CREATE TABLE `t_plan_task` (
  `id` bigint(20) NOT NULL,
  `experiment_id` bigint(20) DEFAULT 0 COMMENT '课题id',
  `technical_indicator` varchar(1024) DEFAULT '' COMMENT '主要技术指标',
  `economic_indicators` varchar(1024) DEFAULT '' COMMENT '经济指标',
  `social_benefit` varchar(1024) DEFAULT '' COMMENT '社会效益',
  `check_content` varchar(60) DEFAULT '' COMMENT '验收内容（存数组） 1工作报告 2技术报告 3计算机软件 4生物品种 5样品或样机 6成套技术设备 7科技论文或著作 8科技报告收录证书',

  `operator` bigint(20) DEFAULT 0 COMMENT '操作人id',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `update_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `rec_status` tinyint(1) unsigned DEFAULT 0 COMMENT '状态 0正常 1禁用 2删除',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `experiment_index` (`experiment_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='计划任务书';    

-- 课题阶段表
DROP TABLE IF EXISTS `t_plan_task_stage`;
CREATE TABLE `t_plan_task_stage` (
  `id` bigint(20) NOT NULL,
  `experiment_id` bigint(20) DEFAULT 0 COMMENT '课题id',
  `start_time` bigint(20) DEFAULT 0 COMMENT '开始时间',
  `end_time` bigint(20) DEFAULT 0 COMMENT '结束时间',
  `remark` varchar(512) DEFAULT '' COMMENT '内容备注',
  `stage`  int(11) unsigned DEFAULT 0 COMMENT '第几阶段',

  `operator` bigint(20) DEFAULT 0 COMMENT '操作人id',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `update_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `rec_status` tinyint(1) unsigned DEFAULT 0 COMMENT '状态 0正常 1禁用 2删除',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `experiment_index` (`experiment_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='计划任务书';    


-- 计划任务书自定义字段表
DROP TABLE IF EXISTS `t_plan_task_defined`;
CREATE TABLE `t_plan_task_defined` (
  `id` bigint(20) NOT NULL,
  `experiment_id` bigint(20) DEFAULT 0 COMMENT '课题id',
  `t_key` varchar(512) DEFAULT '' COMMENT 'key',
  `t_value` varchar(1024) DEFAULT '' COMMENT '内容',

  `operator` bigint(20) DEFAULT 0 COMMENT '操作人id',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `update_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `rec_status` tinyint(1) unsigned DEFAULT 0 COMMENT '状态 0正常 1禁用 2删除',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `experiment_index` (`experiment_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='计划任务书自定义字段表';    



-- 子课题阶段表
DROP TABLE IF EXISTS `t_sub_experiment_stage`;
CREATE TABLE `t_sub_experiment_stage` (
  `id` bigint(20) NOT NULL,
  `experiment_id` bigint(20) DEFAULT 0 COMMENT '子课题id',
  `start_time` bigint(20) DEFAULT 0 COMMENT '开始时间',
  `end_time` bigint(20) DEFAULT 0 COMMENT '结束时间',
  `thesis`  int(11) unsigned DEFAULT 0 COMMENT '论文',
  `sci_thesis`  int(11) unsigned DEFAULT 0 COMMENT 'SCI论文',
  `patent`  int(11) unsigned DEFAULT 0 COMMENT '专利',
  `invent_patent`  int(11) unsigned DEFAULT 0 COMMENT '发明专利',
  `practical_patent`  int(11) unsigned DEFAULT 0 COMMENT '实用新型专利',
  `facade_patent`  int(11) unsigned DEFAULT 0 COMMENT '外观专利',
  `the_soft`  int(11) unsigned DEFAULT 0 COMMENT '软著',

  `operator` bigint(20) DEFAULT 0 COMMENT '操作人id',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `update_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `rec_status` tinyint(1) unsigned DEFAULT 0 COMMENT '状态 0正常 1禁用 2删除',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `experiment_index` (`experiment_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='子课题阶段表';    




-- 实验提交信息状态表
DROP TABLE IF EXISTS `t_experiment_status_record`;
CREATE TABLE `t_experiment_status_record` (
  `id` bigint(20) NOT NULL,
  `experiment_id` bigint(20) DEFAULT 0 COMMENT '实验id',
  `type` tinyint(2) unsigned DEFAULT 0 COMMENT '状态（0已提交，1已锁定，2驳回提交，3解锁申请，4驳回解锁）',
  `submit_id` bigint(20) DEFAULT 0 COMMENT '提交人id',
  `checker_id` bigint(20) DEFAULT 0 COMMENT '审核人id',
  `time` bigint(20) DEFAULT 0 COMMENT '提交的时间',
  `remark` varchar(512) DEFAULT '' COMMENT '备注信息',

  `operator` bigint(20) DEFAULT 0 COMMENT '操作人id',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `update_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `rec_status` tinyint(1) unsigned DEFAULT 0 COMMENT '状态 0正常 1禁用 2删除',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `experiment_index` (`experiment_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='实验信息状态';   



-- 会议表
DROP TABLE IF EXISTS `t_conference`;
CREATE TABLE `t_conference` (
  `id` bigint(20) NOT NULL,
  `type` tinyint(1) unsigned DEFAULT 0 COMMENT '会议类型 0科研会议管理 1子课题会议管理',
  `experiment_id` bigint(20) DEFAULT 0 COMMENT '课题/实验id',
  `name` varchar(1024) DEFAULT '' COMMENT '会议名称',
  `start_time` bigint(20) DEFAULT 0 COMMENT '开始时间',
  `end_time` bigint(20) DEFAULT 0 COMMENT '结束时间',
  `address` varchar(128) DEFAULT '' COMMENT '地点',

  `operator` bigint(20) DEFAULT 0 COMMENT '操作人id',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `update_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `rec_status` tinyint(1) unsigned DEFAULT 0 COMMENT '状态 0正常 1禁用 2删除',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `experiment_index` (`experiment_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='会议表';   

-- 业务文件表--计划任务书和会议上传的文件表（单次会议上传的文件要去重）
DROP TABLE IF EXISTS `t_business_file`;
CREATE TABLE `t_business_file` (
  `id` bigint(20) NOT NULL,
  `business_type` tinyint(1) unsigned DEFAULT 0 COMMENT '文件类型（0会议通知，1会议纪要，2照片附件/其他，3计划任务书）',
  `business_id` bigint(20) DEFAULT 0 COMMENT '课题/实验id',
  `file_id` bigint(20) DEFAULT 0 COMMENT '文件id',
  `path` varchar(128) DEFAULT '' COMMENT '文件路径',
  `name` varchar(128) DEFAULT '' COMMENT '文件名',

  `operator` bigint(20) DEFAULT 0 COMMENT '操作人id',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `update_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `rec_status` tinyint(1) unsigned DEFAULT 0 COMMENT '状态 0正常 1禁用 2删除',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `business_index` (`business_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='业务文件表';   



-- 机构表
DROP TABLE IF EXISTS `t_organization`;
CREATE TABLE `t_organization` (
  `id` bigint(20) NOT NULL,
  `organization_type` tinyint(2) DEFAULT 0 COMMENT '机构类型 0：高校 1：实验室 2：企业',
  `code` varchar(64) DEFAULT '' COMMENT '机构编码',
  `name` varchar(64) DEFAULT '' COMMENT '机构名称',
  `short_name` varchar(64) DEFAULT '' COMMENT '机构简称',
  `introduce` varchar(256) DEFAULT '' COMMENT '机构介绍',
  `parent_id` bigint(20) DEFAULT 0 COMMENT '上级机构id',

  `operator` bigint(20) DEFAULT 0 COMMENT '操作人id',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `rec_status` tinyint(1) unsigned DEFAULT 0 COMMENT '状态，0正常 1禁用 2删除',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `organization_index` (`parent_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='机构表';


-- 机构成员表
DROP TABLE IF EXISTS `t_organization_member`;
CREATE TABLE `t_organization_member` (
  `id` bigint(20) NOT NULL,
  `user_id` bigint(20) DEFAULT 0 COMMENT 'userId',
  `name` varchar(64) DEFAULT '' COMMENT '成员名称',
  `phone` varchar(64) DEFAULT '' COMMENT '联系方式',
  `organization_id` bigint(20) DEFAULT 0 COMMENT '机构id',
  `experiment_id` bigint(20) DEFAULT 0 COMMENT '课题id',

  `operator` bigint(20) DEFAULT 0 COMMENT '操作人id',
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `rec_status` tinyint(1) unsigned DEFAULT 0 COMMENT '状态，0正常 1禁用 2删除',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `member_user_index` (`user_id`) USING BTREE,
  KEY `member_organization_index` (`organization_id`) USING BTREE,
  KEY `member_experiment_index` (`experiment_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='机构成员表';


-- --------------------------------------------------------------------------------------------

-- 实验流程表
DROP TABLE IF EXISTS `t_experiment_flow `;
CREATE TABLE `t_experiment_flow` (
  `id` bigint(20) NOT NULL,
  `name` varchar(225) DEFAULT '' COMMENT '任务名称',
  `description` varchar(225) DEFAULT '' COMMENT '任务描述',
  `experiment_id` bigint(20) DEFAULT 0 COMMENT '课题id',
  `parent_id` bigint(20) DEFAULT 0 COMMENT '上级任务id',
  `type` tinyint(1) unsigned DEFAULT 0 COMMENT '类型 0日常 1定期',
  `start_time` bigint(20) DEFAULT 0 COMMENT '开始时间',
  `end_time` bigint(20) DEFAULT 0 COMMENT '结束时间',
  `duration` bigint(20) DEFAULT 0,
  `created_at` timestamp NOT NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `rec_status` tinyint(1) unsigned DEFAULT 0,
  PRIMARY KEY (`id`) USING BTREE,
  KEY `experiment_index` (`experiment_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=COMPACT COMMENT='实验流程表';


