Selaa lähdekoodia

错位问题解决

rambo 4 kuukautta sitten
vanhempi
commit
d68738a90f

+ 2 - 1
python/databases.py

@@ -79,8 +79,9 @@ def insert_photo_records(
     device_config = PhotoRecord(**data)
     session.add(device_config)
     session.commit()
+    record_id = device_config.id
     session.close()
-    return True
+    return True, record_id
 
 
 # 创建一个通用的 CRUD 类

+ 9 - 3
python/mcu/DeviceControl.py

@@ -1389,17 +1389,19 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
             for idx, item in enumerate(config_list):
                 is_take_picture = item["take_picture"]
                 action_id = item["id"]
+                record_id = -1
                 if is_take_picture:
                     action_names.append(item["action_name"])
                     image_counts += 1
                     # 批量插入
                     image_deal_mode = 0 if action_info == "执行左脚程序" else 1
-                    insert_photo_records(
+                    state,record_id = insert_photo_records(
                         image_deal_mode=image_deal_mode,
                         goods_art_no=goods_art_no,
                         image_index=idx,
                         action_id=action_id,
                     )
+                config_list[idx]["record_id"] = record_id
             total_len = len(config_list)
             self.action_state = 1
             self.msg_type = "image_process"
@@ -1424,9 +1426,12 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
                 if self.is_stop_action == True:
                     self.is_stop_action = False
                     break
-                action_is_take_picture = action["take_picture"]
+                # action_is_take_picture = action["take_picture"]
+                record_id = action["record_id"]
                 image_index = -1
-                if action_is_take_picture:
+                if record_id == -1:
+                    image_index = -1
+                else:
                     image_index = index
                 program_item = ProgramItem(
                     websocket_manager=self.websocket_manager,
@@ -1434,6 +1439,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
                     mcu=self,
                     goods_art_no=goods_art_no,
                     image_index=image_index,
+                    record_id=record_id,
                 )
                 print("self.action_state===>", self.action_state)
                 if self.action_state != 1:

+ 2 - 1
python/mcu/ProgramItem.py

@@ -11,7 +11,7 @@ class ProgramItem(BaseClass):
     # program_sign = Signal(dict)
     # program_refresh_photo_list_sign = Signal()
 
-    def __init__(self,websocket_manager, action_data:any, mcu, goods_art_no:str=None,image_index:int=-1):
+    def __init__(self,websocket_manager, action_data:any, mcu, goods_art_no:str=None,image_index:int=-1,record_id:int=-1):
         super().__init__(BaseClass)
         # 1 表示等待中,2表示没有等待
         self.wait_state = 2
@@ -23,6 +23,7 @@ class ProgramItem(BaseClass):
         self.watch_dog = FileEventHandler()
         self.watch_dog.goods_art_no = goods_art_no
         self.watch_dog.image_index = image_index
+        self.watch_dog.record_id = record_id
         self.watch_dog.mcu = mcu
         self.watch_dog.start_observer(captrure_folder_path)
         print("21 =========ProgramItem=======action_data=====")

+ 16 - 4
python/mcu/capture/module_watch_dog.py

@@ -10,7 +10,7 @@ from databases import CRUD, SqlQuery, PhotoRecord
 import asyncio
 
 
-def updateImageRaw(time_str, image_path, goods_art_no, image_index):
+def updateImageRaw(time_str, image_path, goods_art_no, record_id):
     session = SqlQuery()
     crud = CRUD(PhotoRecord)
     res = crud.read(
@@ -18,7 +18,15 @@ def updateImageRaw(time_str, image_path, goods_art_no, image_index):
         conditions={
             "image_path": None,
             "goods_art_no": goods_art_no,
-            "image_index": image_index,
+            "id": record_id,
+        },
+    )
+    print(
+        "更新图片数据库======>",
+        {
+            "image_path": image_path,
+            "goods_art_no": goods_art_no,
+            "id": record_id,
         },
     )
     if res:
@@ -29,7 +37,7 @@ def updateImageRaw(time_str, image_path, goods_art_no, image_index):
         }
         crud.update(
             session,
-            res.id,
+            record_id,
             **update,
         )
 
@@ -45,6 +53,7 @@ class FileEventHandler(FileSystemEventHandler, metaclass=SingletonType):
         #     self.init_flag = True
         self.goods_art_no = None
         self.image_index = -1
+        self.record_id = -1
         self.mcu = None
         super().__init__()
         # self.window = window
@@ -176,7 +185,10 @@ class FileEventHandler(FileSystemEventHandler, metaclass=SingletonType):
                 )
                 loop.close()
                 updateImageRaw(
-                    create_time, file_path, self.goods_art_no, self.image_index
+                    create_time,
+                    file_path,
+                    self.goods_art_no,
+                    self.record_id,
                 )
             except BaseException as e:
                 print("获取文件create_time失败", e)