root 1 year ago
parent
commit
3f690addfc

+ 21 - 10
data_verification.py

@@ -1,5 +1,6 @@
 import uvicorn
 import warnings
+import os
 from fastapi import FastAPI, UploadFile, File
 from openpyxl import load_workbook
 from openpyxl.utils.cell import coordinate_from_string
@@ -8,6 +9,7 @@ from openpyxl.styles import PatternFill
 from fastapi.middleware.cors import CORSMiddleware
 from datetime import datetime
 from fastapi.responses import FileResponse
+from fastapi.staticfiles import StaticFiles
 
 warnings.filterwarnings("ignore")
 
@@ -22,10 +24,14 @@ app.add_middleware(
     allow_headers=["*"],
 )
 
+shared_dir = 'cache'
+app.mount(f"/{shared_dir}", StaticFiles(directory="download_cache"), name={shared_dir})
+
+
 
 @app.post("/uploadfile")
 async def create_upload_file(file: UploadFile = File(...)):
-    # print(file.filename)
+    print(f"开始处理{file.filename}")
     contents = await file.read()
 
     savename = "download_cache/" + file.filename
@@ -47,9 +53,14 @@ async def create_upload_file(file: UploadFile = File(...)):
     row_range = sheet[1:5]
     for i, r in enumerate(row_range):
         for j, c in enumerate(r):
-            print(f"第{i + 1 }行,第{j}列,值:{c.value}")
+            # print(f"第{i + 1 }行,第{j}列,值:{c.value}")
             if "户主编号" == c.value or "户编号" == c.value:
                 title_row_num = c.row
+
+    if title_row_num == 0:
+        print(f"{file.filename}文件 内容不合格")
+        return {"code": 202, "msg": "不是可以解析的格式"}
+
     # 获取字段名对应的列
     title_dict = {}
     title_rows = sheet[title_row_num]
@@ -61,16 +72,17 @@ async def create_upload_file(file: UploadFile = File(...)):
     # print(title_dict)
 
     # 开始读取表格内容
-    # print(sheet.max_row)
     read_data(sheet, title_row_num + 1, sheet.max_row, title_dict)
 
     # 保存文档
     workbook.save(savename)
 
-    return FileResponse(savename)
-
-
-# return {"code": 200, "msg": "分析完成,请点击下载查看分析结果", "fileName": file.filename}
+    # return FileResponse(savename, media_type="application/octet-stream", filename="deal.xlsx")
+    # return FileResponse(savename)
+    # return FileResponse(savename, media_type='application/xlsx', filename="deal.xlsx")
+    # return savename
+    print(f"处理完了{file.filename}文件")
+    return {"code": 200, "msg": "分析完成,请点击下载查看分析结果", "filePath": f"/{shared_dir}/" + file.filename}
 
 
 def calculate_age_from_id_number(id_number):
@@ -232,7 +244,6 @@ def check_risk_type(ws, row_num, title_dict):
         if risk is not None and len(risk) > 0:
             risks.append((risk, i))
 
-    print(f"risks is {risks}")
 
     # 定义:健康帮扶,"综合保障,社会帮扶,义务教育保障, 教育帮扶, 住房安全保障, 搬迁, 饮水安全保障, 产业帮扶, 就业帮扶, 金融帮扶, 公益岗位帮扶等常量
     HEALTH_SUPPORT = "健康帮扶"
@@ -340,7 +351,7 @@ def check_risk_type(ws, row_num, title_dict):
         must_selected_ok = len(must_selected) > 0 if len(must_selected_option) > 0 else True
         forbiddens_ok = len(forbiddens) == 0 if len(forbinddens_option) > 0 else True
 
-        print(f"risk 为{risk}的必选项当前值:{must_selected},禁选项当前值:{forbiddens}")
+        # print(f"risk 为{risk}的必选项当前值:{must_selected},禁选项当前值:{forbiddens}")
         if not must_selected_ok or not forbiddens_ok:
             target = ws[f"{title_dict[get_key_for(i)]}{row_num}"]
             if not must_selected_ok:
@@ -396,4 +407,4 @@ def comment_and_fill_yellow_for(target, comment):
 if __name__ == "__main__":
     # result = calculate_age_from_id_number("532801200607144126")
     # print(result)
-    uvicorn.run("data_verification:app", host="localhost", port=8000, reload=True)
+    uvicorn.run("data_verification:app", host="0.0.0.0", port=8500, reload=True)

BIN
download_cache/111.xlsx


BIN
download_cache/2022在库项目情况.xlsx


BIN
download_cache/副本账号密码.xlsx


BIN
download_cache/户信息_20230515.xlsx


BIN
download_cache/易返贫致贫户(监测对象)信息_20230515.xlsx


BIN
download_cache/易返贫致贫户1(监测对象)信息_20230515.xlsx


+ 13 - 0
nohup.out

@@ -0,0 +1,13 @@
+INFO:     Will watch for changes in these directories: ['/home/data/service/python/monitoring_data']
+INFO:     Uvicorn running on http://0.0.0.0:8500 (Press CTRL+C to quit)
+INFO:     Started reloader process [64066] using StatReload
+INFO:     Started server process [64158]
+INFO:     Waiting for application startup.
+INFO:     Application startup complete.
+开始处理111.xlsx
+处理完了111.xlsx文件
+INFO:     127.0.0.1:38758 - "POST /uploadfile HTTP/1.0" 200 OK
+
+INFO:     192.168.31.7:59323 - "POST /upload_diff_file HTTP/1.1" 404 Not Found
+INFO:     127.0.0.1:51346 - "POST /upload_diff_file HTTP/1.1" 404 Not Found
+INFO:     127.0.0.1:51346 - "POST /upload_diff_file HTTP/1.1" 404 Not Found