"""打卡记鹿 —— 数据访问(Model/Repository 层)。""" from __future__ import annotations from datetime import datetime from nonebot import require require("nonebot_plugin_orm") from nonebot_plugin_orm import get_session from sqlalchemy import select from .models import CheckInRecord async def record_month(uid): now = datetime.now() async with get_session() as session: session.add(CheckInRecord(uid=int(uid), date=now.date())) await session.commit() async def get_records(uid): now = datetime.now() month_start = datetime(now.year, now.month, 1).date() if now.month == 12: month_end = datetime(now.year + 1, 1, 1).date() else: month_end = datetime(now.year, now.month + 1, 1).date() async with get_session() as session: result = await session.execute( select(CheckInRecord.date).where( CheckInRecord.uid == int(uid), CheckInRecord.date >= month_start, CheckInRecord.date < month_end, ) ) days = result.all() return [row[0].day for row in days]