You've already forked FrameTour-BE
修改
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
package com.ycwl.basic.service.pc.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ycwl.basic.biz.OrderBiz;
|
||||
import com.ycwl.basic.enums.StatisticEnum;
|
||||
import com.ycwl.basic.facebody.FaceBodyFactory;
|
||||
import com.ycwl.basic.facebody.adapter.AliFaceBodyAdapter;
|
||||
import com.ycwl.basic.facebody.adapter.IFaceBodyAdapter;
|
||||
import com.ycwl.basic.mapper.FaceSampleMapper;
|
||||
import com.ycwl.basic.mapper.SourceMapper;
|
||||
import com.ycwl.basic.mapper.StatisticsMapper;
|
||||
@@ -37,6 +41,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -62,8 +67,6 @@ public class FaceServiceImpl implements FaceService {
|
||||
@Autowired
|
||||
private SourceMapper sourceMapper;
|
||||
@Autowired
|
||||
private FaceSampleMapper faceSampleMapper;
|
||||
@Autowired
|
||||
private OrderBiz orderBiz;
|
||||
@Autowired
|
||||
private FaceRepository faceRepository;
|
||||
@@ -120,8 +123,6 @@ public class FaceServiceImpl implements FaceService {
|
||||
|
||||
@Override
|
||||
public FaceRecognizeResp faceUpload(MultipartFile file, Long scenicId, Long userId) {
|
||||
|
||||
|
||||
//1、上传人脸照片
|
||||
IStorageAdapter adapter = StorageFactory.use("faces");
|
||||
String filePath = StorageUtil.joinPath("user-faces", DateUtils.format(new Date(),"yyyy-MM-dd"));
|
||||
@@ -131,17 +132,26 @@ public class FaceServiceImpl implements FaceService {
|
||||
String faceUrl = adapter.uploadFile(file, filePath, fileName);
|
||||
Long newFaceId = SnowFlakeUtil.getLongId();
|
||||
Long oldFaceId = null;
|
||||
SearchFaceRespVo userDbSearchResult = faceService.searchFace(USER_FACE_DB_NAME+scenicId, faceUrl, "判断是否为用户上传过的人脸");
|
||||
ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(scenicId);
|
||||
IFaceBodyAdapter faceBodyAdapter;
|
||||
if (scenicConfig != null && scenicConfig.getFaceType() != null) {
|
||||
faceBodyAdapter = FaceBodyFactory.getAdapter(scenicConfig.getFaceType());
|
||||
faceBodyAdapter.loadConfig(JSONObject.parseObject(scenicConfig.getFaceConfigJson(), Map.class));
|
||||
} else {
|
||||
faceBodyAdapter = FaceBodyFactory.use();
|
||||
}
|
||||
faceService.assureFaceDb(faceBodyAdapter, USER_FACE_DB_NAME+scenicId);
|
||||
SearchFaceRespVo userDbSearchResult = faceService.searchFace(faceBodyAdapter, USER_FACE_DB_NAME+scenicId, faceUrl, "判断是否为用户上传过的人脸");
|
||||
float strictScore = 0.6F;
|
||||
if (userDbSearchResult == null) {
|
||||
// 都是null了,那得是新的
|
||||
faceService.addFaceSample(USER_FACE_DB_NAME+scenicId, newFaceId.toString(), faceUrl, newFaceId.toString());
|
||||
faceBodyAdapter.addFace(USER_FACE_DB_NAME+scenicId, newFaceId.toString(), faceUrl, newFaceId.toString());
|
||||
} else if (userDbSearchResult.getSampleListIds() == null || userDbSearchResult.getSampleListIds().isEmpty()) {
|
||||
// 没有匹配到过,也得是新的
|
||||
faceService.addFaceSample(USER_FACE_DB_NAME+scenicId, newFaceId.toString(), faceUrl, newFaceId.toString());
|
||||
faceBodyAdapter.addFace(USER_FACE_DB_NAME+scenicId, newFaceId.toString(), faceUrl, newFaceId.toString());
|
||||
} else if (userDbSearchResult.getFirstMatchRate() < strictScore) {
|
||||
// 有匹配结果,但是不匹配旧的
|
||||
faceService.addFaceSample(USER_FACE_DB_NAME+scenicId, newFaceId.toString(), faceUrl, newFaceId.toString());
|
||||
faceBodyAdapter.addFace(USER_FACE_DB_NAME+scenicId, newFaceId.toString(), faceUrl, newFaceId.toString());
|
||||
} else {
|
||||
// 有匹配结果,且能匹配旧的数据
|
||||
Optional<Long> faceAny = userDbSearchResult.getSampleListIds().stream().filter(_faceId -> {
|
||||
@@ -155,8 +165,8 @@ public class FaceServiceImpl implements FaceService {
|
||||
oldFaceId = faceAny.get();
|
||||
FaceRespVO oldFace = faceMapper.getById(oldFaceId);
|
||||
if (oldFace == null) {
|
||||
faceService.deleteFaceSample(USER_FACE_DB_NAME+scenicId, oldFaceId.toString());
|
||||
faceService.addFaceSample(USER_FACE_DB_NAME+scenicId, newFaceId.toString(), faceUrl, newFaceId.toString());
|
||||
faceBodyAdapter.deleteFace(USER_FACE_DB_NAME+scenicId, oldFaceId.toString());
|
||||
faceBodyAdapter.addFace(USER_FACE_DB_NAME+scenicId, newFaceId.toString(), faceUrl, newFaceId.toString());
|
||||
oldFaceId = null;
|
||||
} else {
|
||||
newFaceId = oldFaceId;
|
||||
@@ -210,30 +220,27 @@ public class FaceServiceImpl implements FaceService {
|
||||
if (face == null) {
|
||||
return null;
|
||||
}
|
||||
SearchFaceRespVo scenicDbSearchResult = faceService.searchFace(face.getScenicId(), face.getFaceUrl());
|
||||
ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(face.getScenicId());
|
||||
IFaceBodyAdapter faceBodyAdapter;
|
||||
if (scenicConfig != null && scenicConfig.getFaceType() != null) {
|
||||
faceBodyAdapter = FaceBodyFactory.getAdapter(scenicConfig.getFaceType());
|
||||
faceBodyAdapter.loadConfig(JSONObject.parseObject(scenicConfig.getFaceConfigJson(), Map.class));
|
||||
} else {
|
||||
faceBodyAdapter = FaceBodyFactory.use();
|
||||
}
|
||||
SearchFaceRespVo scenicDbSearchResult = faceService.searchFace(faceBodyAdapter, String.valueOf(face.getScenicId()), face.getFaceUrl(), "人脸识别");
|
||||
if (scenicDbSearchResult.getSampleListIds() != null && scenicDbSearchResult.getFirstMatchRate() != null && !scenicDbSearchResult.getSampleListIds().isEmpty()) {
|
||||
if (scenicConfig != null && scenicConfig.getFaceDetectHelperThreshold() != null && scenicConfig.getFaceDetectHelperThreshold() > 0) {
|
||||
if (scenicDbSearchResult.getSampleListIds().size() < scenicConfig.getFaceDetectHelperThreshold()) {
|
||||
// 补救逻辑
|
||||
Long faceSampleId = scenicDbSearchResult.getSampleListIds().get(0);
|
||||
FaceSampleEntity faceSample = faceRepository.getFaceSample(faceSampleId);
|
||||
Long resultItem = scenicDbSearchResult.getSampleListIds().get(0);
|
||||
FaceSampleEntity faceSample = faceRepository.getFaceSample(resultItem);
|
||||
if (faceSample != null) {
|
||||
// 以这个结果为人脸库的匹配结果
|
||||
scenicDbSearchResult = faceService.searchFace(face.getScenicId().toString(), faceSample.getFaceUrl(), "补救措施1:人脸数太少少于设定值"+scenicConfig.getFaceDetectHelperThreshold());
|
||||
scenicDbSearchResult = faceService.searchFace(faceBodyAdapter, String.valueOf(face.getScenicId()), faceSample.getFaceUrl(), "人脸补救措施1");
|
||||
}
|
||||
}
|
||||
}
|
||||
// if (scenicDbSearchResult.getFirstMatchRate() > 0.7) {
|
||||
// // 如果匹配度高于阈值,则使用景区第一张人脸去匹配景区库
|
||||
// // 找第一张人脸
|
||||
// Long faceSampleId = scenicDbSearchResult.getSampleListIds().get(0);
|
||||
// FaceSampleEntity faceSample = faceRepository.getFaceSample(faceSampleId);
|
||||
// if (faceSample != null) {
|
||||
// // 以这个结果为人脸库的匹配结果
|
||||
// scenicDbSearchResult = faceService.searchFace(face.getScenicId().toString(), faceSample.getFaceUrl(), "补救措施2:存在得分够高");
|
||||
// }
|
||||
// }
|
||||
}
|
||||
FaceEntity faceEntity = new FaceEntity();
|
||||
faceEntity.setId(faceId);
|
||||
|
@@ -1,7 +1,10 @@
|
||||
package com.ycwl.basic.service.pc.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ycwl.basic.facebody.FaceBodyFactory;
|
||||
import com.ycwl.basic.facebody.adapter.IFaceBodyAdapter;
|
||||
import com.ycwl.basic.mapper.ScenicAccountMapper;
|
||||
import com.ycwl.basic.mapper.ScenicMapper;
|
||||
import com.ycwl.basic.model.pc.scenic.entity.ScenicAccountEntity;
|
||||
@@ -21,6 +24,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.ycwl.basic.constant.FaceConstant.USER_FACE_DB_NAME;
|
||||
|
||||
@@ -77,8 +81,6 @@ public class ScenicServiceImpl implements ScenicService {
|
||||
account.setIsSuper(1);
|
||||
scenicAccountMapper.add(account);
|
||||
if (add > 0) {
|
||||
taskFaceService.createFaceDB(scenicId.toString());
|
||||
taskFaceService.assureFaceDB(scenicId.toString());
|
||||
return ApiResponse.success(true);
|
||||
} else {
|
||||
return ApiResponse.fail("景区添加失败");
|
||||
@@ -90,12 +92,17 @@ public class ScenicServiceImpl implements ScenicService {
|
||||
public ApiResponse<Boolean> deleteById(Long id) {
|
||||
int i = scenicMapper.deleteById(id);
|
||||
if (i > 0) {
|
||||
scenicMapper.deleteConfigByScenicId(id);
|
||||
scenicAccountMapper.deleteByScenicId(id);
|
||||
(new Thread(() -> {
|
||||
taskFaceService.deleteFaceDB(id.toString());
|
||||
taskFaceService.deleteFaceDB(USER_FACE_DB_NAME + id.toString());
|
||||
})).start();
|
||||
ScenicConfigEntity scenicConfig = scenicRepository.getScenicConfig(id);
|
||||
if (scenicConfig != null && scenicConfig.getFaceType() != null) {
|
||||
IFaceBodyAdapter adapter = FaceBodyFactory.getAdapter(scenicConfig.getFaceType());
|
||||
adapter.loadConfig(JSONObject.parseObject(scenicConfig.getFaceConfigJson(), Map.class));
|
||||
(new Thread(() -> {
|
||||
adapter.deleteFaceDb(id.toString());
|
||||
adapter.deleteFaceDb(USER_FACE_DB_NAME + id);
|
||||
})).start();
|
||||
}
|
||||
scenicMapper.deleteConfigByScenicId(id);
|
||||
scenicRepository.clearCache(id);
|
||||
return ApiResponse.success(true);
|
||||
}else {
|
||||
@@ -131,7 +138,6 @@ public class ScenicServiceImpl implements ScenicService {
|
||||
int i = scenicMapper.update(scenicUpdateReq);
|
||||
if (i > 0) {
|
||||
scenicRepository.clearCache(scenicUpdateReq.getId());
|
||||
taskFaceService.assureFaceDB(scenicUpdateReq.getId().toString());
|
||||
return ApiResponse.success(true);
|
||||
}else {
|
||||
return ApiResponse.fail("景区修改失败");
|
||||
@@ -144,7 +150,6 @@ public class ScenicServiceImpl implements ScenicService {
|
||||
int i = scenicMapper.updateStatus(id);
|
||||
if (i > 0) {
|
||||
scenicRepository.clearCache(id);
|
||||
taskFaceService.assureFaceDB(id.toString());
|
||||
return ApiResponse.success(true);
|
||||
}else {
|
||||
return ApiResponse.fail("景区状态修改失败");
|
||||
@@ -159,7 +164,6 @@ public class ScenicServiceImpl implements ScenicService {
|
||||
int i = scenicMapper.addConfig(scenicConfig);
|
||||
if (i > 0) {
|
||||
scenicRepository.clearCache(scenicConfig.getScenicId());
|
||||
taskFaceService.assureFaceDB(scenicConfig.getScenicId().toString());
|
||||
return ApiResponse.success(true);
|
||||
}else {
|
||||
return ApiResponse.fail("景区配置添加失败");
|
||||
@@ -171,7 +175,6 @@ public class ScenicServiceImpl implements ScenicService {
|
||||
int i = scenicMapper.updateConfigById(scenicConfig);
|
||||
if (i > 0) {
|
||||
scenicRepository.clearCache(scenicConfig.getScenicId());
|
||||
taskFaceService.assureFaceDB(scenicConfig.getScenicId().toString());
|
||||
return ApiResponse.success(true);
|
||||
}else {
|
||||
return ApiResponse.fail("景区配置修改失败");
|
||||
|
Reference in New Issue
Block a user