diff --git a/face-server/src/main/java/com/dkha/server/mappers/FaceLibraryMapper.java b/face-server/src/main/java/com/dkha/server/mappers/FaceLibraryMapper.java index 20e4cd0..2dc158d 100644 --- a/face-server/src/main/java/com/dkha/server/mappers/FaceLibraryMapper.java +++ b/face-server/src/main/java/com/dkha/server/mappers/FaceLibraryMapper.java @@ -33,5 +33,5 @@ public interface FaceLibraryMapper extends BaseMapper { */ Integer getLibraryCount(@Param("idFactory") Long idFactory); - FaceLibrary getLibrary(@Param("factoryName") String factoryName); + FaceLibrary getLibraryByFactoryName(@Param("factoryName") String factoryName); } diff --git a/face-server/src/main/java/com/dkha/server/services/impl/FaceLibraryServiceImpl.java b/face-server/src/main/java/com/dkha/server/services/impl/FaceLibraryServiceImpl.java index 8748909..1a02404 100644 --- a/face-server/src/main/java/com/dkha/server/services/impl/FaceLibraryServiceImpl.java +++ b/face-server/src/main/java/com/dkha/server/services/impl/FaceLibraryServiceImpl.java @@ -67,7 +67,7 @@ public class FaceLibraryServiceImpl extends ServiceImpl portraits = portraitMapper.queryPortraitByFactory(libraryId); - portraitMapper.deletePortrait(libraryId); - if(UtilValidate.isNotEmpty(portraits)){ - for (Portrait p:portraits) { - /**删除文件服务器*/ - try { - minioUtil.removeObject(bucketName,p.getUrl()); - } catch (Exception e) { - log.error(e.getMessage()); - //throw new DkException("文件服务器图片删除失败"); - } + /**调用API*/ + Integer integer = controlLibraryMidMapper.selectByLibID(String.valueOf(libraryId), YNEnums.YES.code); + if(integer<=0) { + int count = faceLibraryMapper.deleteById(faceLibrary); + /**删除对应的人像*/ + List portraits = portraitMapper.queryPortraitByFactory(libraryId); + portraitMapper.deletePortrait(libraryId); + if(UtilValidate.isNotEmpty(portraits)){ + for (Portrait p:portraits) { + /**删除文件服务器*/ + try { + minioUtil.removeObject(bucketName,p.getUrl()); + } catch (Exception e) { + log.error(e.getMessage()); + //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; } diff --git a/face-server/src/main/java/com/dkha/server/services/impl/PortraitServiceImpl.java b/face-server/src/main/java/com/dkha/server/services/impl/PortraitServiceImpl.java index 952b915..9b651d9 100644 --- a/face-server/src/main/java/com/dkha/server/services/impl/PortraitServiceImpl.java +++ b/face-server/src/main/java/com/dkha/server/services/impl/PortraitServiceImpl.java @@ -72,22 +72,18 @@ public class PortraitServiceImpl extends ServiceImpl i public Portrait addPortrait(String libraryId, MultipartFile multipartFile) { /**保存数据*/ Portrait portrait; - String[] identityMessage = new String[2]; + String filename; String multipartFileName = multipartFile.getOriginalFilename(); if (UtilValidate.isNotEmpty(multipartFileName)) { - boolean status = multipartFileName.contains("_"); - if (status) { - String filename = multipartFileName.substring(0, multipartFileName.lastIndexOf(".")); - identityMessage = filename.split("_"); - } else { - throw new DkException(SystemCode.FILE_ERROR.code, multipartFileName + "文件名格式不正确"); - } + filename = multipartFileName.substring(0, multipartFileName.lastIndexOf(".")); + } else { + throw new DkException(SystemCode.FILE_ERROR.code, multipartFileName + "文件名格式不正确"); } ImagesVO imageVO = new ImagesVO(); - setimageVO(imageVO, identityMessage); + setimageVO(imageVO, filename); try { - String card = imageVO.getIdCard(); - int hash = card.hashCode(); + String name = imageVO.getName(); + int hash = name.hashCode(); if (hash < 0) { hash = 0 - hash; } @@ -103,12 +99,8 @@ public class PortraitServiceImpl extends ServiceImpl i /**调用微云新增人像*/ ApiVO face = (ApiVO) httpUtil.post(link + ApiUrlEnum.FACE_POSTURL.getUrl(), imageVO, ApiVO.class); String json = gson.toJson(face.getData()); - ImageReturnVO imageReturnVO = null; - if (UtilValidate.isNotEmpty(json)) { - imageReturnVO = gson.fromJson(json, ImageReturnVO.class); - } - if (UtilValidate.isNotEmpty(imageReturnVO)) { - portrait = save(imageReturnVO, imageVO); + if (UtilValidate.isNotEmpty(face) && face.getCode().equals(200)) { + portrait = save(null, imageVO); } else { throw new DkException(SystemCode.FACESRH_ERROR.code, face.getMessage()); } @@ -225,7 +217,7 @@ public class PortraitServiceImpl extends ServiceImpl i } /**文件名:身份证_姓名*/ ImagesVO imageVO = new ImagesVO(); - setimageVO(imageVO, message); +// setimageVO(imageVO, message); imageVO.setUrl(map.get("url").toString()); List faces = new ArrayList<>(); //faces.add(imageVO); @@ -381,45 +373,44 @@ public class PortraitServiceImpl extends ServiceImpl i */ public Portrait save(ImageReturnVO imageReturnVO, ImagesVO imageVO) { Portrait portrait = new Portrait(); - /**id*/ - if (UtilValidate.isNotEmpty(imageReturnVO.getFaceId())) { - portrait.setIdPortrait(Long.parseLong(imageReturnVO.getFaceId())); - } - //人脸ID - if (UtilValidate.isNotEmpty(imageReturnVO.getIdFaceid())) { - 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()); - } - } + portrait.setIdPortrait(Long.parseLong(imageVO.getFaceId())); + portrait.setFeatId(imageReturnVO.getIdFaceid()); + portrait.setFaceIds(imageReturnVO.getFaceId()); + portrait.setName(imageVO.getName()); + portrait.setIdFactory(Long.parseLong(imageVO.getLibraryId())); + portrait.setUrl(imageVO.getUrl()); - if (UtilValidate.isNotEmpty(imageReturnVO.getLibraryId())) { - portrait.setIdFactory(Long.parseLong(imageReturnVO.getLibraryId())); - } +// 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())) { +// portrait.setIdFactory(Long.parseLong(imageVO.getLibraryId())); +// } /**出生年月*/ - if (UtilValidate.isNotEmpty(imageVO.getIdCard())) { - portrait.setBirthDate(getBirthDate(imageVO.getIdCard())); - } - /**身份证信息*/ - if (UtilValidate.isNotEmpty(imageReturnVO.getFace().getIdCard())) { - portrait.setIdCard(imageReturnVO.getFace().getIdCard()); - } - if (UtilValidate.isNotEmpty(imageVO.getName())) { - portrait.setName(imageVO.getName()); - } - if (UtilValidate.isNotEmpty(imageReturnVO.getFaceId())) { - portrait.setFaceIds(imageReturnVO.getFaceId()); - } - if (UtilValidate.isNotEmpty(imageVO.getGender())) { - portrait.setSex(imageVO.getGender()); - } +// if (UtilValidate.isNotEmpty(imageVO.getIdCard())) { +// portrait.setBirthDate(getBirthDate(imageVO.getIdCard())); +// } +// /**身份证信息*/ +// if (UtilValidate.isNotEmpty(imageReturnVO.getFace().getIdCard())) { +// portrait.setIdCard(imageReturnVO.getFace().getIdCard()); +// } +// if (UtilValidate.isNotEmpty(imageVO.getName())) { +// +// } +// if (UtilValidate.isNotEmpty(imageReturnVO.getFaceId())) { +// portrait.setFaceIds(imageReturnVO.getFaceId()); +// } +// if (UtilValidate.isNotEmpty(imageVO.getGender())) { +// portrait.setSex(imageVO.getGender()); +// } portrait.setIsValid(YNEnums.YES.code); portrait.setCreateTime(new Date()); portrait.setUpdateTime(new Date()); @@ -461,22 +452,27 @@ public class PortraitServiceImpl extends ServiceImpl i } } - 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]); - } - } + private void setimageVO(ImagesVO imageVO, String filename) { + imageVO.setFaceId(String.valueOf(System.currentTimeMillis())); + imageVO.setName(filename); } +// 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 public SearchResultVo libSearchPage(SearchRequestVo searchRequestVo) { //用户传输图片过来进行检索,调用人脸API diff --git a/face-server/src/main/resources/mybatis/mapper/FaceLibraryMapper.xml b/face-server/src/main/resources/mybatis/mapper/FaceLibraryMapper.xml index 2071efc..c5e1adb 100644 --- a/face-server/src/main/resources/mybatis/mapper/FaceLibraryMapper.xml +++ b/face-server/src/main/resources/mybatis/mapper/FaceLibraryMapper.xml @@ -23,7 +23,7 @@ - SELECT f.id_factory as idFactory, f.factory_name as factoryName, @@ -33,6 +33,6 @@ FROM face_library f WHERE - f.id_factory = #{factoryName} + f.factory_name = #{factoryName}