You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iTi-Flask/iti/applications/models/iot/iot_node.py

67 lines
2.5 KiB
Python

from iti.applications.extensions import db
from iti.applications.common.crud import TimeModelMixin
from iti.applications.common.utils import BaseSchema
from apiflask.fields import String, Integer, DateTime, Nested
class IotNode(db.Model, TimeModelMixin):
"""
节点信息表
"""
__tablename__ = "iot_node"
id = db.Column(
db.Integer,
primary_key=True,
autoincrement=True,
comment="标识",
)
workshop_id = db.Column(db.Integer, nullable=False, default=0, unique=True, comment="车间ID")
device_id = db.Column(db.Integer, nullable=False, default=0, unique=True, comment="设备ID")
endpoint_id = db.Column(db.Integer, nullable=False, default=0, unique=True, comment="采集端ID")
node_number = db.Column(db.String(20), nullable=False, unique=True, comment="节点编号")
title = db.Column(db.String(255), nullable=False, unique=True, comment="节点ID")
mark = db.Column(db.String(255), nullable=False, comment="采集标识")
mark_type = db.Column(db.Integer, nullable=False, comment="采集类型 1:只读 2:只写 3:读写")
tag_label = db.Column(db.String(255), nullable=False, comment="变量别名,用于数据存储标记")
data_type = db.Column(db.String(255), nullable=False, comment="值类型 text: 文本 int: 整型 float: 浮点型 boolean:布尔型")
status = db.Column(db.Integer, nullable=False, default=0, comment="状态 0:禁用 1:启用")
#关系
workshop = db.relationship(
"IotWorkshop",
primaryjoin="foreign(IotNode.workshop_id) == IotWorkshop.id",
)
device = db.relationship(
"IotDevice",
primaryjoin="foreign(IotNode.device_id) == IotDevice.id",
)
endpoint = db.relationship(
"IotEndpoint",
primaryjoin="foreign(IotNode.endpoint_id) == IotEndpoint.id",
)
class IotNodeSchema(BaseSchema):
"""
节点信息表响应结构
"""
class Meta:
name = "IotNode"
id = Integer()
workshop_id = Integer()
device_id = Integer()
endpoint_id = Integer()
node_number = String()
title = String()
mark = String()
mark_type = Integer()
tag_label = String()
data_type = String()
status = Integer()
created_at = DateTime(format="%Y-%m-%d %H:%M:%S")
updated_at = DateTime(format="%Y-%m-%d %H:%M:%S")
#关系
workshop = Nested("IotWorkshopSimpleSchema")
device = Nested("IotDeviceSimpleSchema")
endpoint = Nested("IotEndpointSimpleSchema")