-- 创建用户表
CREATE TABLE IF NOT EXISTS sys_user (
  id BIGINT NOT NULL AUTO_INCREMENT,
  username VARCHAR(50) NOT NULL,
  password VARCHAR(100) NOT NULL,
  real_name VARCHAR(50) NOT NULL,
  gender TINYINT DEFAULT 0,
  phone VARCHAR(20) DEFAULT NULL,
  email VARCHAR(100) DEFAULT NULL,
  avatar VARCHAR(255) DEFAULT NULL,
  status TINYINT DEFAULT 1,
  role_type TINYINT NOT NULL,
  create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
  update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  create_by BIGINT DEFAULT NULL,
  update_by BIGINT DEFAULT NULL,
  deleted TINYINT DEFAULT 0,
  PRIMARY KEY (id),
  UNIQUE KEY uk_username (username),
  UNIQUE KEY uk_email (email),
  KEY idx_phone (phone),
  KEY idx_role_type (role_type),
  KEY idx_status (status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- 创建学生信息表
CREATE TABLE IF NOT EXISTS stu_info (
  id BIGINT NOT NULL AUTO_INCREMENT,
  user_id BIGINT NOT NULL,
  student_no VARCHAR(20) NOT NULL,
  college VARCHAR(100) NOT NULL,
  major VARCHAR(100) NOT NULL,
  grade VARCHAR(10) NOT NULL,
  class_name VARCHAR(50) DEFAULT NULL,
  advisor_id BIGINT DEFAULT NULL,
  create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
  update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  deleted TINYINT DEFAULT 0,
  PRIMARY KEY (id),
  UNIQUE KEY uk_student_no (student_no),
  UNIQUE KEY uk_user_id (user_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- 创建教师信息表
CREATE TABLE IF NOT EXISTS teacher_info (
  id BIGINT NOT NULL AUTO_INCREMENT,
  user_id BIGINT NOT NULL,
  teacher_no VARCHAR(20) NOT NULL,
  college VARCHAR(100) NOT NULL,
  title VARCHAR(50) DEFAULT NULL,
  research_field VARCHAR(255) DEFAULT NULL,
  create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
  update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  deleted TINYINT DEFAULT 0,
  PRIMARY KEY (id),
  UNIQUE KEY uk_teacher_no (teacher_no),
  UNIQUE KEY uk_user_id (user_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- 创建项目表
CREATE TABLE IF NOT EXISTS project (
  id BIGINT NOT NULL AUTO_INCREMENT,
  project_no VARCHAR(30) NOT NULL,
  project_name VARCHAR(200) NOT NULL,
  project_type TINYINT NOT NULL,
  project_level TINYINT NOT NULL,
  leader_id BIGINT NOT NULL,
  advisor_id BIGINT NOT NULL,
  description TEXT,
  research_plan TEXT,
  expected_result TEXT,
  budget DECIMAL(10,2) DEFAULT 0.00,
  status TINYINT DEFAULT 1,
  start_time DATE DEFAULT NULL,
  end_time DATE DEFAULT NULL,
  college VARCHAR(100) DEFAULT NULL,
  create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
  update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  create_by BIGINT DEFAULT NULL,
  update_by BIGINT DEFAULT NULL,
  deleted TINYINT DEFAULT 0,
  PRIMARY KEY (id),
  UNIQUE KEY uk_project_no (project_no)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- 创建项目成员表
CREATE TABLE IF NOT EXISTS project_member (
  id BIGINT NOT NULL AUTO_INCREMENT,
  project_id BIGINT NOT NULL,
  user_id BIGINT NOT NULL,
  member_order INT DEFAULT 1,
  role TINYINT DEFAULT 1,
  join_time DATETIME DEFAULT CURRENT_TIMESTAMP,
  create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
  deleted TINYINT DEFAULT 0,
  PRIMARY KEY (id),
  UNIQUE KEY uk_project_user (project_id, user_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- 创建成果表
CREATE TABLE IF NOT EXISTS achievement (
  id BIGINT NOT NULL AUTO_INCREMENT,
  project_id BIGINT NOT NULL,
  achievement_type TINYINT NOT NULL,
  achievement_name VARCHAR(200) NOT NULL,
  achievement_level TINYINT DEFAULT NULL,
  author_names VARCHAR(500) DEFAULT NULL,
  publish_time DATE DEFAULT NULL,
  publish_org VARCHAR(200) DEFAULT NULL,
  description TEXT,
  status TINYINT DEFAULT 1,
  auditor_id BIGINT DEFAULT NULL,
  audit_time DATETIME DEFAULT NULL,
  audit_opinion VARCHAR(500) DEFAULT NULL,
  create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
  update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  create_by BIGINT DEFAULT NULL,
  deleted TINYINT DEFAULT 0,
  PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- 创建评审表
CREATE TABLE IF NOT EXISTS review (
  id BIGINT NOT NULL AUTO_INCREMENT,
  project_id BIGINT NOT NULL,
  reviewer_id BIGINT NOT NULL,
  review_type TINYINT NOT NULL,
  score DECIMAL(5,1) DEFAULT NULL,
  opinion TEXT,
  result TINYINT DEFAULT NULL,
  status TINYINT DEFAULT 1,
  review_time DATETIME DEFAULT NULL,
  create_time DATETIME DEFAULT CURRENT_TIMESTAMP,
  update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  deleted TINYINT DEFAULT 0,
  PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
