import arlo

This commit is contained in:
konjacpotato
2025-11-05 21:00:19 +08:00
commit 2c8426d543
69 changed files with 789 additions and 0 deletions

View File

View File

@ -0,0 +1,38 @@
from dataclasses import dataclass
from datetime import datetime
from typing import Optional
from sqlalchemy import Column, String, TIMESTAMP, func, Boolean
from sqlalchemy.dialects.postgresql import BIGINT
from database.database import Base
@dataclass
class THealthKnowledge(Base):
__tablename__ = 't_health_knowledge'
id: int = Column(BIGINT, primary_key=True, autoincrement=True, comment='序号')
subject: Optional[str] = Column(String, nullable=True, comment='主题')
knowledge: Optional[str] = Column(String, nullable=True, comment='知识内容')
keywords: Optional[str] = Column(String, nullable=True, comment='关键字')
url: Optional[str] = Column(String, nullable=True, comment='链接')
is_used: bool = Column(Boolean, default=False, nullable=False, comment='表示数据条目是否已被使用')
create_time: datetime = Column(TIMESTAMP(timezone=True), server_default=func.now(), nullable=False, comment='创建时间')
def __repr__(self):
return (f"<THealthKnowledge(id={self.id}, "
f"subject={self.subject}, "
f"knowledge={self.knowledge}, "
f"create_time={self.create_time})>")
# 把未使用的数据按照create_time排序获取最老的1条数据
def get_oldest_unused_data(db):
unused_data = db.query(THealthKnowledge).filter(THealthKnowledge.is_used == False).order_by(
THealthKnowledge.create_time).first()
return unused_data
# 把数据标记为已使用
def mark_data_as_used(db, data):
data.is_used = True
db.commit()