You've already forked FrameTour-BE
feat(face): 添加低阈值检测功能
- 在 FaceConstant 中添加 FACE_LOW_THRESHOLD_PFX 常量 - 在 SearchFaceRespVo 中添加 lowThreshold 字段 - 在 FaceServiceImpl 中实现记录低阈值检测人脸的逻辑 - 在 TaskFaceServiceImpl 中添加低阈值检测的判断和结果设置
This commit is contained in:
@@ -69,6 +69,7 @@ import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.ycwl.basic.constant.FaceConstant.FACE_LOW_THRESHOLD_PFX;
|
||||
import static com.ycwl.basic.constant.FaceConstant.FACE_RECOGNITION_COUNT_PFX;
|
||||
import static com.ycwl.basic.constant.FaceConstant.USER_FACE_DB_NAME;
|
||||
import static com.ycwl.basic.constant.StorageConstant.USER_FACE;
|
||||
@@ -333,6 +334,12 @@ public class FaceServiceImpl implements FaceService {
|
||||
}
|
||||
} else {
|
||||
log.warn("人脸匹配无结果:faceId={}", faceId);
|
||||
|
||||
// 检查低阈值检测结果,如果为true则记录该人脸ID到Redis
|
||||
if (scenicDbSearchResult != null && scenicDbSearchResult.isLowThreshold()) {
|
||||
recordLowThresholdFace(faceId);
|
||||
log.debug("触发低阈值检测,记录faceId: {}", faceId);
|
||||
}
|
||||
}
|
||||
|
||||
return scenicDbSearchResult;
|
||||
@@ -835,4 +842,28 @@ public class FaceServiceImpl implements FaceService {
|
||||
log.error("记录人脸识别次数失败:faceId={}", faceId, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录低阈值检测的人脸ID到Redis
|
||||
*
|
||||
* @param faceId 人脸ID
|
||||
*/
|
||||
private void recordLowThresholdFace(Long faceId) {
|
||||
if (faceId == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
String redisKey = FACE_LOW_THRESHOLD_PFX + faceId;
|
||||
|
||||
// 设置标记,表示该人脸ID触发了低阈值检测
|
||||
redisTemplate.opsForValue().set(redisKey, "1", 2, TimeUnit.DAYS);
|
||||
|
||||
log.debug("记录低阈值检测人脸:faceId={}", faceId);
|
||||
|
||||
} catch (Exception e) {
|
||||
// 记录失败不应影响主要业务逻辑,只记录错误日志
|
||||
log.error("记录低阈值检测人脸失败:faceId={}", faceId, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user