fix:修复因数据库缺少 working_hours 列导致 ROI 配置失败的问题。
- 手动执行 SQL:ALTER TABLE rois ADD COLUMN working_hours TEXT - 确保现有 SQLite 数据库(security_monitor.db)结构与模型定义一致 - 避免因字段缺失引发 API 或算法读取异常
This commit is contained in:
@@ -139,6 +139,7 @@ def create_roi(
|
||||
threshold_sec: int = 300,
|
||||
confirm_sec: int = 10,
|
||||
return_sec: int = 30,
|
||||
working_hours: Optional[str] = None,
|
||||
) -> ROI:
|
||||
import json
|
||||
|
||||
@@ -154,6 +155,7 @@ def create_roi(
|
||||
threshold_sec=threshold_sec,
|
||||
confirm_sec=confirm_sec,
|
||||
return_sec=return_sec,
|
||||
working_hours=working_hours,
|
||||
)
|
||||
db.add(roi)
|
||||
db.commit()
|
||||
@@ -173,6 +175,7 @@ def update_roi(
|
||||
threshold_sec: Optional[int] = None,
|
||||
confirm_sec: Optional[int] = None,
|
||||
return_sec: Optional[int] = None,
|
||||
working_hours: Optional[str] = None,
|
||||
) -> Optional[ROI]:
|
||||
import json
|
||||
|
||||
@@ -198,6 +201,8 @@ def update_roi(
|
||||
roi.confirm_sec = confirm_sec
|
||||
if return_sec is not None:
|
||||
roi.return_sec = return_sec
|
||||
if working_hours is not None:
|
||||
roi.working_hours = working_hours
|
||||
|
||||
db.commit()
|
||||
db.refresh(roi)
|
||||
@@ -232,6 +237,7 @@ def get_roi_points(db: Session, camera_id: int) -> List[dict]:
|
||||
"threshold_sec": roi.threshold_sec,
|
||||
"confirm_sec": roi.confirm_sec,
|
||||
"return_sec": roi.return_sec,
|
||||
"working_hours": json.loads(roi.working_hours) if roi.working_hours else None,
|
||||
}
|
||||
for roi in rois
|
||||
]
|
||||
|
||||
@@ -93,6 +93,7 @@ class ROI(Base):
|
||||
threshold_sec: Mapped[int] = mapped_column(Integer, default=300)
|
||||
confirm_sec: Mapped[int] = mapped_column(Integer, default=10)
|
||||
return_sec: Mapped[int] = mapped_column(Integer, default=30)
|
||||
working_hours: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
||||
pending_sync: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
sync_version: Mapped[int] = mapped_column(Integer, default=0)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow)
|
||||
|
||||
Reference in New Issue
Block a user