You've already forked FrameTour-BE
人脸识别日志
This commit is contained in:
@@ -33,6 +33,8 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.ycwl.basic.constant.FaceConstant.USER_FACE_DB_NAME;
|
||||
|
||||
/**
|
||||
* @Author:longbinbin
|
||||
* @Date:2024/12/2 16:39
|
||||
@@ -51,6 +53,7 @@ public class FaceServiceImpl implements FaceService {
|
||||
|
||||
@Value("${face.score}")
|
||||
private float faceScore;
|
||||
private float strictScore = 90F;
|
||||
@Autowired
|
||||
private TaskService taskTaskService;
|
||||
@Autowired
|
||||
@@ -113,7 +116,7 @@ public class FaceServiceImpl implements FaceService {
|
||||
|
||||
@Override
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
public ApiResponse faceUPload(MultipartFile file,Long scenicId) {
|
||||
public ApiResponse faceUpload(MultipartFile file, Long scenicId) {
|
||||
//获取用户id
|
||||
JwtInfo worker = JwtTokenUtil.getWorker();
|
||||
Long userId = worker.getUserId();
|
||||
@@ -121,55 +124,57 @@ public class FaceServiceImpl implements FaceService {
|
||||
|
||||
//1、上传人脸照片
|
||||
String faceUrl = uploadFileALiOss(file, userId);
|
||||
SearchFaceRespVo searchFaceRespVo = faceService.searchFace(scenicId, faceUrl);
|
||||
if (searchFaceRespVo == null) {
|
||||
SearchFaceRespVo scenicDbSearchResult = faceService.searchFace(scenicId, faceUrl);
|
||||
if (scenicDbSearchResult == null) {
|
||||
ossUtil.deleteFileByUrl(faceUrl);
|
||||
throw new BaseException("人脸照片校验失败,请重新上传");
|
||||
}
|
||||
float score = searchFaceRespVo.getScore();
|
||||
float score = scenicDbSearchResult.getScore();
|
||||
if (score<faceScore) {
|
||||
//校验失败,删除,提示重新上传
|
||||
ossUtil.deleteFileByUrl(faceUrl);
|
||||
|
||||
throw new BaseException("人脸照片校验失败,请重新上传");
|
||||
}
|
||||
// 2、查看人脸是否已上传
|
||||
FaceRespVO faceRespVO=faceMapper.getByMemberId(userId, scenicId);
|
||||
|
||||
// 2、通过人脸查找用户库
|
||||
SearchFaceRespVo userDbSearchResult = faceService.searchFace(USER_FACE_DB_NAME, faceUrl);
|
||||
Long newFaceId = SnowFlakeUtil.getLongId();
|
||||
FaceEntity faceEntity = new FaceEntity();
|
||||
faceEntity.setScore(searchFaceRespVo.getScore());
|
||||
faceEntity.setMatchResult(searchFaceRespVo.getSearchResultJson());
|
||||
if (searchFaceRespVo.getFirstMatchRate() != null) {
|
||||
faceEntity.setFirstMatchRate(BigDecimal.valueOf(searchFaceRespVo.getFirstMatchRate()));
|
||||
faceEntity.setScore(scenicDbSearchResult.getScore());
|
||||
faceEntity.setMatchResult(scenicDbSearchResult.getSearchResultJson());
|
||||
if (userDbSearchResult == null) {
|
||||
// 都是null了,那得是新的
|
||||
faceService.addFaceSample(USER_FACE_DB_NAME, newFaceId.toString(), faceUrl, newFaceId.toString());
|
||||
} else if (userDbSearchResult.getSampleListIds() == null || userDbSearchResult.getSampleListIds().isEmpty()) {
|
||||
// 没有匹配到过,也得是新的
|
||||
faceService.addFaceSample(USER_FACE_DB_NAME, newFaceId.toString(), faceUrl, newFaceId.toString());
|
||||
} else if (userDbSearchResult.getFirstMatchRate() < strictScore) {
|
||||
// 有匹配结果,但是不匹配旧的
|
||||
faceService.addFaceSample(USER_FACE_DB_NAME, newFaceId.toString(), faceUrl, newFaceId.toString());
|
||||
} else {
|
||||
// 有匹配结果,且能匹配旧的数据
|
||||
Long oldFaceId = userDbSearchResult.getSampleListIds().get(0);
|
||||
faceEntity.setId(oldFaceId);
|
||||
}
|
||||
if (searchFaceRespVo.getSampleListIds() != null) {
|
||||
faceEntity.setMatchSampleIds(searchFaceRespVo.getSampleListIds().stream().map(String::valueOf).collect(Collectors.joining(",")));
|
||||
if (scenicDbSearchResult.getFirstMatchRate() != null) {
|
||||
faceEntity.setFirstMatchRate(BigDecimal.valueOf(scenicDbSearchResult.getFirstMatchRate()));
|
||||
}
|
||||
if (scenicDbSearchResult.getSampleListIds() != null) {
|
||||
faceEntity.setMatchSampleIds(scenicDbSearchResult.getSampleListIds().stream().map(String::valueOf).collect(Collectors.joining(",")));
|
||||
}
|
||||
faceEntity.setCreateAt(new Date());
|
||||
faceEntity.setScenicId(scenicId);
|
||||
faceEntity.setMemberId(userId);
|
||||
faceEntity.setFaceUrl(faceUrl);
|
||||
if (faceRespVO==null) {
|
||||
if (faceEntity.getId()==null) {
|
||||
//新增人脸
|
||||
faceEntity.setId(SnowFlakeUtil.getLongId());
|
||||
faceEntity.setId(newFaceId);
|
||||
faceMapper.add(faceEntity);
|
||||
taskTaskService.autoCreateTaskByFaceId(faceEntity.getId());
|
||||
} else if (StringUtils.isBlank(faceRespVO.getMatchSampleIds())) {
|
||||
// 如果之前的是没有匹配到的
|
||||
// 也去新增
|
||||
faceEntity.setId(faceRespVO.getId());
|
||||
faceMapper.update(faceEntity);
|
||||
taskTaskService.autoCreateTaskByFaceId(faceEntity.getId());
|
||||
} else {
|
||||
//2、更新人脸
|
||||
faceEntity.setId(faceRespVO.getId());
|
||||
faceMapper.update(faceEntity);
|
||||
if (!Objects.equals(
|
||||
faceRespVO.getMatchSampleIds(),
|
||||
searchFaceRespVo.getSampleListIds().stream().map(String::valueOf).collect(Collectors.joining(","))
|
||||
)) {
|
||||
taskTaskService.autoCreateTaskByFaceId(faceEntity.getId());
|
||||
}
|
||||
taskTaskService.autoCreateTaskByFaceId(faceEntity.getId());
|
||||
}
|
||||
StatisticsRecordAddReq statisticsRecordAddReq = new StatisticsRecordAddReq();
|
||||
statisticsRecordAddReq.setMemberId(userId);
|
||||
|
||||
Reference in New Issue
Block a user