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 IotEndpoint(db.Model, TimeModelMixin): """ 采集端信息表 """ __tablename__ = "iot_endpoint" id = db.Column( db.Integer, primary_key=True, autoincrement=True, comment="标识", ) device_id = db.Column(db.Integer, nullable=False, default=0, unique=True, comment="设备ID") endpoint_name = db.Column(db.String(255), nullable=False, unique=True, comment="采集端名称") endpoint_number = db.Column(db.String(20), nullable=False, comment="采集端编号") description = db.Column(db.Text, nullable=True, comment="采集端描述") ip = db.Column(db.String(255), nullable=False, comment="采集端IP") port = db.Column(db.String(255), nullable=False, comment="采集端端口") brand_name = db.Column(db.String(255), nullable=False, comment="品牌名称") specification_model = db.Column(db.String(255), nullable=False, comment="规格型号") is_online = db.Column(db.Integer, nullable=False, default=0, comment="在线状态 0:离线 1:在线") status = db.Column(db.Integer, nullable=False, default=0, comment="状态 0:停用 1:运行中 2:维修中") #关系 device = db.relationship( "IotDevice", primaryjoin="foreign(IotEndpoint.device_id) == IotDevice.id", ) class IotEndpointSchema(BaseSchema): """ 采集端信息表响应结构 """ class Meta: name = "IotEndpoint" id = Integer() device_id = Integer() endpoint_name = String() endpoint_number = String() description = String() ip = String() port = String() brand_name = String() specification_model = String() is_online = Integer() status = Integer() created_at = DateTime(format="%Y-%m-%d %H:%M:%S") updated_at = DateTime(format="%Y-%m-%d %H:%M:%S") #关系 device = Nested("IotDeviceSimpleSchema") class IotEndpointSimpleSchema(BaseSchema): """ 采集端信息表联合查询响应结构 """ class Meta: name = "IotEndpoint" id = Integer() endpoint_name = String() endpoint_number = String() #关系 device = Nested("IotDeviceSimpleSchema")