feat: 集成 apisbo.com 中国节假日 API 自动获取+缓存
- 新增 holidays.py 服务:按年获取节假日数据,缓存到 system_config - 区分 holiday(工作日假日)和 workday(调休上班日)两种类型 - is_working_day() 支持调休判断:周末在 workdays 集合中视为工作日 - 启动时自动从 API 刷新当年+明年数据,失败则使用缓存 - 系统设置新增「从 API 刷新」按钮,支局长可手动触发 - 支持 2010-2026 年数据,API 免费免鉴权 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@ from sqlalchemy import select
|
||||
from app.database import get_db
|
||||
from app.middleware.auth import get_current_user, require_director
|
||||
from app.models.system_config import SystemConfig
|
||||
from app.services.holidays import refresh_holidays
|
||||
from app.services.scheduler_manager import reschedule_daily_check
|
||||
|
||||
router = APIRouter(prefix="/system-config", tags=["SystemConfig"])
|
||||
@@ -95,3 +96,16 @@ async def update_config(
|
||||
|
||||
await _set_config(db, key, value)
|
||||
return {"key": key, "value": value}
|
||||
|
||||
|
||||
@router.post("/refresh-holidays")
|
||||
async def refresh_holidays_endpoint(
|
||||
current_user: dict = Depends(require_director),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
"""Fetch the latest Chinese holiday data from apisbo.com and cache it."""
|
||||
try:
|
||||
result = await refresh_holidays(db)
|
||||
return {"status": "ok", **result}
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=f"刷新节假日数据失败: {str(e)}")
|
||||
|
||||
Reference in New Issue
Block a user