Explorar el Código

云端同步问题

rambo hace 3 meses
padre
commit
170c536a54
Se han modificado 2 ficheros con 39 adiciones y 2 borrados
  1. 12 2
      python/api.py
  2. 27 0
      python/databases.py

+ 12 - 2
python/api.py

@@ -1364,10 +1364,20 @@ def sync_action_configs(params: SyncLocalConfigs):
         result = requests.post(url=sync_url, headers=headers, data=data_json)
         tabs = result.json().get("data", {}).get("tabs")
         actions = result.json().get("data", {}).get("actions")
+        insert_action_ids = result.json().get("data", {}).get("insert_action_ids")
         if tabs:
             deviceConfigTabs.deleteConditions(session, {})
             deviceConfigs.deleteConditions(session, {})
             batch_insert_device_configsNew(session, tabs, actions)
-    #因为左右脚线上id可能会发生变化  所以需要重新同步一下本地得配置信息
-    syncUserJsonConfigs(hlm_token)
+        if insert_action_ids:
+            for action_item in insert_action_ids:
+                photos = CRUD(PhotoRecord)
+                old_id = action_item.get("old_id")
+                new_id = action_item.get("new_id")
+                kwargs = {"action_id": new_id}
+                photos.updateConditionsAll(
+                    session, conditions={"action_id": old_id}, **kwargs
+                )
+    # 因为左右脚线上id可能会发生变化  所以需要重新同步一下本地得配置信息
+    # syncUserJsonConfigs(hlm_token)
     return {"code": 0, "msg": "操作成功", "data": None}

+ 27 - 0
python/databases.py

@@ -180,6 +180,7 @@ class CRUD:
                 )
             )
         )
+        print("SQL 打印==>",str(query))
         result = session.exec(query).first()
         if result:
             for key, value in kwargs.items():
@@ -188,6 +189,32 @@ class CRUD:
             return result
         return None
 
+    def updateConditionsAll(self, session: Session, conditions: Dict, **kwargs):
+        """
+        根据条件更新记录
+        :param session: 数据库会话
+        :param conditions: 更新条件字典
+        :param kwargs: 需要更新的字段和值
+        :return: 更新后的对象
+        """
+        query = select(self.model).where(
+            and_(
+                *(
+                    getattr(self.model, key) == value
+                    for key, value in conditions.items()
+                )
+            )
+        )
+        print("SQL 打印==>", str(query))
+        results = session.exec(query).fetchall()
+        if results:
+            for obj in results:  # 遍历每个对象
+                for key, value in kwargs.items():
+                    setattr(obj, key, value)  # 对每个对象设置属性
+            session.commit()  # 提交事务以保存更改
+            return results
+        return None
+
 
 # 批量插入数据到设备配置表
 def batch_insert_device_configs(session: Session, action_tabs: list, data_list: list):