ソースを参照

完善验证报告上传流程

Sherlock 8 ヶ月 前
コミット
f2c7a73843
4 ファイル変更25 行追加27 行削除
  1. 20 0
      api/eval_report.py
  2. 1 23
      api_test.py
  3. 3 3
      config/config.py
  4. 1 1
      database/dao/mysql_dao.py

+ 20 - 0
api/eval_report.py

@@ -16,6 +16,18 @@ async def eval_report(request: EvalReportRequest):
     reports_dir = os.path.join('./data/reports', request.city_uuid, request.product_code)
     report_util = ReportUtils(request.city_uuid, request.product_code)
     
+    # 获取report数据表中eval_table的file_id,如果不为空,直接返回结果,如果为空则先创建验证数据
+    eval_file_id = dao.get_report_file_id(request.cultivacation_id)['val_table'].item()
+    if eval_file_id:
+        content = [
+            {
+                "id": 1,
+                "filename": "投放验证报告",
+                "file_id": eval_file_id
+            }
+        ]
+        return {"code": 200, "msg": "success", "data": {"evalReportInfo": content}}
+    
     # 获取推荐列表
     file_id = dao.get_report_file_id(request.cultivacation_id)['recommend_table'].item()
     if file_id is None:
@@ -34,6 +46,14 @@ async def eval_report(request: EvalReportRequest):
     
     dao.update_eval_report_data(request.cultivacation_id, file_id_map.get('投放验证报告'))
     
+    content = [
+        {
+            "id": 1,
+            "filename": "投放验证报告",
+            "file_id": file_id_map.get('投放验证报告')
+        }
+    ]
+    return {"code": 200, "msg": "success", "data": {"evalReportInfo": content}}
 
 @router.post('/eval_report')
 async def eval_report(request: EvalReportRequest):

+ 1 - 23
api_test.py

@@ -29,32 +29,10 @@ url = "http://127.0.0.1:7960/brandcultivation/api/v1/eval_report"
 payload = {
     "city_uuid": "00000000000000000000000011445301",
     "product_code": "440298",
-    "cultivacation_id": "10000001",
+    "cultivacation_id": "10000002",
     "limit_cycle_name": "202502W2(02.10-02.16)"
 }
 headers = {'Content-Type': 'application/json'}
 
 response = requests.post(url, data=json.dumps(payload), headers=headers)
 print(response.json())
-
-# url = "http://127.0.0.1:7960/brandcultivation/api/v1/report"
-# payload = {
-#     "city_uuid": "00000000000000000000000011445301",
-#     "product_code": "440298",
-# }
-# headers = {'Content-Type': 'application/json'}
-
-# response = requests.post(url, data=json.dumps(payload), headers=headers)
-# print(response.json())
-
-# url = "http://127.0.0.1:7960/brandcultivation/api/v1/eval_report"
-# payload = {
-#     "city_uuid": "00000000000000000000000011445301",
-#     "product_code": "440298",
-#     "start_time": "2025/2/10",
-#     "end_time": "2025/2/16"
-# }
-# headers = {'Content-Type': 'application/json'}
-
-# response = requests.post(url, data=json.dumps(payload), headers=headers)
-# print(response.json())

+ 3 - 3
config/config.py

@@ -1,16 +1,16 @@
 import yaml
 
 def load_config():
-    with open('./config/database_config.yaml') as file:
+    with open('./config/database_config.yaml', encoding='utf-8') as file:
         config = yaml.safe_load(file)
     return config
 
 def load_model_config():
-    with open('./config/model_config.yaml') as file:
+    with open('./config/model_config.yaml', encoding='utf-8') as file:
         config = yaml.safe_load(file)
     return config
 
 def load_service_config():
-    with open("./config/service_config.yaml") as file:
+    with open("./config/service_config.yaml", encoding='utf-8') as file:
         config = yaml.safe_load(file)
     return config

+ 1 - 1
database/dao/mysql_dao.py

@@ -307,7 +307,7 @@ class MySqlDao:
     
     def get_report_file_id(self, cultivacation_id):
         """从report中根据cultivacation_id获取对应文件的fileid"""
-        query = f"SELECT product_info_table, relation_table, similarity_product_table, recommend_table FROM {self._report_tablename} WHERE cultivacation_id = :cultivacation_id"
+        query = f"SELECT product_info_table, relation_table, similarity_product_table, recommend_table, val_table FROM {self._report_tablename} WHERE cultivacation_id = :cultivacation_id"
         params = {"cultivacation_id": cultivacation_id}
         
         result = self.db_helper.fetch_one(text(query), params)