|
|
|
@ -147,8 +147,8 @@ async def get_tree_data():
|
|
|
|
|
try:
|
|
|
|
|
pg_pool = await init_postgres_pool()
|
|
|
|
|
async with pg_pool.acquire() as conn:
|
|
|
|
|
async with conn.cursor() as cur:
|
|
|
|
|
await cur.execute("""
|
|
|
|
|
# 执行查询
|
|
|
|
|
rows = await conn.fetch("""
|
|
|
|
|
SELECT id,
|
|
|
|
|
title,
|
|
|
|
|
parent_id,
|
|
|
|
@ -158,8 +158,6 @@ async def get_tree_data():
|
|
|
|
|
FROM knowledge_points
|
|
|
|
|
ORDER BY parent_id, id
|
|
|
|
|
""")
|
|
|
|
|
rows = await cur.fetchall()
|
|
|
|
|
|
|
|
|
|
# 构建节点映射
|
|
|
|
|
nodes = {}
|
|
|
|
|
for row in rows:
|
|
|
|
@ -214,28 +212,29 @@ async def update_knowledge(request: fastapi.Request):
|
|
|
|
|
|
|
|
|
|
pg_pool = await init_postgres_pool()
|
|
|
|
|
async with pg_pool.acquire() as conn:
|
|
|
|
|
async with conn.cursor() as cur:
|
|
|
|
|
if update_type == 'prerequisite':
|
|
|
|
|
await cur.execute(
|
|
|
|
|
"""
|
|
|
|
|
UPDATE knowledge_points
|
|
|
|
|
SET prerequisite = %s
|
|
|
|
|
WHERE id = %s
|
|
|
|
|
""",
|
|
|
|
|
(json.dumps([{"id": p["id"], "title": p["title"]} for p in knowledge], ensure_ascii=False),
|
|
|
|
|
node_id)
|
|
|
|
|
)
|
|
|
|
|
else: # related knowledge
|
|
|
|
|
await cur.execute(
|
|
|
|
|
"""
|
|
|
|
|
UPDATE knowledge_points
|
|
|
|
|
SET related = %s
|
|
|
|
|
WHERE id = %s
|
|
|
|
|
""",
|
|
|
|
|
(json.dumps([{"id": p["id"], "title": p["title"]} for p in knowledge], ensure_ascii=False),
|
|
|
|
|
node_id)
|
|
|
|
|
)
|
|
|
|
|
await conn.commit()
|
|
|
|
|
if update_type == 'prerequisite':
|
|
|
|
|
await conn.execute("""
|
|
|
|
|
UPDATE knowledge_points
|
|
|
|
|
SET prerequisite = $1
|
|
|
|
|
WHERE id = $2
|
|
|
|
|
""",
|
|
|
|
|
json.dumps(
|
|
|
|
|
[{"id": p["id"], "title": p["title"]} for p in knowledge],
|
|
|
|
|
ensure_ascii=False
|
|
|
|
|
),
|
|
|
|
|
node_id)
|
|
|
|
|
else: # related knowledge
|
|
|
|
|
await conn.execute("""
|
|
|
|
|
UPDATE knowledge_points
|
|
|
|
|
SET related = $1
|
|
|
|
|
WHERE id = $2
|
|
|
|
|
""",
|
|
|
|
|
json.dumps(
|
|
|
|
|
[{"id": p["id"], "title": p["title"]} for p in knowledge],
|
|
|
|
|
ensure_ascii=False
|
|
|
|
|
),
|
|
|
|
|
node_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return {"code": 0, "msg": "更新成功"}
|
|
|
|
|
except Exception as e:
|
|
|
|
|