‘liusuyi’
2023-12-06 6ab0ec5ade792e91ba90018c0b7f822abb1db5b2
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;
    }
}