from datetime import datetime from sqlalchemy import Column, String, DateTime, Integer, Text, ForeignKey, Index, BigInteger from sqlalchemy.orm import relationship from app.core.database import Base class Event(Base): __tablename__ = "event" eventId = Column(String(50), primary_key=True) tenantInfoId = Column(String(100)) reportEventId = Column(String(100)) number = Column(String(20)) name = Column(String(20)) eclassify = Column(String(5)) operationType = Column(String(5)) etype = Column(String(20)) etypeName = Column(String(20)) enTypeName = Column(String(30)) hkTypeName = Column(String(20)) reportStatus = Column(String(5)) results = Column(String(5)) insDate = Column(DateTime) insDateShow = Column(DateTime) updDate = Column(DateTime) updDateShow = Column(DateTime) fileType = Column(String(5)) area = Column(String(20)) floor = Column(String(10)) map = Column(String(20)) staffId = Column(String(40)) targetUserId = Column(String(40)) position = Column(String(100)) actualStaffName = Column(String(20)) targetStaffName = Column(String(20)) routeName = Column(String(20)) phoneAddress = Column(String(500)) width = Column(String(10)) height = Column(String(10)) resolution = Column(String(10)) originX = Column(String(20)) originY = Column(String(20)) imgList = Column(String(20)) robotType = Column(String(5)) eventFloor = Column(String(10)) floorName = Column(String(10)) coordId = Column(String(40)) coord = Column(String(40)) coordName = Column(String(30)) positonName = Column(String(20)) processingRemark = Column(String(300)) carId = Column(String(40)) parkingSpaceType = Column(String(10)) parkingSpaceNumber = Column(String(40)) carNumber = Column(String(40)) eno = Column(String(40)) instrument = Column(String(40)) evideo = Column(String(40)) createTime = Column(DateTime, default=datetime.now, comment='本地后台创建时间') updateTime = Column(DateTime, default=datetime.now, onupdate=datetime.now, comment='本地后台更新时间') # 关系 images = relationship("Image", back_populates="event", cascade="all, delete-orphan") temperatures = relationship("Temperature", back_populates="event", cascade="all, delete-orphan") process_logs = relationship("ProcessLog", back_populates="event", cascade="all, delete-orphan") class Image(Base): __tablename__ = "image" imageId = Column(BigInteger, primary_key=True, autoincrement=True, comment='图片ID') eventId = Column(String(50), ForeignKey('event.eventId'), nullable=False, comment='关联事件ID') imageUrl = Column(String(500), nullable=False, comment='图片URL') localPath = Column(String(500), comment='本地存储路径') createTime = Column(DateTime, default=datetime.now, nullable=False, comment='创建时间') # 关系 event = relationship("Event", back_populates="images" ) temperatures = relationship("Temperature", back_populates="image") __table_args__ = ( Index('idx_image_event_id', 'eventId'), ) class Temperature(Base): __tablename__ = "temperature" tempId = Column(BigInteger, primary_key=True, autoincrement=True, comment='温度记录ID') eventId = Column(String(50), ForeignKey('event.eventId'), nullable=False, comment='关联事件ID') imageId = Column(BigInteger, ForeignKey('image.imageId'), nullable=False, comment='关联图片ID') temperature = Column(String(20), nullable=False, comment='温度值') # status = Column(String(2), comment='温度是否正常') confidence = Column(String(40), nullable=False, comment='识别置信度') createTime = Column(DateTime, default=datetime.now, nullable=False, comment='创建时间') # 关系 event = relationship("Event", back_populates="temperatures") image = relationship("Image", back_populates="temperatures") __table_args__ = ( Index('idx_temp_event_id', 'eventId'), Index('idx_temp_create_time', 'createTime'), ) class ProcessLog(Base): __tablename__ = "process_log" logId = Column(BigInteger, primary_key=True, autoincrement=True, comment='日志ID') eventId = Column(String(50), ForeignKey('event.eventId'), nullable=False, comment='关联事件ID') processStatus = Column(Integer, nullable=False, comment='处理状态') errorMessage = Column(Text, comment='错误信息') createTime = Column(DateTime, default=datetime.now, nullable=False, comment='创建时间') # 关系 event = relationship("Event", back_populates="process_logs") __table_args__ = ( Index('idx_log_event_id', 'eventId'), Index('idx_log_create_time', 'createTime'), )