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 IotDevice(db.Model, TimeModelMixin): """ 设备信息表 """ __tablename__ = "iot_device" 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_name = db.Column(db.String(255), nullable=False, unique=True, comment="设备名称") device_number = db.Column(db.String(20), nullable=False, comment="设备编号") description = db.Column(db.Text, nullable=True, comment="设备描述") brand_name = db.Column(db.String(255), nullable=False, comment="品牌名称") specification_model = db.Column(db.String(255), nullable=False, comment="规格型号") status = db.Column(db.Integer, nullable=False, default=0, comment="状态 0:已停机 1:生产中 2:维修中") #关系 workshop = db.relationship( "IotWorkshop", primaryjoin="foreign(IotDevice.workshop_id) == IotWorkshop.id", ) class IotDeviceSchema(BaseSchema): """ 设备信息表响应结构 """ class Meta: name = "IotDevice" id = Integer() workshop_id = Integer() device_name = String() device_number = String() description = String() brand_name = String() specification_model = 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") class IotDeviceSimpleSchema(BaseSchema): """ 设备信息表联合查询响应结构 """ class Meta: name = "IotDevice" id = Integer() device_name = String() device_number = String() #关系 workshop = Nested("IotWorkshopSimpleSchema")