Merge remote-tracking branch 'origin/v12-server-sdk-changqing' into v12-server-sdk-changqing

This commit is contained in:
ovo 2024-10-18 20:31:12 +08:00
commit 8719457339
1 changed files with 68 additions and 22 deletions

View File

@ -1,7 +1,12 @@
package net.shapelight.modules.job.task; package net.shapelight.modules.job.task;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONArray; import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject; 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.MinioClient;
import io.minio.PutObjectOptions; import io.minio.PutObjectOptions;
import lombok.extern.slf4j.Slf4j; 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.Constant;
import net.shapelight.common.utils.SnowflakeIdWorker; import net.shapelight.common.utils.SnowflakeIdWorker;
import net.shapelight.common.utils.UUIDUtil; 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.UserInfo;
import net.shapelight.modules.face.util.UserRamGroup; import net.shapelight.modules.face.util.UserRamGroup;
import net.shapelight.modules.feignClient.CxFeignClient; 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.TenCellEntity;
import net.shapelight.modules.ten.entity.TenPersonCert; import net.shapelight.modules.ten.entity.TenPersonCert;
import net.shapelight.modules.ten.entity.TenPersonEntity; import net.shapelight.modules.ten.entity.TenPersonEntity;
@ -25,8 +33,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.ByteArrayInputStream; import java.io.*;
import java.io.InputStream;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
@ -34,7 +41,7 @@ import java.util.logging.SimpleFormatter;
@Component @Component
@Slf4j @Slf4j
public class PersonSynchronousTask implements ITask { public class PersonSynchronousTask extends AbstractController implements ITask {
@Resource @Resource
private CxFeignClient cxFeignClient; private CxFeignClient cxFeignClient;
@Resource @Resource
@ -51,6 +58,8 @@ public class PersonSynchronousTask implements ITask {
private TenPersonCertService certService; private TenPersonCertService certService;
@Autowired @Autowired
private TenPersonTrainService trainService; private TenPersonTrainService trainService;
@Autowired
private FaceEngineService faceEngineService;
@Override @Override
@ -96,9 +105,29 @@ public class PersonSynchronousTask implements ITask {
JSONObject data = json.getJSONObject("data"); JSONObject data = json.getJSONObject("data");
JSONArray dataList = data.getJSONArray("list"); JSONArray dataList = data.getJSONArray("list");
List<JSONObject> list1 = dataList.toList(JSONObject.class); List<JSONObject> list1 = dataList.toList(JSONObject.class);
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 -> { list1.forEach(person -> {
save(person,item); 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); log.debug("获取人员信息成功"+type);
} else { } else {
log.debug("获取人员信息失败"+json.getStr("message")); 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(); TenPersonEntity tenPerson = new TenPersonEntity();
Date now = new Date(); Date now = new Date();
long id = new SnowflakeIdWorker().nextId(); 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.setIdCard(person.getStr("personnelCardId")!=null?person.getStr("personnelCardId"):null);
tenPerson.setNation(person.getStr("dictNation")!=null?Integer.parseInt(person.getStr("dictNation")):1); tenPerson.setNation(person.getStr("dictNation")!=null?Integer.parseInt(person.getStr("dictNation")):1);
tenPerson.setCellId(cellEntity.getCellId()); 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) { if(person.getStr("pmPersonnelId")!=null) {
tenPerson.setOpenId(person.getStr("pmPersonnelId")); tenPerson.setOpenId(person.getStr("pmPersonnelId"));
} }
@ -223,29 +255,43 @@ public class PersonSynchronousTask implements ITask {
}); });
} }
try { try {
//保存原始图片 //保存原始图片
String userFileUrl = globalValue.getImagesDir() + "/" + String userFileUrl = globalValue.getImagesDir() + "/" +
tenPerson.getCellId().toString() + "/" + tenPerson.getCellId().toString() + "/" +
tenPerson.getPersonId().toString() + "/"; tenPerson.getPersonId().toString() + "/";
String orgImageFileName = userFileUrl + "o_" + UUIDUtil.uuid() + ".jpg"; String orgImageFileName = userFileUrl + "o_" + UUIDUtil.uuid() + ".jpg";
byte[] b = Base64.getDecoder().decode(person.getStr("attachment").replace("\n", "")); byte[] b = Base64.getDecoder().decode(person.getStr("attachment").replace("\n", ""));
ImageInfo rgbData = ImageFactory.getRGBData(b);
List<FaceInfo> 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); InputStream inputStream = new ByteArrayInputStream(b);
PutObjectOptions putObjectOptions = new PutObjectOptions(inputStream.available(), -1); PutObjectOptions putObjectOptions = new PutObjectOptions(inputStream.available(), -1);
putObjectOptions.setContentType("image/jpeg"); putObjectOptions.setContentType("image/jpeg");
minioClient.putObject( minioClient.putObject(
minioConfig.getBucketName(), orgImageFileName, inputStream, putObjectOptions); minioConfig.getBucketName(), orgImageFileName, inputStream, putObjectOptions);
inputStream.close(); inputStream.close();
tenPerson.setOrgImage(orgImageFileName); tenPerson.setOrgImage(orgImageFileName);
tenPerson.setFaceImage(orgImageFileName); tenPerson.setFaceImage(orgImageFileName);
tenPersonService.saveOrUpdateByField(tenPerson,"openId");
tenPersonService.saveOrUpdateByField(tenPerson,"idCard");
UserInfo userInfo = new UserInfo(); UserInfo userInfo = new UserInfo();
UserRamGroup.addUser(userInfo,tenPerson.getOrgId()!=null?UserRamGroup.getOrgCellMap(tenPerson.getOrgId()):null); 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) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} return tenPerson.getOpenId()+"|"+tenPerson.getName()+"|"+"保存照片文件失败";
}
return "";
} }
} }