‘liusuyi’
2023-12-06 6ab0ec5ade792e91ba90018c0b7f822abb1db5b2
增加超脑报警事件
已添加1个文件
已修改3个文件
607 ■■■■ 文件已修改
src/main/java/com/ard/utils/sdk/hiksdk/domain/SuperBrainEventInfo.java 54 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ard/utils/sdk/hiksdk/service/impl/FMSGCallBack.java 529 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ard/utils/sdk/hiksdk/service/impl/HikClientUtil.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ard/utils/sdk/hiksdk/util/hikSdkUtil/HCNetSDK.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ard/utils/sdk/hiksdk/domain/SuperBrainEventInfo.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,54 @@
package com.ard.utils.sdk.hiksdk.domain;
import lombok.Data;
/**
 * @Description:
 * @ClassName: SuperBrainEventInfo
 * @Author: åˆ˜è‹ä¹‰
 * @Date: 2023å¹´12月05日10:39:53
 **/
@Data
public class SuperBrainEventInfo {
    /**
     * æŠ¥è­¦åç§°
     */
    String alarmName;
    /**
     * æŠ¥è­¦ç±»åˆ«
     */
    String alarmType;
    /**
     * æŠ¥è­¦æ—¶é—´
     */
    String alarmTime;
    /**
     * è¶…脑设备ID
     */
    String deviceId;
    /**
     * è¶…脑设备名称
     */
    String deviceName;
    /**
     * è¶…脑设备通道号
     */
    Integer chanNo;
    /**
     * å…³è”超脑经度
     */
    Double longitude;
    /**
     * å…³è”超脑纬度
     */
    Double latitude;
    /**
     * å¤§å›¾url
     */
    String picUrl;
    /**
     * äººè„¸æŠ“拍图片url
     */
    String faceUrl;
}
src/main/java/com/ard/utils/sdk/hiksdk/service/impl/FMSGCallBack.java
@@ -15,6 +15,7 @@
import com.ard.utils.mqtt.MqttProducer;
import com.ard.utils.util.IdUtils;
import com.sun.jna.Pointer;
import javafx.scene.Camera;
import lombok.extern.slf4j.Slf4j;
import java.io.*;
@@ -65,19 +66,20 @@
        if (camera == null && ardEquipExternal == null) {
            return false;
        }
        CameraEventInfo info;
        CameraEventInfo cameraEventInfo;
        SuperBrainEventInfo superBrainEventInfo;
        String alarmName = "";//报警名称
        String alarmTime;//事件时间
        String alarmType = "";//报警类型
        String picUrl = "";//事件图片
        String facePicUrl = "";//人脸图片
        String facePicUrl = "";//人脸抓拍图片
        String faceLibUrl = "";//人脸库图片
        int dwPicDataLen;//图片数据长度
        //lCommand是传的报警类型
        log.debug("【" + sDeviceIP + ":" + wLinkPort + "】报警事件类型:lCommand:" + Integer.toHexString(lCommand));
        switch (lCommand) {
            case COMM_ALARM_V30:
                log.debug("移动侦测报警信息上报");
                if (camera == null) {
                    return false;
                }
                log.debug("移动侦测信息上报");
                //region ç§»åŠ¨ä¾¦æµ‹ã€è§†é¢‘ä¸¢å¤±ã€é®æŒ¡ã€IO信号量等报警信息(V3.0以上版本支持的设备)
                HCNetSDK.NET_DVR_ALARMINFO_V30 netDvrAlarminfoV30 = new HCNetSDK.NET_DVR_ALARMINFO_V30();
                netDvrAlarminfoV30.write();
@@ -86,28 +88,17 @@
                netDvrAlarminfoV30.read();
                switch (netDvrAlarminfoV30.dwAlarmType) {
                    case 3:
                        info = new CameraEventInfo();
                        info.setAlarmName("移动侦测");
                        info.setAlarmTime(fmt.format(new Date()));
                        info.setCameraName(camera.getName());
                        info.setCameraId(camera.getId());
                        info.setCameraIp(camera.getIp());
                        info.setCameraPort(camera.getPort());
                        info.setCameraType(camera.getGdType());
                        info.setCameraChannel(Integer.valueOf(netDvrAlarminfoV30.byChannel[0]));
                        info.setLongitude(camera.getLongitude());
                        info.setLatitude(camera.getLatitude());
                        info.setAlarmType("移动侦测");
                        //图片存入minio
                        picUrl = snapPicture(info);
                        info.setPicUrl(picUrl);
                        publishMqtt(info, "camera");
                        if (camera != null) {
                            cameraEventHandler(camera, "移动侦测", "移动侦测报警", fmt.format(new Date()), "");
                        }
                        break;
                }
                //endregion
                break;
            case COMM_VCA_ALARM:
                log.debug("智能检测通用信息上报(暂不解析)");
            case COMM_ALARM_RULE:
                log.debug("异常行为识别信息报警信息上报");
                log.debug("异常行为识别信息上报");
                //region å¼‚常行为识别信息
                HCNetSDK.NET_VCA_RULE_ALARM strVcaAlarm = new HCNetSDK.NET_VCA_RULE_ALARM();
                strVcaAlarm.write();
@@ -117,74 +108,108 @@
                Integer ruleID = Integer.valueOf(strVcaAlarm.struRuleInfo.byRuleID);
                alarmTime = DateUtils.parseTime(strVcaAlarm.dwAbsTime);//事件时间
                Integer channel = Integer.valueOf(strVcaAlarm.struDevInfo.byChannel);//通道
                info = new CameraEventInfo();
                info.setAlarmName("人员行为分析");
                info.setAlarmTime(alarmTime);
                info.setCameraName(camera.getName());
                info.setCameraId(camera.getId());
                info.setCameraIp(camera.getIp());
                info.setCameraPort(camera.getPort());
                info.setCameraType(camera.getGdType());
                info.setCameraChannel(channel);
                info.setLongitude(camera.getLongitude());
                info.setLatitude(camera.getLatitude());
                info.setRuleId(ruleID);
                switch (strVcaAlarm.struRuleInfo.wEventTypeEx) {
                    case 1: //region穿越警戒面 (越界侦测)
                        info.setAlarmType("越界侦测报警");
                        strVcaAlarm.struRuleInfo.uEventParam.setType(HCNetSDK.NET_VCA_TRAVERSE_PLANE.class);
                        //图片存入minio
                        picUrl = snapPicture(info);
                        info.setPicUrl(picUrl);
                        publishMqtt(info, "camera");
                        alarmType = "越界侦测报警";
                        //endregion
                        break;
//                    case 2: //region ç›®æ ‡è¿›å…¥åŒºåŸŸ
//                        info.setAlarmType("目标进入区域报警");
//                        strVcaAlarm.struRuleInfo.uEventParam.setType(HCNetSDK.NET_VCA_AREA.class);
//                        //endregion
//                        break;
//                    case 3: //region ç›®æ ‡ç¦»å¼€åŒºåŸŸ
//                        info.setAlarmType("目标离开区域报警");
//                        strVcaAlarm.struRuleInfo.uEventParam.setType(HCNetSDK.NET_VCA_AREA.class);
//                        //endregion
//                        break;
                    case 2: //region ç›®æ ‡è¿›å…¥åŒºåŸŸ
                        alarmType = "目标进入区域报警";
                        //endregion
                        break;
                    case 3: //region ç›®æ ‡ç¦»å¼€åŒºåŸŸ
                        alarmType = "目标离开区域报警";
                        //strVcaAlarm.struRuleInfo.uEventParam.setType(HCNetSDK.NET_VCA_AREA.class);
                        //endregion
                        break;
                    case 4: //region å‘¨ç•Œå…¥ä¾µ
                        info.setAlarmType("周界入侵报警");
                        strVcaAlarm.struRuleInfo.uEventParam.setType(HCNetSDK.NET_VCA_INTRUSION.class);
                        //图片存入minio
                        picUrl = snapPicture(info);
                        info.setPicUrl(picUrl);
                        publishMqtt(info, "camera");
                        alarmType = "周界入侵报警";
                        //endregion
                        break;
//                    case 5: //region å¾˜å¾Š
//                        info.setAlarmType("徘徊事件报警");
//                        //endregion
//                        break;
//                    case 8: //region å¿«é€Ÿç§»åЍ(奔跑)
//                        info.setAlarmType("快速移动(奔跑)事件报警");
//                        //endregion
//                        break;
//                    case 13: //region ç‰©å“é—留事件
//                        info.setAlarmType("物品遗留事件报警");
//                        //endregion
//                        break;
//                    case 14: //region ç‰©å“æ‹¿å–事件
//                        info.setAlarmType("物品拿取事件事件报警");
//                        //endregion
//                        break;
//                    case 20: //region å€’地检测
//                        info.setAlarmType("倒地事件触发");
//                        //endregion
//                        break;
//                    case 44: //region çŽ©æ‰‹æœº
//                        info.setAlarmType("玩手机报警事件");
//                        //endregion
//                        break;
                    case 5: //region å¾˜å¾Š
                        alarmType = "徘徊事件报警";
                        //endregion
                        break;
                    case 8: //region å¿«é€Ÿç§»åЍ(奔跑)
                        alarmType = "快速移动报警";
                        //endregion
                        break;
                    case 9: //region äººå‘˜èšé›†æŠ¥è­¦
                        alarmType = "人员聚集报警";
                        //endregion
                        break;
                    case 13: //region ç‰©å“é—留事件
                        alarmType = "物品遗留事件报警";
                        //endregion
                        break;
                    case 14: //region ç‰©å“æ‹¿å–事件
                        alarmType = "物品拿取事件报警";
                        //endregion
                        break;
                    case 15: //region ç¦»å²—事件
                        strVcaAlarm.struRuleInfo.uEventParam.setType(HCNetSDK.NET_VCA_LEAVE_POSITION.class);
                        int byMode = strVcaAlarm.struRuleInfo.uEventParam.struLeavePos.byMode;
                        switch (byMode) {
                            case 0:
                                alarmType = "离岗事件报警";
                                break;
                            case 1:
                                alarmType = "睡岗事件报警";
                                break;
                        }
                        //endregion
                        break;
                    case 20: //region å€’地检测
                        alarmType = "倒地检测事件报警";
                        //endregion
                        break;
                    case 35: //region å€’地检测
                        alarmType = "人数变化事件报警";
                        //endregion
                        break;
                    case 41: //region æ»žç•™æ£€æµ‹
                        alarmType = "滞留检测事件报警";
                        //endregion
                        break;
                    case 44: //region çŽ©æ‰‹æœº
                        alarmType = "玩手机事件报警";
                        //endregion
                        break;
                    default:
                        log.debug("未知异常行为事件类型:" + strVcaAlarm.struRuleInfo.wEventTypeEx);
                        break;
                }
                //图片接收
                int byPicType = strVcaAlarm.byPicType;
                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());
                    }
                }
                if (camera != null) {
                    camera.setChannel(channel);
                    cameraEventHandler(camera, alarmName, alarmType, alarmTime, picUrl);
                }
                if (ardEquipExternal != null) {
                    alarmName = "异常行为识别";
                    superBrainEventHandler(ardEquipExternal, channel, alarmName, alarmType, alarmTime, picUrl, "");
                }
                //endregion
                break;
@@ -249,7 +274,7 @@
                        log.error("人脸抓拍报警信息图片保存失败" + e.getMessage());
                    }
                }
                log.debug("【人脸抓拍报警信息】: alarmTime:" + alarmTime + " picUrl:" + picUrl + " facePicType:" + facePicTyp + " facePicUrl:" + facePicUrl);
                //log.debug("【人脸抓拍报警信息】: alarmTime:" + alarmTime + " picUrl:" + picUrl + " facePicType:" + facePicTyp + " facePicUrl:" + facePicUrl);
                FaceSnapEventInfo faceSnapEventInfo = new FaceSnapEventInfo();
                faceSnapEventInfo.setAlarmTime(alarmTime);
                faceSnapEventInfo.setPicUrl(picUrl);
@@ -260,27 +285,17 @@
                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);//报警时间
                int byMatchPicNum = struFaceMatchAlarm.byMatchPicNum;//匹配图片数量
                String picTransType = "";
                switch (struFaceMatchAlarm.byPicTransType) {
                    case 0:
                        picTransType = "二进制图片";
                        break;
                    case 1:
                        picTransType = "URL路径图片";
                        break;
                }
                String contrastStatus = "";
                switch (struFaceMatchAlarm.byContrastStatus) {
                    case 1:
                        contrastStatus = "比对成功";
                        break;
                    case 2:
                        contrastStatus = "比对失败";
@@ -289,42 +304,157 @@
                        contrastStatus = "未知";
                        break;
                }
                String BlockType = "";
                switch (struFaceMatchAlarm.struBlockListInfo.struBlockListInfo.byType) {
                    case 1:
                        alarmType = "陌生人报警";
                        BlockType = "陌生人报警";
                        break;
                    case 2:
                        alarmType = "人脸比对报警";
                        BlockType = "人脸比对报警";
                        break;
                    default:
                        alarmType = "未知";
                        BlockType = "未知";
                        break;
                }
                if (struFaceMatchAlarm.dwSnapPicLen > 0 && struFaceMatchAlarm.pSnapPicBuffer != null && struFaceMatchAlarm.byPicTransType == 0) {
                    //将字节写入文件
                //人脸比对报警图片保存,图片格式二进制
                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)) {
                    long offset = 0;
                    ByteBuffer buffers = struFaceMatchAlarm.pSnapPicBuffer.getByteBuffer(offset, struFaceMatchAlarm.dwSnapPicLen);
                    byte[] bytes = new byte[struFaceMatchAlarm.dwSnapPicLen];
                    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 = new String(bytes);
                    //log.debug("抓拍图URL:" + picUrl);
                }
                if (struFaceMatchAlarm.struBlockListInfo.dwBlockListPicLen > 0 && struFaceMatchAlarm.struBlockListInfo.pBuffer1 != null) {
                    //将字节写入文件
                if ((struFaceMatchAlarm.struSnapInfo.dwSnapFacePicLen > 0) && (struFaceMatchAlarm.byPicTransType == 1)) {
                    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);
                    facePicUrl = new String(bytes);
                    //System.out.println("抓拍人脸子图URL:" + SnapPicUrl);
                }
                if ((struFaceMatchAlarm.struBlockListInfo.dwBlockListPicLen > 0) && (struFaceMatchAlarm.byPicTransType == 1)) {
                    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);
                    faceLibUrl = new String(bytes);
                    //System.out.println("人脸库人脸图的URL:" + SnapPicUrl);
                }
                if (ardEquipExternal != null) {
                    alarmName = "人脸比对检测";
                    alarmType = contrastStatus + "[" + BlockType + "]";
                    superBrainEventHandler(ardEquipExternal, 0, alarmName, alarmType, alarmTime, picUrl, facePicUrl);
                }
                //endregion
                break;
            case COMM_UPLOAD_AIOP_VIDEO:
                log.debug("AI开放平台接入视频检测报警上传");
                //region AI开放平台接入视频检测
                HCNetSDK.NET_AIOP_VIDEO_HEAD struAIOPVideo = new HCNetSDK.NET_AIOP_VIDEO_HEAD();
                struAIOPVideo.write();
                Pointer pAIOPVideo = struAIOPVideo.getPointer();
                pAIOPVideo.write(0, pAlarmInfo.getByteArray(0, struAIOPVideo.size()), 0, struAIOPVideo.size());
                struAIOPVideo.read();
                log.debug("视频任务ID" + new String(struAIOPVideo.szTaskID).trim());
                log.debug("通道号:" + struAIOPVideo.dwChannel);
                String szMPID = new String(struAIOPVideo.szMPID).trim();//检测模型包ID
                log.debug("检测模型包ID" + szMPID);
                alarmTime = String.format("%04d", struAIOPVideo.struTime.wYear) + "-" +
                        String.format("%02d", struAIOPVideo.struTime.wMonth) + "-" +
                        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开放平台接入视频检测";
                switch (szMPID) {
                    case "H930_MODEL_SPD":
                        alarmType = "抽烟打电话";
                        break;
                }
                //图片数据保存
                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);
@@ -334,34 +464,19 @@
                        boolean uploadObject = MinioUtil.uploadObject(bucketName, objectName, input, input.available(), "image/JPEG");
                        if (uploadObject) {
                            picUrl = MinioUtil.getBucketObjectUrl(bucketName, objectName);
                            //log.debug("上传文件成功!" + url);
                            //log.debug("上传文件成功!" + picUrl);
                        }
                    } catch (Exception e) {
                        log.error("人脸抓拍报警信息图片保存失败" + e.getMessage());
                        log.error("AI开放平台接入视频检测报警上传上报图片保存失败" + e.getMessage());
                    }
                }
                String sAlarmType = "";
                try {
                    sAlarmType = "人脸黑名单比对报警,相识度:" + struFaceMatchAlarm.fSimilarity + ",黑名单姓名:" +
                            new String(struFaceMatchAlarm.struBlockListInfo.struBlockListInfo.struAttribute.byName, "GBK").trim() + ",黑名单证件信息:" +
                            new String(struFaceMatchAlarm.struBlockListInfo.struBlockListInfo.struAttribute.byCertificateNumber).trim();
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                if (ardEquipExternal != null) {
                    superBrainEventHandler(ardEquipExternal, struAIOPVideo.dwChannel, alarmName, alarmType, alarmTime, picUrl, "");
                }
                log.debug(sAlarmType);
                log.debug("【人脸比对报警信息】:" + " æ¯”对结果:" + contrastStatus + " æ¯”对类型:" + alarmType + " æŠ¥è­¦æ—¶é—´:" + alarmTime + " åŒ¹é…å›¾ç‰‡æ•°é‡ï¼š" + byMatchPicNum + " å›¾ç‰‡ç±»åž‹ï¼š" + picTransType + " æ¯”对图片:" + picUrl);
                FaceMatchEventInfo faceMatchEventInfo = new FaceMatchEventInfo();
                faceMatchEventInfo.setAlarmTime(alarmTime);
                faceMatchEventInfo.setStatus(contrastStatus);
                faceMatchEventInfo.setAlarmType(alarmType);
                publishMqtt(faceMatchEventInfo, "faceMatch");
                //endregion
                break;
            case COMM_UPLOAD_AIOP_VIDEO:
                log.debug("设备支持AI开放平台接入,上传视频检测数据(暂不解析)");
                break;
            case COMM_ISAPI_ALARM:
                log.debug("安全帽检测报警信息");
                log.debug("安全帽检测报警信息上报");
                //region å®‰å…¨å¸½æ£€æµ‹æŠ¥è­¦ä¿¡æ¯
                HCNetSDK.NET_DVR_ALARM_ISAPI_INFO struEventISAPI = new HCNetSDK.NET_DVR_ALARM_ISAPI_INFO();
                struEventISAPI.write();
@@ -371,22 +486,53 @@
                int dwAlarmDataLen = struEventISAPI.dwAlarmDataLen;
                int byDataType = struEventISAPI.byDataType;
                int byPicturesNumber = struEventISAPI.byPicturesNumber;
                //处理安全帽检测上传的照片数据
                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(0, struPicData.size()), 0,
                        struPicData.size());
                struPicData.read();
                log.debug("检测到安全帽事件");
                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);
                                }
                            } catch (Exception e) {
                                log.error("异常行为识别信息报警信息上报图片保存失败" + e.getMessage());
                            }
                        }
                    }
                }
                if (ardEquipExternal != null) {
                    alarmName = "安全帽检测";
                    alarmType = "安全帽事件报警";
                    alarmTime = fmt.format(new Date());
                    superBrainEventHandler(ardEquipExternal, 0, alarmName, alarmType, alarmTime, picUrl, "");
                }
                //endregion
                break;
            case COMM_GISINFO_UPLOAD:
                log.debug("GPS报警信息上报(暂不解析)");
                break;
            case COMM_ALARMHOST_CID_ALARM:
                log.debug("报警主机CID报告报警上报");
                log.debug("报警主机CID报告信息上报");
                //region æŠ¥è­¦ä¸»æœºæŠ¥è­¦å¤„理
                HCNetSDK.NET_DVR_CID_ALARM netDvrCidAlarm = new HCNetSDK.NET_DVR_CID_ALARM();
                netDvrCidAlarm.write();
@@ -464,7 +610,7 @@
                //endregion
                break;
            case HCNetSDK.COMM_ALARM_ACS:
                log.debug("门禁主机报警上报");
                log.debug("门禁主机信息上报");
                //region é—¨ç¦ä¸»æœºæŠ¥è­¦å¤„理
                HCNetSDK.NET_DVR_ACS_ALARM_INFO strACSInfo = new HCNetSDK.NET_DVR_ACS_ALARM_INFO();
                strACSInfo.write();
@@ -495,7 +641,7 @@
                alarmTime = DateUtils.convertDate(parseAlarmTime(strACSInfo.struTime), "yyyy-M-d H:m:s");
                //事件图片处理
                int dwPicDataLen = strACSInfo.dwPicDataLen;
                dwPicDataLen = strACSInfo.dwPicDataLen;
                if (dwPicDataLen > 0) {
                    try {
                        //将字节写入文件
@@ -571,12 +717,107 @@
                publishMqtt(accessControlHostEventInfo, "accessControl");
                //endregion
                break;
            case COMM_FIREDETECTION_ALARM: //火点检测报警
                log.debug("火点检测信息上报");
                //region ç«ç‚¹æ£€æµ‹æŠ¥è­¦
                HCNetSDK.NET_DVR_FIREDETECTION_ALARM struFireDecAlarm = new HCNetSDK.NET_DVR_FIREDETECTION_ALARM();
                struFireDecAlarm.write();
                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);
                //图片保存
                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());
                    }
                }
                if (ardEquipExternal != null) {
                    alarmName = "火焰检测信息上报";
                    alarmType = "火焰检测事件报警";
                    int dwVisibleChannel = struFireDecAlarm.dwVisibleChannel;
                    alarmTime = DateUtils.parseTime(struFireDecAlarm.dwAbsTime);//报警时间
                    superBrainEventHandler(ardEquipExternal, dwVisibleChannel, alarmName, alarmType, alarmTime, picUrl, "");
                }
                //endregion
                break;
            case COMM_ITS_PLATE_RESULT://交通抓拍的终端图片上传
                log.debug("交通抓拍的终端图片上报(暂不解析)");
                break;
            default:
                log.debug("未知报警事件类型:lCommand:" + Integer.toHexString(lCommand));
                break;
        }
        return true;
    }
    /**
     * ç›¸æœºäº‹ä»¶å¤„理
     * åˆ˜è‹ä¹‰
     * 2023/12/5 12:56:47
     */
    public void cameraEventHandler(ArdCameras camera, String alarmName, String alarmType, String alarmTime, String picUrl) {
        CameraEventInfo cameraEventInfo = new CameraEventInfo();
        cameraEventInfo.setAlarmName(alarmName);
        cameraEventInfo.setAlarmTime(alarmTime);
        cameraEventInfo.setCameraName(camera.getName());
        cameraEventInfo.setCameraId(camera.getId());
        cameraEventInfo.setCameraIp(camera.getIp());
        cameraEventInfo.setCameraPort(camera.getPort());
        cameraEventInfo.setCameraType(camera.getGdType());
        cameraEventInfo.setCameraChannel(camera.getChannel());
        cameraEventInfo.setLongitude(camera.getLongitude());
        cameraEventInfo.setLatitude(camera.getLatitude());
        cameraEventInfo.setAlarmType(alarmType);
        //图片存入minio
        if (picUrl.equals("")) {
            picUrl = snapPicture(cameraEventInfo);
        }
        cameraEventInfo.setPicUrl(picUrl);
        log.debug("处理通用光电事件报警:【Name】" + alarmName + "【Type】" + alarmType + "【Time】" + alarmTime + "【Device】" + camera.getName() + "【Url】" + picUrl);
        publishMqtt(cameraEventInfo, "camera");
    }
    /**
     * è¶…脑事件处理
     * åˆ˜è‹ä¹‰
     * 2023/12/5 12:56:47
     */
    public void superBrainEventHandler(ArdEquipExternal superBrainDevice, 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());
        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 );
        publishMqtt(superBrainEventInfo, "superBrain");
    }
    /**
@@ -604,7 +845,6 @@
                .filter(camera -> camera.getIp().equals(ip) && camera.getPort() == port)
                .findFirst();
    }
    /**
     * ç›¸æœºæˆªå›¾
@@ -689,4 +929,5 @@
        int bySecond = netDvrTimeEx.dwSecond;
        return wYear + "-" + byMonth + "-" + byDay + " " + byHour + ":" + byMinute + ":" + bySecond;
    }
}
src/main/java/com/ard/utils/sdk/hiksdk/service/impl/HikClientUtil.java
@@ -44,6 +44,7 @@
        if (!hCNetSDK.NET_DVR_Init()) {
            log.error("SDK初始化失败");
        }
        //打印海康sdk日志
        if (Platform.isWindows()) {
            String WIN_PATH = System.getProperty("user.dir") + File.separator + "ardLog" + File.separator + "logs" + File.separator;
@@ -58,6 +59,7 @@
        //设置连接时间与重连时间
        hCNetSDK.NET_DVR_SetConnectTime(2000, 1);
        hCNetSDK.NET_DVR_SetReconnect(100000, true);
        //设备信息, è¾“出参数
        HCNetSDK.NET_DVR_DEVICEINFO_V30 m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V30();
        int lUserID = hCNetSDK.NET_DVR_Login_V30(m_sDeviceIP, m_sPort, m_sUsername, m_sPassword, m_strDeviceInfo);
@@ -86,6 +88,12 @@
        if (!hCNetSDK.NET_DVR_Init()) {
            log.error("SDK初始化失败");
        }
        //设置JSON透传报警数据和图片分离
        HCNetSDK.NET_DVR_LOCAL_GENERAL_CFG struNET_DVR_LOCAL_GENERAL_CFG = new HCNetSDK.NET_DVR_LOCAL_GENERAL_CFG();
        struNET_DVR_LOCAL_GENERAL_CFG.byAlarmJsonPictureSeparate = 1;   //设置JSON透传报警数据和图片分离
        struNET_DVR_LOCAL_GENERAL_CFG.write();
        Pointer pStrNET_DVR_LOCAL_GENERAL_CFG = struNET_DVR_LOCAL_GENERAL_CFG.getPointer();
        hCNetSDK.NET_DVR_SetSDKLocalCfg(17, pStrNET_DVR_LOCAL_GENERAL_CFG);
        //打印海康sdk日志
        if (Platform.isWindows()) {
            String WIN_PATH = System.getProperty("user.dir") + File.separator + "ardLog" + File.separator + "logs" + File.separator;
src/main/java/com/ard/utils/sdk/hiksdk/util/hikSdkUtil/HCNetSDK.java
@@ -3155,7 +3155,7 @@
    public static class NET_DVR_ALARMIN_PARAM extends HIKSDKStructure {
        public int dwSize;
        public byte[] byName = new byte[NAME_LEN];
       // public DETECTOR_TYPE wDetectorType;
        // public DETECTOR_TYPE wDetectorType;
        public byte byType;
        public byte byUploadAlarmRecoveryReport;
        public int dwParam;
@@ -4608,6 +4608,16 @@
        public byte byIvmsChannel;
    }
    public static class NET_VCA_LEAVE_POSITION extends HIKSDKStructure {
        public NET_VCA_POLYGON struRegion; //区域范围
        public short wLeaveDelay;  //无人报警时间,单位:s
        public short wStaticDelay; //睡觉报警时间,单位:s
        public byte byMode;       //模式,0-离岗事件,1-睡岗事件,2-离岗睡岗事件,3-在岗(当离岗人员回到岗位)
        public byte byPersonType; //值岗人数类型,0-单人值岗,1-双人值岗
        public byte byOnPosition; //在岗人数,1-10,默认1
        public byte bySensitivity;     //灵敏度参数,范围[1,5]
    }
    //事件规则信息
    public static class NET_VCA_RULE_INFO extends HIKSDKStructure {
        public byte byRuleID;
@@ -4626,6 +4636,9 @@
                case 2:
                case 3:
                    uEventParam.setType(NET_VCA_AREA.class);
                    break;
                case 15:
                    uEventParam.setType(NET_VCA_LEAVE_POSITION.class);
                    break;
                default:
                    break;
@@ -4646,6 +4659,7 @@
        public NET_VCA_TRAVERSE_PLANE struTraversePlane;
        public NET_VCA_AREA struArea;
        public NET_VCA_INTRUSION struIntrusion;
        public NET_VCA_LEAVE_POSITION struLeavePos;        //离岗参数
    }
    //穿越警戒面参数