89 lines
3.6 KiB
Python
89 lines
3.6 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
呼叫器设备模型
|
|
对应vwed_calldevice表和vwed_calldevice_button表
|
|
"""
|
|
|
|
import datetime
|
|
import json
|
|
from sqlalchemy import Column, String, Integer, Boolean, DateTime, Text, Index, ForeignKey
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.dialects.mysql import LONGTEXT
|
|
from data.models.base import BaseModel
|
|
|
|
class VWEDCallDevice(BaseModel):
|
|
"""
|
|
呼叫器设备模型
|
|
对应vwed_calldevice表
|
|
功能:定义呼叫器设备配置
|
|
"""
|
|
__tablename__ = 'vwed_calldevice'
|
|
|
|
__table_args__ = (
|
|
Index('idx_vwed_calldevice_protocol', 'protocol'),
|
|
Index('idx_vwed_calldevice_brand', 'brand'),
|
|
Index('idx_vwed_calldevice_ip', 'ip'),
|
|
Index('idx_vwed_calldevice_device_name', 'device_name'),
|
|
Index('idx_vwed_calldevice_status', 'status'),
|
|
{
|
|
'mysql_engine': 'InnoDB',
|
|
'mysql_charset': 'utf8mb4',
|
|
'mysql_collate': 'utf8mb4_general_ci',
|
|
'info': {'order_by': 'created_at DESC'}
|
|
}
|
|
)
|
|
|
|
id = Column(String(255), primary_key=True, nullable=False, comment='呼叫器设备唯一标识')
|
|
protocol = Column(String(50), nullable=False, comment='协议类型')
|
|
brand = Column(String(100), nullable=False, comment='品牌')
|
|
ip = Column(String(50), nullable=False, comment='IP地址')
|
|
port = Column(Integer, nullable=False, comment='端口号')
|
|
device_name = Column(String(100), nullable=False, comment='设备名称')
|
|
status = Column(Integer, default=0, comment='状态(0:禁用,1:启用)')
|
|
|
|
# 定义关联关系
|
|
buttons = relationship("VWEDCallDeviceButton", back_populates="call_device", cascade="all, delete-orphan")
|
|
|
|
def __repr__(self):
|
|
return f"<VWEDCallDevice(id='{self.id}', protocol='{self.protocol}', brand='{self.brand}', ip='{self.ip}', port='{self.port}', device_name='{self.device_name}', status='{self.status}')>"
|
|
|
|
def to_dict(self):
|
|
result = super().to_dict()
|
|
result['buttons'] = [button.to_dict() for button in self.buttons]
|
|
return result
|
|
|
|
class VWEDCallDeviceButton(BaseModel):
|
|
"""
|
|
呼叫器设备按钮模型
|
|
对应vwed_calldevice_button表
|
|
功能:定义呼叫器设备的按钮配置
|
|
"""
|
|
__tablename__ = 'vwed_calldevice_button'
|
|
|
|
__table_args__ = (
|
|
Index('idx_vwed_calldevice_button_device_id', 'device_id'),
|
|
Index('idx_vwed_calldevice_button_button_address', 'button_address'),
|
|
Index('idx_vwed_calldevice_button_light_address', 'light_address'),
|
|
{
|
|
'mysql_engine': 'InnoDB',
|
|
'mysql_charset': 'utf8mb4',
|
|
'mysql_collate': 'utf8mb4_general_ci',
|
|
'info': {'order_by': 'created_at DESC'}
|
|
}
|
|
)
|
|
|
|
id = Column(String(255), primary_key=True, nullable=False, comment='按钮唯一标识')
|
|
device_id = Column(String(255), ForeignKey('vwed_calldevice.id'), nullable=False, comment='所属呼叫器设备ID')
|
|
button_address = Column(String(100), nullable=False, comment='按钮地址')
|
|
remark = Column(String(255), comment='备注')
|
|
light_address = Column(String(100), comment='灯地址')
|
|
press_task_id = Column(String(255), comment='按下灯亮绑定的VWED任务ID')
|
|
long_press_task_id = Column(String(255), comment='长按取消后触发VWED任务ID')
|
|
|
|
# 定义关联关系
|
|
call_device = relationship("VWEDCallDevice", back_populates="buttons")
|
|
|
|
def __repr__(self):
|
|
return f"<VWEDCallDeviceButton(id='{self.id}', device_id='{self.device_id}', button_address='{self.button_address}', remark='{self.remark}', light_address='{self.light_address}')>" |