| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- from database import MySqlDao
- from fastapi import APIRouter, status, HTTPException
- import os
- from .request_body import ReportRequest
- dao =MySqlDao()
- router = APIRouter()
- @router.post("/report")
- async def report(request: ReportRequest):
- """获取推荐相关报告接口"""
- file_id_record = dao.get_report_file_id(request.cultivacation_id)
- if file_id_record.empty:
- raise HTTPException(
- status_code=status.HTTP_404_NOT_FOUND,
- detail="Reports not found"
- )
-
- file_id_map = {
- '卷烟信息表': file_id_record['product_info_table'].item(),
- '品规商户特征关系表': file_id_record['relation_table'].item(),
- '相似卷烟表': file_id_record['similarity_product_table'].item()
- }
-
- request_data = []
- for index, filename in enumerate(file_id_map):
- request_data.append(
- {
- "id": index+1,
- "filename": filename,
- "file_id": file_id_map.get(filename)
- }
- )
-
- return {"code": 200, "msg": "success", "data": {"reportInfo": request_data}}
- # @router.post("/report")
- # async def report_api(request: ReportRequest):
- # """获取推荐相关报告接口"""
- # files_id_path = os.path.join("./data/reports", request.city_uuid, request.product_code, "files_id.txt")
- # if not os.path.exists(files_id_path):
- # raise HTTPException(
- # status_code=status.HTTP_404_NOT_FOUND,
- # detail="Reports not found"
- # )
-
- # with open(files_id_path, 'r', encoding="utf-8") as file:
- # lines = file.readlines()
-
- # if lines[0].strip() == "failed":
- # raise HTTPException(
- # status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
- # detail="reports upload failed"
- # )
-
- # request_data = []
- # for index, line in enumerate(lines):
- # filename, file_id = line.strip().split(",")
- # request_data.append(
- # {
- # "id": index+1,
- # "filename": filename,
- # "file_id": file_id
- # }
- # )
-
- # return {"code": 200, "msg": "success", "data": {"reportInfo": request_data}}
|