diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/task/KitchenStaffInfoFaceTask.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/task/KitchenStaffInfoFaceTask.java new file mode 100644 index 0000000..c99af8d --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/task/KitchenStaffInfoFaceTask.java @@ -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 list=this.kitchenStaffInfoService.selectKitchenStaffInfoList(new KitchenStaffInfo()); + int userl=-1; + for(KitchenStaffInfo info:list){ + if("1".equals(info.getFaceFlage())){ + continue; + } + List 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()); + + } +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/domain/KitchenStaffIllegalWarning.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/domain/KitchenStaffIllegalWarning.java index 44b3e62..453ee2f 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/domain/KitchenStaffIllegalWarning.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/domain/KitchenStaffIllegalWarning.java @@ -3,6 +3,8 @@ package com.bonus.canteen.core.kitchen.domain; import java.io.Serializable; import java.time.LocalDateTime; import java.util.Date; + +import com.bonus.canteen.core.common.utils.FileUrlUtil; import com.fasterxml.jackson.annotation.JsonFormat; import com.bonus.common.core.annotation.Excel; import com.fasterxml.jackson.annotation.JsonIgnore; @@ -13,7 +15,7 @@ import com.bonus.common.core.web.domain.BaseEntity; /** * 厨房员工违规报警对象 kitchen_staff_illegal_warning - * + * * @author xsheng * @date 2025-06-16 */ @@ -42,6 +44,11 @@ public class KitchenStaffIllegalWarning extends BaseEntity { @ApiModelProperty(value = "记录照片地址") private String imgUrl; + + public String getImgUrl() { + return FileUrlUtil.getFileUrl(this.imgUrl); + } + /** 记录内容 */ @Excel(name = "记录内容") @ApiModelProperty(value = "记录内容") diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/domain/KitchenStaffInfo.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/domain/KitchenStaffInfo.java index 910ea0d..8a9be1a 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/domain/KitchenStaffInfo.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/domain/KitchenStaffInfo.java @@ -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); } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/mapper/KitchenDeviceInfoMapper.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/mapper/KitchenDeviceInfoMapper.java index 4b15a9d..36a4b34 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/mapper/KitchenDeviceInfoMapper.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/mapper/KitchenDeviceInfoMapper.java @@ -43,6 +43,7 @@ public interface KitchenDeviceInfoMapper extends BaseMapper { */ public int insertKitchenDeviceInfo(KitchenDeviceInfo kitchenDeviceInfo); + /** * 修改厨房设备基础信息 * diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/mapper/KitchenStaffInfoMapper.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/mapper/KitchenStaffInfoMapper.java index 73f6a5a..bbc9a39 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/mapper/KitchenStaffInfoMapper.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/mapper/KitchenStaffInfoMapper.java @@ -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); /** * 删除厨房员工资料 * diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/service/IKitchenStaffInfoService.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/service/IKitchenStaffInfoService.java index 9f79096..83a923b 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/service/IKitchenStaffInfoService.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/service/IKitchenStaffInfoService.java @@ -42,6 +42,7 @@ public interface IKitchenStaffInfoService { */ public int updateKitchenStaffInfo(KitchenStaffInfo kitchenStaffInfo); + public int updateKitchenStaffInfoFaceFlage(KitchenStaffInfo kitchenStaffInfo); /** * 修改厨房员工人脸状态 * diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/service/impl/KitchenStaffFaceServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/service/impl/KitchenStaffFaceServiceImpl.java index 788d542..21a5ee8 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/service/impl/KitchenStaffFaceServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/service/impl/KitchenStaffFaceServiceImpl.java @@ -63,47 +63,67 @@ public class KitchenStaffFaceServiceImpl implements IKitchenStaffFaceService { } else { long startTime = System.currentTimeMillis(); //发送请求 调用人脸特征提取接口 - String url = FileUrlUtil.getFileUrl(dto.getPhotoUrl()); - System.out.println("人脸特征提取url:" + url); - String response = FaceFeatureDetector.detectFaceFeature(url); - System.out.println("人脸特征提取接口返回结果:" + response); - JSONObject jsonResponse = JSONObject.parseObject(response.toString()); - if (jsonResponse.getInteger("code") != 30002) { - System.out.println("人脸特征提取失败," + jsonResponse.getString("msg")); - log.error("人脸特征提取失败,{}", jsonResponse.getString("msg")); - throw new ServiceException("人脸特征提取失败," + jsonResponse.getString("msg")); - } - long endTime = System.currentTimeMillis(); - System.out.println("人脸特征提取耗时:" + (endTime - startTime) + "ms"); - List list = new ArrayList<>(); - String dataStr = jsonResponse.getString("data"); - // 将data字符串解析为JSONArray - JSONArray dataArray = JSONArray.parseArray(dataStr); - if (dataArray != null && !dataArray.isEmpty()) { - Object faceFeature = dataArray.get(0); - KitchenStaffFace faceVO = new KitchenStaffFace(); - faceVO.setErrorMsg("[软件]成功"); - faceVO.setFeatures(faceFeature.toString()); - faceVO.setCreateBy(String.valueOf(SecurityUtils.getUserId())); - faceVO.setStaffId(dto.getStaffId()); - faceVO.setPhotoUrl(dto.getPhotoUrl()); - faceVO.setCreateBy(String.valueOf(SecurityUtils.getUserId())); - faceVO.setUpdateBy(String.valueOf(SecurityUtils.getUserId())); - faceVO.setCreateTime(DateUtils.getTime()); - faceVO.setUpdateTime(DateUtils.getTime()); - list.add(faceVO); - int code = kitchenStaffFaceMapper.insertStaffFace(list.get(0)); - if (code == 0) { - System.out.println("[人脸识别算法]:保存失败"); - log.error("[人脸识别算法]:保存失败"); - throw new ServiceException("[人脸识别算法]:保存失败"); - } - DeviceMqPersonalUpdateMessageDTO bean = new DeviceMqPersonalUpdateMessageDTO().setUpdatePersonPhoto(dto.getStaffId().intValue(),"update"); - MqUtil.pushToTenantAllDevice(bean, LeMqConstant.Topic.MORNING_INSPECTION_DEVICE_UPDATE_PERSONAL_CONFIG_V4); - }else{ - throw new ServiceException("人脸特征提取失败,未检测到人脸"); +// String url = FileUrlUtil.getFileUrl(dto.getPhotoUrl()); +// System.out.println("人脸特征提取url:" + url); +// String response = FaceFeatureDetector.detectFaceFeature(url); +// System.out.println("人脸特征提取接口返回结果:" + response); +// JSONObject jsonResponse = JSONObject.parseObject(response.toString()); +// if (jsonResponse.getInteger("code") != 30002) { +// System.out.println("人脸特征提取失败," + jsonResponse.getString("msg")); +// log.error("人脸特征提取失败,{}", jsonResponse.getString("msg")); +// throw new ServiceException("人脸特征提取失败," + jsonResponse.getString("msg")); +// } +// long endTime = System.currentTimeMillis(); +// System.out.println("人脸特征提取耗时:" + (endTime - startTime) + "ms"); +// List list = new ArrayList<>(); +// String dataStr = jsonResponse.getString("data"); +// // 将data字符串解析为JSONArray +// JSONArray dataArray = JSONArray.parseArray(dataStr); +// if (dataArray != null && !dataArray.isEmpty()) { +// Object faceFeature = dataArray.get(0); +// KitchenStaffFace faceVO = new KitchenStaffFace(); +// faceVO.setErrorMsg("[软件]成功"); +// faceVO.setFeatures(faceFeature.toString()); +// faceVO.setCreateBy(String.valueOf(SecurityUtils.getUserId())); +// faceVO.setStaffId(dto.getStaffId()); +// faceVO.setPhotoUrl(dto.getPhotoUrl()); +// faceVO.setCreateBy(String.valueOf(SecurityUtils.getUserId())); +// faceVO.setUpdateBy(String.valueOf(SecurityUtils.getUserId())); +// faceVO.setCreateTime(DateUtils.getTime()); +// faceVO.setUpdateTime(DateUtils.getTime()); +// list.add(faceVO); +// int code = kitchenStaffFaceMapper.insertStaffFace(list.get(0)); +// if (code == 0) { +// System.out.println("[人脸识别算法]:保存失败"); +// log.error("[人脸识别算法]:保存失败"); +// throw new ServiceException("[人脸识别算法]:保存失败"); +// } +// +// DeviceMqPersonalUpdateMessageDTO bean = new DeviceMqPersonalUpdateMessageDTO().setUpdatePersonPhoto(dto.getStaffId().intValue(),"update"); +// MqUtil.pushToTenantAllDevice(bean, LeMqConstant.Topic.MORNING_INSPECTION_DEVICE_UPDATE_PERSONAL_CONFIG_V4); +// }else{ +// throw new ServiceException("人脸特征提取失败,未检测到人脸"); +// } + KitchenStaffFace faceVO = new KitchenStaffFace(); + faceVO.setErrorMsg("[软件]成功"); + faceVO.setFeatures(""); + faceVO.setCreateBy(String.valueOf(SecurityUtils.getUserId())); + faceVO.setStaffId(dto.getStaffId()); + faceVO.setPhotoUrl(dto.getPhotoUrl()); + faceVO.setCreateBy(String.valueOf(SecurityUtils.getUserId())); + faceVO.setUpdateBy(String.valueOf(SecurityUtils.getUserId())); + faceVO.setCreateTime(DateUtils.getTime()); + faceVO.setUpdateTime(DateUtils.getTime()); + int code = kitchenStaffFaceMapper.insertStaffFace(faceVO); + DeviceMqPersonalUpdateMessageDTO bean = new DeviceMqPersonalUpdateMessageDTO().setUpdatePersonPhoto(dto.getStaffId().intValue(),"update"); + MqUtil.pushToTenantAllDevice(bean, LeMqConstant.Topic.MORNING_INSPECTION_DEVICE_UPDATE_PERSONAL_CONFIG_V4); + if (code == 0) { + System.out.println("[人脸识别算法]:保存失败"); + log.error("[人脸识别算法]:保存失败"); + throw new ServiceException("[人脸识别算法]:保存失败"); } } + return AjaxResult.success(); } } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/service/impl/KitchenStaffIllegalWarningServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/service/impl/KitchenStaffIllegalWarningServiceImpl.java index dca94f6..5942ed0 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/service/impl/KitchenStaffIllegalWarningServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/service/impl/KitchenStaffIllegalWarningServiceImpl.java @@ -135,6 +135,7 @@ public class KitchenStaffIllegalWarningServiceImpl implements IKitchenStaffIlleg @Override public void uploadVideoPhoto(byte[] imageBytes, VideoPhotoDTO videoPhotoDTO) { + System.err.println("接收到图片 bytes 长度=" + (imageBytes != null ? imageBytes.length : 0)); AjaxResult ar = fileServiceClient.uploadVideoFile(convertByteToMultipartFile(imageBytes,"demo.jpg")); SysFile sysFile = ar.getDataAs(SysFile.class); KitchenStaffIllegalWarning kitchenStaffIllegalWarning = new KitchenStaffIllegalWarning(); @@ -148,7 +149,9 @@ public class KitchenStaffIllegalWarningServiceImpl implements IKitchenStaffIlleg kitchenStaffIllegalWarning.setCreateBy(SecurityUtils.getUsername()); kitchenStaffIllegalWarning.setCreateTime(DateUtils.getNowDate()); kitchenStaffIllegalWarning.setStaffId(11L); - KitchenDeviceInfo kitchenDeviceInfo = kitchenDeviceInfoMapper.selectKitchenDeviceInfoByChannelAndDeviceType(videoPhotoDTO.getChannel(), DeviceTypeEnum.CAMERA.getKey()+""); + int channel = Integer.parseInt(videoPhotoDTO.getChannel())-33; + + KitchenDeviceInfo kitchenDeviceInfo = kitchenDeviceInfoMapper.selectKitchenDeviceInfoByChannelAndDeviceType(channel+"", DeviceTypeEnum.CAMERA.getKey()+""); if(kitchenDeviceInfo != null){ kitchenStaffIllegalWarning.setDeviceId(kitchenDeviceInfo.getDeviceId()); }else { diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/service/impl/KitchenStaffInfoServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/service/impl/KitchenStaffInfoServiceImpl.java index cbbb899..d6f175a 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/service/impl/KitchenStaffInfoServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/service/impl/KitchenStaffInfoServiceImpl.java @@ -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())) { diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/utils/NetSDK/FaceManage.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/utils/NetSDK/FaceManage.java index 2fa8a7f..0f1f58a 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/utils/NetSDK/FaceManage.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/utils/NetSDK/FaceManage.java @@ -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; } } /** diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/utils/initServer.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/utils/initServer.java index a8a6cd0..e80592d 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/utils/initServer.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/kitchen/utils/initServer.java @@ -28,7 +28,7 @@ public class initServer implements CommandLineRunner { public static String devPass = "hzx12345"; public static int lUserID2 = -1;//用户句柄 - public static String devIp2 = "192.168.10.89"; + public static String devIp2 = "192.168.20.32"; public static String devUser2 = "admin"; public static String devPass2 = "JYY202509"; @Override @@ -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 + } + } } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/user/controller/UserFaceController.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/user/controller/UserFaceController.java index fac243d..ea70582 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/user/controller/UserFaceController.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/user/controller/UserFaceController.java @@ -5,6 +5,7 @@ import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import cn.hutool.core.util.ObjectUtil; +import com.bonus.canteen.core.user.domain.AppUserFace; import com.bonus.common.core.exception.ServiceException; import com.bonus.common.houqin.constant.RetCodeEnum; import com.bonus.common.houqin.encrypt.RequiresGuest; @@ -52,4 +53,17 @@ public class UserFaceController extends BaseController { return UserFaceService.uploadUserFace(dto); } + @ApiOperation("保存APP人脸图片特征值") + @PostMapping({"/saveAppFaceEigenvalue"}) + @RequiresGuest + public AjaxResult saveAppFaceEigenvalue(@RequestBody @Valid AppUserFace dto) { + return UserFaceService.saveAppFaceEigenvalue(dto); + } + @ApiOperation("保存APP人脸图片特征值") + @PostMapping({"/saveHealthAppFaceEigenvalue"}) + @RequiresGuest + public AjaxResult saveHealthAppFaceEigenvalue(@RequestBody @Valid AppUserFace dto) { + return UserFaceService.saveHealthAppFaceEigenvalue(dto); + } + } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/user/domain/AppUserFace.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/user/domain/AppUserFace.java new file mode 100644 index 0000000..a5e5b04 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/user/domain/AppUserFace.java @@ -0,0 +1,10 @@ +package com.bonus.canteen.core.user.domain; + +import lombok.Data; + +import java.util.List; + +@Data +public class AppUserFace { + private List userFaceList; +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/user/mapper/UserFaceMapper.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/user/mapper/UserFaceMapper.java index 8aed641..3f42fb9 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/user/mapper/UserFaceMapper.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/user/mapper/UserFaceMapper.java @@ -2,6 +2,7 @@ package com.bonus.canteen.core.user.mapper; import java.util.List; import com.bonus.canteen.core.user.domain.UserFace; +import org.apache.ibatis.annotations.Param; /** * 人员生物识别特征Mapper接口 @@ -13,4 +14,8 @@ public interface UserFaceMapper { int insertUserFace(UserFace userFace); int deleteUserFace(UserFace userFace); + + int saveBatch(@Param("list") List list); + + int saveHealthBatch(@Param("list") List list); } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/user/service/IUserFaceService.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/user/service/IUserFaceService.java index 6b3a525..425c25c 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/user/service/IUserFaceService.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/user/service/IUserFaceService.java @@ -1,6 +1,8 @@ package com.bonus.canteen.core.user.service; import java.util.List; + +import com.bonus.canteen.core.user.domain.AppUserFace; import com.bonus.canteen.core.user.domain.UserFace; import com.bonus.common.core.web.domain.AjaxResult; @@ -20,4 +22,13 @@ public interface IUserFaceService { * @return 人员生物识别特征 */ AjaxResult uploadUserFace(@Valid UserFace dto); + /** + * 保存APP人脸图片特征值 + * + * @param dto 人员生物识别特征主键 + * @return 人员生物识别特征 + */ + AjaxResult saveAppFaceEigenvalue(AppUserFace dto); + + AjaxResult saveHealthAppFaceEigenvalue(AppUserFace dto); } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/user/service/impl/UserFaceServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/user/service/impl/UserFaceServiceImpl.java index 2b057e1..33846a1 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/user/service/impl/UserFaceServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/user/service/impl/UserFaceServiceImpl.java @@ -3,10 +3,8 @@ package com.bonus.canteen.core.user.service.impl; import java.beans.FeatureDescriptor; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Base64; -import java.util.List; +import java.util.*; +import java.util.stream.Collectors; import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSONArray; @@ -14,6 +12,7 @@ import com.alibaba.fastjson.JSONObject; import com.bonus.canteen.core.common.utils.FileUrlUtil; import com.bonus.canteen.core.common.utils.HttpClient; import com.bonus.canteen.core.common.utils.MqUtil; +import com.bonus.canteen.core.user.domain.AppUserFace; import com.bonus.canteen.core.user.domain.DeviceMqPersonalUpdateMessageDTO; import com.bonus.canteen.core.user.utils.ArcFaceHelper; import com.bonus.canteen.core.user.utils.FaceFeatureDetector; @@ -31,6 +30,7 @@ import org.springframework.stereotype.Service; import com.bonus.canteen.core.user.mapper.UserFaceMapper; import com.bonus.canteen.core.user.domain.UserFace; import com.bonus.canteen.core.user.service.IUserFaceService; +import org.springframework.transaction.annotation.Transactional; /** * 人员生物识别特征Service业务层处理 @@ -105,10 +105,69 @@ public class UserFaceServiceImpl implements IUserFaceService { } DeviceMqPersonalUpdateMessageDTO bean = new DeviceMqPersonalUpdateMessageDTO().setUpdatePersonPhoto(dto.getUserId().intValue(), "update"); MqUtil.pushToTenantAllDevice(bean, LeMqConstant.Topic.DEVICE_UPDATE_PERSONAL_CONFIG_V4); - }else{ + } else { throw new ServiceException("人脸特征提取失败,未检测到人脸"); } } return AjaxResult.success(); } + + /** + * 保存APP人脸图片特征值 + * + * @param dto 人员生物识别特征主键 + * @return 人员生物识别特征 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public AjaxResult saveAppFaceEigenvalue(AppUserFace dto) { + if (ObjectUtil.isNull(dto)) { + throw new ServiceException("参数为空!"); + } + if (ObjectUtil.isNull(dto.getUserFaceList()) || dto.getUserFaceList().isEmpty()) { + throw new ServiceException("人脸特征值为空!"); + } + List list = dto.getUserFaceList(); + list.forEach(faceVO -> { + faceVO.setErrorMsg("[软件]成功"); + faceVO.setUpdateBy(String.valueOf(SecurityUtils.getUserId())); + faceVO.setUpdateTime(DateUtils.getTime()); + faceVO.setPhotoType(1L); + }); + int code = userFaceMapper.saveBatch(list); + if (code > 0) { + DeviceMqPersonalUpdateMessageDTO bean = new DeviceMqPersonalUpdateMessageDTO().setUpdatePersonPhoto(null, "update"); + MqUtil.pushToTenantAllDevice(bean, LeMqConstant.Topic.DEVICE_UPDATE_PERSONAL_CONFIG_V4); + return AjaxResult.success(); + } else { + throw new ServiceException("保存失败"); + } + + } + + @Override + public AjaxResult saveHealthAppFaceEigenvalue(AppUserFace dto) { + if (ObjectUtil.isNull(dto)) { + throw new ServiceException("参数为空!"); + } + if (ObjectUtil.isNull(dto.getUserFaceList()) || dto.getUserFaceList().isEmpty()) { + throw new ServiceException("人脸特征值为空!"); + } + List list = dto.getUserFaceList(); + list.forEach(faceVO -> { + faceVO.setErrorMsg("[软件]成功"); + faceVO.setUpdateBy(String.valueOf(SecurityUtils.getUserId())); + faceVO.setUpdateTime(DateUtils.getTime()); + faceVO.setPhotoType(1L); + }); + int code = userFaceMapper.saveHealthBatch(list); + if (code > 0) { + DeviceMqPersonalUpdateMessageDTO bean = new DeviceMqPersonalUpdateMessageDTO().setUpdatePersonPhoto(null, "update"); + MqUtil.pushToTenantAllDevice(bean, LeMqConstant.Topic.MORNING_INSPECTION_DEVICE_UPDATE_PERSONAL_CONFIG_V4); + return AjaxResult.success(); + } else { + throw new ServiceException("保存失败"); + } + + } } diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/android/FaceMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/android/FaceMapper.xml index 35e98c9..b77382a 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/android/FaceMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/android/FaceMapper.xml @@ -9,8 +9,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" features, face_state from user_face - where face_state = '1' - and features_build_time >= NOW() - INTERVAL 1 DAY + where face_state = '1' and features_state = '0' and user_id = #{userId} @@ -23,10 +22,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" features, face_state from kitchen_staff_face - where face_state = '1' - and features_build_time >= NOW() - INTERVAL 1 DAY - - and staff_id = #{userId} - + where face_state = '1' and features_state = '0' + + and staff_id = #{userId} + \ No newline at end of file diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookDishesMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookDishesMapper.xml index 6ef6b67..100a083 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookDishesMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookDishesMapper.xml @@ -593,7 +593,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" unit_price = #{unitPrice}, large_price = #{largePrice}, little_price = #{littlePrice}, - image_url = #{imageUrl}, + image_url = #{imageUrl}, particulars = #{particulars}, recommend = #{recommend}, index_recommend = #{indexRecommend}, diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/healthmachine/HealthMachineMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/healthmachine/HealthMachineMapper.xml index 26c5295..0a284cf 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/healthmachine/HealthMachineMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/healthmachine/HealthMachineMapper.xml @@ -17,15 +17,16 @@ insert into kitchen_staff_physical_examination(staff_id, device_id, sex, age, height, weight, bmi, bodyFat, muscle, boneMass, - waterContent, extwater, protein, metabolism, fatLevel, bodyAge) + waterContent, extwater, protein, metabolism, fatLevel, bodyAge,phone) values (#{dto.userId},#{dto.machineId},#{dto.sex},#{dto.age},#{dto.height},#{dto.weight},#{dto.bmi},#{dto.bodyFat},#{dto.muscle},#{dto.boneMass},#{dto.waterContent},#{dto.extwater},#{dto.protein} - ,#{dto.metabolism},#{dto.fatLevel},#{dto.bodyAge}) + ,#{dto.metabolism},#{dto.fatLevel},#{dto.bodyAge},#{dto.phone}) - \ No newline at end of file + diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/kitchen/KitchenStaffFaceMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/kitchen/KitchenStaffFaceMapper.xml index 4fcab36..d52223b 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/kitchen/KitchenStaffFaceMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/kitchen/KitchenStaffFaceMapper.xml @@ -10,13 +10,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - insert into kitchen_staff_face(staff_id,photo_url,features,create_by,error_msg,create_time,update_by,update_time) - values(#{staffId},#{photoUrl},#{features},#{createBy},#{errorMsg},#{createTime},#{updateBy},#{updateTime}) + insert into kitchen_staff_face(staff_id,photo_url,features,create_by,error_msg,create_time,update_by,update_time,features_state) + values(#{staffId},#{photoUrl},#{features},#{createBy},#{errorMsg},#{createTime},#{updateBy},#{updateTime},'0') on duplicate key update features = #{features}, photo_url = #{photoUrl}, error_msg = #{errorMsg}, update_by = #{updateBy}, - update_time = #{updateTime} + update_time = #{updateTime}, + features_state = '0' diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/kitchen/KitchenStaffInfoMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/kitchen/KitchenStaffInfoMapper.xml index bbc364e..bdf304c 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/kitchen/KitchenStaffInfoMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/kitchen/KitchenStaffInfoMapper.xml @@ -26,13 +26,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + 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 kitchen_staff_info set face_flage='1' where staff_id=#{staffId} + delete from kitchen_staff_info where staff_id = #{staffId} diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/user/UserFaceMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/user/UserFaceMapper.xml index bebd292..1232ce7 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/user/UserFaceMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/user/UserFaceMapper.xml @@ -4,17 +4,48 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - insert into user_face(user_id,photo_url,features,create_by,error_msg,create_time,update_by,update_time) - values(#{userId},#{photoUrl},#{features},#{createBy},#{errorMsg},#{createTime},#{updateBy},#{updateTime}) + insert into user_face(user_id,photo_url,features,create_by,error_msg,create_time,update_by,update_time,features_state) + values(#{userId},#{photoUrl},#{features},#{createBy},#{errorMsg},#{createTime},#{updateBy},#{updateTime},'0') on duplicate key update features = #{features}, photo_url = #{photoUrl}, error_msg = #{errorMsg}, update_by = #{updateBy}, - update_time = #{updateTime} + update_time = #{updateTime}, + features_state = '0' delete from user_face where user_id = #{userId} + + + insert into user_face(user_id,photo_url,features,create_by,error_msg,create_time,update_by,update_time,features_state) + values + + (#{item.userId},#{item.photoUrl},#{item.features},#{item.createBy},#{item.errorMsg},#{item.createTime},#{item.updateBy},#{item.updateTime},'1') + + on duplicate key update features = values(features), + photo_url = values(photo_url), + error_msg = values(error_msg), + update_by = values(update_by), + update_time = values(update_time), + features_state = '1' + + + \ No newline at end of file