完成查询犯人带出次数

This commit is contained in:
zqc
2026-01-09 17:33:50 +08:00
parent 1eb3e50d49
commit ec96e161bc
2 changed files with 57 additions and 5 deletions

View File

@@ -264,19 +264,30 @@ class VideoFacePrisonBiz(BaseFaceBiz):
self.person_tracking[best_name] = []
self.person_tracking[best_name].append(current_time)
if has_passed:
# 插入数据库告警记录
# 查询历史报警记录数
historical_alert_count = 0
if has_passed and passed_person_id:
try:
with db_manager.get_session() as db:
alert_service = SurAlertRecordService(db)
# 插入数据库告警记录
alert_service.create_alert_record(
alert_type=AlertType.PRISONER_OUT,
person_id=int(passed_person_id),
# camera_id=cam_id #todo设置cam_id如果每个摄像头创建一个实例则可以将cam_id放到成员变量里
)
# logger.debug(f"[INFO] 告警记录已插入数据库: person_id={result['passed_person_id']}")
# 查询近escort_window_hours小时内的PRISONER_OUT记录数
historical_alert_count = alert_service.get_alert_count_by_person_and_time(
person_id=int(passed_person_id),
alert_type=AlertType.PRISONER_OUT,
hours=self.escort_window_hours
)
logger.info(f"[INFO] 告警记录已插入数据库: person_id={passed_person_id}, 历史记录数: {historical_alert_count}")
except Exception as e:
logger.error(f"[ERROR] 插入告警记录失败: {e}")
logger.error(f"[ERROR] 数据库操作失败: {e}")
result = {
'bbox': face.bbox.astype(int).tolist(),
@@ -285,6 +296,7 @@ class VideoFacePrisonBiz(BaseFaceBiz):
'is_match': is_match,
'has_passed': has_passed, # 新增:是否已经通过
'passed_person_id': passed_person_id, # 新增通过的person_id
'historical_alert_count': historical_alert_count, # 新增:历史报警记录数
'det_score': float(face.det_score),
'quality_metrics': quality_metrics,
'is_acceptable': is_acceptable