feat: 添加 Goal, GoalRelation, StudentGoal 三个数据模型

- Goal: 目标表,支持存储学习目标
- GoalRelation: 目标自关联多对多表,支持 DAG 结构
- StudentGoal: 学员目标记录表,关联学员和目标
This commit is contained in:
hmo
2026-04-23 20:10:08 +08:00
parent 285979ff70
commit b54b6c7aec
21 changed files with 3229 additions and 0 deletions
+60
View File
@@ -190,6 +190,66 @@ class StudentProblem(db.Model):
}
class Goal(db.Model):
"""目标表"""
__tablename__ = "goals"
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(100), nullable=False)
content = db.Column(db.Text)
created_at = db.Column(db.DateTime, default=datetime.now)
updated_at = db.Column(db.DateTime, default=datetime.now, onupdate=datetime.now)
def to_dict(self):
return {
"id": self.id,
"name": self.name,
"content": self.content,
"created_at": self.created_at.isoformat() if self.created_at else None,
"updated_at": self.updated_at.isoformat() if self.updated_at else None,
}
class GoalRelation(db.Model):
"""目标关联表 - 自关联多对多"""
__tablename__ = "goal_relations"
parent_goal_id = db.Column(db.Integer, db.ForeignKey("goals.id"), primary_key=True)
child_goal_id = db.Column(db.Integer, db.ForeignKey("goals.id"), primary_key=True)
parent = db.relationship("Goal", foreign_keys=[parent_goal_id], backref="child_relations")
child = db.relationship("Goal", foreign_keys=[child_goal_id], backref="parent_relations")
class StudentGoal(db.Model):
"""学员目标记录表"""
__tablename__ = "student_goals"
id = db.Column(db.Integer, primary_key=True)
student_id = db.Column(db.Integer, db.ForeignKey("students.id"), nullable=False)
goal_id = db.Column(db.Integer, db.ForeignKey("goals.id"), nullable=False)
status = db.Column(db.String(20), default="未开始") # 未开始/进行中/已完成
mastery_level = db.Column(db.Integer, default=1) # 1-5
deadline = db.Column(db.DateTime)
completed_at = db.Column(db.DateTime)
created_at = db.Column(db.DateTime, default=datetime.now)
student = db.relationship("Student", backref="goal_records")
goal = db.relationship("Goal")
def to_dict(self):
return {
"id": self.id,
"student_id": self.student_id,
"goal_id": self.goal_id,
"goal_name": self.goal.name if self.goal else None,
"status": self.status,
"mastery_level": self.mastery_level,
"deadline": self.deadline.isoformat() if self.deadline else None,
"completed_at": self.completed_at.isoformat() if self.completed_at else None,
}
class PracticePlan(db.Model):
"""练习方案表"""