修改路径,从src放到根目录
This commit is contained in:
89
repositories/sur_person_repository.py
Normal file
89
repositories/sur_person_repository.py
Normal file
@@ -0,0 +1,89 @@
|
||||
"""
|
||||
人员相关数据访问层
|
||||
"""
|
||||
|
||||
from typing import List, Dict, Optional
|
||||
from sqlalchemy.orm import Session
|
||||
from models.sur_person import SurPersonBlacklist, SurFaceFeature
|
||||
from config import settings
|
||||
|
||||
|
||||
class SurPersonRepository:
|
||||
"""人员数据访问类"""
|
||||
|
||||
def __init__(self, db: Session):
|
||||
self.db = db
|
||||
|
||||
def get_blacklist_face_features(self) -> Dict[int, str]:
|
||||
"""
|
||||
获取黑名单人员的人脸特征
|
||||
|
||||
返回:
|
||||
字典 {person_id: feature_data}
|
||||
"""
|
||||
try:
|
||||
# 查询启用的黑名单人员
|
||||
blacklist_persons = self.db.query(SurPersonBlacklist).filter(
|
||||
SurPersonBlacklist.status == 1
|
||||
).all()
|
||||
|
||||
if not blacklist_persons:
|
||||
return {}
|
||||
|
||||
person_ids = [person.person_id for person in blacklist_persons]
|
||||
|
||||
# 查询对应的人脸特征
|
||||
face_features = self.db.query(SurFaceFeature).filter(
|
||||
SurFaceFeature.person_id.in_(person_ids),
|
||||
SurFaceFeature.feature_type == settings.FACE_MODEL_VERSION,
|
||||
SurFaceFeature.status == 2 # 计算成功的特征
|
||||
).all()
|
||||
|
||||
# 构建特征字典
|
||||
feature_dict = {}
|
||||
for feature in face_features:
|
||||
if feature.feature_data:
|
||||
feature_dict[feature.person_id] = feature.feature_data
|
||||
|
||||
return feature_dict
|
||||
|
||||
except Exception as e:
|
||||
print(f"获取黑名单人脸特征失败: {e}")
|
||||
return {}
|
||||
|
||||
def get_blacklist_person_count(self) -> int:
|
||||
"""获取黑名单人员数量"""
|
||||
try:
|
||||
count = self.db.query(SurPersonBlacklist).filter(
|
||||
SurPersonBlacklist.status == 1
|
||||
).count()
|
||||
return count
|
||||
except Exception as e:
|
||||
print(f"获取黑名单人员数量失败: {e}")
|
||||
return 0
|
||||
|
||||
def get_blacklist_face_feature_count(self) -> int:
|
||||
"""获取有特征数据的黑名单人员数量"""
|
||||
try:
|
||||
# 查询启用的黑名单人员
|
||||
blacklist_persons = self.db.query(SurPersonBlacklist).filter(
|
||||
SurPersonBlacklist.status == 1
|
||||
).all()
|
||||
|
||||
if not blacklist_persons:
|
||||
return 0
|
||||
|
||||
person_ids = [person.person_id for person in blacklist_persons]
|
||||
|
||||
# 查询对应的人脸特征数量
|
||||
count = self.db.query(SurFaceFeature).filter(
|
||||
SurFaceFeature.person_id.in_(person_ids),
|
||||
SurFaceFeature.feature_type == settings.FACE_MODEL_VERSION,
|
||||
SurFaceFeature.status == 2 # 计算成功的特征
|
||||
).count()
|
||||
|
||||
return count
|
||||
|
||||
except Exception as e:
|
||||
print(f"获取黑名单人脸特征数量失败: {e}")
|
||||
return 0
|
||||
Reference in New Issue
Block a user