添加人像
parent
fcebcdb78d
commit
a1fc93e59c
|
@ -33,5 +33,5 @@ public interface FaceLibraryMapper extends BaseMapper<FaceLibrary> {
|
||||||
*/
|
*/
|
||||||
Integer getLibraryCount(@Param("idFactory") Long idFactory);
|
Integer getLibraryCount(@Param("idFactory") Long idFactory);
|
||||||
|
|
||||||
FaceLibrary getLibrary(@Param("factoryName") String factoryName);
|
FaceLibrary getLibraryByFactoryName(@Param("factoryName") String factoryName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class FaceLibraryServiceImpl extends ServiceImpl<FaceLibraryMapper, FaceL
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public FaceLibrary addLibrary(FaceLibrary faceLibrary) {
|
public FaceLibrary addLibrary(FaceLibrary faceLibrary) {
|
||||||
try {
|
try {
|
||||||
if (faceLibraryMapper.getLibrary(faceLibrary.getFactoryName()) != null) {
|
if (faceLibraryMapper.getLibraryByFactoryName(faceLibrary.getFactoryName()) != null) {
|
||||||
throw new DkException("库名称已存在");
|
throw new DkException("库名称已存在");
|
||||||
}
|
}
|
||||||
FaceLibraryVO faceLibraryVO = new FaceLibraryVO();
|
FaceLibraryVO faceLibraryVO = new FaceLibraryVO();
|
||||||
|
@ -93,35 +93,37 @@ public class FaceLibraryServiceImpl extends ServiceImpl<FaceLibraryMapper, FaceL
|
||||||
faceLibrary.setIsValid(YNEnums.NO.code);
|
faceLibrary.setIsValid(YNEnums.NO.code);
|
||||||
faceLibrary.setIdFactory(libraryId);
|
faceLibrary.setIdFactory(libraryId);
|
||||||
try {
|
try {
|
||||||
|
ApiVO faceLibrary1 = (ApiVO) httpUtil.delete(link + ApiUrlEnum.FACELIB_POSTURL.getUrl() + "/" + libraryId, ApiVO.class);
|
||||||
ApiVO faceLibrary1 = (ApiVO) httpUtil.delete(link+ ApiUrlEnum.FACELIB_POSTURL.getUrl()+"/"+String.valueOf(libraryId), ApiVO.class);
|
if (! faceLibrary1.getCode().equals(200)) {
|
||||||
|
throw new DkException("删除库失败, " + faceLibrary1.getMessage());
|
||||||
|
}
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
throw new DkException("删除库失败");
|
throw new DkException(e.getMessage());
|
||||||
}
|
}
|
||||||
/**调用API*/
|
/**调用API*/
|
||||||
Integer integer = controlLibraryMidMapper.selectByLibID(String.valueOf(libraryId), YNEnums.YES.code);
|
Integer integer = controlLibraryMidMapper.selectByLibID(String.valueOf(libraryId), YNEnums.YES.code);
|
||||||
if(integer<=0) {
|
if(integer<=0) {
|
||||||
int count = faceLibraryMapper.deleteById(faceLibrary);
|
int count = faceLibraryMapper.deleteById(faceLibrary);
|
||||||
/**删除对应的人像*/
|
/**删除对应的人像*/
|
||||||
List<Portrait> portraits = portraitMapper.queryPortraitByFactory(libraryId);
|
List<Portrait> portraits = portraitMapper.queryPortraitByFactory(libraryId);
|
||||||
portraitMapper.deletePortrait(libraryId);
|
portraitMapper.deletePortrait(libraryId);
|
||||||
if(UtilValidate.isNotEmpty(portraits)){
|
if(UtilValidate.isNotEmpty(portraits)){
|
||||||
for (Portrait p:portraits) {
|
for (Portrait p:portraits) {
|
||||||
/**删除文件服务器*/
|
/**删除文件服务器*/
|
||||||
try {
|
try {
|
||||||
minioUtil.removeObject(bucketName,p.getUrl());
|
minioUtil.removeObject(bucketName,p.getUrl());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage());
|
log.error(e.getMessage());
|
||||||
//throw new DkException("文件服务器图片删除失败");
|
//throw new DkException("文件服务器图片删除失败");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (count < 0) {
|
|
||||||
throw new DkException("删除库失败");
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
throw new DkException(SystemCode.DELETELIB_ERROR.code,"该库有关联的布控信息,不能删除!");
|
|
||||||
}
|
}
|
||||||
|
if (count < 0) {
|
||||||
|
throw new DkException("删除库失败");
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
throw new DkException(SystemCode.DELETELIB_ERROR.code,"该库有关联的布控信息,不能删除!");
|
||||||
|
}
|
||||||
|
|
||||||
return faceLibrary;
|
return faceLibrary;
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,22 +72,18 @@ public class PortraitServiceImpl extends ServiceImpl<PortraitMapper, Portrait> i
|
||||||
public Portrait addPortrait(String libraryId, MultipartFile multipartFile) {
|
public Portrait addPortrait(String libraryId, MultipartFile multipartFile) {
|
||||||
/**保存数据*/
|
/**保存数据*/
|
||||||
Portrait portrait;
|
Portrait portrait;
|
||||||
String[] identityMessage = new String[2];
|
String filename;
|
||||||
String multipartFileName = multipartFile.getOriginalFilename();
|
String multipartFileName = multipartFile.getOriginalFilename();
|
||||||
if (UtilValidate.isNotEmpty(multipartFileName)) {
|
if (UtilValidate.isNotEmpty(multipartFileName)) {
|
||||||
boolean status = multipartFileName.contains("_");
|
filename = multipartFileName.substring(0, multipartFileName.lastIndexOf("."));
|
||||||
if (status) {
|
} else {
|
||||||
String filename = multipartFileName.substring(0, multipartFileName.lastIndexOf("."));
|
throw new DkException(SystemCode.FILE_ERROR.code, multipartFileName + "文件名格式不正确");
|
||||||
identityMessage = filename.split("_");
|
|
||||||
} else {
|
|
||||||
throw new DkException(SystemCode.FILE_ERROR.code, multipartFileName + "文件名格式不正确");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ImagesVO imageVO = new ImagesVO();
|
ImagesVO imageVO = new ImagesVO();
|
||||||
setimageVO(imageVO, identityMessage);
|
setimageVO(imageVO, filename);
|
||||||
try {
|
try {
|
||||||
String card = imageVO.getIdCard();
|
String name = imageVO.getName();
|
||||||
int hash = card.hashCode();
|
int hash = name.hashCode();
|
||||||
if (hash < 0) {
|
if (hash < 0) {
|
||||||
hash = 0 - hash;
|
hash = 0 - hash;
|
||||||
}
|
}
|
||||||
|
@ -103,12 +99,8 @@ public class PortraitServiceImpl extends ServiceImpl<PortraitMapper, Portrait> i
|
||||||
/**调用微云新增人像*/
|
/**调用微云新增人像*/
|
||||||
ApiVO face = (ApiVO) httpUtil.post(link + ApiUrlEnum.FACE_POSTURL.getUrl(), imageVO, ApiVO.class);
|
ApiVO face = (ApiVO) httpUtil.post(link + ApiUrlEnum.FACE_POSTURL.getUrl(), imageVO, ApiVO.class);
|
||||||
String json = gson.toJson(face.getData());
|
String json = gson.toJson(face.getData());
|
||||||
ImageReturnVO imageReturnVO = null;
|
if (UtilValidate.isNotEmpty(face) && face.getCode().equals(200)) {
|
||||||
if (UtilValidate.isNotEmpty(json)) {
|
portrait = save(null, imageVO);
|
||||||
imageReturnVO = gson.fromJson(json, ImageReturnVO.class);
|
|
||||||
}
|
|
||||||
if (UtilValidate.isNotEmpty(imageReturnVO)) {
|
|
||||||
portrait = save(imageReturnVO, imageVO);
|
|
||||||
} else {
|
} else {
|
||||||
throw new DkException(SystemCode.FACESRH_ERROR.code, face.getMessage());
|
throw new DkException(SystemCode.FACESRH_ERROR.code, face.getMessage());
|
||||||
}
|
}
|
||||||
|
@ -225,7 +217,7 @@ public class PortraitServiceImpl extends ServiceImpl<PortraitMapper, Portrait> i
|
||||||
}
|
}
|
||||||
/**文件名:身份证_姓名*/
|
/**文件名:身份证_姓名*/
|
||||||
ImagesVO imageVO = new ImagesVO();
|
ImagesVO imageVO = new ImagesVO();
|
||||||
setimageVO(imageVO, message);
|
// setimageVO(imageVO, message);
|
||||||
imageVO.setUrl(map.get("url").toString());
|
imageVO.setUrl(map.get("url").toString());
|
||||||
List<ImageVO> faces = new ArrayList<>();
|
List<ImageVO> faces = new ArrayList<>();
|
||||||
//faces.add(imageVO);
|
//faces.add(imageVO);
|
||||||
|
@ -381,45 +373,44 @@ public class PortraitServiceImpl extends ServiceImpl<PortraitMapper, Portrait> i
|
||||||
*/
|
*/
|
||||||
public Portrait save(ImageReturnVO imageReturnVO, ImagesVO imageVO) {
|
public Portrait save(ImageReturnVO imageReturnVO, ImagesVO imageVO) {
|
||||||
Portrait portrait = new Portrait();
|
Portrait portrait = new Portrait();
|
||||||
/**id*/
|
portrait.setIdPortrait(Long.parseLong(imageVO.getFaceId()));
|
||||||
if (UtilValidate.isNotEmpty(imageReturnVO.getFaceId())) {
|
portrait.setFeatId(imageReturnVO.getIdFaceid());
|
||||||
portrait.setIdPortrait(Long.parseLong(imageReturnVO.getFaceId()));
|
portrait.setFaceIds(imageReturnVO.getFaceId());
|
||||||
}
|
portrait.setName(imageVO.getName());
|
||||||
//人脸ID
|
portrait.setIdFactory(Long.parseLong(imageVO.getLibraryId()));
|
||||||
if (UtilValidate.isNotEmpty(imageReturnVO.getIdFaceid())) {
|
portrait.setUrl(imageVO.getUrl());
|
||||||
portrait.setFeatId(imageReturnVO.getIdFaceid());
|
|
||||||
}
|
|
||||||
if (UtilValidate.isNotEmpty(imageReturnVO.getFace())) {
|
|
||||||
/**背景地址*/
|
|
||||||
if (UtilValidate.isNotEmpty(imageReturnVO.getFace().getUrl())) {
|
|
||||||
portrait.setBackgroundUrl(imageReturnVO.getFace().getUrl());
|
|
||||||
}
|
|
||||||
/**人脸地址*/
|
|
||||||
if (UtilValidate.isNotEmpty(imageReturnVO.getFace().getFaceUrl())) {
|
|
||||||
portrait.setUrl(imageReturnVO.getFace().getFaceUrl());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (UtilValidate.isNotEmpty(imageReturnVO.getLibraryId())) {
|
// if (UtilValidate.isNotEmpty(imageReturnVO.getFace())) {
|
||||||
portrait.setIdFactory(Long.parseLong(imageReturnVO.getLibraryId()));
|
// /**背景地址*/
|
||||||
}
|
// if (UtilValidate.isNotEmpty(imageReturnVO.getFace().getUrl())) {
|
||||||
|
// portrait.setBackgroundUrl(imageReturnVO.getFace().getUrl());
|
||||||
|
// }
|
||||||
|
// /**人脸地址*/
|
||||||
|
// if (UtilValidate.isNotEmpty(imageReturnVO.getFace().getFaceUrl())) {
|
||||||
|
// portrait.setUrl(imageReturnVO.getFace().getFaceUrl());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if (UtilValidate.isNotEmpty(imageReturnVO.getLibraryId())) {
|
||||||
|
// portrait.setIdFactory(Long.parseLong(imageVO.getLibraryId()));
|
||||||
|
// }
|
||||||
/**出生年月*/
|
/**出生年月*/
|
||||||
if (UtilValidate.isNotEmpty(imageVO.getIdCard())) {
|
// if (UtilValidate.isNotEmpty(imageVO.getIdCard())) {
|
||||||
portrait.setBirthDate(getBirthDate(imageVO.getIdCard()));
|
// portrait.setBirthDate(getBirthDate(imageVO.getIdCard()));
|
||||||
}
|
// }
|
||||||
/**身份证信息*/
|
// /**身份证信息*/
|
||||||
if (UtilValidate.isNotEmpty(imageReturnVO.getFace().getIdCard())) {
|
// if (UtilValidate.isNotEmpty(imageReturnVO.getFace().getIdCard())) {
|
||||||
portrait.setIdCard(imageReturnVO.getFace().getIdCard());
|
// portrait.setIdCard(imageReturnVO.getFace().getIdCard());
|
||||||
}
|
// }
|
||||||
if (UtilValidate.isNotEmpty(imageVO.getName())) {
|
// if (UtilValidate.isNotEmpty(imageVO.getName())) {
|
||||||
portrait.setName(imageVO.getName());
|
//
|
||||||
}
|
// }
|
||||||
if (UtilValidate.isNotEmpty(imageReturnVO.getFaceId())) {
|
// if (UtilValidate.isNotEmpty(imageReturnVO.getFaceId())) {
|
||||||
portrait.setFaceIds(imageReturnVO.getFaceId());
|
// portrait.setFaceIds(imageReturnVO.getFaceId());
|
||||||
}
|
// }
|
||||||
if (UtilValidate.isNotEmpty(imageVO.getGender())) {
|
// if (UtilValidate.isNotEmpty(imageVO.getGender())) {
|
||||||
portrait.setSex(imageVO.getGender());
|
// portrait.setSex(imageVO.getGender());
|
||||||
}
|
// }
|
||||||
portrait.setIsValid(YNEnums.YES.code);
|
portrait.setIsValid(YNEnums.YES.code);
|
||||||
portrait.setCreateTime(new Date());
|
portrait.setCreateTime(new Date());
|
||||||
portrait.setUpdateTime(new Date());
|
portrait.setUpdateTime(new Date());
|
||||||
|
@ -461,22 +452,27 @@ public class PortraitServiceImpl extends ServiceImpl<PortraitMapper, Portrait> i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setimageVO(ImagesVO imageVO, String[] identityMessage) {
|
private void setimageVO(ImagesVO imageVO, String filename) {
|
||||||
if (identityMessage.length > 0) {
|
imageVO.setFaceId(String.valueOf(System.currentTimeMillis()));
|
||||||
/**文件名:身份证_姓名_性别*/
|
imageVO.setName(filename);
|
||||||
if (!IdCardUtil.isValidatedAllIdcard(identityMessage[0])) {
|
|
||||||
throw new DkException(SystemCode.IDCARD_ERROR.code, "身份证号码输入不正确");
|
|
||||||
}
|
|
||||||
if (UtilValidate.isNotEmpty(identityMessage[0])) {
|
|
||||||
setSex(imageVO, identityMessage[0]);
|
|
||||||
imageVO.setIdCard(identityMessage[0]);
|
|
||||||
}
|
|
||||||
if (UtilValidate.isNotEmpty(identityMessage[1])) {
|
|
||||||
imageVO.setName(identityMessage[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public void setimageVO(ImagesVO imageVO, String[] identityMessage) {
|
||||||
|
// if (identityMessage.length > 0) {
|
||||||
|
// /**文件名:身份证_姓名_性别*/
|
||||||
|
// if (!IdCardUtil.isValidatedAllIdcard(identityMessage[0])) {
|
||||||
|
// throw new DkException(SystemCode.IDCARD_ERROR.code, "身份证号码输入不正确");
|
||||||
|
// }
|
||||||
|
// if (UtilValidate.isNotEmpty(identityMessage[0])) {
|
||||||
|
// setSex(imageVO, identityMessage[0]);
|
||||||
|
// imageVO.setIdCard(identityMessage[0]);
|
||||||
|
// }
|
||||||
|
// if (UtilValidate.isNotEmpty(identityMessage[1])) {
|
||||||
|
// imageVO.setName(identityMessage[1]);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SearchResultVo libSearchPage(SearchRequestVo searchRequestVo) {
|
public SearchResultVo libSearchPage(SearchRequestVo searchRequestVo) {
|
||||||
//用户传输图片过来进行检索,调用人脸API
|
//用户传输图片过来进行检索,调用人脸API
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
<select id="getLibraryCount" resultType="java.lang.Integer">
|
<select id="getLibraryCount" resultType="java.lang.Integer">
|
||||||
select COUNT(*) from portrait p where p.is_valid='Y'and p.id_factory= #{idFactory}
|
select COUNT(*) from portrait p where p.is_valid='Y'and p.id_factory= #{idFactory}
|
||||||
</select>
|
</select>
|
||||||
<select id="getLibrary" resultType="com.dkha.server.modules.entities.FaceLibrary">
|
<select id="getLibraryByFactoryName" resultType="com.dkha.server.modules.entities.FaceLibrary">
|
||||||
SELECT
|
SELECT
|
||||||
f.id_factory as idFactory,
|
f.id_factory as idFactory,
|
||||||
f.factory_name as factoryName,
|
f.factory_name as factoryName,
|
||||||
|
@ -33,6 +33,6 @@
|
||||||
FROM
|
FROM
|
||||||
face_library f
|
face_library f
|
||||||
WHERE
|
WHERE
|
||||||
f.id_factory = #{factoryName}
|
f.factory_name = #{factoryName}
|
||||||
</select>
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
Loading…
Reference in New Issue