225 lines
9.0 KiB
Python
225 lines
9.0 KiB
Python
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(500))
|
|
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", passive_deletes=True)
|
|
temperatures = relationship("Temperature", back_populates="event", cascade="all, delete", passive_deletes=True)
|
|
process_logs = relationship("ProcessLog", back_populates="event", cascade="all, delete", passive_deletes=True)
|
|
messages = relationship("Message", back_populates="event", cascade="all, delete", passive_deletes=True)
|
|
|
|
|
|
class Image(Base):
|
|
__tablename__ = "image"
|
|
|
|
imageId = Column(BigInteger, primary_key=True, autoincrement=True, comment='图片ID')
|
|
eventId = Column(String(50), ForeignKey('event.eventId', ondelete="CASCADE"), 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', ondelete="CASCADE"), nullable=False, comment='关联事件ID')
|
|
imageId = Column(BigInteger, ForeignKey('image.imageId', ondelete="CASCADE"), nullable=False, comment='关联图片ID')
|
|
temperature = Column(String(100), nullable=False, comment='温度值')
|
|
status = Column(String(5), 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', ondelete="CASCADE"), 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'),
|
|
)
|
|
|
|
class Message(Base):
|
|
__tablename__ = "message"
|
|
|
|
messageId = Column(BigInteger, primary_key=True, autoincrement=True, comment='消息ID')
|
|
eventId = Column(String(50), ForeignKey('event.eventId', ondelete="CASCADE"), nullable=False, comment='关联事件ID')
|
|
messageType = Column(String(5), comment='消息类型')
|
|
eventType = Column(String(5), comment='事件类型')
|
|
handle = Column(String(5), default='0', comment='是否处理' )
|
|
remark = Column(String(500), comment='备注')
|
|
createTime = Column(DateTime, default=datetime.now, nullable=False, comment='创建时间')
|
|
updateTime = Column(DateTime, default=datetime.now, nullable=False, comment='更新时间')
|
|
|
|
event = relationship("Event", back_populates="messages")
|
|
|
|
__table_args__ = (
|
|
Index('idx_message_event_id', 'eventId'),
|
|
Index('idx_message_create_time', 'createTime'),
|
|
Index('idx_message_update_time', 'updateTime'),
|
|
)
|
|
|
|
|
|
class Robot(Base):
|
|
__tablename__ = "robot"
|
|
|
|
robotId = Column(String(100), primary_key=True, comment='机器人ID')
|
|
number = Column(String(50), comment='机器人名称/名称')
|
|
groupingId = Column(String(100), comment='分组ID')
|
|
onlineStatus = Column(String(5), comment='在线状态')
|
|
status = Column(String(5), comment='机器人状态')
|
|
createTime = Column(DateTime, default=datetime.now, nullable=False, comment='创建时间')
|
|
updateTime = Column(DateTime, default=datetime.now, nullable=False, comment='更新时间')
|
|
|
|
|
|
# class RobotInfo(Base):
|
|
# __tablename__ = "robot_info"
|
|
# robotInfoId = Column()
|
|
|
|
# hkStstusName = Column(String(20))
|
|
# code = Column(String(5))
|
|
# errorType = Column(String(5))
|
|
# remoteControl = Column(String(5))
|
|
# buttonStop = Column(String(5))
|
|
# vertical = Column(String(5))
|
|
# versionName = Column(String(50))
|
|
# theta = Column(String(20))
|
|
# speed = Column(String(5))
|
|
# routeName = Column(String(20))
|
|
# charingTaskStatus = Column(String(5))
|
|
# socketType = Column(String(5))
|
|
# horizontal = Column( String(5))
|
|
# ststusName = Column(String(20))
|
|
# enStstusName = Column(String(20))
|
|
# aistatus = Column(String(5))
|
|
# pm2_5 = Column(String(20))
|
|
# temperature = Column(String(20))
|
|
# humidity = Column(String(20))
|
|
# power = Column(String(5))
|
|
# floor = Column(String(5))
|
|
# map = Column(String(20))
|
|
# mileage = Column(String(5))
|
|
# area = Column(String(5))
|
|
# nextTaskTime = Column('nextTaskTime', String)
|
|
# address = Column('address', String)
|
|
# fromUserId = Column('fromUserId', String)
|
|
# ip = Column('ip', String)
|
|
# pm10 = Column('pm10', String)
|
|
# index = Column('index', String) # 使用引号避免关键字冲突
|
|
# message = Column('message', String)
|
|
# robotId = Column('robotId', String)
|
|
# versionCode = Column('versionCode', String)
|
|
# videoStatus = Column('videoStatus', String)
|
|
# voltage = Column('voltage', String)
|
|
# focal = Column('focal', String)
|
|
# ststus = Column('ststus', String)
|
|
# positon = Column('positon', String) # 注意原始JSON中的拼写
|
|
# robotType = Column('robotType', String)
|
|
# clearCharingTaskTime = Column('clearCharingTaskTime', String)
|
|
# cmd = Column('cmd', String)
|
|
# vehicleid = Column('vehicleid', String)
|
|
# device = Column('device', String)
|
|
# status = Column('status', String)
|
|
|
|
|
|
class Group(Base):
|
|
__tablename__ = "group"
|
|
groupingId = Column(String(100), primary_key=True, comment="分组id")
|
|
name = Column(String(20), comment="组名")
|
|
|
|
# 后续可能要单独拆分一张表
|
|
tenantInfoId = Column(String(100), comment="租户Id")
|
|
|
|
|
|
# 组和机器人对应表
|
|
class GroupRobot(Base):
|
|
__tablename__ = "group_robot"
|
|
|
|
id = Column(BigInteger, primary_key=True, autoincrement=True, comment="id主键")
|
|
groupingId = Column(String(100), ForeignKey('group.groupingId', ondelete="CASCADE"),comment='分组ID')
|
|
robotId = Column(String(100), ForeignKey("robot.robotId", ondelete="CASCADE"), comment='机器人ID')
|
|
|
|
|