Procházet zdrojové kódy

Merge branch 'feature/xueyiming/2025-09-23-chat-res' of Server/rag_server into master

luojunhui před 2 týdny
rodič
revize
dd4e226063
2 změnil soubory, kde provedl 21 přidání a 3 odebrání
  1. 6 0
      applications/utils/mysql/mapper.py
  2. 15 3
      routes/buleprint.py

+ 6 - 0
applications/utils/mysql/mapper.py

@@ -44,6 +44,12 @@ class Dataset(BaseMySQLClient):
         """
         return await self.pool.async_fetch(query=query, params=(id_, status))
 
+    async def select_dataset_by_name(self, name, status: int = 1):
+        query = """
+            SELECT * FROM dataset WHERE name = %s AND status = %s;
+        """
+        return await self.pool.async_fetch(query=query, params=(name, status))
+
 
 class Contents(BaseMySQLClient):
     async def insert_content(self, doc_id, text, text_type, title, dataset_id):

+ 15 - 3
routes/buleprint.py

@@ -176,15 +176,25 @@ async def dataset_list():
 @server_bp.route("/dataset/add", methods=["POST"])
 async def add_dataset():
     resource = get_resource_manager()
-    dataset = Dataset(resource.mysql_client)
+    dataset_mapper = Dataset(resource.mysql_client)
     # 从请求体里取参数
     body = await request.get_json()
     name = body.get("name")
     if not name:
         return jsonify({"status_code": 400, "detail": "name is required"})
     # 执行新增
-    await dataset.add_dataset(name)
-    return jsonify({"status_code": 200, "detail": "success"})
+    dataset = await dataset_mapper.select_dataset_by_name(name)
+    if dataset:
+        return jsonify({"status_code": 400, "detail": "name is exist"})
+    await dataset_mapper.add_dataset(name)
+    new_dataset = await dataset_mapper.select_dataset_by_name(name)
+    return jsonify(
+        {
+            "status_code": 200,
+            "detail": "success",
+            "data": {"datasetId": new_dataset[0]["id"]},
+        }
+    )
 
 
 @server_bp.route("/content/get", methods=["GET"])
@@ -253,6 +263,7 @@ async def content_list():
             "doc_id": row["doc_id"],
             "title": row.get("title") or "",
             "text": row.get("text") or "",
+            "statusDesc": "可用" if row.get("status") == 2 else "不可用",
         }
         for row in result["entities"]
     ]
@@ -454,6 +465,7 @@ async def chunk_list():
             "doc_id": row["doc_id"],
             "summary": row.get("summary") or "",
             "text": row.get("text") or "",
+            "statusDesc": "可用" if row.get("chunk_status") == 2 else "不可用",
         }
         for row in result["entities"]
     ]