From 1868637993060010da78006b1348bb4fcc137917 Mon Sep 17 00:00:00 2001 From: P3ngSaM <61768364+P3ngSaM@users.noreply.github.com> Date: Thu, 17 Nov 2022 16:08:03 +0800 Subject: [PATCH] =?UTF-8?q?changes=20=E6=8E=A5=E5=8F=A3=E9=87=8D=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- APPData/Crud/MacroDataCrud.py | 10 ++++++++++ APPData/Router/MacroDataRouter.py | 10 +++++----- 2 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 APPData/Crud/MacroDataCrud.py diff --git a/APPData/Crud/MacroDataCrud.py b/APPData/Crud/MacroDataCrud.py new file mode 100644 index 0000000..1d6e0f5 --- /dev/null +++ b/APPData/Crud/MacroDataCrud.py @@ -0,0 +1,10 @@ +def upsert_data(mongodb, data): + mongodb.upsert_data("WR_DataBase_v2_test", 'C12.2_区域经济', + {"省/直辖市": data['省/直辖市'], "地区": data['地区'], "年份": data["年份"]}, data) + return True + + +def find_data(mongodb, condition): + data = mongodb.find_all_data("WR_DataBase_v2_test", 'C12.2_区域经济', + {"省/直辖市": condition.provinces, "地区": condition.region, "年份": condition.year}, []) + return data diff --git a/APPData/Router/MacroDataRouter.py b/APPData/Router/MacroDataRouter.py index 9326906..6eac6e6 100644 --- a/APPData/Router/MacroDataRouter.py +++ b/APPData/Router/MacroDataRouter.py @@ -3,6 +3,8 @@ import math import pandas as pd from fastapi import APIRouter, Depends, UploadFile, File, HTTPException from sqlalchemy.orm import Session + +from APPData.Crud import MacroDataCrud from APPData.Schemas import CompanySchemas from Utils.DataBase.MongoHelperUtils import get_mongodb from Utils.DataBase.SqlAlchemyUtils import get_db @@ -29,14 +31,12 @@ async def func01(region: str, excel: UploadFile = File(...), db: Session = Depen df_line[key] = None except TypeError: continue - mongodb.upsert_data("WR_DataBase_v2_test", 'C12.2_区域经济', - {"省/直辖市": region, "地区": df_line['地区'], "年份": df_line["年份"]}, df_line) + MacroDataCrud.upsert_data(mongodb=mongodb, data=df_line) return {"info": "Success"} @router.post("/view", summary="查看数据") -def func03(req_body: CompanySchemas.MacroSearch, db: Session = Depends(get_db)): +def func03(req_body: CompanySchemas.MacroSearch): mongodb = get_mongodb() - data = mongodb.find_all_data("WR_DataBase_v2_test", 'C12.2_区域经济', - {"省/直辖市": req_body.provinces, "地区": req_body.region, "年份": req_body.year}, []) + data = MacroDataCrud.find_data(mongodb=mongodb, condition=req_body) return data