小程序后端增强绑定能力并支持多设备列表

This commit is contained in:
stu2not
2026-04-16 18:20:56 +08:00
parent 0683de528a
commit fb78863ee6
3 changed files with 79 additions and 1 deletions

View File

@@ -252,6 +252,40 @@ class BindingDAO(BaseDAO):
.first()
)
def list_by_user(self, user_id: int, limit: int = 20, cursor: int = None) -> list[Mapping]:
params = {"user_id": user_id, "limit": limit + 1}
where = "db.owner_user_id = :user_id AND db.status = 1"
if cursor is not None:
where += " AND db.id < :cursor"
params["cursor"] = cursor
rows = (
self.db.execute(
text(
f"""
SELECT
db.id,
db.device_id,
db.child_id,
c.child_name,
db.status,
db.bound_at
FROM device_bindings AS db
LEFT JOIN children AS c
ON c.child_id = db.child_id
AND c.status = 1
WHERE {where}
ORDER BY db.id DESC
LIMIT :limit
"""
),
params,
)
.mappings()
.all()
)
return rows
def get_by_device(self, device_id: str, user_id: int) -> Optional[Mapping]:
return (
self.db.execute(