班组管理接口修改

This commit is contained in:
cwchen 2024-08-12 13:44:42 +08:00
parent 7b6f3d28c5
commit c7e93f9fd5
6 changed files with 105 additions and 4 deletions

View File

@ -51,6 +51,8 @@ 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 CELL_1 = 1;
public final static Integer CELL_2 = 2;

View File

@ -8,6 +8,7 @@ import org.springframework.web.multipart.commons.CommonsMultipartFile;
import java.io.*;
import java.nio.file.Files;
import java.util.Base64;
/**
* @authorcwchen
@ -102,4 +103,22 @@ public class BytesToMultipartFileUtil {
}
}
}
/**
* MultipartFile文件转base64
* @param file
* @return String
* @author cwchen
* @date 2024/8/12 13:18
*/
public static String multipartFileToBase64(MultipartFile file){
try {
byte[] fileBytes = file.getBytes();
String base64String = Base64.getEncoder().encodeToString(fileBytes);
return base64String;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}

View File

@ -178,7 +178,7 @@ public class PersonVo implements Serializable {
/**
* 是否推送至人脸库 0.未推送 1.已推送
*/
private Integer isPush;
private Integer isPush = 0;
/**
* 查询条件限制

View File

@ -211,4 +211,13 @@ public interface PersonMgeMapper {
*/
@MapKey("name")
List<Map<String, String>> getPostType();
/**
* 更新人脸库推送状态
* @param id
* @return void
* @author cwchen
* @date 2024/8/12 13:12
*/
void updatePeoplePushStatus(Long id);
}

View File

@ -6,11 +6,14 @@ import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bonus.bracelet.mapper.PersonMgeMapper;
import com.bonus.bracelet.mapper.ResourceFileMapper;
import com.bonus.bracelet.service.FaceInterService;
import com.bonus.bracelet.service.IPersonMgeService;
import com.bonus.common.core.constant.BusinessConstants;
import com.bonus.common.core.constant.HttpStatus;
import com.bonus.common.core.constant.SecurityConstants;
import com.bonus.common.core.domain.R;
import com.bonus.common.core.utils.BytesToMultipartFileUtil;
import com.bonus.common.core.utils.FaceCodeUtil;
import com.bonus.common.core.utils.ImportExcelUtils;
import com.bonus.common.core.utils.UploadCheckUtils;
import com.bonus.common.core.utils.encryption.Sm4Utils;
@ -31,6 +34,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -70,6 +74,9 @@ public class PersonMgeServiceImpl implements IPersonMgeService {
@Resource
private RemoteFileService remoteFileService;
@Autowired
private FaceInterService faceInterService;
@Value("${file.temp_file_path}")
private String tempFilePath;
@ -145,10 +152,16 @@ public class PersonMgeServiceImpl implements IPersonMgeService {
vo.setPhone(Sm4Utils.encode(vo.getPhone()));
mapper.addPerson(vo);
delFileId = uploadFile(file, vo);
// 添加人脸照片至人脸库
Integer isPush = addFaceToLibrary(BytesToMultipartFileUtil.multipartFileToBase64(file), FaceCodeUtil.ADD, "rs-" + vo.getId());
if (isPush != null) {
// 更新人脸库推送状态
mapper.updatePeoplePushStatus(vo.getId());
}
} catch (Exception e) {
log.error("新增人员", e);
// 添加失败-删除文件
if (StringUtils.isNotEmpty(delFileId)) {
if (delFileId != null) {
remoteFileService.delFile(delFileId, SecurityConstants.INNER);
}
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
@ -207,6 +220,15 @@ public class PersonMgeServiceImpl implements IPersonMgeService {
resourceFileMapper.delResourceFile(vo.getFileId());
remoteFileService.delFile(fileId, SecurityConstants.INNER);
}
// 删除人脸库添加人脸照片至人脸库
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());
}
}
}
} catch (Exception e) {
log.error("修改人员", e);
@ -220,6 +242,48 @@ public class PersonMgeServiceImpl implements IPersonMgeService {
return AjaxResult.success();
}
/**
* 添加人脸库
*
* @param base64
* @param type
* @param id
* @return Integer
* @author cwchen
* @date 2024/8/12 13:20
*/
public Integer addFaceToLibrary(String base64, String type, String id) {
if (base64 == null) {
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;
}
/**
* 删除人脸库
* @param base64
* @param type
* @param id
* @return Integer
* @author cwchen
* @date 2024/8/12 13:27
*/
public Integer delFaceToLibrary(String base64, String type, String id) {
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;
}
@Override
public AjaxResult getPersonInfo(BraceletParamsDto dto) {
try {
@ -253,6 +317,8 @@ public class PersonMgeServiceImpl implements IPersonMgeService {
mapper.delCertificate(dto);
resourceFileMapper.delResourceFile(dto.getFileId());
remoteFileService.delFile(dto.getFilePath(), SecurityConstants.INNER);
// 删除人脸库
delFaceToLibrary(null, FaceCodeUtil.DEL, "rs-" + dto.getId());
return AjaxResult.success();
} catch (Exception e) {
log.error("删除人员", e);
@ -265,7 +331,7 @@ public class PersonMgeServiceImpl implements IPersonMgeService {
@Transactional(rollbackFor = Exception.class)
public AjaxResult excelUpload(MultipartFile file, HttpServletRequest request, HttpServletResponse response) {
String result = UploadCheckUtils.uploadExcelVerify(file);
if(StringUtils.isNotBlank(result)){
if (StringUtils.isNotBlank(result)) {
return AjaxResult.error(result);
}
List<String> errorFileLists = new ArrayList<>();
@ -459,12 +525,13 @@ public class PersonMgeServiceImpl implements IPersonMgeService {
vo.setIdCard(handleData(obj.getString("idCard")));
vo.setPhone(handleData(obj.getString("phone")));
vo.setFile(obj.get("file") != null ? (MultipartFile) obj.get("file") : null);
vo.setPost(setPost(postList,handleData(obj.getString("post"))));
vo.setPost(setPost(postList, handleData(obj.getString("post"))));
return vo;
}
/**
* 设置人员岗位
*
* @param postList
* @param value
* @return String

View File

@ -251,4 +251,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<update id="delCertificateResourceFile">
UPDATE sys_file_source SET del_flag = 1 WHERE source_id = #{id} and source_type = (#{certificateType})
</update>
<!--更新人脸库推送状态-->
<update id="updatePeoplePushStatus">
UPDATE tb_people SET is_push = 1 WHERE id = #{id}
</update>
</mapper>