jsk 人脸下发

This commit is contained in:
jiask 2025-11-14 10:43:21 +08:00
parent ca56aa4f55
commit 27e892fa54
5 changed files with 152 additions and 45 deletions

View File

@ -1,5 +1,6 @@
package com.bonus.canteen.core.kitchen.service.impl;
import java.io.File;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
@ -13,13 +14,17 @@ import com.bonus.canteen.core.kitchen.domain.constants.HealthCertStatusEnum;
import com.bonus.canteen.core.kitchen.service.IKitchenStaffDevicePrivilegeService;
import com.bonus.canteen.core.kitchen.service.IKitchenStaffFaceService;
import com.bonus.canteen.core.kitchen.utils.FileCommonUtils;
import com.bonus.canteen.core.kitchen.utils.NetSDK.FaceManage;
import com.bonus.canteen.core.kitchen.utils.initServer;
import com.bonus.canteen.core.kitchen.vo.KitchenDeviceListVO;
import com.bonus.canteen.core.user.domain.DeviceMqPersonalUpdateMessageDTO;
import com.bonus.canteen.core.user.domain.UserFace;
import com.bonus.canteen.core.user.service.IUserFaceService;
import com.bonus.canteen.core.utils.BnsUtils;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.core.utils.DateUtils;
import com.bonus.common.core.utils.StringUtils;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.houqin.constant.DeviceTypeEnum;
import com.bonus.common.houqin.mq.constant.LeMqConstant;
import com.bonus.common.houqin.utils.SM4EncryptUtils;
@ -179,7 +184,7 @@ public class KitchenStaffInfoServiceImpl implements IKitchenStaffInfoService {
KitchenStaffFace kitchenStaffFace = new KitchenStaffFace();
kitchenStaffFace.setStaffId(kitchenStaffInfo.getStaffId());
kitchenStaffFace.setPhotoUrl(kitchenStaffInfo.getFaceUrl());
kitchenStaffFaceService.uploadUserFace(kitchenStaffFace);
AjaxResult AR=kitchenStaffFaceService.uploadUserFace(kitchenStaffFace);
return result;
} catch (Exception e) {
throw new ServiceException(e.getMessage());
@ -224,8 +229,9 @@ public class KitchenStaffInfoServiceImpl implements IKitchenStaffInfoService {
KitchenStaffFace kitchenStaffFace = new KitchenStaffFace();
kitchenStaffFace.setStaffId(kitchenStaffInfo.getStaffId());
kitchenStaffFace.setPhotoUrl(kitchenStaffInfo.getFaceUrl());
kitchenStaffFaceService.uploadUserFace(kitchenStaffFace);
AjaxResult AR=kitchenStaffFaceService.uploadUserFace(kitchenStaffFace);
} catch (Exception e) {
e.printStackTrace();
throw new ServiceException(e.getMessage());
}
return 1;
@ -270,6 +276,17 @@ public class KitchenStaffInfoServiceImpl implements IKitchenStaffInfoService {
kitchenStaffDevicePrivilege.setPrivilegeName("is_enable");
kitchenStaffDevicePrivilege.setPrivilegeValue(access.getPrivilegeValue());
kitchenStaffDevicePrivilegeList.add(kitchenStaffDevicePrivilege);
if((access.getDeviceId()!=null&&access.getDeviceId()==6)&&kitchenStaffInfo.getFaceUrl()!=null&&!"".equals(kitchenStaffInfo.getFaceUrl())){
try{
FaceManage.deleteFaceInfo(initServer.lUserID,kitchenStaffInfo.getStaffNo());
int numd=FaceManage.addFaceByUrl(initServer.lUserID,kitchenStaffInfo.getStaffNo(),kitchenStaffInfo.getFaceUrl());
if(numd>0){
System.out.println(kitchenStaffInfo.getStaffNo()+" "+kitchenStaffInfo.getStaffName()+" "+"门禁人脸下发成功!");
}
}catch (Exception e){
e.printStackTrace();
}
}
}
kitchenStaffDevicePrivilegeService.insertKitchenStaffDevicePrivilege(kitchenStaffDevicePrivilegeList);
}

View File

@ -26,48 +26,64 @@ public final class FaceManage {
* @throws JSONException
* @throws InterruptedException
*/
public static void addFaceByBinary(int userID,String employeeNo,String filePath ) throws JSONException, InterruptedException{
public static int AddFaceByBinary(int userID,String employeeNo,String pathName ) throws JSONException, InterruptedException{
int userl=-1;
HCNetSDK.BYTE_ARRAY ptrByteArray = new HCNetSDK.BYTE_ARRAY(1024); //数组
String strInBuffer = "PUT /ISAPI/Intelligent/FDLib/FDSetUp?format=json";
System.arraycopy(strInBuffer.getBytes(), 0, ptrByteArray.byValue, 0, strInBuffer.length());//字符串拷贝到数组中
ptrByteArray.write();
int lHandler = initServer.hCNetSDK.NET_DVR_StartRemoteConfig(userID, HCNetSDK.NET_DVR_FACE_DATA_RECORD, ptrByteArray.getPointer(), strInBuffer.length(), null, null);
if (lHandler < 0){
if (lHandler < 0)
{
System.out.println("Addface NET_DVR_StartRemoteConfig 失败,错误码为"+initServer.hCNetSDK.NET_DVR_GetLastError());
return;
}else{
return userl;
}
else{
System.out.println("Addface NET_DVR_StartRemoteConfig 成功!");
HCNetSDK.NET_DVR_JSON_DATA_CFG struAddFaceDataCfg = new HCNetSDK.NET_DVR_JSON_DATA_CFG();
struAddFaceDataCfg.read();
//输入参数XML或者JSON数据,添加人脸图片json报文
Map<String, Object> parameter = new HashMap<>();
parameter.put("employeeNo", employeeNo); // 员工ID号
String strJsonData = ConfigFileUtil.getReqBodyFromTemplate("/bonus-modules/bonus-smart-canteen/src/main/resources/conf/acs/AddFaceInfoParam.json", parameter);
System.out.println("下个人员参数:"+strJsonData);
JSONObject jsonObject = new JSONObject();
jsonObject.put("faceLibType", "blackFD");
jsonObject.put("FDID", "1");
jsonObject.put("FPID", employeeNo);//人脸下发关联的工号
String strJsonData = jsonObject.toString();
System.arraycopy(strJsonData.getBytes(), 0, ptrByteArray.byValue, 0, strJsonData.length());//字符串拷贝到数组中
ptrByteArray.write();
struAddFaceDataCfg.dwSize = struAddFaceDataCfg.size();
struAddFaceDataCfg.lpJsonData = ptrByteArray.getPointer();
struAddFaceDataCfg.dwJsonDataSize = strJsonData.length();
/*****************************************
* 从本地文件里面读取JPEG图片二进制数据
*****************************************/
FileInputStream picfile = null;
int picdataLength = 0;
try{
picfile = new FileInputStream(new File(filePath));
}catch(FileNotFoundException e){
picfile = new FileInputStream(new File(pathName));
}
catch(FileNotFoundException e)
{
e.printStackTrace();
}
try{
picdataLength = picfile.available();
}catch(IOException e1){
}
catch(IOException e1)
{
e1.printStackTrace();
}
if(picdataLength < 0){
if(picdataLength < 0)
{
System.out.println("input file dataSize < 0");
return;
return userl;
}
HCNetSDK.BYTE_ARRAY ptrpicByte = new HCNetSDK.BYTE_ARRAY(picdataLength);
try {
picfile.read(ptrpicByte.byValue);
@ -78,51 +94,71 @@ public final class FaceManage {
struAddFaceDataCfg.dwPicDataSize = picdataLength;
struAddFaceDataCfg.lpPicData = ptrpicByte.getPointer();
struAddFaceDataCfg.write();
HCNetSDK.BYTE_ARRAY ptrOutuff = new HCNetSDK.BYTE_ARRAY(1024);
IntByReference pInt = new IntByReference(0);
while(true){
int dwState = initServer.hCNetSDK.NET_DVR_SendWithRecvRemoteConfig(lHandler, struAddFaceDataCfg.getPointer(), struAddFaceDataCfg.dwSize ,ptrOutuff.getPointer(), 1024, pInt);
if(dwState == -1){
System.out.println("NET_DVR_SendWithRecvRemoteConfig接口调用失败错误码" + initServer.hCNetSDK.NET_DVR_GetLastError());
break;
}
//读取返回的json并解析
ptrOutuff.read();
String strResult = new String(ptrOutuff.byValue).trim();
System.out.println("dwState:" + dwState + ",strResult:" + strResult);
JSONObject jsonResult = new JSONObject(strResult);
int statusCode = jsonResult.getInt("statusCode");
String statusString = jsonResult.getString("statusString");
if(dwState == HCNetSDK.NET_SDK_CONFIG_STATUS_NEED_WAIT){
System.out.println("配置等待");
if(dwState == -1){
System.out.println("NET_DVR_SendWithRecvRemoteConfig接口调用失败错误码" + initServer.hCNetSDK.NET_DVR_GetLastError());
break;
}
else if(dwState == HCNetSDK.NET_SDK_CONFIG_STATUS_NEED_WAIT)
{
Thread.sleep(10);
continue;
}else if(dwState == HCNetSDK.NET_SDK_CONFIG_STATUS_FAILED){
}
else if(dwState == HCNetSDK.NET_SDK_CONFIG_STATUS_FAILED)
{
System.out.println("下发人脸失败, json retun:" + jsonResult.toString());
break;
}else if(dwState == HCNetSDK.NET_SDK_CONFIG_STATUS_EXCEPTION){
}
else if(dwState == HCNetSDK.NET_SDK_CONFIG_STATUS_EXCEPTION)
{
System.out.println("下发人脸异常, json retun:" + jsonResult.toString());
break;
}else if(dwState == HCNetSDK.NET_SDK_CONFIG_STATUS_SUCCESS){//返回NET_SDK_CONFIG_STATUS_SUCCESS代表流程走通了但并不代表下发成功比如人脸图片不符合设备规范等原因所以需要解析Json报文
}
else if(dwState == HCNetSDK.NET_SDK_CONFIG_STATUS_SUCCESS)
{//返回NET_SDK_CONFIG_STATUS_SUCCESS代表流程走通了但并不代表下发成功比如人脸图片不符合设备规范等原因所以需要解析Json报文
if (statusCode != 1){
System.out.println("下发人脸成功,但是有异常情况:" + jsonResult.toString());
}else{
}
else{
System.out.println("下发人脸成功, json retun:" + jsonResult.toString());
userl=1;
}
break;
}else if(dwState == HCNetSDK.NET_SDK_CONFIG_STATUS_FINISH) {
}
else if(dwState == HCNetSDK.NET_SDK_CONFIG_STATUS_FINISH) {
//下发人脸时dwState其实不会走到这里因为设备不知道我们会下发多少个人所以长连接需要我们主动关闭
System.out.println("下发人脸完成");
userl=1;
break;
}
}
if(!initServer.hCNetSDK.NET_DVR_StopRemoteConfig(lHandler)){
System.out.println("NET_DVR_StopRemoteConfig接口调用失败错误码" + initServer.hCNetSDK.NET_DVR_GetLastError());
}else{
}
else{
System.out.println("NET_DVR_StopRemoteConfig接口成功");
}
}
return userl;
}
/**
* 按URL方式下发人脸图片
* @param userID 用户注销ID
@ -148,6 +184,8 @@ public final class FaceManage {
jsonObject.put("faceLibType", "blackFD");
jsonObject.put("FDID", "1");
jsonObject.put("FPID", employeeNo);//人脸下发关联的工号
System.out.println("fileUrl:"+fileUrl);
System.out.println("employeeNo:"+employeeNo);
String strJsonData = jsonObject.toString();
System.arraycopy(strJsonData.getBytes(), 0, ptrByteArray.byValue, 0, strJsonData.length());//字符串拷贝到数组中
ptrByteArray.write();

View File

@ -26,7 +26,8 @@ public class UserManage {
* @throws InterruptedException
* @throws JSONException
*/
public static void addUserInfo(int lUserID, String employeeNo,String userName) throws UnsupportedEncodingException, InterruptedException, JSONException {
public static int addUserInfo(int lUserID, String employeeNo,String userName) throws UnsupportedEncodingException, InterruptedException, JSONException {
int userl=-1;
HCNetSDK.BYTE_ARRAY ptrByteArray = new HCNetSDK.BYTE_ARRAY(1024); //数组
String strInBuffer = "POST /ISAPI/AccessControl/UserInfo/Record?format=json"; //此URL也是下发人员
// String strInBuffer = "PUT /ISAPI/AccessControl/UserInfo/SetUp?format=json";
@ -35,7 +36,7 @@ public class UserManage {
int lHandler = initServer.hCNetSDK.NET_DVR_StartRemoteConfig(lUserID, HCNetSDK.NET_DVR_JSON_CONFIG, ptrByteArray.getPointer(), strInBuffer.length(), null, null);
if (lHandler < 0) {
System.out.println("AddUserInfo NET_DVR_StartRemoteConfig 失败,错误码为" + initServer.hCNetSDK.NET_DVR_GetLastError());
return;
return userl;
} else {
System.out.println("AddUserInfo NET_DVR_StartRemoteConfig 成功!");
//输入参数XML或者JSON数据,下发人员信息json报文,其他参数设置参考conf/acs/AddUserInfoParam.json中报文参数
@ -116,11 +117,13 @@ public class UserManage {
System.out.println("下发人员成功,但是有异常情况:" + jsonResult.toString());
} else {
System.out.println("下发人员成功: json retun:" + jsonResult.toString());
userl=1;
}
break;
} else if (dwState == HCNetSDK.NET_SDK_CONFIG_STATUS_FINISH) {
//下发人员时dwState其实不会走到这里因为设备不知道我们会下发多少个人所以长连接需要我们主动关闭
System.out.println("下发人员完成");
userl=1;
break;
}
}
@ -130,6 +133,7 @@ public class UserManage {
System.out.println("NET_DVR_StopRemoteConfig接口成功");
}
}
return userl;
}
/**

View File

@ -23,10 +23,9 @@ public class initServer implements CommandLineRunner {
public static int lListenHandle = -1;
public static FMSGCallBack_V31 fMSFCallBack_V31 = null;
public static int iCharEncodeType = 0;//设备字符集
public static String devIp = "192.168.1.69";
public static String devIp = "192.168.20.51";
public static String devUser = "admin";
public static String devPass = "hzx12345";
public static String devPass = "JYY202509";
public static int lUserID2 = -1;//用户句柄
public static String devIp2 = "192.168.20.32";
public static String devUser2 = "admin";
@ -43,20 +42,24 @@ public class initServer implements CommandLineRunner {
hCNetSDK.NET_DVR_Init();
boolean i= hCNetSDK.NET_DVR_SetLogToFile(3, "..//sdklog", false);
//设置报警回调函
if (fMSFCallBack_V31 == null) {
fMSFCallBack_V31 = new FMSGCallBack_V31();
Pointer pUser = null;
if (!initServer.hCNetSDK.NET_DVR_SetDVRMessageCallBack_V31(fMSFCallBack_V31, pUser)) {
System.out.println("设置回调函数失败!");
} else {
System.out.println("设置回调函数成功!");
}
}
// if (fMSFCallBack_V31 == null) {
// fMSFCallBack_V31 = new FMSGCallBack_V31();
// Pointer pUser = null;
// if (!initServer.hCNetSDK.NET_DVR_SetDVRMessageCallBack_V31(fMSFCallBack_V31, pUser)) {
// System.out.println("设置回调函数失败!");
// } else {
// System.out.println("设置回调函数成功!");
// }
// }
// Login("192.168.0.199","admin","bouns@ltfk",(short) 8000); //登陆
Login(devIp,devUser,devPass,(short) 8000,1); //登陆
Login(devIp2,devUser2,devPass2,(short) 8000,2); //登陆
Alarm.SetAlarm(lUserID);
Alarm.SetAlarm(lUserID2);
System.out.println(devIp+":用户权柄=="+lUserID);
// UserManage.addUserInfo(lUserID,"131551","贾胜凯");
// int faceres=FaceManage.AddFaceByBinary(lUserID,"131551","C:\\Users\\Bonus\\Desktop\\jsk.jpg");
// Login(devIp2,devUser2,devPass2,(short) 8000,2); //登陆
// Alarm.SetAlarm(lUserID);
// Alarm.SetAlarm(lUserID2);
// getAllUser();
// UserManage.searchUserInfo(lUserID);
// UserManage.addUserInfo(lUserID,"15357932237","贾胜凯22");

View File

@ -6,6 +6,11 @@ import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
import java.beans.PropertyDescriptor;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.util.HashSet;
import java.util.Set;
@ -41,4 +46,44 @@ public class BnsUtils {
String[] result = new String[emptyNames.size()];
return (String[])emptyNames.toArray(result);
}
public static File getFile(String url, String fileName) throws Exception {
//对本地文件命名
File file = null;
String prefix="";
String suffix="";
prefix = fileName.substring(0,fileName.lastIndexOf("."));
suffix = fileName.substring(fileName.lastIndexOf("."),fileName.length());
URL urlfile;
InputStream inStream = null;
OutputStream os = null;
try {
file = File.createTempFile("newImg",suffix);
//下载
urlfile = new URL(url);
inStream = urlfile.openStream();
os = new FileOutputStream(file);
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = inStream.read(buffer, 0, 8192)) != -1) {
os.write(buffer, 0, bytesRead);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (null != os) {
os.close();
}
if (null != inStream) {
inStream.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return file;
}
}