You've already forked FrameTour-BE
无识别结果时返回
This commit is contained in:
@ -6,7 +6,7 @@ import java.util.List;
|
||||
|
||||
@Data
|
||||
public class SearchFaceRespVo {
|
||||
private Float score;
|
||||
private float score;
|
||||
private List<Long> sampleListIds;
|
||||
private String searchResultJson;
|
||||
private Float firstMatchRate;
|
||||
|
@ -19,6 +19,7 @@ import com.ycwl.basic.service.task.TaskService;
|
||||
import com.ycwl.basic.task.FaceCleaner;
|
||||
import com.ycwl.basic.utils.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -121,6 +122,10 @@ public class FaceServiceImpl implements FaceService {
|
||||
//1、上传人脸照片
|
||||
String faceUrl = uploadFileALiOss(file, userId);
|
||||
SearchFaceRespVo searchFaceRespVo = faceService.searchFace(scenicId, faceUrl);
|
||||
if (searchFaceRespVo == null) {
|
||||
ossUtil.deleteFileByUrl(faceUrl);
|
||||
throw new BaseException("人脸照片校验失败,请重新上传");
|
||||
}
|
||||
float score = searchFaceRespVo.getScore();
|
||||
if (score<faceScore) {
|
||||
//校验失败,删除,提示重新上传
|
||||
@ -134,8 +139,12 @@ public class FaceServiceImpl implements FaceService {
|
||||
FaceEntity faceEntity = new FaceEntity();
|
||||
faceEntity.setScore(searchFaceRespVo.getScore());
|
||||
faceEntity.setMatchResult(searchFaceRespVo.getSearchResultJson());
|
||||
faceEntity.setFirstMatchRate(BigDecimal.valueOf(searchFaceRespVo.getFirstMatchRate()));
|
||||
faceEntity.setMatchSampleIds(searchFaceRespVo.getSampleListIds().stream().map(String::valueOf).collect(Collectors.joining(",")));
|
||||
if (searchFaceRespVo.getFirstMatchRate() != null) {
|
||||
faceEntity.setFirstMatchRate(BigDecimal.valueOf(searchFaceRespVo.getFirstMatchRate()));
|
||||
}
|
||||
if (searchFaceRespVo.getSampleListIds() != null) {
|
||||
faceEntity.setMatchSampleIds(searchFaceRespVo.getSampleListIds().stream().map(String::valueOf).collect(Collectors.joining(",")));
|
||||
}
|
||||
faceEntity.setCreateAt(new Date());
|
||||
faceEntity.setScenicId(scenicId);
|
||||
faceEntity.setMemberId(userId);
|
||||
@ -145,7 +154,13 @@ public class FaceServiceImpl implements FaceService {
|
||||
faceEntity.setId(SnowFlakeUtil.getLongId());
|
||||
faceMapper.add(faceEntity);
|
||||
taskTaskService.autoCreateTaskByFaceId(faceEntity.getId());
|
||||
}else {
|
||||
} 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);
|
||||
|
@ -89,20 +89,20 @@ public class TaskFaceServiceImpl implements TaskFaceService {
|
||||
if (matchList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
if (matchList.get(0).getFaceItems().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
SearchFaceRespVo respVo = new SearchFaceRespVo();
|
||||
respVo.setScore(matchList.get(0).getQualitieScore());
|
||||
respVo.setSearchResultJson(JSON.toJSONString(matchList.get(0)));
|
||||
if (matchList.get(0).getFaceItems().isEmpty()) {
|
||||
return respVo;
|
||||
}
|
||||
List<SearchFaceResponse.Data.MatchListItem.FaceItemsItem> faceItems = matchList.get(0).getFaceItems().stream()
|
||||
.filter(faceItemsItem -> faceItemsItem.getConfidence() > 50).collect(Collectors.toList());
|
||||
List<Long> faceSampleIds = faceItems.stream()
|
||||
.map(SearchFaceResponse.Data.MatchListItem.FaceItemsItem::getExtraData)
|
||||
.map(Long::parseLong)
|
||||
.collect(Collectors.toList());
|
||||
respVo.setSearchResultJson(JSON.toJSONString(matchList.get(0)));
|
||||
respVo.setFirstMatchRate(matchList.get(0).getFaceItems().get(0).getConfidence());
|
||||
respVo.setSampleListIds(faceSampleIds);
|
||||
respVo.setScore(matchList.get(0).getQualitieScore());
|
||||
return respVo;
|
||||
} catch (Exception e) {
|
||||
log.error("人脸搜索失败:{}", e.getMessage());
|
||||
|
Reference in New Issue
Block a user