fix: 修复编码导入时将编码解析为int

This commit is contained in:
皓月归尘 2025-02-19 02:28:49 +08:00
parent 0a2372a99c
commit fe708aa0c8

View File

@ -104,9 +104,11 @@ async def add_code_by_file(request: Request, id: str = Path(description="文件I
uploader_id = await file.first().values(id="uploader__id")
if str(uploader_id["id"]) == user_id:
try:
df = pd.read_excel(file.absolute_path)
df = pd.read_excel(file.absolute_path, dtype={"code": str})
df["code"] = df["code"].astype(str).str.zfill(8)
for index, row in df.iterrows():
row["code"] = str(row["code"]).replace(".", "").replace("/", "").replace("_", "").replace("-",
print(row['code'],type(row['code']))
row["code"] = row["code"].replace(".", "").replace("/", "").replace("_", "").replace("-",
"").replace(
"?",
"").replace(
@ -276,7 +278,7 @@ async def get_code_list(request: Request,
max_score = data["hits"].get("max_score", 1)
# 处理每一条匹配结果
for hit in data["hits"]["hits"]:
code = await Code.get_or_none(code=str(hit["_source"]["code"]))
code = await Code.get_or_none(code=hit["_source"]["code"])
# 归一化匹配度,转换为百分比
match_rate = round((hit["_score"] / max_score) * 100, 2) # 归一化后计算百分比
# 将匹配结果添加到列表中
@ -377,7 +379,7 @@ async def get_code_list(request: Request,
max_score = data["hits"].get("max_score", 1)
# 处理每一条匹配结果
for hit in data["hits"]["hits"]:
code = await Code.get_or_none(code=str(hit["_source"]["code"]))
code = await Code.get_or_none(code=hit["_source"]["code"])
# 归一化匹配度,转换为百分比
match_rate = round((hit["_score"] / max_score) * 100, 2) # 归一化后计算百分比
# 将匹配结果添加到列表中