|
@@ -102,22 +102,29 @@ public class DatabaseInitializer implements CommandLineRunner {
|
|
|
"id BIGINT AUTO_INCREMENT PRIMARY KEY, " +
|
|
"id BIGINT AUTO_INCREMENT PRIMARY KEY, " +
|
|
|
"family_id BIGINT NOT NULL, " +
|
|
"family_id BIGINT NOT NULL, " +
|
|
|
"creator_id BIGINT NOT NULL, " +
|
|
"creator_id BIGINT NOT NULL, " +
|
|
|
- "child_id BIGINT NOT NULL, " +
|
|
|
|
|
|
|
+ "child_id BIGINT COMMENT '执行者ID(child任务时必填,parent任务时可空)', " +
|
|
|
|
|
+ "executor_type VARCHAR(20) COMMENT '执行者类型: child/parent', " +
|
|
|
|
|
+ "executor_id BIGINT COMMENT '执行者ID', " +
|
|
|
"title VARCHAR(200) NOT NULL, " +
|
|
"title VARCHAR(200) NOT NULL, " +
|
|
|
"description VARCHAR(500), " +
|
|
"description VARCHAR(500), " +
|
|
|
"points TINYINT DEFAULT 2, " +
|
|
"points TINYINT DEFAULT 2, " +
|
|
|
- "deadline DATETIME NOT NULL, " +
|
|
|
|
|
|
|
+ "deadline DATETIME, " +
|
|
|
"repeat_type ENUM('none','daily','weekly') DEFAULT 'none', " +
|
|
"repeat_type ENUM('none','daily','weekly') DEFAULT 'none', " +
|
|
|
"category VARCHAR(32), " +
|
|
"category VARCHAR(32), " +
|
|
|
"need_review TINYINT DEFAULT 0, " +
|
|
"need_review TINYINT DEFAULT 0, " +
|
|
|
"review_by_category TINYINT DEFAULT 0, " +
|
|
"review_by_category TINYINT DEFAULT 0, " +
|
|
|
"status ENUM('pending','completed','overdue','cancelled') DEFAULT 'pending', " +
|
|
"status ENUM('pending','completed','overdue','cancelled') DEFAULT 'pending', " +
|
|
|
"completed_at DATETIME, " +
|
|
"completed_at DATETIME, " +
|
|
|
|
|
+ "bonus_rule VARCHAR(500), " +
|
|
|
|
|
+ "points_expire_days INT DEFAULT 0, " +
|
|
|
|
|
+ "template_id BIGINT, " +
|
|
|
|
|
+ "is_template TINYINT DEFAULT 0, " +
|
|
|
"created_at DATETIME DEFAULT CURRENT_TIMESTAMP, " +
|
|
"created_at DATETIME DEFAULT CURRENT_TIMESTAMP, " +
|
|
|
"updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, " +
|
|
"updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, " +
|
|
|
"INDEX idx_child_id_deadline (child_id, deadline), " +
|
|
"INDEX idx_child_id_deadline (child_id, deadline), " +
|
|
|
"INDEX idx_status (status), " +
|
|
"INDEX idx_status (status), " +
|
|
|
- "INDEX idx_category (category)" +
|
|
|
|
|
|
|
+ "INDEX idx_category (category), " +
|
|
|
|
|
+ "INDEX idx_executor (executor_type, executor_id)" +
|
|
|
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4",
|
|
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4",
|
|
|
|
|
|
|
|
// 积分流水表
|
|
// 积分流水表
|
|
@@ -635,12 +642,55 @@ public class DatabaseInitializer implements CommandLineRunner {
|
|
|
|
|
|
|
|
// 迁移13: admin_task_templates表添加teacher_id字段
|
|
// 迁移13: admin_task_templates表添加teacher_id字段
|
|
|
try {
|
|
try {
|
|
|
-jdbcTemplate.execute("ALTER TABLE admin_task_templates ADD COLUMN teacher_id BIGINT COMMENT \'指导师ID\'");
|
|
|
|
|
|
|
+jdbcTemplate.execute("ALTER TABLE admin_task_templates ADD COLUMN teacher_id BIGINT COMMENT '指导师ID'");
|
|
|
log.info("已添加teacher_id列到admin_task_templates表");
|
|
log.info("已添加teacher_id列到admin_task_templates表");
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
// 列已存在,忽略错误
|
|
// 列已存在,忽略错误
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// 迁移13b: admin_task_templates表添加新字段
|
|
|
|
|
+try {
|
|
|
|
|
+jdbcTemplate.execute("ALTER TABLE admin_task_templates ADD COLUMN complete_types VARCHAR(100) COMMENT '完成方式JSON'");
|
|
|
|
|
+log.info("已添加complete_types列到admin_task_templates表");
|
|
|
|
|
+} catch (Exception e) {
|
|
|
|
|
+// 列已存在,忽略错误
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+try {
|
|
|
|
|
+jdbcTemplate.execute("ALTER TABLE admin_task_templates ADD COLUMN duration INT COMMENT '预计完成时长(分钟)'");
|
|
|
|
|
+log.info("已添加duration列到admin_task_templates表");
|
|
|
|
|
+} catch (Exception e) {
|
|
|
|
|
+// 列已存在,忽略错误
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+try {
|
|
|
|
|
+jdbcTemplate.execute("ALTER TABLE admin_task_templates ADD COLUMN review_type VARCHAR(20) COMMENT '审核人类型: creator/parent/teacher/ai'");
|
|
|
|
|
+log.info("已添加review_type列到admin_task_templates表");
|
|
|
|
|
+} catch (Exception e) {
|
|
|
|
|
+// 列已存在,忽略错误
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+try {
|
|
|
|
|
+jdbcTemplate.execute("ALTER TABLE admin_task_templates ADD COLUMN task_type VARCHAR(20) COMMENT '任务性质: onetime/recurring'");
|
|
|
|
|
+log.info("已添加task_type列到admin_task_templates表");
|
|
|
|
|
+} catch (Exception e) {
|
|
|
|
|
+// 列已存在,忽略错误
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+try {
|
|
|
|
|
+jdbcTemplate.execute("ALTER TABLE admin_task_templates ADD COLUMN frequency VARCHAR(20) COMMENT '频率: daily/weekly/monthly'");
|
|
|
|
|
+log.info("已添加frequency列到admin_task_templates表");
|
|
|
|
|
+} catch (Exception e) {
|
|
|
|
|
+// 列已存在,忽略错误
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+try {
|
|
|
|
|
+jdbcTemplate.execute("ALTER TABLE admin_task_templates ADD COLUMN max_frequency INT COMMENT '周期内最多完成次数'");
|
|
|
|
|
+log.info("已添加max_frequency列到admin_task_templates表");
|
|
|
|
|
+} catch (Exception e) {
|
|
|
|
|
+// 列已存在,忽略错误
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// 迁移14: rewards表child_id字段允许NULL(模板奖励不需要child_id)
|
|
// 迁移14: rewards表child_id字段允许NULL(模板奖励不需要child_id)
|
|
|
try {
|
|
try {
|
|
|
jdbcTemplate.execute("ALTER TABLE rewards MODIFY COLUMN child_id BIGINT NULL COMMENT \'孩子ID,模板奖励为NULL\'");
|
|
jdbcTemplate.execute("ALTER TABLE rewards MODIFY COLUMN child_id BIGINT NULL COMMENT \'孩子ID,模板奖励为NULL\'");
|
|
@@ -713,15 +763,80 @@ log.info("已添加template_id列到tasks表");
|
|
|
// 列已存在,忽略错误
|
|
// 列已存在,忽略错误
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// 迁移21: tasks表添加is_template字段(TASK-004: 标记模板任务)
|
|
|
|
|
-try {
|
|
|
|
|
-jdbcTemplate.execute("ALTER TABLE tasks ADD COLUMN is_template TINYINT DEFAULT 0 COMMENT \'是否为模板任务\'");
|
|
|
|
|
-log.info("已添加is_template列到tasks表");
|
|
|
|
|
-} catch (Exception e) {
|
|
|
|
|
-// 列已存在,忽略错误
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ // 迁移21: tasks表添加is_template字段(TASK-004: 标记模板任务)
|
|
|
|
|
+ try {
|
|
|
|
|
+ jdbcTemplate.execute("ALTER TABLE tasks ADD COLUMN is_template TINYINT DEFAULT 0 COMMENT '是否为模板任务'");
|
|
|
|
|
+ log.info("已添加is_template列到tasks表");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 列已存在,忽略错误
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 迁移22: 修复tasks表child_id和deadline允许NULL(支持多孩子和家长任务)
|
|
|
|
|
+ try {
|
|
|
|
|
+ jdbcTemplate.execute("ALTER TABLE tasks MODIFY COLUMN child_id BIGINT NULL COMMENT '执行者ID'");
|
|
|
|
|
+ log.info("已修改tasks.child_id允许NULL");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 修改失败,忽略错误
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ jdbcTemplate.execute("ALTER TABLE tasks MODIFY COLUMN deadline DATETIME NULL COMMENT '截止时间'");
|
|
|
|
|
+ log.info("已修改tasks.deadline允许NULL");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 修改失败,忽略错误
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 迁移23: tasks表添加新字段
|
|
|
|
|
+ try {
|
|
|
|
|
+ jdbcTemplate.execute("ALTER TABLE tasks ADD COLUMN task_type VARCHAR(20) COMMENT '任务性质: onetime/recurring'");
|
|
|
|
|
+ log.info("已添加task_type列到tasks表");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 列已存在,忽略错误
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ jdbcTemplate.execute("ALTER TABLE tasks ADD COLUMN frequency VARCHAR(20) COMMENT '频率: daily/weekly/monthly'");
|
|
|
|
|
+ log.info("已添加frequency列到tasks表");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 列已存在,忽略错误
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ jdbcTemplate.execute("ALTER TABLE tasks ADD COLUMN max_frequency INT COMMENT '周期内最多完成次数'");
|
|
|
|
|
+ log.info("已添加max_frequency列到tasks表");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 列已存在,忽略错误
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ jdbcTemplate.execute("ALTER TABLE tasks ADD COLUMN complete_types VARCHAR(100) COMMENT '完成方式JSON'");
|
|
|
|
|
+ log.info("已添加complete_types列到tasks表");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 列已存在,忽略错误
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ jdbcTemplate.execute("ALTER TABLE tasks ADD COLUMN review_type VARCHAR(20) COMMENT '审核人类型: creator/parent/teacher/ai'");
|
|
|
|
|
+ log.info("已添加review_type列到tasks表");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 列已存在,忽略错误
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ jdbcTemplate.execute("ALTER TABLE tasks ADD COLUMN earliest_start DATETIME COMMENT '最早开始时间'");
|
|
|
|
|
+ log.info("已添加earliest_start列到tasks表");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 列已存在,忽略错误
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ jdbcTemplate.execute("ALTER TABLE tasks ADD COLUMN latest_end DATETIME COMMENT '最晚结束时间'");
|
|
|
|
|
+ log.info("已添加latest_end列到tasks表");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 列已存在,忽略错误
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
-log.info("数据库迁移完成");
|
|
|
|
|
|
|
+ log.info("数据库迁移完成");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void initializeDefaultData() {
|
|
private void initializeDefaultData() {
|