diff --git a/shapelight-admin/src/main/java/net/shapelight/modules/job/task/PersonSynchronousTask.java b/shapelight-admin/src/main/java/net/shapelight/modules/job/task/PersonSynchronousTask.java index bca879d..c51fb34 100644 --- a/shapelight-admin/src/main/java/net/shapelight/modules/job/task/PersonSynchronousTask.java +++ b/shapelight-admin/src/main/java/net/shapelight/modules/job/task/PersonSynchronousTask.java @@ -1,7 +1,12 @@ package net.shapelight.modules.job.task; +import cn.hutool.core.collection.CollectionUtil; import cn.hutool.json.JSONArray; import cn.hutool.json.JSONObject; +import com.arcsoft.face.FaceInfo; +import com.arcsoft.face.enums.ExtractType; +import com.arcsoft.face.toolkit.ImageFactory; +import com.arcsoft.face.toolkit.ImageInfo; import io.minio.MinioClient; import io.minio.PutObjectOptions; import lombok.extern.slf4j.Slf4j; @@ -10,9 +15,12 @@ import net.shapelight.common.config.MinioConfig; import net.shapelight.common.utils.Constant; import net.shapelight.common.utils.SnowflakeIdWorker; import net.shapelight.common.utils.UUIDUtil; +import net.shapelight.modules.face.dto.FaceRecognitionResDTO; +import net.shapelight.modules.face.service.FaceEngineService; import net.shapelight.modules.face.util.UserInfo; import net.shapelight.modules.face.util.UserRamGroup; import net.shapelight.modules.feignClient.CxFeignClient; +import net.shapelight.modules.sys.controller.AbstractController; import net.shapelight.modules.ten.entity.TenCellEntity; import net.shapelight.modules.ten.entity.TenPersonCert; import net.shapelight.modules.ten.entity.TenPersonEntity; @@ -25,8 +33,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.annotation.Resource; -import java.io.ByteArrayInputStream; -import java.io.InputStream; +import java.io.*; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; @@ -34,7 +41,7 @@ import java.util.logging.SimpleFormatter; @Component @Slf4j -public class PersonSynchronousTask implements ITask { +public class PersonSynchronousTask extends AbstractController implements ITask { @Resource private CxFeignClient cxFeignClient; @Resource @@ -51,6 +58,8 @@ public class PersonSynchronousTask implements ITask { private TenPersonCertService certService; @Autowired private TenPersonTrainService trainService; + @Autowired + private FaceEngineService faceEngineService; @Override @@ -96,9 +105,29 @@ public class PersonSynchronousTask implements ITask { JSONObject data = json.getJSONObject("data"); JSONArray dataList = data.getJSONArray("list"); List list1 = dataList.toList(JSONObject.class); - list1.forEach(person -> { - save(person,item); - }); + String filePath = "C:\\zhihuiyuanqu\\firePerson.txt"; + // 创建一个File对象 + File file = new File(filePath); + // 确保父目录存在 + if (file.getParentFile() != null) { + file.getParentFile().mkdirs(); + } + try (FileWriter writer = new FileWriter(file)) { + // 写入数据 + list1.forEach(person -> { + String msg = save(person,item); + if(!msg.isEmpty()) { + try { + writer.write(msg); + writer.write(System.getProperty("line.separator")); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + }); + } catch (IOException e) { + e.printStackTrace(); + } log.debug("获取人员信息成功"+type); } else { log.debug("获取人员信息失败"+json.getStr("message")); @@ -111,7 +140,7 @@ public class PersonSynchronousTask implements ITask { } - private void save(JSONObject person,TenCellEntity cellEntity) { + private String save(JSONObject person,TenCellEntity cellEntity) { TenPersonEntity tenPerson = new TenPersonEntity(); Date now = new Date(); long id = new SnowflakeIdWorker().nextId(); @@ -131,6 +160,9 @@ public class PersonSynchronousTask implements ITask { tenPerson.setIdCard(person.getStr("personnelCardId")!=null?person.getStr("personnelCardId"):null); tenPerson.setNation(person.getStr("dictNation")!=null?Integer.parseInt(person.getStr("dictNation")):1); tenPerson.setCellId(cellEntity.getCellId()); + tenPerson.setTenantId(getUser().getTenantId()); + tenPerson.setRegisterType(Constant.RESGISTER_TYPE_Device); + tenPerson.setStatus(Constant.PESON_SUATUS_NOMOR); if(person.getStr("pmPersonnelId")!=null) { tenPerson.setOpenId(person.getStr("pmPersonnelId")); } @@ -223,29 +255,43 @@ public class PersonSynchronousTask implements ITask { }); } try { + + //保存原始图片 String userFileUrl = globalValue.getImagesDir() + "/" + tenPerson.getCellId().toString() + "/" + tenPerson.getPersonId().toString() + "/"; String orgImageFileName = userFileUrl + "o_" + UUIDUtil.uuid() + ".jpg"; - byte[] b = Base64.getDecoder().decode(person.getStr("attachment").replace("\n", "")); - - InputStream inputStream = new ByteArrayInputStream(b); - PutObjectOptions putObjectOptions = new PutObjectOptions(inputStream.available(), -1); - putObjectOptions.setContentType("image/jpeg"); - minioClient.putObject( - minioConfig.getBucketName(), orgImageFileName, inputStream, putObjectOptions); - inputStream.close(); - - tenPerson.setOrgImage(orgImageFileName); - tenPerson.setFaceImage(orgImageFileName); - - tenPersonService.saveOrUpdateByField(tenPerson,"idCard"); - UserInfo userInfo = new UserInfo(); - UserRamGroup.addUser(userInfo,tenPerson.getOrgId()!=null?UserRamGroup.getOrgCellMap(tenPerson.getOrgId()):null); + ImageInfo rgbData = ImageFactory.getRGBData(b); + List faceInfoList = faceEngineService.detectFaces(rgbData); + if (CollectionUtil.isNotEmpty(faceInfoList)) { + FaceInfo faceInfo = faceInfoList.get(0); + FaceRecognitionResDTO faceRecognitionResDTO = new FaceRecognitionResDTO(); + faceRecognitionResDTO.setRect(faceInfo.getRect()); + byte[] featureBytes = faceEngineService.extractFaceFeature(rgbData, faceInfo, ExtractType.REGISTER); + if (featureBytes != null) { + tenPerson.setFeature(Base64.getEncoder().encodeToString(featureBytes)); + InputStream inputStream = new ByteArrayInputStream(b); + PutObjectOptions putObjectOptions = new PutObjectOptions(inputStream.available(), -1); + putObjectOptions.setContentType("image/jpeg"); + minioClient.putObject( + minioConfig.getBucketName(), orgImageFileName, inputStream, putObjectOptions); + inputStream.close(); + tenPerson.setOrgImage(orgImageFileName); + tenPerson.setFaceImage(orgImageFileName); + tenPersonService.saveOrUpdateByField(tenPerson,"openId"); + UserInfo userInfo = new UserInfo(); + UserRamGroup.addUser(userInfo,tenPerson.getOrgId()!=null?UserRamGroup.getOrgCellMap(tenPerson.getOrgId()):null); + }else{ + log.error(tenPerson.getPersonId()+tenPerson.getName()+"图片不合格,未检测到人脸"); + return tenPerson.getOpenId()+"|"+tenPerson.getName()+"|"+"图片不合格,未检测到人脸"; + } + } } catch (Exception e) { e.printStackTrace(); + return tenPerson.getOpenId()+"|"+tenPerson.getName()+"|"+"保存照片文件失败"; } + return ""; } }