回滚:移除告警处理图片字段,告警只记录状态

告警只需记录处理状态(已处理/误报),图片等信息在工单体系中管理。
移除 handle_image_url 字段、自动迁移和相关参数。
This commit is contained in:
2026-03-25 15:10:40 +08:00
parent d623f6b340
commit adf8d63da6
3 changed files with 0 additions and 26 deletions

View File

@@ -281,7 +281,6 @@ 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(),
@@ -313,7 +312,6 @@ 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,
@@ -537,27 +535,9 @@ 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):

View File

@@ -101,7 +101,6 @@ async def _alarm_to_camel(alarm_dict: dict, camera_info_map: dict = None, camera
"edgeNodeId": alarm_dict.get("edge_node_id"),
"handler": alarm_dict.get("handler"),
"handleRemark": alarm_dict.get("handle_remark"),
"handleImageUrl": alarm_dict.get("handle_image_url"),
"handledAt": alarm_dict.get("handled_at"),
"createdAt": alarm_dict.get("created_at"),
"updatedAt": alarm_dict.get("updated_at"),
@@ -220,7 +219,6 @@ async def handle_alert(
handleStatus: Optional[str] = Query(None, description="处理状态: HANDLING/DONE/IGNORED"),
status: Optional[str] = Query(None, description="处理状态(兼容旧接口)"),
remark: Optional[str] = Query(None, description="处理备注"),
handleImageUrl: Optional[str] = Query(None, description="处理图片URL"),
service: AlarmEventService = Depends(get_alarm_event_service),
current_user: dict = Depends(get_current_user)
):
@@ -244,7 +242,6 @@ async def handle_alert(
handle_status=handleStatus,
remark=remark,
handler=handler,
handle_image_url=handleImageUrl,
)
if not alarm:
raise HTTPException(status_code=404, detail="告警不存在")

View File

@@ -427,7 +427,6 @@ class AlarmEventService:
handle_status: Optional[str] = None,
remark: Optional[str] = None,
handler: Optional[str] = None,
handle_image_url: Optional[str] = None,
) -> Optional[AlarmEvent]:
"""处理告警"""
db = get_session()
@@ -444,8 +443,6 @@ class AlarmEventService:
alarm.handle_remark = remark
if handler:
alarm.handler = handler
if handle_image_url:
alarm.handle_image_url = handle_image_url
now = beijing_now()
alarm.handled_at = now