人员管理接口修改

This commit is contained in:
cwchen 2024-08-12 15:22:47 +08:00
parent 160ecc1d8d
commit 53fffe8856
4 changed files with 29 additions and 34 deletions

View File

@ -51,7 +51,7 @@ public class BusinessConstants {
public final static Integer CONFIG_TYPE = 1;
public final static Integer CONFIG_TYPE2 = 2;
public final static Integer SUCCESS_CODE = 201;
public final static Integer SUCCESS_CODE = 200;
public final static Integer CELL_1 = 1;

View File

@ -114,8 +114,11 @@ public class BytesToMultipartFileUtil {
public static String multipartFileToBase64(MultipartFile file){
try {
byte[] fileBytes = file.getBytes();
String originalFilename = file.getOriginalFilename();
int lastIndexOf = originalFilename.lastIndexOf(".");
String suffix = originalFilename.substring(lastIndexOf + 1);
String base64String = Base64.getEncoder().encodeToString(fileBytes);
return base64String;
return "data:image/" + suffix + ";base64," + base64String;
} catch (IOException e) {
e.printStackTrace();
}

View File

@ -69,7 +69,7 @@ public class FaceInterServiceImpl implements FaceInterService {
result.put("code",201);
result.put("msg","人脸识别接口异常!请检查人脸服务!");
}
AjaxResult.success(result);
return AjaxResult.success(result);
}catch (Exception e){
log.error(e.toString(),e);
}

View File

@ -153,8 +153,8 @@ public class PersonMgeServiceImpl implements IPersonMgeService {
mapper.addPerson(vo);
delFileId = uploadFile(file, vo);
// 添加人脸照片至人脸库
Integer isPush = addFaceToLibrary(BytesToMultipartFileUtil.multipartFileToBase64(file), FaceCodeUtil.ADD, "rs-" + vo.getId());
if (isPush != null) {
AjaxResult ajaxResult = addFaceToLibrary(BytesToMultipartFileUtil.multipartFileToBase64(file), FaceCodeUtil.ADD, "rs-" + vo.getId());
if (ajaxResult != null && Objects.equals((Integer) ajaxResult.get("code"), BusinessConstants.SUCCESS_CODE)) {
// 更新人脸库推送状态
mapper.updatePeoplePushStatus(vo.getId());
}
@ -223,8 +223,8 @@ public class PersonMgeServiceImpl implements IPersonMgeService {
String personImgBase64 = getPersonImgBase64(vo.getDelFiles());
// 删除人脸库添加人脸照片至人脸库
delFaceToLibrary(personImgBase64, FaceCodeUtil.DEL, "rs-" + vo.getId());
Integer isPush = addFaceToLibrary(BytesToMultipartFileUtil.multipartFileToBase64(file), FaceCodeUtil.ADD, "rs-" + vo.getId());
if (isPush != null) {
AjaxResult ajaxResult = addFaceToLibrary(BytesToMultipartFileUtil.multipartFileToBase64(file), FaceCodeUtil.ADD, "rs-" + vo.getId());
if (ajaxResult != null && Objects.equals((Integer) ajaxResult.get("code"), BusinessConstants.SUCCESS_CODE)) {
// 更新人脸库推送状态
mapper.updatePeoplePushStatus(vo.getId());
}
@ -251,21 +251,18 @@ public class PersonMgeServiceImpl implements IPersonMgeService {
* @author cwchen
* @date 2024/8/12 13:20
*/
public Integer addFaceToLibrary(String base64, String type, String id) {
public AjaxResult addFaceToLibrary(String base64, String type, String id) {
if (StringUtils.isEmpty(base64)) {
return null;
}
AjaxResult ajaxResult = faceInterService.addFace(base64, type, id);
log.info("添加人脸库返回结果:{}", ajaxResult);
Integer code = (Integer) ajaxResult.get("code");
if (Objects.equals(code, BusinessConstants.SUCCESS_CODE)) {
return 1;
}
return null;
return ajaxResult;
}
/**
* 删除人脸库
*
* @param base64
* @param type
* @param id
@ -273,17 +270,13 @@ public class PersonMgeServiceImpl implements IPersonMgeService {
* @author cwchen
* @date 2024/8/12 13:27
*/
public Integer delFaceToLibrary(String base64, String type, String id) {
if(StringUtils.isEmpty(base64)){
public AjaxResult 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);
if (Objects.equals(code, BusinessConstants.SUCCESS_CODE)) {
return 1;
}
return null;
return ajaxResult;
}
@Override
@ -320,7 +313,8 @@ public class PersonMgeServiceImpl implements IPersonMgeService {
resourceFileMapper.delResourceFile(dto.getFileId());
remoteFileService.delFile(dto.getFilePath(), SecurityConstants.INNER);
// 删除人脸库
delFaceToLibrary(null, FaceCodeUtil.DEL, "rs-" + dto.getId());
String base64Data = getPersonImgBase64(dto.getFilePath());
delFaceToLibrary(base64Data, FaceCodeUtil.DEL, "rs-" + dto.getId());
return AjaxResult.success();
} catch (Exception e) {
log.error("删除人员", e);
@ -334,17 +328,17 @@ public class PersonMgeServiceImpl implements IPersonMgeService {
public AjaxResult pushFace(BraceletParamsDto dto) {
try {
String base64Data = getPersonImgBase64(dto.getFilePath());
if(StringUtils.isEmpty(base64Data)){
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) {
AjaxResult ajaxResult = addFaceToLibrary(base64Data, FaceCodeUtil.ADD, "rs-" + dto.getId());
if (ajaxResult != null && Objects.equals((Integer) ajaxResult.get("code"), BusinessConstants.SUCCESS_CODE)) {
// 更新人脸库推送状态
mapper.updatePeoplePushStatus(dto.getId());
}else{
return AjaxResult.error("人脸识别接口异常!请检查人脸服务!");
} else {
return AjaxResult.error((String) ajaxResult.get("msg"));
}
} catch (Exception e) {
log.error(e.toString(), e);
@ -356,21 +350,19 @@ public class PersonMgeServiceImpl implements IPersonMgeService {
/**
* 根据文件ID获取图片base64
*
* @param filePath
* @return String
* @author cwchen
* @date 2024/8/12 14:35
*/
public String getPersonImgBase64(String filePath){
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 base64;
}
return null;
}
@ -435,13 +427,13 @@ public class PersonMgeServiceImpl implements IPersonMgeService {
vo.setPhone(Sm4Utils.encode(vo.getPhone()));
mapper.addPerson(vo);
// 推送人脸照片到人脸库并更新推送状态
Integer isPush = addFaceToLibrary(BytesToMultipartFileUtil.multipartFileToBase64(vo.getFile()), FaceCodeUtil.ADD, "rs-" + vo.getId());
if (isPush != null) {
AjaxResult ajaxResult = addFaceToLibrary(BytesToMultipartFileUtil.multipartFileToBase64(vo.getFile()), FaceCodeUtil.ADD, "rs-" + vo.getId());
if (ajaxResult != null && Objects.equals((Integer) ajaxResult.get("code"), BusinessConstants.SUCCESS_CODE)) {
mapper.updatePeoplePushStatus(vo.getId());
}
String delFileId = uploadFile(vo.getFile(), vo);
errorFileLists.add(delFileId);
errorIdLists.add("rs-"+vo.getId());
errorIdLists.add("rs-" + vo.getId());
}
} catch (RuntimeException runtimeException) {
if (runtimeException.getMessage() == null) {