feat(M3.1-发题时机): 教师公告智能插入——后端增量公告接口(/api/chat/announcements?after_id)+按hydro题号查题(/problems/hydro/);前端 AI_BUSY+公告队列+浮动条(回复中暂存、结束后插入对话流)+6s轮询+打开题目按钮
这个提交包含在:
@@ -113,6 +113,17 @@ async def history(limit: int = 200, authorization: str | None = Header(None), se
|
||||
return {"messages": [m.to_dict() for m in msgs]}
|
||||
|
||||
|
||||
@router.get("/announcements")
|
||||
async def announcements(after_id: int = 0, authorization: str | None = Header(None),
|
||||
session: Session = Depends(get_session)):
|
||||
"""学生端增量拉取教师公告(不占用 AI 调用,按消息 ID 增量轮询)。"""
|
||||
user = _current_user(_bearer(authorization), session)
|
||||
if not user:
|
||||
raise HTTPException(401, "未登录")
|
||||
msgs = MessageRepo(session).list_announcements(user["id"], after_id=after_id)
|
||||
return {"messages": [m.to_dict() for m in msgs]}
|
||||
|
||||
|
||||
@router.post("/explain")
|
||||
async def explain(body: ExplainBody, authorization: str | None = Header(None), session: Session = Depends(get_session)):
|
||||
user = _current_user(_bearer(authorization), session)
|
||||
|
||||
@@ -16,6 +16,15 @@ async def list_problems(course: str | None = None, session: Session = Depends(ge
|
||||
return [p.to_dict() for p in rows]
|
||||
|
||||
|
||||
@router.get("/hydro/{hydro_pid}")
|
||||
async def get_problem_by_hydro(hydro_pid: str, session: Session = Depends(get_session)):
|
||||
"""按 HydroOJ 题号取题(教师公告打开题目用)。"""
|
||||
row = ProblemRepo(session).get_by_hydro_pid(hydro_pid)
|
||||
if not row:
|
||||
raise HTTPException(404, "题目不存在")
|
||||
return row.to_dict()
|
||||
|
||||
|
||||
@router.get("/{pid}")
|
||||
async def get_problem(pid: int, session: Session = Depends(get_session)):
|
||||
row = ProblemRepo(session).get(pid)
|
||||
|
||||
@@ -79,3 +79,19 @@ class MessageRepo:
|
||||
if not rows:
|
||||
return None
|
||||
return self.session.get(Message, rows[0][0])
|
||||
|
||||
def list_announcements(self, user_id: int, after_id: int = 0, limit: int = 10) -> list[Message]:
|
||||
"""学生端增量拉取教师公告(meta.announcement=true 的 sys 消息,id 升序)。"""
|
||||
from sqlalchemy import text as sql_text
|
||||
|
||||
rows = list(
|
||||
self.session.execute(
|
||||
sql_text(
|
||||
"SELECT id FROM messages WHERE user_id = :u "
|
||||
"AND meta LIKE '%\"announcement\": true%' AND id > :a "
|
||||
"ORDER BY id ASC LIMIT :l"
|
||||
),
|
||||
{"u": user_id, "a": after_id, "l": limit},
|
||||
)
|
||||
)
|
||||
return [self.session.get(Message, r[0]) for r in rows if self.session.get(Message, r[0])]
|
||||
|
||||
在新工单中引用
屏蔽一个用户