diff --git a/api/code.py b/api/code.py index 18a27ad..b892030 100644 --- a/api/code.py +++ b/api/code.py @@ -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) # 归一化后计算百分比 # 将匹配结果添加到列表中