|
|
|
@ -2,6 +2,7 @@ from apiflask import APIBlueprint
|
|
|
|
from iti.applications.extensions import db, sys_log
|
|
|
|
from iti.applications.extensions import db, sys_log
|
|
|
|
from iti.applications.common.utils import success, page_schema, page
|
|
|
|
from iti.applications.common.utils import success, page_schema, page
|
|
|
|
from iti.applications.models import (
|
|
|
|
from iti.applications.models import (
|
|
|
|
|
|
|
|
IotEndpoint,
|
|
|
|
IotNode,
|
|
|
|
IotNode,
|
|
|
|
IotNodeSchema,
|
|
|
|
IotNodeSchema,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
@ -59,6 +60,14 @@ def add_node(json_data: dict):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
node = IotNode(**json_data)
|
|
|
|
node = IotNode(**json_data)
|
|
|
|
|
|
|
|
endpoint = db.session.scalar(
|
|
|
|
|
|
|
|
select(IotEndpoint)
|
|
|
|
|
|
|
|
.options(noload(IotEndpoint.workshop), noload(IotEndpoint.device))
|
|
|
|
|
|
|
|
.filter_by(id=node.endpoint_id))
|
|
|
|
|
|
|
|
if not endpoint:
|
|
|
|
|
|
|
|
raise BizException("采集端信息不存在")
|
|
|
|
|
|
|
|
node.device_id = endpoint.device_id
|
|
|
|
|
|
|
|
node.workshop_id = endpoint.workshop_id
|
|
|
|
node.status = 0
|
|
|
|
node.status = 0
|
|
|
|
db.session.add(node)
|
|
|
|
db.session.add(node)
|
|
|
|
db.session.commit()
|
|
|
|
db.session.commit()
|
|
|
|
@ -75,7 +84,10 @@ def update_node(id: int, json_data: dict):
|
|
|
|
更新采集节点信息
|
|
|
|
更新采集节点信息
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
node = db.session.scalar(select(IotNode).filter_by(id=id))
|
|
|
|
node = db.session.scalar(
|
|
|
|
|
|
|
|
select(IotNode)
|
|
|
|
|
|
|
|
.options(noload(IotNode.workshop), noload(IotNode.device), noload(IotNode.endpoint))
|
|
|
|
|
|
|
|
.filter_by(id=id))
|
|
|
|
if not node:
|
|
|
|
if not node:
|
|
|
|
raise BizException("节点信息不存在")
|
|
|
|
raise BizException("节点信息不存在")
|
|
|
|
for key, value in json_data.items():
|
|
|
|
for key, value in json_data.items():
|
|
|
|
@ -95,7 +107,10 @@ def delete_node(id: int):
|
|
|
|
删除采集节点信息
|
|
|
|
删除采集节点信息
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
node = db.session.scalar(select(IotNode).filter_by(id=id))
|
|
|
|
node = db.session.scalar(
|
|
|
|
|
|
|
|
select(IotNode)
|
|
|
|
|
|
|
|
.options(noload(IotNode.workshop), noload(IotNode.device), noload(IotNode.endpoint))
|
|
|
|
|
|
|
|
.filter_by(id=id))
|
|
|
|
if not node:
|
|
|
|
if not node:
|
|
|
|
raise BizException("采集节点不存在")
|
|
|
|
raise BizException("采集节点不存在")
|
|
|
|
|
|
|
|
|
|
|
|
@ -112,6 +127,10 @@ def get_page(query_data: NodeQuery):
|
|
|
|
query = select(IotNode).order_by(IotNode.created_at.desc())
|
|
|
|
query = select(IotNode).order_by(IotNode.created_at.desc())
|
|
|
|
if query_data.endpoint_id:
|
|
|
|
if query_data.endpoint_id:
|
|
|
|
query = query.filter(IotNode.endpoint_id == query_data.endpoint_id)
|
|
|
|
query = query.filter(IotNode.endpoint_id == query_data.endpoint_id)
|
|
|
|
|
|
|
|
elif query_data.device_id:
|
|
|
|
|
|
|
|
query = query.filter(IotNode.device_id == query_data.device_id)
|
|
|
|
|
|
|
|
elif query_data.workshop_id:
|
|
|
|
|
|
|
|
query = query.filter(IotNode.workshop_id == query_data.workshop_id)
|
|
|
|
if query_data.status is not None:
|
|
|
|
if query_data.status is not None:
|
|
|
|
query = query.filter(IotNode.status == query_data.status)
|
|
|
|
query = query.filter(IotNode.status == query_data.status)
|
|
|
|
|
|
|
|
|
|
|
|
@ -122,9 +141,13 @@ def get_list(query_data: NodeQuery):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
获取采集节点列表
|
|
|
|
获取采集节点列表
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
query = select(IotNode).options(noload(IotNode.endpoint)).order_by(IotNode.created_at.desc())
|
|
|
|
query = select(IotNode).options(noload(IotNode.workshop), noload(IotNode.device), noload(IotNode.endpoint)).order_by(IotNode.created_at.desc())
|
|
|
|
if query_data.endpoint_id:
|
|
|
|
if query_data.endpoint_id:
|
|
|
|
query = query.filter(IotNode.endpoint_id == query_data.endpoint_id)
|
|
|
|
query = query.filter(IotNode.endpoint_id == query_data.endpoint_id)
|
|
|
|
|
|
|
|
elif query_data.device_id:
|
|
|
|
|
|
|
|
query = query.filter(IotNode.device_id == query_data.device_id)
|
|
|
|
|
|
|
|
elif query_data.workshop_id:
|
|
|
|
|
|
|
|
query = query.filter(IotNode.workshop_id == query_data.workshop_id)
|
|
|
|
if query_data.status is not None:
|
|
|
|
if query_data.status is not None:
|
|
|
|
query = query.filter(IotNode.status == query_data.status)
|
|
|
|
query = query.filter(IotNode.status == query_data.status)
|
|
|
|
return db.session.scalars(query).all()
|
|
|
|
return db.session.scalars(query).all()
|