feat: 同一交易日内可随时重新生成报告
This commit is contained in:
@@ -35,21 +35,8 @@ def _has_ai_report(trade_date: str) -> bool:
|
|||||||
|
|
||||||
|
|
||||||
def _can_trigger(trade_date: str) -> tuple[bool, str]:
|
def _can_trigger(trade_date: str) -> tuple[bool, str]:
|
||||||
"""检查是否可以触发分析(12小时频率限制)"""
|
"""检查是否可以触发分析(同一交易日内可随时重新生成)"""
|
||||||
conn = get_connection()
|
return True, ""
|
||||||
try:
|
|
||||||
row = conn.execute(
|
|
||||||
"SELECT created_at FROM ai_reports WHERE trade_date = ? ORDER BY id DESC LIMIT 1",
|
|
||||||
(trade_date,)
|
|
||||||
).fetchone()
|
|
||||||
if row:
|
|
||||||
last_time = datetime.strptime(row["created_at"], "%Y-%m-%d %H:%M:%S")
|
|
||||||
now = datetime.now(_CST)
|
|
||||||
if (now - last_time).total_seconds() < 12 * 3600:
|
|
||||||
return False, "12小时内已触发过,请稍后再试"
|
|
||||||
return True, ""
|
|
||||||
finally:
|
|
||||||
conn.close()
|
|
||||||
|
|
||||||
|
|
||||||
@router.get("/ai-analysis/latest", summary="最新 AI 分析报告")
|
@router.get("/ai-analysis/latest", summary="最新 AI 分析报告")
|
||||||
@@ -111,13 +98,6 @@ async def trigger_analysis():
|
|||||||
now = datetime.now(_CST)
|
now = datetime.now(_CST)
|
||||||
trade_date = now.strftime("%Y-%m-%d")
|
trade_date = now.strftime("%Y-%m-%d")
|
||||||
|
|
||||||
if _has_ai_report(trade_date):
|
|
||||||
raise HTTPException(status_code=400, detail="今日已有分析报告")
|
|
||||||
|
|
||||||
can, msg = _can_trigger(trade_date)
|
|
||||||
if not can:
|
|
||||||
raise HTTPException(status_code=429, detail=msg)
|
|
||||||
|
|
||||||
from services.ai_service import collect_ai_analysis
|
from services.ai_service import collect_ai_analysis
|
||||||
result = await collect_ai_analysis(trade_date)
|
result = await collect_ai_analysis(trade_date)
|
||||||
return JSONResponse({"data": result})
|
return JSONResponse({"data": result})
|
||||||
@@ -134,10 +114,6 @@ async def regenerate_report(report_id: int):
|
|||||||
finally:
|
finally:
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
can, msg = _can_trigger(trade_date)
|
|
||||||
if not can:
|
|
||||||
raise HTTPException(status_code=429, detail=msg)
|
|
||||||
|
|
||||||
from services.ai_service import collect_ai_analysis
|
from services.ai_service import collect_ai_analysis
|
||||||
result = await collect_ai_analysis(trade_date)
|
result = await collect_ai_analysis(trade_date)
|
||||||
return JSONResponse({"data": result})
|
return JSONResponse({"data": result})
|
||||||
|
|||||||
Reference in New Issue
Block a user