diff --git a/app/__pycache__/models.cpython-310.pyc b/app/__pycache__/models.cpython-310.pyc index 211c121..846f2db 100644 Binary files a/app/__pycache__/models.cpython-310.pyc and b/app/__pycache__/models.cpython-310.pyc differ diff --git a/app/models.py b/app/models.py index 56e7fe7..4b278c3 100644 --- a/app/models.py +++ b/app/models.py @@ -40,14 +40,21 @@ def handle_change(mapper, connection, target): """监听器函数""" if target.__class__.__name__ == 'User': # 确保只监听User类的变动 changed_fields = [] + original_value=None + new_value=None + + for attr in target.__mapper__.column_attrs: history = get_history(target, attr.key) if history.has_changes(): changed_fields.append(attr.key) + original_value = history.deleted[0] if history.deleted else None + new_value = history.added[0] if history.added else None + if changed_fields: - print(f"检测到用户 {target.id} 的字段变化: {changed_fields}") - msg=f"检测到用户 {target.id} 的字段变化: {changed_fields}" + print(f"检测到用户 {target.nickname}-{target.remark} 的字段变化: {changed_fields}-{new_value}") + msg=f"检测到用户 {target.nickname}-{target.remark} 的字段变化: {changed_fields}-{new_value}" sengTgmesage(msg) # 发起HTTP请求 # requests.post("http://your-fastapi-endpoint/notify_change", json={"user_id": target.id, "changed_fields": changed_fields})