|
|
|
|
@ -31,7 +31,7 @@ def list_device(query_data: DeviceQuery):
|
|
|
|
|
获取设备列表
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
return success(get_list_or_page(query_data))
|
|
|
|
|
return success(get_list(query_data))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp.get("/page")
|
|
|
|
|
@ -45,7 +45,7 @@ def page_device(query_data: DeviceQuery):
|
|
|
|
|
分页获取设备列表
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
return page(get_list_or_page(query_data))
|
|
|
|
|
return page(get_page(query_data))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@bp.post("/add")
|
|
|
|
|
@ -105,9 +105,9 @@ def delete_device(id: int):
|
|
|
|
|
return success()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_list_or_page(query_data: DeviceQuery):
|
|
|
|
|
def get_page(query_data: DeviceQuery):
|
|
|
|
|
"""
|
|
|
|
|
获取设备信息列表或分页
|
|
|
|
|
获取设备信息分页
|
|
|
|
|
"""
|
|
|
|
|
query = select(IotDevice).order_by(IotDevice.created_at.desc())
|
|
|
|
|
if query_data.keyword:
|
|
|
|
|
@ -118,9 +118,26 @@ def get_list_or_page(query_data: DeviceQuery):
|
|
|
|
|
)
|
|
|
|
|
if query_data.workshop_id:
|
|
|
|
|
query = query.filter(IotDevice.workshop_id == query_data.workshop_id)
|
|
|
|
|
if query_data.status:
|
|
|
|
|
if query_data.status is not None:
|
|
|
|
|
query = query.filter(IotDevice.status == query_data.status)
|
|
|
|
|
if query_data.page and query_data.size:
|
|
|
|
|
|
|
|
|
|
return db.paginate(query, page=query_data.page, per_page=query_data.size)
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_list(query_data: DeviceQuery):
|
|
|
|
|
"""
|
|
|
|
|
获取设备列表
|
|
|
|
|
"""
|
|
|
|
|
query = select(IotDevice).options(noload(IotDevice.workshop)).order_by(IotDevice.created_at.desc())
|
|
|
|
|
if query_data.keyword:
|
|
|
|
|
kw = ModelFilter.escape_like(query_data.keyword)
|
|
|
|
|
query = query.filter(
|
|
|
|
|
IotDevice.device_name.like(f"%{kw}%")
|
|
|
|
|
| IotDevice.device_number.like(f"%{kw}%")
|
|
|
|
|
)
|
|
|
|
|
if query_data.workshop_id:
|
|
|
|
|
query = query.filter(IotDevice.workshop_id == query_data.workshop_id)
|
|
|
|
|
if query_data.status is not None:
|
|
|
|
|
query = query.filter(IotDevice.status == query_data.status)
|
|
|
|
|
|
|
|
|
|
return db.session.scalars(query).all()
|