refactor: upload excel error tips

This commit is contained in:
junjun
2026-04-20 13:29:17 +08:00
parent 20632f8486
commit 0e0b8736fe
5 changed files with 14 additions and 7 deletions
+10 -7
View File
@@ -565,7 +565,7 @@ async def parse_excel(file: UploadFile = File(..., description=f"{PLACEHOLDER_PR
@router.post("/importToDb", response_model=None, summary=f"{PLACEHOLDER_PREFIX}ds_import_to_db")
async def import_to_db(session: SessionDep, import_req: ImportRequest):
async def import_to_db(session: SessionDep, trans: Trans, import_req: ImportRequest):
save_path = os.path.join(path, import_req.filePath)
if not os.path.exists(save_path):
raise HTTPException(400, "File not found")
@@ -585,11 +585,14 @@ async def import_to_db(session: SessionDep, import_req: ImportRequest):
for col in field_mapping.keys()
}
if save_path.endswith(".csv"):
df = pd.read_csv(save_path, engine='c', dtype=dtype_dict)
sheet_name = "Sheet1"
else:
df = pd.read_excel(save_path, sheet_name=sheet_name, engine='calamine', dtype=dtype_dict)
try:
if save_path.endswith(".csv"):
df = pd.read_csv(save_path, engine='c', dtype=dtype_dict)
sheet_name = "Sheet1"
else:
df = pd.read_excel(save_path, sheet_name=sheet_name, engine='calamine', dtype=dtype_dict)
except Exception as e:
raise HTTPException(500, f"{trans('i18n_ds_upload_error')}: {str(e)}")
conn = engine.raw_connection()
cursor = conn.cursor()
@@ -615,7 +618,7 @@ async def import_to_db(session: SessionDep, import_req: ImportRequest):
"rows": len(df)
})
except Exception as e:
raise HTTPException(400, f"Insert data failed for {table_name}: {str(e)}")
raise HTTPException(500, f"Insert data failed for {table_name}: {str(e)}")
finally:
cursor.close()
conn.close()
+1
View File
@@ -51,6 +51,7 @@
"miss_default": "Default large language model has not been configured"
},
"i18n_ds_invalid": "Datasource connection is invalid",
"i18n_ds_upload_error": "Upload Failed",
"i18n_embedded": {
"invalid_origin": "Domain name validation failed【{origin}】"
},
+1
View File
@@ -51,6 +51,7 @@
"miss_default": "기본 대형 언어 모델이 구성되지 않았습니다"
},
"i18n_ds_invalid": "데이터 소스 연결이 무효합니다",
"i18n_ds_upload_error": "파일 업로드 실패",
"i18n_embedded": {
"invalid_origin": "도메인 이름 검증 실패 【{origin}】"
},
+1
View File
@@ -51,6 +51,7 @@
"miss_default": "尚未配置默认大语言模型"
},
"i18n_ds_invalid": "数据源连接无效",
"i18n_ds_upload_error": "上传文件失败",
"i18n_embedded": {
"invalid_origin": "域名校验失败【{origin}】"
},
+1
View File
@@ -51,6 +51,7 @@
"miss_default": "尚未配置默認大語言模型"
},
"i18n_ds_invalid": "數據源連接無效",
"i18n_ds_upload_error": "上傳文件失敗",
"i18n_embedded": {
"invalid_origin": "網域校驗失敗【{origin}】"
},