release: Elysia ToDo v1.0.0
鍏ㄦ爤涓汉淇℃伅绠$悊搴旂敤锛岄泦鎴愬緟鍔炰换鍔°€佷範鎯墦鍗°€佺邯蹇垫棩鎻愰啋銆佽祫浜ф€昏鍔熻兘銆 Made-with: Cursor
This commit is contained in:
14
api/app/models/__init__.py
Normal file
14
api/app/models/__init__.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from app.models.task import Task
|
||||
from app.models.category import Category
|
||||
from app.models.tag import Tag, task_tags
|
||||
from app.models.user_settings import UserSettings
|
||||
from app.models.habit import HabitGroup, Habit, HabitCheckin
|
||||
from app.models.anniversary import AnniversaryCategory, Anniversary
|
||||
from app.models.account import FinancialAccount, AccountHistory, DebtInstallment
|
||||
|
||||
__all__ = [
|
||||
"Task", "Category", "Tag", "task_tags", "UserSettings",
|
||||
"HabitGroup", "Habit", "HabitCheckin",
|
||||
"AnniversaryCategory", "Anniversary",
|
||||
"FinancialAccount", "AccountHistory", "DebtInstallment",
|
||||
]
|
||||
61
api/app/models/account.py
Normal file
61
api/app/models/account.py
Normal file
@@ -0,0 +1,61 @@
|
||||
from sqlalchemy import Column, Integer, String, Text, Boolean, Float, DateTime, ForeignKey, Date
|
||||
from sqlalchemy.orm import relationship
|
||||
from app.database import Base
|
||||
from app.utils.datetime import utcnow
|
||||
|
||||
|
||||
class FinancialAccount(Base):
|
||||
"""财务账户模型"""
|
||||
__tablename__ = "financial_accounts"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String(100), nullable=False)
|
||||
account_type = Column(String(20), nullable=False, default="savings") # savings / debt
|
||||
balance = Column(Float, default=0.0)
|
||||
icon = Column(String(50), default="wallet")
|
||||
color = Column(String(20), default="#FFB7C5")
|
||||
sort_order = Column(Integer, default=0)
|
||||
is_active = Column(Boolean, default=True)
|
||||
description = Column(Text, nullable=True)
|
||||
created_at = Column(DateTime, default=utcnow)
|
||||
updated_at = Column(DateTime, default=utcnow, onupdate=utcnow)
|
||||
|
||||
# 关联关系
|
||||
history_records = relationship("AccountHistory", back_populates="account", cascade="all, delete-orphan")
|
||||
debt_installments = relationship("DebtInstallment", back_populates="account", cascade="all, delete-orphan")
|
||||
|
||||
|
||||
class AccountHistory(Base):
|
||||
"""余额变更历史"""
|
||||
__tablename__ = "account_history"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
account_id = Column(Integer, ForeignKey("financial_accounts.id"), nullable=False)
|
||||
change_amount = Column(Float, nullable=False)
|
||||
balance_before = Column(Float, nullable=False)
|
||||
balance_after = Column(Float, nullable=False)
|
||||
note = Column(String(200), nullable=True)
|
||||
created_at = Column(DateTime, default=utcnow)
|
||||
|
||||
# 关联关系
|
||||
account = relationship("FinancialAccount", back_populates="history_records")
|
||||
|
||||
|
||||
class DebtInstallment(Base):
|
||||
"""分期还款计划"""
|
||||
__tablename__ = "debt_installments"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
account_id = Column(Integer, ForeignKey("financial_accounts.id"), nullable=False)
|
||||
total_amount = Column(Float, nullable=False)
|
||||
total_periods = Column(Integer, nullable=False)
|
||||
current_period = Column(Integer, nullable=False, default=1) # 1-based, 指向下一期待还
|
||||
payment_day = Column(Integer, nullable=False) # 每月还款日 1-31
|
||||
payment_amount = Column(Float, nullable=False)
|
||||
start_date = Column(Date, nullable=False)
|
||||
is_completed = Column(Boolean, default=False)
|
||||
created_at = Column(DateTime, default=utcnow)
|
||||
updated_at = Column(DateTime, default=utcnow, onupdate=utcnow)
|
||||
|
||||
# 关联关系
|
||||
account = relationship("FinancialAccount", back_populates="debt_installments")
|
||||
37
api/app/models/anniversary.py
Normal file
37
api/app/models/anniversary.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from sqlalchemy import Column, Integer, String, Text, Boolean, DateTime, ForeignKey, Date
|
||||
from sqlalchemy.orm import relationship
|
||||
from app.database import Base
|
||||
from app.utils.datetime import utcnow
|
||||
|
||||
|
||||
class AnniversaryCategory(Base):
|
||||
"""纪念日分类模型"""
|
||||
__tablename__ = "anniversary_categories"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String(50), nullable=False)
|
||||
icon = Column(String(50), default="calendar")
|
||||
color = Column(String(20), default="#FFB7C5")
|
||||
sort_order = Column(Integer, default=0)
|
||||
|
||||
# 关联关系
|
||||
anniversaries = relationship("Anniversary", back_populates="category")
|
||||
|
||||
|
||||
class Anniversary(Base):
|
||||
"""纪念日模型"""
|
||||
__tablename__ = "anniversaries"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
title = Column(String(200), nullable=False)
|
||||
date = Column(Date, nullable=False) # 月-日,年份部分可选
|
||||
year = Column(Integer, nullable=True) # 年份,用于计算第 N 个周年
|
||||
category_id = Column(Integer, ForeignKey("anniversary_categories.id"), nullable=True)
|
||||
description = Column(Text, nullable=True)
|
||||
is_recurring = Column(Boolean, default=True)
|
||||
remind_days_before = Column(Integer, default=3)
|
||||
created_at = Column(DateTime, default=utcnow)
|
||||
updated_at = Column(DateTime, default=utcnow, onupdate=utcnow)
|
||||
|
||||
# 关联关系
|
||||
category = relationship("AnniversaryCategory", back_populates="anniversaries")
|
||||
16
api/app/models/category.py
Normal file
16
api/app/models/category.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from sqlalchemy import Column, Integer, String
|
||||
from sqlalchemy.orm import relationship
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class Category(Base):
|
||||
"""分类模型"""
|
||||
__tablename__ = "categories"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String(100), nullable=False)
|
||||
color = Column(String(20), default="#FFB7C5") # 默认樱花粉
|
||||
icon = Column(String(50), default="folder") # 默认图标
|
||||
|
||||
# 关联关系
|
||||
tasks = relationship("Task", back_populates="category")
|
||||
55
api/app/models/habit.py
Normal file
55
api/app/models/habit.py
Normal file
@@ -0,0 +1,55 @@
|
||||
from sqlalchemy import Column, Integer, String, Text, Boolean, Date, DateTime, ForeignKey, UniqueConstraint
|
||||
from sqlalchemy.orm import relationship
|
||||
from app.database import Base
|
||||
from app.utils.datetime import utcnow
|
||||
|
||||
|
||||
class HabitGroup(Base):
|
||||
"""习惯分组模型"""
|
||||
__tablename__ = "habit_groups"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String(100), nullable=False)
|
||||
color = Column(String(20), default="#FFB7C5")
|
||||
icon = Column(String(50), default="flag")
|
||||
sort_order = Column(Integer, default=0)
|
||||
|
||||
# 关联关系
|
||||
habits = relationship("Habit", back_populates="group", order_by="Habit.created_at")
|
||||
|
||||
|
||||
class Habit(Base):
|
||||
"""习惯模型"""
|
||||
__tablename__ = "habits"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String(200), nullable=False)
|
||||
description = Column(Text, nullable=True)
|
||||
group_id = Column(Integer, ForeignKey("habit_groups.id"), nullable=True)
|
||||
target_count = Column(Integer, default=1)
|
||||
frequency = Column(String(20), default="daily") # daily / weekly
|
||||
active_days = Column(String(100), nullable=True) # JSON 数组, 如 [0,2,4] 表示周一三五
|
||||
is_archived = Column(Boolean, default=False)
|
||||
created_at = Column(DateTime, default=utcnow)
|
||||
updated_at = Column(DateTime, default=utcnow, onupdate=utcnow)
|
||||
|
||||
# 关联关系
|
||||
group = relationship("HabitGroup", back_populates="habits")
|
||||
checkins = relationship("HabitCheckin", back_populates="habit", cascade="all, delete-orphan")
|
||||
|
||||
|
||||
class HabitCheckin(Base):
|
||||
"""习惯打卡记录模型"""
|
||||
__tablename__ = "habit_checkins"
|
||||
__table_args__ = (
|
||||
UniqueConstraint("habit_id", "checkin_date", name="uq_habit_checkin_date"),
|
||||
)
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
habit_id = Column(Integer, ForeignKey("habits.id"), nullable=False)
|
||||
checkin_date = Column(Date, nullable=False)
|
||||
count = Column(Integer, default=0)
|
||||
created_at = Column(DateTime, default=utcnow)
|
||||
|
||||
# 关联关系
|
||||
habit = relationship("Habit", back_populates="checkins")
|
||||
23
api/app/models/tag.py
Normal file
23
api/app/models/tag.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from sqlalchemy import Column, Integer, String, Table, ForeignKey
|
||||
from sqlalchemy.orm import relationship
|
||||
from app.database import Base
|
||||
|
||||
|
||||
# 任务-标签关联表(多对多)
|
||||
task_tags = Table(
|
||||
"task_tags",
|
||||
Base.metadata,
|
||||
Column("task_id", Integer, ForeignKey("tasks.id"), primary_key=True),
|
||||
Column("tag_id", Integer, ForeignKey("tags.id"), primary_key=True)
|
||||
)
|
||||
|
||||
|
||||
class Tag(Base):
|
||||
"""标签模型"""
|
||||
__tablename__ = "tags"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String(50), nullable=False, unique=True)
|
||||
|
||||
# 关联关系
|
||||
tasks = relationship("Task", secondary=task_tags, back_populates="tags")
|
||||
23
api/app/models/task.py
Normal file
23
api/app/models/task.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from sqlalchemy import Column, Integer, String, Text, Boolean, DateTime, ForeignKey
|
||||
from sqlalchemy.orm import relationship
|
||||
from app.database import Base
|
||||
from app.utils.datetime import utcnow
|
||||
|
||||
|
||||
class Task(Base):
|
||||
"""任务模型"""
|
||||
__tablename__ = "tasks"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
title = Column(String(200), nullable=False)
|
||||
description = Column(Text, nullable=True)
|
||||
priority = Column(String(20), default="q4") # q1(重要紧急), q2(重要不紧急), q3(不重要紧急), q4(不重要不紧急)
|
||||
due_date = Column(DateTime, nullable=True)
|
||||
is_completed = Column(Boolean, default=False)
|
||||
category_id = Column(Integer, ForeignKey("categories.id"), nullable=True)
|
||||
created_at = Column(DateTime, default=utcnow)
|
||||
updated_at = Column(DateTime, default=utcnow, onupdate=utcnow)
|
||||
|
||||
# 关联关系
|
||||
category = relationship("Category", back_populates="tasks")
|
||||
tags = relationship("Tag", secondary="task_tags", back_populates="tasks")
|
||||
36
api/app/models/user_settings.py
Normal file
36
api/app/models/user_settings.py
Normal file
@@ -0,0 +1,36 @@
|
||||
from sqlalchemy import Column, Integer, String, Text, DateTime, Date
|
||||
from datetime import datetime, timezone, date
|
||||
from app.database import Base
|
||||
|
||||
|
||||
def utcnow():
|
||||
"""统一获取 UTC 时间的工厂函数"""
|
||||
return datetime.now(timezone.utc)
|
||||
|
||||
|
||||
class UserSettings(Base):
|
||||
"""用户设置模型(单例,始终只有一条记录 id=1)"""
|
||||
__tablename__ = "user_settings"
|
||||
|
||||
id = Column(Integer, primary_key=True, default=1)
|
||||
|
||||
# 个人信息
|
||||
nickname = Column(String(50), default="爱莉希雅")
|
||||
avatar = Column(Text, nullable=True)
|
||||
signature = Column(String(200), nullable=True)
|
||||
birthday = Column(Date, nullable=True)
|
||||
email = Column(String(100), nullable=True)
|
||||
|
||||
# 应用信息
|
||||
site_name = Column(String(50), default="爱莉希雅待办")
|
||||
|
||||
# 应用偏好
|
||||
theme = Column(String(20), default="pink")
|
||||
language = Column(String(10), default="zh-CN")
|
||||
default_view = Column(String(20), default="list")
|
||||
default_sort_by = Column(String(20), default="created_at")
|
||||
default_sort_order = Column(String(10), default="desc")
|
||||
|
||||
# 时间戳
|
||||
created_at = Column(DateTime, default=utcnow)
|
||||
updated_at = Column(DateTime, default=utcnow, onupdate=utcnow)
|
||||
Reference in New Issue
Block a user