|
@@ -13,22 +13,18 @@ import com.face.monitor.model.FaceModel;
|
|
|
import com.iden.bms.tool.FaceIdenTool;
|
|
|
import com.iden.common.cache.DictCache;
|
|
|
import com.iden.common.cache.FaceMoniterCache;
|
|
|
+import com.iden.common.cache.RedisKeyConstant;
|
|
|
+import com.iden.common.cache.RedisUtil;
|
|
|
import com.iden.common.constant.Constants;
|
|
|
-import com.iden.common.entity.IdenCommunity;
|
|
|
-import com.iden.common.entity.IdenCrowd;
|
|
|
-import com.iden.common.entity.IdenPerson;
|
|
|
+import com.iden.common.entity.*;
|
|
|
|
|
|
-import com.iden.common.entity.IdenPersonCrowdRef;
|
|
|
import com.iden.common.enums.CredentialsTypeEnum;
|
|
|
import com.iden.common.enums.GenderEnum;
|
|
|
import com.iden.common.enums.PersonTypeEnum;
|
|
|
import com.iden.common.enums.PopulationTypeEnum;
|
|
|
import com.iden.common.exceltool.RowWriteHandler;
|
|
|
import com.iden.common.exception.BDException;
|
|
|
-import com.iden.common.service.IdenCommunityService;
|
|
|
-import com.iden.common.service.IdenCrowdService;
|
|
|
-import com.iden.common.service.IdenPersonCrowdRefService;
|
|
|
-import com.iden.common.service.IdenPersonService;
|
|
|
+import com.iden.common.service.*;
|
|
|
import com.iden.common.util.ByteUtil;
|
|
|
import com.iden.common.util.DateUtils;
|
|
|
import com.iden.common.util.ImgUtil;
|
|
@@ -71,6 +67,11 @@ public class PersonService {
|
|
|
private IdenCrowdService idenCrowdService;
|
|
|
@Resource
|
|
|
private IdenCommunityService idenCommunityService;
|
|
|
+ @Resource
|
|
|
+ private IdenWarningPersonService idenWarningPersonService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private RedisUtil redisUtil;
|
|
|
|
|
|
@Value("${iden.root:#{null}}")
|
|
|
private String idenRoot;
|
|
@@ -526,6 +527,7 @@ public class PersonService {
|
|
|
|
|
|
idenPerson.setCreateTime(new Date());
|
|
|
idenPersonService.save(idenPerson);
|
|
|
+ appendFaceDataset(idenPerson);
|
|
|
|
|
|
personIdList.add(idenPerson.getId());
|
|
|
List<Long> crowdIds = item.getCrowdIds();
|
|
@@ -567,24 +569,46 @@ public class PersonService {
|
|
|
* @return
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public boolean deleteById(Long id){
|
|
|
- IdenPerson idenPerson = this.idenPersonService.getById(id);
|
|
|
+ public void deleteById(Long id) throws BDException {
|
|
|
+ String key = RedisKeyConstant.PERSON_DELETE;
|
|
|
+ String requestId = UUID.randomUUID().toString();
|
|
|
+ boolean result = redisUtil.tryLock(key,requestId,10 * 60);
|
|
|
+ try {
|
|
|
+ if (result) {
|
|
|
+ QueryWrapper<IdenWarningPerson> queryWrapper0 = new QueryWrapper<>();
|
|
|
+ queryWrapper0.lambda().eq(IdenWarningPerson::getPersonId,id);
|
|
|
+ int cnt = this.idenWarningPersonService.count(queryWrapper0);
|
|
|
+ if(cnt > 0){
|
|
|
+ throw new BDException("人员被引用,不能删除");
|
|
|
+ }
|
|
|
|
|
|
- QueryWrapper<IdenPersonCrowdRef> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.lambda().eq(IdenPersonCrowdRef::getPersonId,idenPerson.getId());
|
|
|
- idenPersonCrowdRefService.remove(queryWrapper);
|
|
|
+ IdenPerson idenPerson = this.idenPersonService.getById(id);
|
|
|
|
|
|
- String image = idenPerson.getImage();
|
|
|
- IdenCommunity idenCommunity = this.idenCommunityService.getById(idenPerson.getCommunityId());
|
|
|
- if (StringUtils.isNotEmpty(image) && idenCommunity != null) {
|
|
|
- File imageFile = new File(idenRoot + "data/final/person/image/" + idenCommunity.getCode() + "/" + image.substring(image.lastIndexOf("/")));
|
|
|
- if(imageFile.exists()){
|
|
|
- imageFile.delete();
|
|
|
+ QueryWrapper<IdenPersonCrowdRef> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.lambda().eq(IdenPersonCrowdRef::getPersonId,idenPerson.getId());
|
|
|
+ idenPersonCrowdRefService.remove(queryWrapper);
|
|
|
+
|
|
|
+ String image = idenPerson.getImage();
|
|
|
+ IdenCommunity idenCommunity = this.idenCommunityService.getById(idenPerson.getCommunityId());
|
|
|
+ if (StringUtils.isNotEmpty(image) && idenCommunity != null) {
|
|
|
+ File imageFile = new File(idenRoot + "data/final/person/image/" + idenCommunity.getCode() + "/" + image.substring(image.lastIndexOf("/")));
|
|
|
+ if(imageFile.exists()){
|
|
|
+ imageFile.delete();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.idenPersonService.removeById(id);
|
|
|
+ reloadFaceDataset();
|
|
|
+
|
|
|
+ } else {
|
|
|
+ throw new BDException("不能多人同时删除,稍后再试");
|
|
|
}
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.getMessage();
|
|
|
+
|
|
|
+ } finally {
|
|
|
+ redisUtil.releaseLock(key,requestId);
|
|
|
}
|
|
|
- this.idenPersonService.removeById(id);
|
|
|
- reloadFaceDataset();
|
|
|
- return true;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -744,47 +768,60 @@ public class PersonService {
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void updatePerson(PersonVO vo) throws BDException {
|
|
|
- vo.setCommunityId(null);//不能修改小区
|
|
|
+ String key = RedisKeyConstant.PERSON_UPDATE;
|
|
|
+ String requestId = UUID.randomUUID().toString();
|
|
|
+ boolean result = redisUtil.tryLock(key,requestId,10 * 60);
|
|
|
+ try {
|
|
|
+ if (result) {
|
|
|
+ vo.setCommunityId(null);//不能修改小区
|
|
|
+
|
|
|
+ IdenPerson idenPerson = this.idenPersonService.getById(vo.getId());
|
|
|
+ Long communityId = idenPerson.getCommunityId();
|
|
|
+ IdenCommunity idenCommunity = this.idenCommunityService.getById(communityId);
|
|
|
+
|
|
|
+ //保存人员
|
|
|
+ String oldImage = idenPerson.getImage();
|
|
|
+ BeanUtil.copyProperties(vo,idenPerson);
|
|
|
+ String newImage = vo.getImage();
|
|
|
+ if (StringUtils.isNotEmpty(newImage) && !newImage.equals(oldImage)){
|
|
|
+ //识别
|
|
|
+ String fileNameNew = newImage.substring(newImage.lastIndexOf("/"));
|
|
|
+ File imgFileNew = new File(idenRoot + "data/final/person/image/" + idenCommunity.getCode() + "/" + fileNameNew);
|
|
|
+ String featPtr = FaceIdenTool.getFeatPtr(idenRoot,imgFileNew);
|
|
|
+ if (FaceIdenTool.isBad(featPtr)){
|
|
|
+ File discardDir = new File(imgFileNew.getParentFile().getAbsolutePath().replace("final","discard"));
|
|
|
+ if(!discardDir.exists()){
|
|
|
+ discardDir.mkdirs();
|
|
|
+ }
|
|
|
+ File discardImgFile = new File(discardDir, fileNameNew);
|
|
|
+ imgFileNew.renameTo(discardImgFile);//移动到废弃目录
|
|
|
+ throw new BDException("图像识别失败,请上传正确人脸图像");
|
|
|
+ }
|
|
|
|
|
|
- IdenPerson idenPerson = this.idenPersonService.getById(vo.getId());
|
|
|
- Long communityId = idenPerson.getCommunityId();
|
|
|
- IdenCommunity idenCommunity = this.idenCommunityService.getById(communityId);
|
|
|
+ idenPerson.setFeatPtr(featPtr);
|
|
|
+ // 删除老的文件
|
|
|
+ if(StringUtils.isNotEmpty(oldImage)){
|
|
|
+ String fileNameOld = oldImage.substring(oldImage.lastIndexOf("/"));
|
|
|
+ File imgFileOld = new File(idenRoot + "data/final/person/image/" + idenCommunity.getCode() + "/" + fileNameOld);
|
|
|
+ if(imgFileOld.exists()){
|
|
|
+ imgFileOld.delete();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- //保存人员
|
|
|
- String oldImage = idenPerson.getImage();
|
|
|
- BeanUtil.copyProperties(vo,idenPerson);
|
|
|
- String newImage = vo.getImage();
|
|
|
- if (StringUtils.isNotEmpty(newImage) && !newImage.equals(oldImage)){
|
|
|
- //识别
|
|
|
- String fileNameNew = newImage.substring(newImage.lastIndexOf("/"));
|
|
|
- File imgFileNew = new File(idenRoot + "data/final/person/image/" + idenCommunity.getCode() + "/" + fileNameNew);
|
|
|
- String featPtr = FaceIdenTool.getFeatPtr(idenRoot,imgFileNew);
|
|
|
- if (FaceIdenTool.isBad(featPtr)){
|
|
|
- File discardDir = new File(imgFileNew.getParentFile().getAbsolutePath().replace("final","discard"));
|
|
|
- if(!discardDir.exists()){
|
|
|
- discardDir.mkdirs();
|
|
|
}
|
|
|
- File discardImgFile = new File(discardDir, fileNameNew);
|
|
|
- imgFileNew.renameTo(discardImgFile);//移动到废弃目录
|
|
|
- throw new BDException("图像识别失败,请上传正确人脸图像");
|
|
|
- }
|
|
|
+ idenPerson.setModifyTime(new Date());
|
|
|
|
|
|
- idenPerson.setFeatPtr(featPtr);
|
|
|
- // 删除老的文件
|
|
|
- if(StringUtils.isNotEmpty(oldImage)){
|
|
|
- String fileNameOld = oldImage.substring(oldImage.lastIndexOf("/"));
|
|
|
- File imgFileOld = new File(idenRoot + "data/final/person/image/" + idenCommunity.getCode() + "/" + fileNameOld);
|
|
|
- if(imgFileOld.exists()){
|
|
|
- imgFileOld.delete();
|
|
|
- }
|
|
|
- }
|
|
|
+ this.idenPersonService.updateById(idenPerson);
|
|
|
|
|
|
+ reloadFaceDataset();
|
|
|
+ } else {
|
|
|
+ throw new BDException("不能多人同时修改,稍后再试");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.getMessage();
|
|
|
+ } finally {
|
|
|
+ redisUtil.releaseLock(key,requestId);
|
|
|
}
|
|
|
- idenPerson.setModifyTime(new Date());
|
|
|
-
|
|
|
- this.idenPersonService.updateById(idenPerson);
|
|
|
-
|
|
|
- reloadFaceDataset();
|
|
|
|
|
|
}
|
|
|
|
|
@@ -817,16 +854,5 @@ public class PersonService {
|
|
|
return featPtr;
|
|
|
|
|
|
}
|
|
|
- /**
|
|
|
- * 根据图像文件名称得到IdenPerson
|
|
|
- * @param imageFileName
|
|
|
- * @return
|
|
|
- */
|
|
|
- public IdenPerson getPersonIdByImageFileName(String imageFileName){
|
|
|
|
|
|
- QueryWrapper<IdenPerson> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.lambda().like(IdenPerson::getImage,imageFileName);
|
|
|
- IdenPerson idenPerson = idenPersonService.getOne(queryWrapper);
|
|
|
- return idenPerson;
|
|
|
- }
|
|
|
}
|