无识别结果时返回
This commit is contained in:
parent
43ae10916c
commit
30314ecd48
@ -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());
|
||||
|
@ -14,9 +14,9 @@ spring:
|
||||
datasource: # 数据源的相关配置
|
||||
type: com.zaxxer.hikari.HikariDataSource # 数据源类型:HikariCP
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver # mysql驱动
|
||||
url: jdbc:mysql://8.134.112.96:3306/liuying_mgmt_re?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
|
||||
username: root
|
||||
password: yckj2017
|
||||
url: jdbc:mysql://106.14.162.214:3306/zt?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
|
||||
username: zt
|
||||
password: ZhEnTuAi2024zHeNtUaI
|
||||
hikari:
|
||||
connection-timeout: 30000 # 等待连接池分配连接的最大时长(毫秒),超过这个时长还没可用的连接则发生SQLException, 默认:30秒
|
||||
minimum-idle: 5 # 最小连接数
|
||||
|
Loading…
x
Reference in New Issue
Block a user