diff --git a/bonus-modules/bonus-bracelet/src/main/java/com/bonus/bracelet/service/impl/PersonMgeServiceImpl.java b/bonus-modules/bonus-bracelet/src/main/java/com/bonus/bracelet/service/impl/PersonMgeServiceImpl.java index e15c7b7..5633b4a 100644 --- a/bonus-modules/bonus-bracelet/src/main/java/com/bonus/bracelet/service/impl/PersonMgeServiceImpl.java +++ b/bonus-modules/bonus-bracelet/src/main/java/com/bonus/bracelet/service/impl/PersonMgeServiceImpl.java @@ -186,7 +186,7 @@ public class PersonMgeServiceImpl implements IPersonMgeService { // 添加人脸照片至人脸库 AjaxResult ajaxResult = addFaceToLibrary(BytesToMultipartFileUtil.multipartFileToBase64(file), FaceCodeUtil.ADD, "bz-" + vo.getId()); if(ajaxResult.get("data") == null){ - throw new ServiceException("人脸照片未检测到人脸"); + throw new ServiceException(String.valueOf(ajaxResult.get("msg"))); } JSONObject data = JSONObject.parseObject(JSONObject.toJSONString(ajaxResult.get("data"))); Integer code = data.getInteger("code"); @@ -199,14 +199,14 @@ public class PersonMgeServiceImpl implements IPersonMgeService { } } catch (Exception e) { log.error("新增人员", e); + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); // 添加失败-删除文件 if (delFileId != null) { remoteFileService.delFile(delFileId, SecurityConstants.INNER); } - if(Objects.equals(e.getMessage(),"人脸照片未检测到人脸")){ - return AjaxResult.error("人脸照片未检测到人脸"); + if (e instanceof ServiceException) { + return AjaxResult.error(e.getMessage()); } - TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); return AjaxResult.error(); } return AjaxResult.success(); @@ -274,7 +274,7 @@ public class PersonMgeServiceImpl implements IPersonMgeService { } AjaxResult ajaxResult = addFaceToLibrary(BytesToMultipartFileUtil.multipartFileToBase64(file), FaceCodeUtil.ADD, "bz-" + vo.getId()); if(ajaxResult.get("data") == null){ - throw new ServiceException("人脸照片未检测到人脸"); + throw new ServiceException(String.valueOf(ajaxResult.get("msg"))); } JSONObject data = JSONObject.parseObject(JSONObject.toJSONString(ajaxResult.get("data"))); Integer code = data.getInteger("code"); @@ -288,14 +288,14 @@ public class PersonMgeServiceImpl implements IPersonMgeService { } } catch (Exception e) { log.error("修改人员", e); + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); // 添加失败-删除文件 if (StringUtils.isNotEmpty(delFileId)) { remoteFileService.delFile(delFileId, SecurityConstants.INNER); } - if(Objects.equals(e.getMessage(),"人脸照片未检测到人脸")){ - return AjaxResult.error("人脸照片未检测到人脸"); + if (e instanceof ServiceException) { + return AjaxResult.error(e.getMessage()); } - TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); return AjaxResult.error(); } return AjaxResult.success(); @@ -514,7 +514,8 @@ public class PersonMgeServiceImpl implements IPersonMgeService { // 推送人脸照片到人脸库,并更新推送状态 AjaxResult ajaxResult = addFaceToLibrary(BytesToMultipartFileUtil.multipartFileToBase64(vo.getFile()), FaceCodeUtil.ADD, "bz-" + vo.getId()); if(ajaxResult.get("data") == null){ - throw new ServiceException("第" + vo.getSerialNumber() +"人脸照片未检测到人脸"); + throw new ServiceException(String.valueOf(ajaxResult.get("msg"))); +// throw new ServiceException("第" + vo.getSerialNumber() +"人脸照片未检测到人脸"); } JSONObject data = JSONObject.parseObject(JSONObject.toJSONString(ajaxResult.get("data"))); Integer code = data.getInteger("code"); @@ -536,6 +537,7 @@ public class PersonMgeServiceImpl implements IPersonMgeService { return AjaxResult.error(runtimeException.getMessage()); } catch (Exception e) { log.error(e.toString(), e); + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); // 添加失败-删除文件、删除人脸库照片 if (CollectionUtils.isNotEmpty(errorFileLists)) { for (int i = 0; i < errorFileLists.size(); i++) { @@ -543,10 +545,12 @@ public class PersonMgeServiceImpl implements IPersonMgeService { delFaceToLibrary(null, FaceCodeUtil.DEL, errorIdLists.get(i)); } } - if(e.getMessage().contains("人脸照片未检测到人脸")){ + if (e instanceof ServiceException) { return AjaxResult.error(e.getMessage()); } - TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + /*if(e.getMessage().contains("人脸照片未检测到人脸")){ + return AjaxResult.error(e.getMessage()); + }*/ return AjaxResult.error(); } return AjaxResult.success();