jsk 门禁人脸下发

This commit is contained in:
jiask 2025-09-29 09:54:40 +08:00
parent b9c6165229
commit b214fb353a
9 changed files with 160 additions and 5 deletions

View File

@ -0,0 +1,86 @@
package com.bonus.canteen.core.cook.task;
import com.bonus.canteen.core.common.utils.RedisUtil;
import com.bonus.canteen.core.cook.service.ICookRecipeService;
import com.bonus.canteen.core.kitchen.domain.AccessAuthority;
import com.bonus.canteen.core.kitchen.domain.KitchenStaffInfo;
import com.bonus.canteen.core.kitchen.service.IKitchenDeviceInfoService;
import com.bonus.canteen.core.kitchen.service.IKitchenStaffInfoService;
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.common.houqin.constant.DeviceTypeEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.support.TransactionTemplate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
@Component
public class KitchenStaffInfoFaceTask {
private static final Logger logger = LoggerFactory.getLogger(KitchenStaffInfoFaceTask.class);
@Autowired
private IKitchenStaffInfoService kitchenStaffInfoService;
@Autowired
private IKitchenDeviceInfoService kitchenDeviceInfoService;
// @Autowired
// private TransactionTemplate transactionTemplate;
//@XxlJob("cookRecipeHandler")
@Scheduled(fixedDelay = 10*60*1000)
public void KitchenStaffInfoFaceHandler() {
if(1==1){
return;
}
logger.info("[定时修复发送门禁人脸信息]开始:{},{}", "0", LocalDateTime.now());
try{
List<KitchenStaffInfo> list=this.kitchenStaffInfoService.selectKitchenStaffInfoList(new KitchenStaffInfo());
int userl=-1;
for(KitchenStaffInfo info:list){
if("1".equals(info.getFaceFlage())){
continue;
}
List<AccessAuthority> devlist=new ArrayList<>();
if(info.getAccessAuthorityList()!=null&&info.getAccessAuthorityList().size()>0){
for(AccessAuthority aaInfo:info.getAccessAuthorityList()){
if(DeviceTypeEnum.DOOR.getKey().equals(aaInfo.getDeviceType())){
devlist.add(aaInfo);
}
}
}
if(devlist!=null&&devlist.size()>0){
for(AccessAuthority aaInfo:devlist){
KitchenDeviceListVO vo=kitchenDeviceInfoService.selectKitchenDeviceInfoByDeviceId(aaInfo.getDeviceId());
String ip="192.168.20.51";
String user="admin";
String pass="JYY202509";
userl=initServer.LoginReture(ip,user,pass,(short) 8000,1);
if(userl==-1){
logger.info("[定时修复发送门禁人脸信息]{},{}", ip+"无法登录", LocalDateTime.now());
}else{
logger.info("[定时修复发送门禁人脸信息]{},{}", ip+"登录成功", LocalDateTime.now());
logger.info(info.getStaffNo());
logger.info(info.getFaceUrl());
int faceres=FaceManage.addFaceByUrl(userl,info.getStaffNo(),info.getFaceUrl());
if(faceres==1){
kitchenStaffInfoService.updateKitchenStaffInfoFaceFlage(info);
}
}
}
}
}
initServer.logout(userl);
}catch (Exception e){
e.printStackTrace();
}
logger.info("[定时修复发送门禁人脸信息]结束:{},{}", "1", LocalDateTime.now());
}
}

View File

@ -121,7 +121,7 @@ public class KitchenStaffInfo extends BaseEntity {
private String encryptedSearchValue;
private String searchValue;
private String faceFlage;
public String getHealthCertFrontImg() {
return FileUrlUtil.getFileUrl(this.healthCertFrontImg);
}

View File

@ -43,6 +43,7 @@ public interface KitchenDeviceInfoMapper extends BaseMapper<KitchenDeviceInfo> {
*/
public int insertKitchenDeviceInfo(KitchenDeviceInfo kitchenDeviceInfo);
/**
* 修改厨房设备基础信息
*

View File

@ -1,6 +1,8 @@
package com.bonus.canteen.core.kitchen.mapper;
import java.util.List;
import com.bonus.canteen.core.kitchen.domain.KitchenDeviceInfo;
import com.bonus.canteen.core.kitchen.domain.KitchenStaffInfo;
import org.apache.ibatis.annotations.Param;
@ -42,7 +44,7 @@ public interface KitchenStaffInfoMapper {
* @return 结果
*/
public int updateKitchenStaffInfo(KitchenStaffInfo kitchenStaffInfo);
public int updateKitchenStaffInfoFaceFlage(KitchenStaffInfo kitchenStaffInfo);
/**
* 删除厨房员工资料
*

View File

@ -42,6 +42,7 @@ public interface IKitchenStaffInfoService {
*/
public int updateKitchenStaffInfo(KitchenStaffInfo kitchenStaffInfo);
public int updateKitchenStaffInfoFaceFlage(KitchenStaffInfo kitchenStaffInfo);
/**
* 修改厨房员工人脸状态
*

View File

@ -217,6 +217,10 @@ public class KitchenStaffInfoServiceImpl implements IKitchenStaffInfoService {
return 1;
}
@Override
public int updateKitchenStaffInfoFaceFlage(KitchenStaffInfo kitchenStaffInfo){
return kitchenStaffInfoMapper.updateKitchenStaffInfoFaceFlage(kitchenStaffInfo);
}
@Override
public int updateKitchenStaffFaceState(KitchenStaffInfo kitchenStaffInfo) {
if(Objects.isNull(kitchenStaffInfo.getStaffId())) {

View File

@ -129,7 +129,8 @@ public final class FaceManage {
* @param employeeNo 人员工号
* @throws JSONException
*/
public static void addFaceByUrl(int userID,String employeeNo,String fileUrl) throws JSONException {
public static int addFaceByUrl(int userID,String employeeNo,String fileUrl) throws JSONException {
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());//字符串拷贝到数组中
@ -137,7 +138,7 @@ public final class FaceManage {
int lHandler = initServer.hCNetSDK.NET_DVR_StartRemoteConfig(userID, HCNetSDK.NET_DVR_FACE_DATA_RECORD, ptrByteArray.getPointer(), strInBuffer.length(), null, null);
if (lHandler < 0){
System.out.println("Addface NET_DVR_StartRemoteConfig 失败,错误码为"+initServer.hCNetSDK.NET_DVR_GetLastError());
return;
return userl;
}else{
System.out.println("Addface NET_DVR_StartRemoteConfig 成功!");
HCNetSDK.NET_DVR_JSON_DATA_CFG struAddFaceDataCfg = new HCNetSDK.NET_DVR_JSON_DATA_CFG();
@ -190,11 +191,13 @@ public final class FaceManage {
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;
}
}
@ -202,7 +205,9 @@ public final class FaceManage {
System.out.println("NET_DVR_StopRemoteConfig接口调用失败错误码" + initServer.hCNetSDK.NET_DVR_GetLastError());
}else{
System.out.println("NET_DVR_StopRemoteConfig接口成功");
userl=1;
}
return userl;
}
}
/**

View File

@ -193,5 +193,57 @@ public class initServer implements CommandLineRunner {
}
}
public static int LoginReture(String ipadress, String user, String psw, short port,int type) {
int returnl=-1;
//注册
HCNetSDK.NET_DVR_USER_LOGIN_INFO m_strLoginInfo = new HCNetSDK.NET_DVR_USER_LOGIN_INFO();//设备登录信息
String m_sDeviceIP = ipadress;//设备ip地址
m_strLoginInfo.sDeviceAddress = new byte[HCNetSDK.NET_DVR_DEV_ADDRESS_MAX_LEN];
System.arraycopy(m_sDeviceIP.getBytes(), 0, m_strLoginInfo.sDeviceAddress, 0, m_sDeviceIP.length());
String m_sUsername = user;//设备用户名
m_strLoginInfo.sUserName = new byte[HCNetSDK.NET_DVR_LOGIN_USERNAME_MAX_LEN];
System.arraycopy(m_sUsername.getBytes(), 0, m_strLoginInfo.sUserName, 0, m_sUsername.length());
String m_sPassword = psw;//设备密码
m_strLoginInfo.sPassword = new byte[HCNetSDK.NET_DVR_LOGIN_PASSWD_MAX_LEN];
System.arraycopy(m_sPassword.getBytes(), 0, m_strLoginInfo.sPassword, 0, m_sPassword.length());
m_strLoginInfo.wPort = port; //sdk端口
m_strLoginInfo.bUseAsynLogin = false; //是否异步登录0- 1-
m_strLoginInfo.write();
HCNetSDK.NET_DVR_DEVICEINFO_V40 m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V40();//设备信息
if(type == 1){
returnl = hCNetSDK.NET_DVR_Login_V40(m_strLoginInfo, m_strDeviceInfo);
if (returnl == -1){
System.out.println(ipadress+"门禁登录失败,错误码为" + hCNetSDK.NET_DVR_GetLastError());
}else{
System.out.println(ipadress+"门禁登录成功!");
m_strDeviceInfo.read();
iCharEncodeType = m_strDeviceInfo.byCharEncodeType;
}
}else{
returnl = hCNetSDK.NET_DVR_Login_V40(m_strLoginInfo, m_strDeviceInfo);
if (returnl == -1){
System.out.println("智能识别登录失败,错误码为" + hCNetSDK.NET_DVR_GetLastError());
}else{
System.out.println("智能识别登录成功!");
m_strDeviceInfo.read();
iCharEncodeType = m_strDeviceInfo.byCharEncodeType;
}
}
return returnl;
}
public static void logout(int m_lUserID) {
if (m_lUserID != -1) {
boolean result = hCNetSDK.NET_DVR_Logout_V30(m_lUserID); // 使用V30版本注销根据你的SDK版本选择合适的注销方法
if (result) {
System.out.println("Logout successful");
} else {
System.out.println("Logout failed");
}
m_lUserID = -1; // 重置用户ID
}
}
}

View File

@ -26,13 +26,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="faceFlage" column="face_flage" />
</resultMap>
<sql id="selectKitchenStaffInfoVo">
select kst.staff_id, kst.canteen_id, staff_no, staff_name, post_name, mobile, password, sex, kst.area_id, health_cert_expire,
health_cert_front_img, health_cert_back_img, nutrity_cert_expire,
safety_cert_expire, kst.create_by, kst.create_time, kst.update_by, kst.update_time,
ksf.photo_url, ksf.face_state, bc.canteen_name, ba.area_name
ksf.photo_url, ksf.face_state, bc.canteen_name, ba.area_name,kst.face_flage
from kitchen_staff_info kst
left join kitchen_staff_face ksf on kst.staff_id = ksf.staff_id
left join basic_canteen bc on kst.canteen_id = bc.canteen_id
@ -159,6 +160,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where staff_id = #{staffId}
</update>
<update id="updateKitchenStaffInfoFaceFlage" parameterType="com.bonus.canteen.core.kitchen.domain.KitchenStaffInfo">
update kitchen_staff_info set face_flage='1' where staff_id=#{staffId}
</update>
<delete id="deleteKitchenStaffInfoByStaffId" parameterType="Long">
delete from kitchen_staff_info where staff_id = #{staffId}
</delete>