Sfoglia il codice sorgente

```
feat(api): 优化货号删除功能并修复日志格式化问题

- 注释掉文件目录清理逻辑,避免

rambo 2 settimane fa
parent
commit
61dc2d9633
4 ha cambiato i file con 36 aggiunte e 22 eliminazioni
  1. 5 7
      python/api.py
  2. 1 1
      python/config.ini
  3. 10 11
      python/mcu/DeviceControl.py
  4. 20 3
      python/settings.py

+ 5 - 7
python/api.py

@@ -1264,17 +1264,15 @@ def delete_all_goods_arts():
             raise UnicornException("没有可删除的货号")
 
         # 2. 清理文件目录 (复用现有的 handlerFolderDelete 逻辑)
-        limit_path = "{}/{}".format(settings.OUTPUT_DIR,
-                        time.strftime("%Y-%m-%d", time.localtime(time.time()))
-                    )
+        # limit_path = "{}/{}".format(settings.OUTPUT_DIR,
+        #                 time.strftime("%Y-%m-%d", time.localtime(time.time()))
+        #             )
         # 注意:handlerFolderDelete 内部可能涉及大量IO操作,如果数据量极大可能需要异步或后台任务
         # 这里保持同步以符合原接口风格,但需注意超时风险
-        handlerFolderDelete(limit_path, list(all_goods_art_nos), False)
+        # handlerFolderDelete(limit_path, list(all_goods_art_nos), False)
 
         # 3. 同步线上状态 (如果需要)
-        for item in all_goods_art_nos:
-            settings.syncPhotoRecord({"goods_art_no": item}, action_type=2)
-
+        settings.syncBatchPhotoRecordDelete({"goods_art_no": item}, action_type=2)
         # 4. 批量删除数据库记录
         # 使用 deleteConditions 一次性删除所有符合条件的记录,比循环删除效率高
         photos.deleteConditions(session, conditions={"delete_time": None})

+ 1 - 1
python/config.ini

@@ -4,7 +4,7 @@ app_name=智慧拍-后端应用
 # 应用版本号
 version=1.0.0
 # 应用host地址
-host=127.0.0.1
+host=10.56.42.17
 # 应用服务启动名称
 app_run=api:app
 # 端口号

+ 10 - 11
python/mcu/DeviceControl.py

@@ -219,7 +219,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
                     pass
             except BaseException as e:
                 print("121231298908", e)
-                logger.info("121231298908", e)
+                logger.info(f"121231298908{e}")
                 break
 
         self.is_running = False
@@ -459,14 +459,14 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
             data = receive_data[1:].decode()
             if "设备初始化完成" in data:
                 self.init_state = True
-                logger.info("设备初始化完成:%s", data)
+                logger.info(f"设备初始化完成:%{data}")
                 self.sendSocketMessage(msg=data, device_status=2)
             else:
                 print("设备异常数据打印:", data)
-                logger.info("115  设备异常数据打印:%s", data)
+                logger.info(f"115  设备异常数据打印:%{data}")
         except BaseException as e:
             print("117 error {}".format(e))
-            logger.info("117 error %s", e)
+            logger.info(f"117 error %{e}")
         return
     def print_mcu_noraml_data(self, receive_data):
         # 扫码数据
@@ -501,12 +501,12 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
                 device_name_info = self.device_name_dict_mapping[device_id]
                 message_info = {"设备名称":device_name_info,"运动值":device_value}
                 print("【设备运动】消息回执:", message_info)
-                logger.info("设备运动消息回执:%s", message_info)
+                logger.info(f"设备运动消息回执:{message_info}")
             print("接收设备消息回执:", command_text)
-            logger.info("接收设备消息回执:%s", receive_data_temp_text)
+            logger.info(f"接收设备消息回执:{receive_data_temp_text}")
         except BaseException as e:
-            print("255 error {}".format(e))
-            logger.info("255 error %s", e)
+            print(f"255 error {e}")
+            logger.info(f"255 error {e}")
         return
     def get_from_mcu_move_respond_data(self, receive_data):
         self.last_from_mcu_move_respond_data = receive_data
@@ -1772,8 +1772,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
             await program_item.run(3)
             self.msg_type = "mcu"
             logger.info(
-                "发送 run_mcu_signle消息",
-                "{} 执行完成~".format(program_item.action_name),
+                "发送 run_mcu_signle消息{} 执行完成~".format(program_item.action_name)
             )
             self.sendSocketMessage(
                 code=0,
@@ -1800,7 +1799,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
         await asyncio.sleep(0.1)
         print("only_take_photo=====>", goods_art_no, image_index, record_id)
         logger.info(
-            "only_take_photo=====> %s %s %s", goods_art_no, image_index, record_id
+            f"only_take_photo=====> {goods_art_no} {image_index} {record_id}"
         )
         if goods_art_no == "":
             print("only_take_photo 数据查询异常")

+ 20 - 3
python/settings.py

@@ -314,6 +314,25 @@ def syncPhotoRecord(data,action_type=0):
     postData = {"data":data,"machine_type":machine_type,'action_type':action_type}
     response = requests.post(url=url,data=json.dumps(postData, ensure_ascii=False, default=str), headers=headers)
     print("用户token",response.content)
+
+
+def syncBatchPhotoRecordDelete():
+    """同步图片记录"""
+    headers = {
+        "Authorization": f"Bearer {USER_TOKEN}",
+        "content-type": "application/json",
+    }
+    machine_type = MACHINE_TYPE
+    url = getDoman(USER_ENV) + f"/api/ai_image/camera_machine/photo_records_handler"
+    postData = {"machine_type": machine_type, "action_type": 4}
+    response = requests.post(
+        url=url,
+        data=json.dumps(postData, ensure_ascii=False, default=str),
+        headers=headers,
+    )
+    print("用户token", response.content)
+
+
 def checkRecordSyncStatus():
     # check_photo_record_sync_status
     headers = {
@@ -376,8 +395,6 @@ print("SCAN_DIR",SCAN_DIR)
 CUSTOMER_TEMPLATE_URL = config.get("customer_template", "template_url")
 
 
-
-
 def hex_to_rgb(hex_color):
     """
     将十六进制颜色值转换为RGB颜色值
@@ -413,4 +430,4 @@ def rgb_to_hex(r, g, b):
     if not all(0 <= val <= 255 for val in [r, g, b]):
         return "#FFFFFF"
     
-    return "#{:02X}{:02X}{:02X}".format(r, g, b)
+    return "#{:02X}{:02X}{:02X}".format(r, g, b)