Browse Source

get_last_photo_record

rambo 7 months ago
parent
commit
3cc160a9ff
1 changed files with 64 additions and 37 deletions
  1. 64 37
      python/api.py

+ 64 - 37
python/api.py

@@ -124,6 +124,7 @@ async def forwardRequest(request: HlmForwardRequest):
     except Exception as e:
         raise UnicornException(e)
 
+
 def fromExcelHandler(params: HandlerDetail):
     excel_path = params.excel_path
     excel_df = pd.read_excel(excel_path, sheet_name=0, header=0)
@@ -260,6 +261,8 @@ def fromExcelHandler(params: HandlerDetail):
         "msg": "",
         "data": {"output_folder": handler_result_folder, "list": handler_result},
     }
+
+
 @app.post("/handle_detail")
 async def handle_detail(request: Request, params: HandlerDetail):
     goods_art_no_array = params.goods_art_no
@@ -296,28 +299,30 @@ async def handle_detail(request: Request, params: HandlerDetail):
                 temp_class[tempItem.template_id] = tempItem.template_local_classes
                 temp_name_list.append(tempItem.template_id)
             config_data = {
-                    "image_dir": path,
-                    "image_order": params.template_image_order,
-                    "goods_art_no": goods_art_no,
-                    "is_check_number": False,
-                    "resize_image_view": "后跟",
-                    "cutout_mode": settings.CUTOUT_MODE,
-                    "logo_path": params.logo_path,
-                    "special_goods_art_no_folder_line": "",
-                    "is_use_excel": False if params.excel_path == "" else True,  # 是否使用excel
-                    "excel_path": params.excel_path,  # excel路径
-                    "is_check_color_is_all": False,
-                    "cutout_is_pass": True,
-                    "assigned_page_dict": {},
-                    "detail_is_pass": True,
-                    "upload_is_pass": False,
-                    "upload_is_enable": False,
-                    "is_filter": False,
-                    "temp_class": temp_class,
-                    "temp_name": params.temp_name,
-                    "temp_name_list": temp_name_list,
-                    "target_error_folder": f"{path}/软件-生成详情错误",
-                }
+                "image_dir": path,
+                "image_order": params.template_image_order,
+                "goods_art_no": goods_art_no,
+                "is_check_number": False,
+                "resize_image_view": "后跟",
+                "cutout_mode": settings.CUTOUT_MODE,
+                "logo_path": params.logo_path,
+                "special_goods_art_no_folder_line": "",
+                "is_use_excel": (
+                    False if params.excel_path == "" else True
+                ),  # 是否使用excel
+                "excel_path": params.excel_path,  # excel路径
+                "is_check_color_is_all": False,
+                "cutout_is_pass": True,
+                "assigned_page_dict": {},
+                "detail_is_pass": True,
+                "upload_is_pass": False,
+                "upload_is_enable": False,
+                "is_filter": False,
+                "temp_class": temp_class,
+                "temp_name": params.temp_name,
+                "temp_name_list": temp_name_list,
+                "target_error_folder": f"{path}/软件-生成详情错误",
+            }
             # 动态导入类
             temp_class_dict = {}
             for key, class_path in config_data["temp_class"].items():
@@ -328,18 +333,21 @@ async def handle_detail(request: Request, params: HandlerDetail):
 
             config_data["temp_class"] = temp_class_dict
             obj = None
-            run_main = RunMain(obj,token)
+            run_main = RunMain(obj, token)
             return_data = run_main.check_before_cutout(config_data)
             cutout_res = run_main.check_for_cutout_image_first_call_back(return_data)
             check_for_detail_first_res = None
             if cutout_res == True:
-                return_data_check_before_detail = run_main.check_before_detail(config_data)
+                return_data_check_before_detail = run_main.check_before_detail(
+                    config_data
+                )
                 print(
-                    "return_data_check_before_detail======> 测试 ==>", return_data_check_before_detail
+                    "return_data_check_before_detail======> 测试 ==>",
+                    return_data_check_before_detail,
                 )
                 check_for_detail_first_res = run_main.check_for_detail_first_call_back(
-                        return_data_check_before_detail
-                    )
+                    return_data_check_before_detail
+                )
             if isinstance(check_for_detail_first_res, partial):
                 result = check_for_detail_first_res()
                 try:
@@ -355,22 +363,24 @@ async def handle_detail(request: Request, params: HandlerDetail):
                     print("to_deal_dir", to_deal_dir)
                     if os.path.exists(to_deal_dir):
                         upload_pic = UploadPic(
-                                windows=None,
-                                to_deal_dir=to_deal_dir,
-                                config_data=config_data,
-                                token=token,
-                            )
+                            windows=None,
+                            to_deal_dir=to_deal_dir,
+                            config_data=config_data,
+                            token=token,
+                        )
                         upload_pic.run()
                 out_put_dir = config_data["out_put_dir"]
-                out_put_dir_path = "{}/{}".format(os.getcwd(), out_put_dir).replace("\\", "/")
+                out_put_dir_path = "{}/{}".format(os.getcwd(), out_put_dir).replace(
+                    "\\", "/"
+                )
                 handler_result_folder = os.path.dirname(out_put_dir_path)
                 handler_result.append(
-                        {"goods_art_no": goods_art_no, "success": True, "info": "处理成功"}
-                    )
+                    {"goods_art_no": goods_art_no, "success": True, "info": "处理成功"}
+                )
             else:
                 handler_result.append(
-                        {"goods_art_no": goods_art_no, "success": False, "info": "处理失败"}
-                    )
+                    {"goods_art_no": goods_art_no, "success": False, "info": "处理失败"}
+                )
         except Exception as e:
             handler_result.append(
                 {"goods_art_no": goods_art_no, "success": False, "info": str(e)}
@@ -381,6 +391,7 @@ async def handle_detail(request: Request, params: HandlerDetail):
         "data": {"output_folder": handler_result_folder, "list": handler_result},
     }
 
+
 @app.post("/get_device_configs", description="获取可执行程序命令列表")
 def get_device_configs(params: ModelGetDeviceConfig):
     mode_type = params.mode_type
@@ -507,6 +518,22 @@ def get_photo_records(page: int = 1, size: int = 5):
     }
 
 
+@app.get("/get_last_photo_record", description="获取最后一条拍照记录")
+def get_last_photo_record():
+
+    session = SqlQuery()
+    statement = (
+        select(PhotoRecord).where(PhotoRecord.image_path!=None).order_by(desc("photo_create_time"))
+    )
+    result = session.exec(statement).first()
+    session.close()
+    return {
+        "code": 0,
+        "msg": "",
+        "data": result,
+    }
+
+
 @app.get("/get_photo_record_detail", description="通过货号获取拍照记录详情")
 def get_photo_records(goods_art_no: str = None):
     if goods_art_no == None: