|
@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.iden.bms.face.FaceIdenTool;
|
|
import com.iden.bms.face.FaceIdenTool;
|
|
|
|
+import com.iden.common.entity.IdenCommunity;
|
|
import com.iden.common.entity.IdenCrowd;
|
|
import com.iden.common.entity.IdenCrowd;
|
|
import com.iden.common.entity.IdenPerson;
|
|
import com.iden.common.entity.IdenPerson;
|
|
|
|
|
|
@@ -14,6 +15,7 @@ import com.iden.common.entity.IdenPersonCrowdRef;
|
|
import com.iden.common.enums.PersonTypeEnum;
|
|
import com.iden.common.enums.PersonTypeEnum;
|
|
import com.iden.common.enums.PopulationTypeEnum;
|
|
import com.iden.common.enums.PopulationTypeEnum;
|
|
import com.iden.common.exception.BDException;
|
|
import com.iden.common.exception.BDException;
|
|
|
|
+import com.iden.common.service.IdenCommunityService;
|
|
import com.iden.common.service.IdenCrowdService;
|
|
import com.iden.common.service.IdenCrowdService;
|
|
import com.iden.common.service.IdenPersonCrowdRefService;
|
|
import com.iden.common.service.IdenPersonCrowdRefService;
|
|
import com.iden.common.service.IdenPersonService;
|
|
import com.iden.common.service.IdenPersonService;
|
|
@@ -51,6 +53,8 @@ public class PersonService {
|
|
private IdenPersonCrowdRefService idenPersonCrowdRefService;
|
|
private IdenPersonCrowdRefService idenPersonCrowdRefService;
|
|
@Resource
|
|
@Resource
|
|
private IdenCrowdService idenCrowdService;
|
|
private IdenCrowdService idenCrowdService;
|
|
|
|
+ @Resource
|
|
|
|
+ private IdenCommunityService idenCommunityService;
|
|
|
|
|
|
@Value("${iden.root:#{null}}")
|
|
@Value("${iden.root:#{null}}")
|
|
private String idenRoot;
|
|
private String idenRoot;
|
|
@@ -212,7 +216,15 @@ public class PersonService {
|
|
* @param file
|
|
* @param file
|
|
* @return 访问URL
|
|
* @return 访问URL
|
|
*/
|
|
*/
|
|
- public String uploadImage(MultipartFile file) throws BDException {
|
|
|
|
|
|
+ public String uploadImage(MultipartFile file,Long communityId) throws BDException {
|
|
|
|
+ if(communityId == null ){
|
|
|
|
+ throw new BDException("必须选择小区");
|
|
|
|
+ }
|
|
|
|
+ IdenCommunity idenCommunity = this.idenCommunityService.getById(communityId);
|
|
|
|
+ if(idenCommunity == null ){
|
|
|
|
+ throw new BDException("小区不能为空");
|
|
|
|
+ }
|
|
|
|
+
|
|
String image = null;
|
|
String image = null;
|
|
try {
|
|
try {
|
|
if (file != null) {
|
|
if (file != null) {
|
|
@@ -225,8 +237,9 @@ public class PersonService {
|
|
if (!ImgUtil.isImg(fileName)) {
|
|
if (!ImgUtil.isImg(fileName)) {
|
|
throw new BDException("图像文件必须是图片格式!");
|
|
throw new BDException("图像文件必须是图片格式!");
|
|
}
|
|
}
|
|
|
|
+
|
|
String saveFileName = DateUtils.getCurrYyyyMMddHHmmssDate() + "_" + UUID.randomUUID().toString() + fileName.substring(fileName.lastIndexOf("."), fileName.length());
|
|
String saveFileName = DateUtils.getCurrYyyyMMddHHmmssDate() + "_" + UUID.randomUUID().toString() + fileName.substring(fileName.lastIndexOf("."), fileName.length());
|
|
- String picFullFileName = idenRoot + "data/final/person/" + saveFileName;
|
|
|
|
|
|
+ String picFullFileName = idenRoot + "data/final/person/" + idenCommunity.getCode() + "/" + saveFileName;
|
|
FileOutputStream fos = new FileOutputStream(picFullFileName);
|
|
FileOutputStream fos = new FileOutputStream(picFullFileName);
|
|
fos.write(file.getBytes());
|
|
fos.write(file.getBytes());
|
|
image = fileUrl + "person/" + saveFileName;
|
|
image = fileUrl + "person/" + saveFileName;
|
|
@@ -247,8 +260,15 @@ public class PersonService {
|
|
* @param vo
|
|
* @param vo
|
|
*/
|
|
*/
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
- public int createPerson(PersonVO vo, UserLoginedConvertVO loginUser){
|
|
|
|
-
|
|
|
|
|
|
+ public void createPerson(PersonVO vo, UserLoginedConvertVO loginUser) throws BDException {
|
|
|
|
+ Long communityId = vo.getCommunityId();
|
|
|
|
+ if(communityId == null ){
|
|
|
|
+ throw new BDException("必须选择小区");
|
|
|
|
+ }
|
|
|
|
+ IdenCommunity idenCommunity = this.idenCommunityService.getById(communityId);
|
|
|
|
+ if(idenCommunity == null ){
|
|
|
|
+ throw new BDException("小区不能为空");
|
|
|
|
+ }
|
|
//保存人员
|
|
//保存人员
|
|
IdenPerson idenPerson = new IdenPerson();
|
|
IdenPerson idenPerson = new IdenPerson();
|
|
BeanUtil.copyProperties(vo,idenPerson);
|
|
BeanUtil.copyProperties(vo,idenPerson);
|
|
@@ -258,13 +278,22 @@ public class PersonService {
|
|
String image = idenPerson.getImage();
|
|
String image = idenPerson.getImage();
|
|
if(StringUtils.isNotEmpty(image)){
|
|
if(StringUtils.isNotEmpty(image)){
|
|
String fileName = image.substring(image.lastIndexOf("/"));
|
|
String fileName = image.substring(image.lastIndexOf("/"));
|
|
- File imgFile = new File(idenRoot + "data/final/person/" + fileName);
|
|
|
|
|
|
+ File imgFile = new File(idenRoot + "data/final/person/"+ idenCommunity.getCode() + "/" + fileName);
|
|
String featPtr = FaceIdenTool.getFeatPtr(idenRoot,imgFile);
|
|
String featPtr = FaceIdenTool.getFeatPtr(idenRoot,imgFile);
|
|
|
|
+ if (FaceIdenTool.isBad(featPtr)) {
|
|
|
|
+ File discardDir = new File(imgFile.getParentFile().getAbsolutePath().replace("final","discard"));
|
|
|
|
+ if(!discardDir.exists()){
|
|
|
|
+ discardDir.mkdirs();
|
|
|
|
+ }
|
|
|
|
+ File discardImgFile = new File(discardDir, fileName);
|
|
|
|
+ imgFile.renameTo(discardImgFile);//移动到废弃目录
|
|
|
|
+ throw new BDException("图像识别失败,请上传正确人脸图像");
|
|
|
|
+ }
|
|
idenPerson.setFeatPtr(featPtr);
|
|
idenPerson.setFeatPtr(featPtr);
|
|
}
|
|
}
|
|
|
|
|
|
this.idenPersonService.save(idenPerson);
|
|
this.idenPersonService.save(idenPerson);
|
|
- return 0;
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -272,7 +301,15 @@ public class PersonService {
|
|
* @param vo
|
|
* @param vo
|
|
*/
|
|
*/
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
- public void updatePerson(PersonVO vo){
|
|
|
|
|
|
+ public void updatePerson(PersonVO vo) throws BDException {
|
|
|
|
+ Long communityId = vo.getCommunityId();
|
|
|
|
+ if(communityId == null ){
|
|
|
|
+ throw new BDException("必须选择小区");
|
|
|
|
+ }
|
|
|
|
+ IdenCommunity idenCommunity = this.idenCommunityService.getById(communityId);
|
|
|
|
+ if(idenCommunity == null ){
|
|
|
|
+ throw new BDException("小区不能为空");
|
|
|
|
+ }
|
|
//保存人员
|
|
//保存人员
|
|
IdenPerson idenPerson = new IdenPerson();
|
|
IdenPerson idenPerson = new IdenPerson();
|
|
String oldImage = idenPerson.getImage();
|
|
String oldImage = idenPerson.getImage();
|
|
@@ -281,13 +318,23 @@ public class PersonService {
|
|
if (StringUtils.isNotEmpty(newImage) && !newImage.equals(oldImage)){
|
|
if (StringUtils.isNotEmpty(newImage) && !newImage.equals(oldImage)){
|
|
//识别
|
|
//识别
|
|
String fileNameNew = newImage.substring(newImage.lastIndexOf("/"));
|
|
String fileNameNew = newImage.substring(newImage.lastIndexOf("/"));
|
|
- File imgFileNew = new File(idenRoot + "data/final/person/" + fileNameNew);
|
|
|
|
|
|
+ File imgFileNew = new File(idenRoot + "data/final/person/" + idenCommunity.getCode() + "/" + fileNameNew);
|
|
String featPtr = FaceIdenTool.getFeatPtr(idenRoot,imgFileNew);
|
|
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.setFeatPtr(featPtr);
|
|
idenPerson.setFeatPtr(featPtr);
|
|
// 删除老的文件
|
|
// 删除老的文件
|
|
if(StringUtils.isNotEmpty(oldImage)){
|
|
if(StringUtils.isNotEmpty(oldImage)){
|
|
String fileNameOld = oldImage.substring(oldImage.lastIndexOf("/"));
|
|
String fileNameOld = oldImage.substring(oldImage.lastIndexOf("/"));
|
|
- File imgFileOld = new File(idenRoot + "data/final/person/" + fileNameOld);
|
|
|
|
|
|
+ File imgFileOld = new File(idenRoot + "data/final/person/" + idenCommunity.getCode() + "/" + fileNameOld);
|
|
if(imgFileOld.exists()){
|
|
if(imgFileOld.exists()){
|
|
imgFileOld.delete();
|
|
imgFileOld.delete();
|
|
}
|
|
}
|