人员管理接口修改

This commit is contained in:
cwchen 2024-08-12 14:47:11 +08:00
parent c7e93f9fd5
commit 160ecc1d8d
3 changed files with 83 additions and 11 deletions

View File

@ -83,6 +83,13 @@ public class PersonMgeController extends BaseController {
return service.delPerson(dto);
}
// @RequiresPermissions("basic:person:push")
@PostMapping("pushFace")
@SysLog(title = "人员管理", businessType = OperaType.DELETE,logType = 0,module = "基础管理->人员管理",details ="推送人脸库" )
public AjaxResult pushFace(@RequestBody BraceletParamsDto dto) {
return service.pushFace(dto);
}
@PostMapping("excelUpload")
// @RequiresPermissions("basic:person:excelUpload")
@SysLog(title = "人员管理", businessType = OperaType.IMPORT,logType = 0,module = "基础管理->人员管理",details ="人员导入" )

View File

@ -100,4 +100,13 @@ public interface IPersonMgeService {
* @date 2024/8/9 8:51
*/
List<PersonVo> getExportPersonLists(BraceletParamsDto dto);
/**
* 推送人脸照片到人脸库
* @param dto
* @return AjaxResult
* @author cwchen
* @date 2024/8/12 14:11
*/
AjaxResult pushFace(BraceletParamsDto dto);
}

View File

@ -220,14 +220,13 @@ public class PersonMgeServiceImpl implements IPersonMgeService {
resourceFileMapper.delResourceFile(vo.getFileId());
remoteFileService.delFile(fileId, SecurityConstants.INNER);
}
String personImgBase64 = getPersonImgBase64(vo.getDelFiles());
// 删除人脸库添加人脸照片至人脸库
Integer isDel = delFaceToLibrary(null, FaceCodeUtil.DEL, "rs-" + vo.getId());
if(isDel !=null){
Integer isPush = addFaceToLibrary(BytesToMultipartFileUtil.multipartFileToBase64(file), FaceCodeUtil.ADD, "rs-" + vo.getId());
if (isPush != null) {
// 更新人脸库推送状态
mapper.updatePeoplePushStatus(vo.getId());
}
delFaceToLibrary(personImgBase64, FaceCodeUtil.DEL, "rs-" + vo.getId());
Integer isPush = addFaceToLibrary(BytesToMultipartFileUtil.multipartFileToBase64(file), FaceCodeUtil.ADD, "rs-" + vo.getId());
if (isPush != null) {
// 更新人脸库推送状态
mapper.updatePeoplePushStatus(vo.getId());
}
}
} catch (Exception e) {
@ -253,7 +252,7 @@ public class PersonMgeServiceImpl implements IPersonMgeService {
* @date 2024/8/12 13:20
*/
public Integer addFaceToLibrary(String base64, String type, String id) {
if (base64 == null) {
if (StringUtils.isEmpty(base64)) {
return null;
}
AjaxResult ajaxResult = faceInterService.addFace(base64, type, id);
@ -275,6 +274,9 @@ public class PersonMgeServiceImpl implements IPersonMgeService {
* @date 2024/8/12 13:27
*/
public Integer delFaceToLibrary(String base64, String type, String id) {
if(StringUtils.isEmpty(base64)){
return null;
}
AjaxResult ajaxResult = faceInterService.addFace(base64, type, id);
Integer code = (Integer) ajaxResult.get("code");
log.info("删除人脸库返回结果:{}", ajaxResult);
@ -327,6 +329,52 @@ public class PersonMgeServiceImpl implements IPersonMgeService {
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public AjaxResult pushFace(BraceletParamsDto dto) {
try {
String base64Data = getPersonImgBase64(dto.getFilePath());
if(StringUtils.isEmpty(base64Data)){
return AjaxResult.error("未上传人脸照片");
}
// 删除人脸库添加人脸照片至人脸库
delFaceToLibrary(base64Data, FaceCodeUtil.DEL, "rs-" + dto.getId());
Integer isPush = addFaceToLibrary(base64Data, FaceCodeUtil.ADD, "rs-" + dto.getId());
if (isPush != null) {
// 更新人脸库推送状态
mapper.updatePeoplePushStatus(dto.getId());
}else{
return AjaxResult.error("人脸识别接口异常!请检查人脸服务!");
}
} catch (Exception e) {
log.error(e.toString(), e);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return AjaxResult.error();
}
return AjaxResult.success();
}
/**
* 根据文件ID获取图片base64
* @param filePath
* @return String
* @author cwchen
* @date 2024/8/12 14:35
*/
public String getPersonImgBase64(String filePath){
R<SysFile> result = remoteFileService.getImgBase64(filePath, SecurityConstants.INNER);
if (result != null && result.getCode() == HttpStatus.SUCCESS && result.getData() != null) {
String jsonString = JSON.toJSONString(result.getData());
JSONObject item = JSON.parseObject(jsonString);
String base64 = item.getString("url");
if(StringUtils.isNotBlank(base64)){
// 去除前缀部分
return base64.split(",")[1];
}
}
return null;
}
@Override
@Transactional(rollbackFor = Exception.class)
public AjaxResult excelUpload(MultipartFile file, HttpServletRequest request, HttpServletResponse response) {
@ -335,6 +383,7 @@ public class PersonMgeServiceImpl implements IPersonMgeService {
return AjaxResult.error(result);
}
List<String> errorFileLists = new ArrayList<>();
List<String> errorIdLists = new ArrayList<>();
try {
List<JSONObject> lstObj = (List<JSONObject>) ImportExcelUtils.readExcel(file, PersonImportVo.class, tempFilePath);
List<PersonVo> list = new ArrayList<>();
@ -385,8 +434,14 @@ public class PersonMgeServiceImpl implements IPersonMgeService {
vo.setIdCard(Sm4Utils.encode(vo.getIdCard()));
vo.setPhone(Sm4Utils.encode(vo.getPhone()));
mapper.addPerson(vo);
// 推送人脸照片到人脸库并更新推送状态
Integer isPush = addFaceToLibrary(BytesToMultipartFileUtil.multipartFileToBase64(vo.getFile()), FaceCodeUtil.ADD, "rs-" + vo.getId());
if (isPush != null) {
mapper.updatePeoplePushStatus(vo.getId());
}
String delFileId = uploadFile(vo.getFile(), vo);
errorFileLists.add(delFileId);
errorIdLists.add("rs-"+vo.getId());
}
} catch (RuntimeException runtimeException) {
if (runtimeException.getMessage() == null) {
@ -395,10 +450,11 @@ public class PersonMgeServiceImpl implements IPersonMgeService {
return AjaxResult.error(runtimeException.getMessage());
} catch (Exception e) {
log.error(e.toString(), e);
// 添加失败-删除文件
// 添加失败-删除文件删除人脸库照片
if (CollectionUtils.isNotEmpty(errorFileLists)) {
for (String delFileId : errorFileLists) {
remoteFileService.delFile(delFileId, SecurityConstants.INNER);
for (int i = 0; i < errorFileLists.size(); i++) {
remoteFileService.delFile(errorFileLists.get(i), SecurityConstants.INNER);
delFaceToLibrary(null, FaceCodeUtil.DEL, errorIdLists.get(i));
}
}
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();