1f18d2ec87
- 新增 chinese_holidays 表,通过 timor.tech API 同步节假日数据 - 修正 holiday 字段解读:holiday=true → 休息日,holiday=false → 调休工作日 - 工作日 8:00-22:00 每小时爬取,周末/节假日/夜间自动跳过 - 新增 /api/v1/holidays/sync 和 /api/v1/holidays/today 接口 - 企微菜单新增「同步节假日」按钮,支持手动触发同步
31 lines
970 B
Python
31 lines
970 B
Python
from fastapi import APIRouter, Depends, Query
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.api.deps import get_db
|
|
from app.services.holiday_service import now_in_china, sync_holidays
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.post("/holidays/sync")
|
|
async def sync_holidays_endpoint(
|
|
year: int | None = Query(None, description="同步年份,默认当前年份"),
|
|
db: AsyncSession = Depends(get_db),
|
|
):
|
|
if year is None:
|
|
year = now_in_china().year
|
|
count = await sync_holidays(db, year)
|
|
return {"status": "ok", "year": year, "synced": count}
|
|
|
|
|
|
@router.get("/holidays/today")
|
|
async def get_today_status(db: AsyncSession = Depends(get_db)):
|
|
from app.services.holiday_service import is_workday
|
|
today = now_in_china()
|
|
workday = await is_workday(db, today)
|
|
return {
|
|
"date": today.isoformat(),
|
|
"is_workday": workday,
|
|
"message": "工作日,正常爬取" if workday else "非工作日,跳过爬取",
|
|
}
|