修复:告警状态流转统一 — 前端处理直接结单(CLOSED),支持处理图片上传
1. handle接口状态映射:handled→CLOSED(而非CONFIRMED),ignored→FALSE 2. handle_status同步设置:handled→DONE,ignored→IGNORED 3. 新增handle_image_url字段支持处理图片存储 4. 自动迁移:启动时自动ALTER TABLE添加新列
This commit is contained in:
@@ -281,6 +281,7 @@ class AlarmEvent(Base):
|
||||
area_id = Column(BigInteger, comment="所属区域ID")
|
||||
handler = Column(String(64), comment="处理人")
|
||||
handle_remark = Column(Text, comment="处理备注")
|
||||
handle_image_url = Column(String(512), comment="处理图片URL")
|
||||
handled_at = Column(DateTime, comment="处理时间")
|
||||
created_at = Column(DateTime, default=lambda: beijing_now())
|
||||
updated_at = Column(DateTime, default=lambda: beijing_now(),
|
||||
@@ -312,6 +313,7 @@ class AlarmEvent(Base):
|
||||
"area_id": self.area_id,
|
||||
"handler": self.handler,
|
||||
"handle_remark": self.handle_remark,
|
||||
"handle_image_url": self.handle_image_url,
|
||||
"handled_at": self.handled_at.strftime('%Y-%m-%d %H:%M:%S') if self.handled_at else None,
|
||||
"created_at": self.created_at.strftime('%Y-%m-%d %H:%M:%S') if self.created_at else None,
|
||||
"updated_at": self.updated_at.strftime('%Y-%m-%d %H:%M:%S') if self.updated_at else None,
|
||||
@@ -535,9 +537,27 @@ def get_session():
|
||||
return _SessionLocal()
|
||||
|
||||
|
||||
def _auto_migrate(engine):
|
||||
"""自动添加缺失的列(create_all 不会 ALTER 已有表)"""
|
||||
from sqlalchemy import inspect, text
|
||||
insp = inspect(engine)
|
||||
migrations = [
|
||||
("alarm_event", "handle_image_url", "VARCHAR(512) COMMENT '处理图片URL'"),
|
||||
]
|
||||
with engine.connect() as conn:
|
||||
for table, column, col_def in migrations:
|
||||
if table in insp.get_table_names():
|
||||
existing = [c["name"] for c in insp.get_columns(table)]
|
||||
if column not in existing:
|
||||
conn.execute(text(f"ALTER TABLE {table} ADD COLUMN {column} {col_def}"))
|
||||
conn.commit()
|
||||
|
||||
|
||||
def init_db():
|
||||
engine = get_engine()
|
||||
Base.metadata.create_all(bind=engine)
|
||||
# 自动添加新列(ALTER TABLE 不会被 create_all 处理)
|
||||
_auto_migrate(engine)
|
||||
|
||||
|
||||
class NotifyArea(Base):
|
||||
|
||||
Reference in New Issue
Block a user