2026-09-03 00:44:38 +08:00
|
|
|
"""打卡记鹿 —— 数据访问(Model/Repository 层)。"""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
2026-09-01 13:13:40 +08:00
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
from nonebot import require
|
|
|
|
|
|
|
|
|
|
require("nonebot_plugin_orm")
|
|
|
|
|
|
2026-09-03 00:44:38 +08:00
|
|
|
from nonebot_plugin_orm import get_session
|
|
|
|
|
from sqlalchemy import select
|
2026-09-01 13:13:40 +08:00
|
|
|
|
2026-09-03 00:44:38 +08:00
|
|
|
from .models import CheckInRecord
|
2026-09-01 13:13:40 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
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]
|