diff --git a/backend/apps/datasource/api/datasource.py b/backend/apps/datasource/api/datasource.py
index afd7595d..37e555f8 100644
--- a/backend/apps/datasource/api/datasource.py
+++ b/backend/apps/datasource/api/datasource.py
@@ -1,4 +1,4 @@
-from fastapi import APIRouter, File, UploadFile
+from fastapi import APIRouter, File, UploadFile, HTTPException
from ..crud.datasource import get_datasource_list, check_status, create_ds, update_ds, delete_ds, getTables, getFields, \
execSql, update_table_and_fields, getTablesByDs, chooseTables, preview
from common.core.deps import SessionDep
@@ -6,6 +6,9 @@ from ..models.datasource import CoreDatasource, CreateDatasource, EditObj, CoreT
from ..crud.table import get_tables_by_ds_id
from ..crud.field import get_fields_by_table_id
from typing import List
+import uuid
+import pandas as pd
+import hashlib
router = APIRouter(tags=["datasource"], prefix="/datasource")
@@ -80,7 +83,27 @@ async def edit_local(session: SessionDep, id: int, data: EditObj):
return preview(session, id, data)
-@router.post("/uploadExcel/")
+@router.post("/uploadExcel")
async def upload_excel(session: SessionDep, file: UploadFile = File(...)):
+ ALLOWED_EXTENSIONS = {"xlsx", "xls", "csv"}
+ if not file.filename.lower().endswith(tuple(ALLOWED_EXTENSIONS)):
+ raise HTTPException(400, "Only support .xlsx/.xls/.csv")
+
+ contents = await file.read()
+ df_sheets = pd.read_excel(contents, sheet_name=None)
+ # build columns and data to insert db
# todo
- pass
+ sheets = []
+ for sheet_name, df in df_sheets.items():
+ print("--------------------")
+ print(f"Sheet: {sheet_name}, {hashlib.sha256(uuid.uuid4().bytes).hexdigest()[:10]}")
+ sheets.append({"name": f"{sheet_name}",
+ "uniqueName": f"{sheet_name}_{hashlib.sha256(uuid.uuid4().bytes).hexdigest()[:10]}"})
+ column_len = len(df.dtypes)
+ for i in range(column_len):
+ print(f"{df.columns[i]} , {df.dtypes[i]}")
+
+ for row in df.values:
+ print(row)
+
+ return {"filename": file.filename, "sheets": sheets}
diff --git a/backend/apps/db/engine.py b/backend/apps/db/engine.py
new file mode 100644
index 00000000..1d125831
--- /dev/null
+++ b/backend/apps/db/engine.py
@@ -0,0 +1,2 @@
+# Author: Junjun
+# Date: 2025/5/19
diff --git a/backend/pyproject.toml b/backend/pyproject.toml
index a5e85165..d165de11 100644
--- a/backend/pyproject.toml
+++ b/backend/pyproject.toml
@@ -29,7 +29,9 @@ dependencies = [
"pymysql (>=1.1.1,<2.0.0)",
"cryptography (>=44.0.3,<45.0.0)",
"llama_index>=0.12.35",
- "pymssql (>=2.3.4,<3.0.0)"
+ "pymssql (>=2.3.4,<3.0.0)",
+ "pandas (>=2.2.3,<3.0.0)",
+ "openpyxl (>=3.1.5,<4.0.0)"
]
[[tool.uv.index]]
url = "https://pypi.tuna.tsinghua.edu.cn/simple"
diff --git a/frontend/src/views/ds/form.vue b/frontend/src/views/ds/form.vue
index dd50d0e9..009b485c 100644
--- a/frontend/src/views/ds/form.vue
+++ b/frontend/src/views/ds/form.vue
@@ -29,28 +29,47 @@
/>
-