fix: 专家库connected和我的团队改为查expert_services,选定专家后即时体现
This commit is contained in:
@@ -1384,8 +1384,8 @@ def list_experts(category: str | None = None, authorization: str | None = Header
|
|||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
expert_ids = [r["id"] for r in results]
|
expert_ids = [r["id"] for r in results]
|
||||||
cur.execute(
|
cur.execute(
|
||||||
"SELECT DISTINCT expert_id FROM expert_consultations "
|
"SELECT DISTINCT expert_id FROM expert_services "
|
||||||
"WHERE user_phone = %s AND expert_id = ANY(%s)",
|
"WHERE user_phone = %s AND expert_id = ANY(%s) AND status IN ('pending', 'active')",
|
||||||
(phone, expert_ids),
|
(phone, expert_ids),
|
||||||
)
|
)
|
||||||
connected_ids = {r[0] for r in cur.fetchall()}
|
connected_ids = {r[0] for r in cur.fetchall()}
|
||||||
@@ -2750,31 +2750,41 @@ def dashboard_timeline(authorization: str | None = Header(default=None)):
|
|||||||
|
|
||||||
@app.get("/team")
|
@app.get("/team")
|
||||||
def my_team(authorization: str | None = Header(default=None)):
|
def my_team(authorization: str | None = Header(default=None)):
|
||||||
"""我的团队:咨询过的专家自动沉淀"""
|
"""我的团队:已建立服务联系的专家(pending/active),含咨询统计"""
|
||||||
phone = get_current_phone(authorization)
|
phone = get_current_phone(authorization)
|
||||||
if not phone:
|
if not phone:
|
||||||
raise HTTPException(401, "未登录")
|
raise HTTPException(401, "未登录")
|
||||||
conn = _matter_dsn()
|
conn = _matter_dsn()
|
||||||
try:
|
try:
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
# 从 expert_consultations 聚合关系
|
# 从 expert_services 查已建立联系的专家,左连 expert_consultations 获取咨询统计
|
||||||
cur.execute(
|
cur.execute(
|
||||||
"SELECT e.id, e.name, e.avatar_url, e.category, e.title, e.expertise, "
|
"SELECT e.id, e.name, e.avatar_url, e.category, e.title, e.expertise, "
|
||||||
"COUNT(c.id) as cnt, MAX(c.replied_at) as last_at, "
|
"es.status, es.created_at, "
|
||||||
"(SELECT c2.topic FROM expert_consultations c2 WHERE c2.expert_id = e.id AND c2.user_phone = %s ORDER BY c2.created_at DESC LIMIT 1) as last_topic "
|
"COALESCE(cnt.c, 0) as consultation_count, "
|
||||||
"FROM experts e JOIN expert_consultations c ON c.expert_id = e.id "
|
"cnt.last_at, cnt.last_topic "
|
||||||
"WHERE c.user_phone = %s "
|
"FROM expert_services es "
|
||||||
"GROUP BY e.id, e.name, e.avatar_url, e.category, e.title, e.expertise "
|
"JOIN experts e ON es.expert_id = e.id "
|
||||||
"ORDER BY last_at DESC NULLS LAST",
|
"LEFT JOIN LATERAL ("
|
||||||
(phone, phone),
|
" SELECT COUNT(*) as c, MAX(replied_at) as last_at, "
|
||||||
|
" (SELECT topic FROM expert_consultations c2 "
|
||||||
|
" WHERE c2.expert_id = es.expert_id AND c2.user_phone = es.user_phone "
|
||||||
|
" ORDER BY c2.created_at DESC LIMIT 1) as last_topic "
|
||||||
|
" FROM expert_consultations c "
|
||||||
|
" WHERE c.expert_id = es.expert_id AND c.user_phone = es.user_phone"
|
||||||
|
") cnt ON true "
|
||||||
|
"WHERE es.user_phone = %s AND es.status IN ('pending', 'active') "
|
||||||
|
"ORDER BY es.created_at DESC",
|
||||||
|
(phone,),
|
||||||
)
|
)
|
||||||
rows = cur.fetchall()
|
rows = cur.fetchall()
|
||||||
results = [{
|
results = [{
|
||||||
"expert_id": r[0], "name": r[1], "avatar_url": r[2], "category": r[3],
|
"expert_id": r[0], "name": r[1], "avatar_url": r[2], "category": r[3],
|
||||||
"title": r[4], "expertise": r[5], "online": False, # 在线状态待接入
|
"title": r[4], "expertise": r[5], "online": False,
|
||||||
"consultation_count": r[6],
|
"service_status": r[6],
|
||||||
"last_consulted_at": r[7].isoformat() if r[7] else None,
|
"consultation_count": r[8],
|
||||||
"last_topic": r[8], "tags": r[5],
|
"last_consulted_at": r[9].isoformat() if r[9] else None,
|
||||||
|
"last_topic": r[10], "tags": r[5],
|
||||||
} for r in rows]
|
} for r in rows]
|
||||||
return {"results": results}
|
return {"results": results}
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
Reference in New Issue
Block a user