Parcourir la source

```
feat(api): 优化设备配置查询和照片记录同步功能

- 修改设备配置详情接口,提供更明确的错误提示信息
- 将PhotoRecord查询中的join改为outerjoin,确保所有记录都能被查询到
- 添加照片记录同步状态检查功能,避免重复同步
- 在远程控制模块中增加设备配置不存在的错误处理逻辑
- 新增checkRecordSyncStatus函数用于检查同步状态
```

rambo il y a 2 semaines
Parent
commit
29d31986c9
3 fichiers modifiés avec 29 ajouts et 2 suppressions
  1. 6 2
      python/api.py
  2. 10 0
      python/mcu/RemoteControlV2.py
  3. 13 0
      python/settings.py

+ 6 - 2
python/api.py

@@ -1000,7 +1000,7 @@ def device_config_detail(params: ModelGetDeviceConfigDetail):
     model = configModel.read(session, conditions={"id": action_id})
     session.close()
     if model == None:
-        return {"code": 1, "msg": "数据不存在", "data": None}
+        return {"code": 1, "msg": "相关配置不存在,请删除当前货号后重新拍摄", "data": None}
     return {"code": 0, "msg": "", "data": model}
 
 
@@ -1117,7 +1117,7 @@ def get_photo_records(page: int = 1, size: int = 5):
         # 查询这些货号的所有记录
         query = (
             select(PhotoRecord, DeviceConfig.action_name)
-            .join(DeviceConfig, PhotoRecord.action_id == DeviceConfig.id)
+            .outerjoin(DeviceConfig, PhotoRecord.action_id == DeviceConfig.id)
             .where(PhotoRecord.goods_art_no.in_(current_goods_art_nos))
             .where(PhotoRecord.delete_time == None)
             .order_by(PhotoRecord.goods_art_no, asc("id"))  # 按货号分组并按ID倒序
@@ -1692,6 +1692,10 @@ async def syncPhotoRecord(params:SyncPhotoRecord):
     # 查询所有不重复的货号及对应的最大时间,进行分页
     settings.USER_TOKEN = params.token
     settings.USER_ENV = params.env
+    syncStatus = settings.checkRecordSyncStatus()
+    if syncStatus == True:
+        # 同步过就无需再同步
+        return {"code": 0, "message": "同步完成", "data": None}
     session = SqlQuery()
     base_statement = (
         select(PhotoRecord)

+ 10 - 0
python/mcu/RemoteControlV2.py

@@ -263,6 +263,16 @@ class RemoteControlV2(BaseClass):
         deviceConfigData = deviceConfig.read(
             session=session, conditions={"id": record.action_id}
         )
+        if deviceConfigData == None:
+            self.msg_type = "photo_take"
+            self.sendSocketMessage(
+                code=1,
+                msg="相关配置不存在,请删除当前货号后重新拍摄",
+                data=None,
+                device_status=2,
+            )
+            self.msg_type = "blue_tooth"
+            return
         select_tab_id = deviceConfigData.tab_id
         AllTabConfig = deviceConfig.read_all(
             session=session, conditions={"tab_id": select_tab_id}

+ 13 - 0
python/settings.py

@@ -310,6 +310,19 @@ 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 checkRecordSyncStatus():
+    # check_photo_record_sync_status
+    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?machine_type={machine_type}"
+    try:
+        response = requests.get(url=url, headers=headers).json()
+        return response.get("data").get('status',True)
+    except Exception as e:
+        return True
 
 async def sendSocketMessage(
     code=0, msg="", data=None, device_status=2, msg_type=""