| | |
| | | package com.ard.utils.sdk.hiksdk.service.impl; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.ard.alarm.camera.domain.ArdCameras; |
| | | import com.ard.alarm.camera.domain.CameraCmd; |
| | | import com.ard.alarm.camera.service.impl.ArdCamerasServiceImpl; |
| | |
| | | import com.ard.alarm.external.service.impl.ArdEquipExternalServiceImpl; |
| | | import com.ard.utils.sdk.hiksdk.domain.*; |
| | | import com.ard.utils.minio.MinioUtil; |
| | | import com.ard.utils.sdk.hiksdk.domain.isapi.FaceCapture; |
| | | import com.ard.utils.sdk.hiksdk.domain.isapi.IsapiAlarm; |
| | | import com.ard.utils.util.ByteUtils; |
| | | import com.ard.utils.sdk.hiksdk.common.GlobalVariable; |
| | | import com.ard.utils.sdk.hiksdk.util.hikSdkUtil.HCNetSDK; |
| | |
| | | import java.nio.ByteBuffer; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Optional; |
| | | |
| | | import static com.ard.utils.sdk.hiksdk.util.hikSdkUtil.HCNetSDK.*; |
| | |
| | | public boolean invoke(int lCommand, HCNetSDK.NET_DVR_ALARMER pAlarmer, Pointer pAlarmInfo, int dwBufLen, Pointer pUser) { |
| | | SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | String sDeviceIP = ByteUtils.bytesToStringZh(pAlarmer.sDeviceIP).trim();//设备IP地址 |
| | | Integer wLinkPort = Integer.valueOf(pAlarmer.wLinkPort);//设备通讯端口 |
| | | int wLinkPort = pAlarmer.wLinkPort;//设备通讯端口 |
| | | //通过ip和端口查询设备 |
| | | Optional<ArdCameras> foundCamera = findArdCameraByIpAndPort(sDeviceIP, wLinkPort); |
| | | Optional<ArdEquipExternal> foundExternal = findArdEquipExternalByIpAndPort(sDeviceIP, wLinkPort); |
| | |
| | | if (camera == null && ardEquipExternal == null) { |
| | | return false; |
| | | } |
| | | CameraEventInfo cameraEventInfo; |
| | | SuperBrainEventInfo superBrainEventInfo; |
| | | String alarmName = "";//报警名称 |
| | | String alarmTime;//事件时间 |
| | | String alarmType = "";//报警类型 |
| | | String picUrl = "";//事件图片 |
| | | String facePicUrl = "";//人脸抓拍图片 |
| | | String faceLibUrl = "";//人脸库图片 |
| | | int dwPicDataLen;//图片数据长度 |
| | | int chanNo = 0;//通道号 |
| | | //lCommand是传的报警类型 |
| | | log.debug("【" + sDeviceIP + ":" + wLinkPort + "】报警事件类型:lCommand:" + Integer.toHexString(lCommand)); |
| | | switch (lCommand) { |
| | |
| | | switch (netDvrAlarminfoV30.dwAlarmType) { |
| | | case 3: |
| | | if (camera != null) { |
| | | cameraEventHandler(camera, "移动侦测", "移动侦测报警", fmt.format(new Date()), ""); |
| | | for (byte b : netDvrAlarminfoV30.byChannel) { |
| | | if (b == 1) { |
| | | chanNo = b; |
| | | switch (camera.getGdType()) { |
| | | case "0": |
| | | cameraEventHandler(camera, chanNo, "移动侦测", "移动侦测报警", fmt.format(new Date()), picUrl, ""); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | } |
| | |
| | | strVcaAlarm.read(); |
| | | Integer ruleID = Integer.valueOf(strVcaAlarm.struRuleInfo.byRuleID); |
| | | alarmTime = DateUtils.parseTime(strVcaAlarm.dwAbsTime);//事件时间 |
| | | Integer channel = Integer.valueOf(strVcaAlarm.struDevInfo.byChannel);//通道 |
| | | chanNo = Integer.valueOf(strVcaAlarm.struDevInfo.byChannel);//通道 |
| | | switch (strVcaAlarm.struRuleInfo.wEventTypeEx) { |
| | | case 1: //region穿越警戒面 (越界侦测) |
| | | alarmType = "越界侦测报警"; |
| | |
| | | alarmType = "倒地检测事件报警"; |
| | | //endregion |
| | | break; |
| | | case 35: //region 倒地检测 |
| | | case 35: //region 人数变化事件报警 |
| | | alarmType = "人数变化事件报警"; |
| | | //endregion |
| | | break; |
| | |
| | | dwPicDataLen = strVcaAlarm.dwPicDataLen; |
| | | int byPicTransType = strVcaAlarm.byPicTransType; |
| | | if (dwPicDataLen > 0 && strVcaAlarm.pImage != null && byPicTransType == 0) { |
| | | //将字节写入文件 |
| | | long offset = 0; |
| | | ByteBuffer buffers = strVcaAlarm.pImage.getByteBuffer(offset, dwPicDataLen); |
| | | byte[] bytes = new byte[dwPicDataLen]; |
| | | buffers.rewind(); |
| | | buffers.get(bytes); |
| | | InputStream input = new ByteArrayInputStream(bytes); |
| | | try { |
| | | String bucketName = "pic"; |
| | | String objectName = "alarm/" + IdUtils.simpleUUID() + ".jpeg"; |
| | | boolean uploadObject = MinioUtil.uploadObject(bucketName, objectName, input, input.available(), "image/JPEG"); |
| | | if (uploadObject) { |
| | | picUrl = MinioUtil.getBucketObjectUrl(bucketName, objectName); |
| | | //log.debug("上传文件成功!" + picUrl); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("异常行为识别信息报警信息上报图片保存失败" + e.getMessage()); |
| | | } |
| | | picUrl = saveBinPicToMinio(strVcaAlarm.pImage, dwPicDataLen); |
| | | } |
| | | if (camera != null) { |
| | | camera.setChannel(channel); |
| | | cameraEventHandler(camera, alarmName, alarmType, alarmTime, picUrl); |
| | | } |
| | | if (ardEquipExternal != null) { |
| | | alarmName = "异常行为识别"; |
| | | superBrainEventHandler(ardEquipExternal, channel, alarmName, alarmType, alarmTime, picUrl, ""); |
| | | switch (camera.getGdType()) { |
| | | case "0": |
| | | cameraEventHandler(camera, chanNo, alarmName, alarmType, alarmTime, picUrl, ""); |
| | | break; |
| | | case "3": |
| | | superBrainEventHandler(camera, chanNo, alarmName, alarmType, alarmTime, picUrl, ""); |
| | | break; |
| | | } |
| | | } |
| | | //endregion |
| | | break; |
| | | case COMM_UPLOAD_FACESNAP_RESULT: |
| | | log.debug("人脸抓拍报警信息(暂不解析)"); |
| | | log.debug("人脸抓拍报警信息上报"); |
| | | //region 人脸抓拍报警信息 |
| | | HCNetSDK.NET_VCA_FACESNAP_RESULT struFaceSnap = new HCNetSDK.NET_VCA_FACESNAP_RESULT(); |
| | | struFaceSnap.write(); |
| | |
| | | struFaceSnap.read(); |
| | | alarmTime = DateUtils.parseTime(struFaceSnap.dwAbsTime); |
| | | String facePicTyp; |
| | | chanNo = struFaceSnap.struDevInfo.byChannel; |
| | | switch (struFaceSnap.byUploadEventDataType) { |
| | | case 0: |
| | | facePicTyp = "二进制数据"; |
| | |
| | | break; |
| | | } |
| | | if (struFaceSnap.dwFacePicLen > 0 && struFaceSnap.pBuffer1 != null) { |
| | | //将字节写入文件 |
| | | long offset = 0; |
| | | ByteBuffer buffers = struFaceSnap.pBuffer1.getByteBuffer(offset, struFaceSnap.dwBackgroundPicLen); |
| | | byte[] bytes = new byte[struFaceSnap.dwBackgroundPicLen]; |
| | | buffers.rewind(); |
| | | buffers.get(bytes); |
| | | InputStream input = new ByteArrayInputStream(bytes); |
| | | try { |
| | | String bucketName = "pic"; |
| | | String objectName = "alarm/" + IdUtils.simpleUUID() + ".jpeg"; |
| | | boolean uploadObject = MinioUtil.uploadObject(bucketName, objectName, input, input.available(), "image/JPEG"); |
| | | if (uploadObject) { |
| | | facePicUrl = MinioUtil.getBucketObjectUrl(bucketName, objectName); |
| | | //log.debug("上传文件成功!" + url); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("人脸抓拍报警信息图片保存失败" + e.getMessage()); |
| | | } |
| | | facePicUrl = saveBinPicToMinio(struFaceSnap.pBuffer1, struFaceSnap.dwFacePicLen); |
| | | } |
| | | if (struFaceSnap.dwBackgroundPicLen > 0 && struFaceSnap.pBuffer2 != null) { |
| | | //将字节写入文件 |
| | | long offset = 0; |
| | | ByteBuffer buffers = struFaceSnap.pBuffer2.getByteBuffer(offset, struFaceSnap.dwBackgroundPicLen); |
| | | byte[] bytes = new byte[struFaceSnap.dwBackgroundPicLen]; |
| | | buffers.rewind(); |
| | | buffers.get(bytes); |
| | | InputStream input = new ByteArrayInputStream(bytes); |
| | | try { |
| | | String bucketName = "pic"; |
| | | String objectName = "alarm/" + IdUtils.simpleUUID() + ".jpeg"; |
| | | boolean uploadObject = MinioUtil.uploadObject(bucketName, objectName, input, input.available(), "image/JPEG"); |
| | | if (uploadObject) { |
| | | picUrl = MinioUtil.getBucketObjectUrl(bucketName, objectName); |
| | | //log.debug("上传文件成功!" + url); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("人脸抓拍报警信息图片保存失败" + e.getMessage()); |
| | | } |
| | | picUrl = saveBinPicToMinio(struFaceSnap.pBuffer2, struFaceSnap.dwBackgroundPicLen); |
| | | } |
| | | //log.debug("【人脸抓拍报警信息】: alarmTime:" + alarmTime + " picUrl:" + picUrl + " facePicType:" + facePicTyp + " facePicUrl:" + facePicUrl); |
| | | FaceSnapEventInfo faceSnapEventInfo = new FaceSnapEventInfo(); |
| | | faceSnapEventInfo.setAlarmTime(alarmTime); |
| | | faceSnapEventInfo.setPicUrl(picUrl); |
| | | publishMqtt(faceSnapEventInfo, "superbrain"); |
| | | if (camera != null) { |
| | | alarmName = "人脸抓拍检测"; |
| | | alarmType = "人脸抓拍报警"; |
| | | switch (camera.getGdType()) { |
| | | case "0": |
| | | cameraEventHandler(camera, chanNo, alarmName, alarmType, alarmTime, "", ""); |
| | | break; |
| | | case "3": |
| | | superBrainEventHandler(camera, chanNo, alarmName, alarmType, alarmTime, picUrl, facePicUrl); |
| | | break; |
| | | } |
| | | } |
| | | //endregion |
| | | break; |
| | | case COMM_SNAP_MATCH_ALARM: |
| | | log.debug("人脸比对报警信息"); |
| | | log.debug("人脸比对报警信息上报"); |
| | | //region 人脸比对报警信息 |
| | | HCNetSDK.NET_VCA_FACESNAP_MATCH_ALARM struFaceMatchAlarm = new HCNetSDK.NET_VCA_FACESNAP_MATCH_ALARM(); |
| | | struFaceMatchAlarm.byPicTransType = 0; |
| | | struFaceMatchAlarm.write(); |
| | | Pointer fmaInfo = struFaceMatchAlarm.getPointer(); |
| | | fmaInfo.write(0, pAlarmInfo.getByteArray(0, struFaceMatchAlarm.size()), 0, struFaceMatchAlarm.size()); |
| | | struFaceMatchAlarm.read(); |
| | | alarmTime = DateUtils.parseTime(struFaceMatchAlarm.struSnapInfo.dwAbsTime);//报警时间 |
| | | chanNo = struFaceMatchAlarm.struSnapInfo.struDevInfo.byChannel; |
| | | int byMatchPicNum = struFaceMatchAlarm.byMatchPicNum;//匹配图片数量 |
| | | int picTransType = struFaceMatchAlarm.byPicTransType;////图片数据传输方式: 0-二进制;1-url |
| | | String contrastStatus = ""; |
| | | switch (struFaceMatchAlarm.byContrastStatus) { |
| | | case 1: |
| | |
| | | default: |
| | | BlockType = "未知"; |
| | | break; |
| | | } |
| | | //人脸比对报警图片保存,图片格式二进制 |
| | | if ((struFaceMatchAlarm.dwSnapPicLen > 0) && (struFaceMatchAlarm.byPicTransType == 0)) { |
| | | SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss"); |
| | | String newName = sf.format(new Date()); |
| | | FileOutputStream fout; |
| | | try { |
| | | String filename = "../pic/" + newName + "_pSnapPicBuffer" + ".jpg"; |
| | | fout = new FileOutputStream(filename); |
| | | //将字节写入文件 |
| | | long offset = 0; |
| | | ByteBuffer buffers = struFaceMatchAlarm.pSnapPicBuffer.getByteBuffer(offset, struFaceMatchAlarm.dwSnapPicLen); |
| | | byte[] bytes = new byte[struFaceMatchAlarm.dwSnapPicLen]; |
| | | buffers.rewind(); |
| | | buffers.get(bytes); |
| | | fout.write(bytes); |
| | | fout.close(); |
| | | } catch (FileNotFoundException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | } catch (IOException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | if ((struFaceMatchAlarm.struSnapInfo.dwSnapFacePicLen > 0) && (struFaceMatchAlarm.byPicTransType == 0)) { |
| | | SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss"); |
| | | String newName = sf.format(new Date()); |
| | | FileOutputStream fout; |
| | | try { |
| | | String filename = "../pic/" + newName + "_struSnapInfo_pBuffer1" + ".jpg"; |
| | | fout = new FileOutputStream(filename); |
| | | //将字节写入文件 |
| | | long offset = 0; |
| | | ByteBuffer buffers = struFaceMatchAlarm.struSnapInfo.pBuffer1.getByteBuffer(offset, struFaceMatchAlarm.struSnapInfo.dwSnapFacePicLen); |
| | | byte[] bytes = new byte[struFaceMatchAlarm.struSnapInfo.dwSnapFacePicLen]; |
| | | buffers.rewind(); |
| | | buffers.get(bytes); |
| | | fout.write(bytes); |
| | | fout.close(); |
| | | } catch (FileNotFoundException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | } catch (IOException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | if ((struFaceMatchAlarm.struBlockListInfo.dwBlockListPicLen > 0) && (struFaceMatchAlarm.byPicTransType == 0)) { |
| | | SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss"); |
| | | String newName = sf.format(new Date()); |
| | | FileOutputStream fout; |
| | | try { |
| | | String filename = "../pic/" + newName + "_fSimilarity_" + struFaceMatchAlarm.fSimilarity + "_struBlackListInfo_pBuffer1" + ".jpg"; |
| | | fout = new FileOutputStream(filename); |
| | | //将字节写入文件 |
| | | long offset = 0; |
| | | ByteBuffer buffers = struFaceMatchAlarm.struBlockListInfo.pBuffer1.getByteBuffer(offset, struFaceMatchAlarm.struBlockListInfo.dwBlockListPicLen); |
| | | byte[] bytes = new byte[struFaceMatchAlarm.struBlockListInfo.dwBlockListPicLen]; |
| | | buffers.rewind(); |
| | | buffers.get(bytes); |
| | | fout.write(bytes); |
| | | fout.close(); |
| | | } catch (FileNotFoundException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | } catch (IOException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | //人脸比对报警图片保存,图片格式URL格式 |
| | | if ((struFaceMatchAlarm.dwSnapPicLen > 0) && (struFaceMatchAlarm.byPicTransType == 1)) { |
| | |
| | | byte[] bytes = new byte[struFaceMatchAlarm.struBlockListInfo.dwBlockListPicLen]; |
| | | buffers.rewind(); |
| | | buffers.get(bytes); |
| | | faceLibUrl = new String(bytes); |
| | | String faceLibUrl = new String(bytes); |
| | | //System.out.println("人脸库人脸图的URL:" + SnapPicUrl); |
| | | } |
| | | if (ardEquipExternal != null) { |
| | | //人脸比对报警图片保存,图片格式二进制 |
| | | //if ((struFaceMatchAlarm.dwSnapPicLen > 0) && (struFaceMatchAlarm.byPicTransType == 0)) { |
| | | // picUrl = saveBinPicToMinio(struFaceMatchAlarm.pSnapPicBuffer, struFaceMatchAlarm.dwSnapPicLen); |
| | | //} |
| | | //if ((struFaceMatchAlarm.struSnapInfo.dwSnapFacePicLen > 0) && (struFaceMatchAlarm.byPicTransType == 0)) { |
| | | // facePicUrl = saveBinPicToMinio(struFaceMatchAlarm.struSnapInfo.pBuffer1, struFaceMatchAlarm.struSnapInfo.dwSnapFacePicLen); |
| | | //} |
| | | //if ((struFaceMatchAlarm.struBlockListInfo.dwBlockListPicLen > 0) && (struFaceMatchAlarm.byPicTransType == 0)) { |
| | | // //String faceBlockPicUrl = saveBinPicToMinio(struFaceMatchAlarm.struBlockListInfo.pBuffer1, struFaceMatchAlarm.struBlockListInfo.dwBlockListPicLen); |
| | | //} |
| | | if (camera != null) { |
| | | alarmName = "人脸比对检测"; |
| | | alarmType = contrastStatus + "[" + BlockType + "]"; |
| | | superBrainEventHandler(ardEquipExternal, 0, alarmName, alarmType, alarmTime, picUrl, facePicUrl); |
| | | alarmType = BlockType + "[" + contrastStatus + "]"; |
| | | switch (camera.getGdType()) { |
| | | case "0": |
| | | cameraEventHandler(camera, chanNo, alarmName, alarmType, alarmTime, "", ""); |
| | | break; |
| | | case "3": |
| | | superBrainEventHandler(camera, chanNo, alarmName, alarmType, alarmTime, picUrl, facePicUrl); |
| | | break; |
| | | } |
| | | } |
| | | //endregion |
| | | break; |
| | | case COMM_UPLOAD_AIOP_VIDEO: |
| | | log.debug("AI开放平台接入视频检测报警上传"); |
| | | log.debug("AI视频检测报警上传"); |
| | | //region AI开放平台接入视频检测 |
| | | HCNetSDK.NET_AIOP_VIDEO_HEAD struAIOPVideo = new HCNetSDK.NET_AIOP_VIDEO_HEAD(); |
| | | struAIOPVideo.write(); |
| | |
| | | String.format("%02d", struAIOPVideo.struTime.wDay) + " " + |
| | | String.format("%02d", struAIOPVideo.struTime.wHour) + ":" + |
| | | String.format("%02d", struAIOPVideo.struTime.wMinute) + ":" + |
| | | String.format("%02d", struAIOPVideo.struTime.wSecond) + "." + |
| | | String.format("%03d", struAIOPVideo.struTime.wMilliSec); |
| | | alarmName = "AI开放平台接入视频检测"; |
| | | String.format("%02d", struAIOPVideo.struTime.wSecond); |
| | | // + "." + String.format("%03d", struAIOPVideo.struTime.wMilliSec); |
| | | chanNo = struAIOPVideo.dwChannel; |
| | | switch (szMPID) { |
| | | case "H930_MODEL_SPD": |
| | | alarmType = "抽烟打电话"; |
| | |
| | | } |
| | | //图片数据保存 |
| | | if (struAIOPVideo.dwPictureSize > 0) { |
| | | //将字节写入文件 |
| | | long offset = 0; |
| | | ByteBuffer buffers = struAIOPVideo.pBufferPicture.getByteBuffer(offset, struAIOPVideo.dwPictureSize); |
| | | byte[] bytes = new byte[struAIOPVideo.dwPictureSize]; |
| | | buffers.rewind(); |
| | | buffers.get(bytes); |
| | | InputStream input = new ByteArrayInputStream(bytes); |
| | | try { |
| | | String bucketName = "pic"; |
| | | String objectName = "alarm/" + IdUtils.simpleUUID() + ".jpeg"; |
| | | boolean uploadObject = MinioUtil.uploadObject(bucketName, objectName, input, input.available(), "image/JPEG"); |
| | | if (uploadObject) { |
| | | picUrl = MinioUtil.getBucketObjectUrl(bucketName, objectName); |
| | | //log.debug("上传文件成功!" + picUrl); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("AI开放平台接入视频检测报警上传上报图片保存失败" + e.getMessage()); |
| | | } |
| | | picUrl = saveBinPicToMinio(struAIOPVideo.pBufferPicture, struAIOPVideo.dwPictureSize); |
| | | } |
| | | if (ardEquipExternal != null) { |
| | | superBrainEventHandler(ardEquipExternal, struAIOPVideo.dwChannel, alarmName, alarmType, alarmTime, picUrl, ""); |
| | | if (camera != null) { |
| | | alarmName = "AI视频检测"; |
| | | switch (camera.getGdType()) { |
| | | case "3": |
| | | superBrainEventHandler(camera, chanNo, alarmName, alarmType, alarmTime, picUrl, facePicUrl); |
| | | break; |
| | | } |
| | | } |
| | | //endregion |
| | | break; |
| | | case COMM_ISAPI_ALARM: |
| | | log.debug("安全帽检测报警信息上报"); |
| | | //region 安全帽检测报警信息 |
| | | case COMM_ISAPI_ALARM://ISAPI协议报警信息 |
| | | log.debug("ISAPI协议报警信息上报"); |
| | | //region ISAPI协议报警信息 |
| | | HCNetSDK.NET_DVR_ALARM_ISAPI_INFO struEventISAPI = new HCNetSDK.NET_DVR_ALARM_ISAPI_INFO(); |
| | | struEventISAPI.write(); |
| | | Pointer pEventISAPI = struEventISAPI.getPointer(); |
| | | pEventISAPI.write(0, pAlarmInfo.getByteArray(0, struEventISAPI.size()), 0, struEventISAPI.size()); |
| | | struEventISAPI.read(); |
| | | int dwAlarmDataLen = struEventISAPI.dwAlarmDataLen; |
| | | int byDataType = struEventISAPI.byDataType; |
| | | int byPicturesNumber = struEventISAPI.byPicturesNumber; |
| | | //处理安全帽检测上传的照片数据 |
| | | Pointer pPicPackData = struEventISAPI.pPicPackData; |
| | | if (pPicPackData != null) { |
| | | HCNetSDK.NET_DVR_ALARM_ISAPI_PICDATA struPicData = new HCNetSDK.NET_DVR_ALARM_ISAPI_PICDATA(); |
| | | struPicData.write(); |
| | | if (struPicData.size() > 0) { |
| | | Pointer pPicData = struPicData.getPointer(); |
| | | pPicData.write(0, pPicPackData.getByteArray(0, struPicData.size()), 0, struPicData.size()); |
| | | struPicData.read(); |
| | | int dwPicLen = struPicData.dwPicLen; |
| | | pPicData = struPicData.pPicData; |
| | | if (dwPicLen > 0 && pPicData != null) { |
| | | //将字节写入文件 |
| | | long offset = 0; |
| | | ByteBuffer buffers = pPicData.getByteBuffer(offset, dwPicLen); |
| | | byte[] bytes = new byte[dwPicLen]; |
| | | buffers.rewind(); |
| | | buffers.get(bytes); |
| | | InputStream input = new ByteArrayInputStream(bytes); |
| | | try { |
| | | String bucketName = "pic"; |
| | | String objectName = "alarm/" + IdUtils.simpleUUID() + ".jpeg"; |
| | | boolean uploadObject = MinioUtil.uploadObject(bucketName, objectName, input, input.available(), "image/JPEG"); |
| | | if (uploadObject) { |
| | | picUrl = MinioUtil.getBucketObjectUrl(bucketName, objectName); |
| | | //log.debug("上传文件成功!" + picUrl); |
| | | int dwAlarmDataLen = struEventISAPI.dwAlarmDataLen;// 报警数据长度 |
| | | int byDataType = struEventISAPI.byDataType;// 0-invalid,1-xml,2-json |
| | | int byPicturesNumber = struEventISAPI.byPicturesNumber;// 图片数量 |
| | | if (dwAlarmDataLen > 0) {//报警数据打印 |
| | | HCNetSDK.BYTE_ARRAY m_strISAPIData = new HCNetSDK.BYTE_ARRAY(struEventISAPI.dwAlarmDataLen); |
| | | m_strISAPIData.write(); |
| | | Pointer pPlateInfo = m_strISAPIData.getPointer(); |
| | | pPlateInfo.write(0, struEventISAPI.pAlarmData.getByteArray(0, m_strISAPIData.size()), 0, m_strISAPIData.size()); |
| | | m_strISAPIData.read(); |
| | | String json = new String(m_strISAPIData.byValue).trim(); |
| | | // log.debug(new String(m_strISAPIData.byValue).trim() + "\n"); |
| | | //解析JSON数据 |
| | | if (byDataType == 2) { |
| | | IsapiAlarm isapiAlarm = JSONObject.parseObject(json, IsapiAlarm.class); |
| | | alarmName = "ISAPI协议信息检测"; |
| | | switch (isapiAlarm.getEventType()) { |
| | | //case "HFPD": |
| | | //chanNo = isapiAlarm.getChannelID(); |
| | | //alarmType = "高频人员事件报警"; |
| | | //picUrl = isapiAlarm.getFaceCapture().get(0).getTargetAttrs().getBkgUrl(); |
| | | //facePicUrl = isapiAlarm.getFaceCapture().get(0).getFaces().get(0).getURL(); |
| | | // break; |
| | | case "safetyHelmetDetection": |
| | | chanNo = isapiAlarm.getChannelID(); |
| | | alarmType = "安全帽事件报警"; |
| | | alarmTime = fmt.format(isapiAlarm.getDateTime()); |
| | | //图片保存 |
| | | for (int i = 0; i < struEventISAPI.byPicturesNumber; i++) { |
| | | HCNetSDK.NET_DVR_ALARM_ISAPI_PICDATA struPicData = new HCNetSDK.NET_DVR_ALARM_ISAPI_PICDATA(); |
| | | struPicData.write(); |
| | | Pointer pPicData = struPicData.getPointer(); |
| | | pPicData.write(0, struEventISAPI.pPicPackData.getByteArray(i * struPicData.size(), struPicData.size()), 0, struPicData.size()); |
| | | struPicData.read(); |
| | | switch (i) { |
| | | case 0: |
| | | picUrl = saveBinPicToMinio(struPicData.pPicData, struPicData.dwPicLen); |
| | | break; |
| | | case 1: |
| | | facePicUrl = saveBinPicToMinio(struPicData.pPicData, struPicData.dwPicLen); |
| | | break; |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("异常行为识别信息报警信息上报图片保存失败" + e.getMessage()); |
| | | } |
| | | if (camera != null) { |
| | | switch (camera.getGdType()) { |
| | | case "3": |
| | | superBrainEventHandler(camera, chanNo, alarmName, alarmType, alarmTime, picUrl, facePicUrl); |
| | | break; |
| | | } |
| | | } |
| | | break; |
| | | } |
| | | |
| | | } |
| | | } |
| | | if (ardEquipExternal != null) { |
| | | alarmName = "安全帽检测"; |
| | | alarmType = "安全帽事件报警"; |
| | | alarmTime = fmt.format(new Date()); |
| | | superBrainEventHandler(ardEquipExternal, 0, alarmName, alarmType, alarmTime, picUrl, ""); |
| | | } |
| | | //endregion |
| | | break; |
| | |
| | | //事件图片处理 |
| | | dwPicDataLen = strACSInfo.dwPicDataLen; |
| | | if (dwPicDataLen > 0) { |
| | | try { |
| | | //将字节写入文件 |
| | | long offset = 0; |
| | | ByteBuffer buffers = strACSInfo.pPicData.getByteBuffer(offset, strACSInfo.dwPicDataLen); |
| | | byte[] bytes = new byte[strACSInfo.dwPicDataLen]; |
| | | buffers.rewind(); |
| | | buffers.get(bytes); |
| | | InputStream input = new ByteArrayInputStream(bytes); |
| | | String bucketName = "pic"; |
| | | String objectName = "alarm/" + IdUtils.simpleUUID() + ".jpeg"; |
| | | boolean uploadObject = MinioUtil.uploadObject(bucketName, objectName, input, input.available(), "image/JPEG"); |
| | | if (uploadObject) { |
| | | picUrl = MinioUtil.getBucketObjectUrl(bucketName, objectName); |
| | | //log.debug("上传文件成功!" + url); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("图片保存失败"); |
| | | } |
| | | picUrl = saveBinPicToMinio(strACSInfo.pPicData, strACSInfo.dwPicDataLen); |
| | | } |
| | | HCNetSDK.NET_DVR_ACS_EVENT_INFO struAcsEventInfo = strACSInfo.struAcsEventInfo; |
| | | int byType = struAcsEventInfo.byType; |
| | |
| | | Pointer pFireDecAlarm = struFireDecAlarm.getPointer(); |
| | | pFireDecAlarm.write(0, pAlarmInfo.getByteArray(0, struFireDecAlarm.size()), 0, struFireDecAlarm.size()); |
| | | struFireDecAlarm.read(); |
| | | String sFireDecAlarmInfo = "绝对时间:" + struFireDecAlarm.dwAbsTime + ",报警子类型:" + struFireDecAlarm.byAlarmSubType + ",火点最高温度 :" + |
| | | struFireDecAlarm.wFireMaxTemperature + ",火点目标距离:" + struFireDecAlarm.wTargetDistance; |
| | | System.out.println(sFireDecAlarmInfo); |
| | | switch (struFireDecAlarm.byAlarmSubType) { |
| | | case 0: |
| | | alarmType = "火点检测报警"; |
| | | break; |
| | | case 1: |
| | | alarmType = "烟雾检测报警"; |
| | | break; |
| | | case 2: |
| | | alarmType = "烟火报警 "; |
| | | break; |
| | | } |
| | | //String sFireDecAlarmInfo = "绝对时间:" + struFireDecAlarm.dwAbsTime + ",报警子类型:" + struFireDecAlarm.byAlarmSubType + ",火点最高温度 :" + |
| | | // struFireDecAlarm.wFireMaxTemperature + ",火点目标距离:" + struFireDecAlarm.wTargetDistance; |
| | | //System.out.println(sFireDecAlarmInfo); |
| | | //图片保存 |
| | | if ((struFireDecAlarm.dwPicDataLen > 0) && (struFireDecAlarm.byPicTransType == 0)) { |
| | | long offset = 0; |
| | | ByteBuffer buffers = struFireDecAlarm.pBuffer.getByteBuffer(offset, struFireDecAlarm.dwPicDataLen); |
| | | byte[] bytes = new byte[struFireDecAlarm.dwPicDataLen]; |
| | | buffers.rewind(); |
| | | buffers.get(bytes); |
| | | InputStream input = new ByteArrayInputStream(bytes); |
| | | try { |
| | | String bucketName = "pic"; |
| | | String objectName = "alarm/" + IdUtils.simpleUUID() + ".jpeg"; |
| | | boolean uploadObject = MinioUtil.uploadObject(bucketName, objectName, input, input.available(), "image/JPEG"); |
| | | if (uploadObject) { |
| | | picUrl = MinioUtil.getBucketObjectUrl(bucketName, objectName); |
| | | //log.debug("上传文件成功!" + picUrl); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("火点检测事件报警上报热成像图片保存失败" + e.getMessage()); |
| | | } |
| | | |
| | | picUrl = saveBinPicToMinio(struFireDecAlarm.pBuffer, struFireDecAlarm.dwPicDataLen); |
| | | } |
| | | if (ardEquipExternal != null) { |
| | | chanNo = struFireDecAlarm.dwVisibleChannel; |
| | | alarmTime = DateUtils.parseTime(struFireDecAlarm.dwAbsTime);//报警时间 |
| | | if (camera != null) { |
| | | alarmName = "火焰检测信息上报"; |
| | | alarmType = "火焰检测事件报警"; |
| | | int dwVisibleChannel = struFireDecAlarm.dwVisibleChannel; |
| | | alarmTime = DateUtils.parseTime(struFireDecAlarm.dwAbsTime);//报警时间 |
| | | superBrainEventHandler(ardEquipExternal, dwVisibleChannel, alarmName, alarmType, alarmTime, picUrl, ""); |
| | | switch (camera.getGdType()) { |
| | | case "3": |
| | | superBrainEventHandler(camera, chanNo, alarmName, alarmType, alarmTime, picUrl, facePicUrl); |
| | | break; |
| | | } |
| | | } |
| | | //endregion |
| | | break; |
| | |
| | | return true; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 相机事件处理 |
| | | * 刘苏义 |
| | | * 2023/12/5 12:56:47 |
| | | */ |
| | | public void cameraEventHandler(ArdCameras camera, String alarmName, String alarmType, String alarmTime, String picUrl) { |
| | | |
| | | public void cameraEventHandler(ArdCameras camera, Integer chanNo, String alarmName, String alarmType, String alarmTime, String picUrl, String faceUrl) { |
| | | CameraEventInfo cameraEventInfo = new CameraEventInfo(); |
| | | cameraEventInfo.setAlarmName(alarmName); |
| | | cameraEventInfo.setAlarmTime(alarmTime); |
| | |
| | | cameraEventInfo.setCameraIp(camera.getIp()); |
| | | cameraEventInfo.setCameraPort(camera.getPort()); |
| | | cameraEventInfo.setCameraType(camera.getGdType()); |
| | | cameraEventInfo.setCameraChannel(camera.getChannel()); |
| | | cameraEventInfo.setCameraChannel(chanNo); |
| | | cameraEventInfo.setLongitude(camera.getLongitude()); |
| | | cameraEventInfo.setLatitude(camera.getLatitude()); |
| | | cameraEventInfo.setAlarmType(alarmType); |
| | |
| | | * 刘苏义 |
| | | * 2023/12/5 12:56:47 |
| | | */ |
| | | public void superBrainEventHandler(ArdEquipExternal superBrainDevice, Integer chanNo, String alarmName, String alarmType, String alarmTime, String picUrl, String faceUrl) { |
| | | public void superBrainEventHandler(ArdCameras camera, Integer chanNo, String alarmName, String alarmType, String alarmTime, String picUrl, String faceUrl) { |
| | | |
| | | SuperBrainEventInfo superBrainEventInfo = new SuperBrainEventInfo(); |
| | | superBrainEventInfo.setAlarmName(alarmName); |
| | | superBrainEventInfo.setAlarmType(alarmType); |
| | | superBrainEventInfo.setAlarmTime(alarmTime); |
| | | superBrainEventInfo.setDeviceId(superBrainDevice.getId()); |
| | | superBrainEventInfo.setDeviceName(superBrainDevice.getName()); |
| | | List<ChannelInfo> channelInfoList = GlobalVariable.deviceChanMap.get(camera.getId());//获取超脑的通道集合 |
| | | if (channelInfoList.size() > 0) { |
| | | if (chanNo > 0) { |
| | | ChannelInfo channelInfo = channelInfoList.get(chanNo - 1);//根据通道号获取通道信息 |
| | | if (channelInfo != null) { |
| | | Optional<ArdCameras> foundCamera = findArdCameraByIpAndPort(channelInfo.getIp(), channelInfo.getPort()); |
| | | if (foundCamera.isPresent()) { |
| | | camera = foundCamera.get(); |
| | | superBrainEventInfo.setDeviceId(camera.getId()); |
| | | superBrainEventInfo.setDeviceName(camera.getName()); |
| | | superBrainEventInfo.setLongitude(camera.getLongitude()); |
| | | superBrainEventInfo.setLatitude(camera.getLatitude()); |
| | | superBrainEventInfo.setAltitude(camera.getAltitude()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | superBrainEventInfo.setChanNo(chanNo); |
| | | superBrainEventInfo.setLongitude(superBrainDevice.getLongitude()); |
| | | superBrainEventInfo.setLatitude(superBrainDevice.getLatitude()); |
| | | superBrainEventInfo.setPicUrl(picUrl); |
| | | superBrainEventInfo.setFaceUrl(faceUrl); |
| | | log.debug("处理通超脑事件报警:【Name】" + alarmName + "【Type】" + alarmType + "【Time】" + alarmTime + "【Device】" + superBrainDevice.getName() + "【Url】" + picUrl + "【faceUrl】" + faceUrl ); |
| | | log.debug("处理超脑事件报警:【Name】" + alarmName + "【Type】" + alarmType + "【Time】" + alarmTime + "【Device】" + camera.getName() + "【Url】" + picUrl + "【faceUrl】" + faceUrl); |
| | | publishMqtt(superBrainEventInfo, "superBrain"); |
| | | } |
| | | |
| | |
| | | return wYear + "-" + byMonth + "-" + byDay + " " + byHour + ":" + byMinute + ":" + bySecond; |
| | | } |
| | | |
| | | //二进制图片接收写入minio返回url |
| | | private String saveBinPicToMinio(Pointer picData, int picDataLen) { |
| | | String picUrl = ""; |
| | | try { |
| | | //将字节写入文件 |
| | | long offset = 0; |
| | | ByteBuffer buffers = picData.getByteBuffer(offset, picDataLen); |
| | | byte[] bytes = new byte[picDataLen]; |
| | | buffers.rewind(); |
| | | buffers.get(bytes); |
| | | InputStream input = new ByteArrayInputStream(bytes); |
| | | String bucketName = "pic"; |
| | | String objectName = "alarm/" + IdUtils.simpleUUID() + ".jpeg"; |
| | | boolean uploadObject = MinioUtil.uploadObject(bucketName, objectName, input, picDataLen, "image/JPEG"); |
| | | if (uploadObject) { |
| | | picUrl = MinioUtil.getBucketObjectUrl(bucketName, objectName); |
| | | //log.debug("上传文件成功!" + picUrl); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("图片保存失败:" + e.getMessage()); |
| | | } |
| | | return picUrl; |
| | | } |
| | | |
| | | } |