package com.ard.utils.hiksdk.service.impl;
|
|
import com.alibaba.fastjson2.JSON;
|
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.domain.ArdEquipExternal;
|
import com.ard.alarm.external.service.impl.ArdEquipExternalServiceImpl;
|
import com.ard.utils.hiksdk.domain.*;
|
import com.ard.utils.minio.MinioUtil;
|
import com.ard.utils.other.ByteUtils;
|
import com.ard.utils.hiksdk.common.GlobalVariable;
|
import com.ard.utils.hiksdk.util.hikSdkUtil.HCNetSDK;
|
import com.ard.utils.other.DateUtils;
|
import com.ard.utils.mqtt.MqttProducer;
|
import com.ard.utils.uuid.IdUtils;
|
import com.sun.jna.Pointer;
|
import lombok.extern.slf4j.Slf4j;
|
|
import java.io.*;
|
import java.nio.ByteBuffer;
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
import java.util.Optional;
|
|
import static com.ard.utils.hiksdk.util.hikSdkUtil.HCNetSDK.*;
|
|
/**
|
* @ClassName: FMSGCallBack
|
* @Description:
|
* @Author: Administrator
|
* @Date: 2023年02月15日 12:16
|
* @Version: 1.0
|
**/
|
@Slf4j(topic = "hikSdk")
|
public class FMSGCallBack implements HCNetSDK.FMSGCallBack_V31 {
|
|
/**
|
* 报警信息回调函数
|
*
|
* @param lCommand 上传消息类型
|
* @param pAlarmer 报警设备信息
|
* @param pAlarmInfo 报警信息
|
* @param dwBufLen 报警信息缓存大小
|
* @param pUser 用户数据
|
*/
|
@Override
|
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);//设备通讯端口
|
//通过ip和端口查询设备
|
Optional<ArdCameras> foundCamera = findArdCameraByIpAndPort(sDeviceIP, wLinkPort);
|
Optional<ArdEquipExternal> foundExternal = findArdEquipExternalByIpAndPort(sDeviceIP, wLinkPort);
|
ArdCameras camera = null;
|
ArdEquipExternal ardEquipExternal = null;
|
if (foundCamera.isPresent()) {
|
camera = foundCamera.get();
|
} else {
|
if (foundExternal.isPresent()) {
|
ardEquipExternal = foundExternal.get();
|
}
|
}
|
//如果没有找到设备,直接返回
|
if (camera == null && ardEquipExternal == null) {
|
return false;
|
}
|
CameraEventInfo info;
|
String alarmTime;//事件时间
|
String alarmType = "";//报警类型
|
String picUrl = "";//事件图片
|
String facePicUrl = "";//人脸图片
|
//lCommand是传的报警类型
|
log.debug("【" + sDeviceIP + ":" + wLinkPort + "】报警事件类型:lCommand:" + Integer.toHexString(lCommand));
|
switch (lCommand) {
|
case COMM_ALARM_V30:
|
log.debug("移动侦测报警信息上报");
|
if (camera == null) {
|
return false;
|
}
|
//region 移动侦测、视频丢失、遮挡、IO信号量等报警信息(V3.0以上版本支持的设备)
|
HCNetSDK.NET_DVR_ALARMINFO_V30 netDvrAlarminfoV30 = new HCNetSDK.NET_DVR_ALARMINFO_V30();
|
netDvrAlarminfoV30.write();
|
Pointer pNDAInfo = netDvrAlarminfoV30.getPointer();
|
pNDAInfo.write(0, pAlarmInfo.getByteArray(0, netDvrAlarminfoV30.size()), 0, netDvrAlarminfoV30.size());
|
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");
|
break;
|
}
|
//endregion
|
break;
|
case COMM_ALARM_RULE:
|
log.debug("异常行为识别信息报警信息上报");
|
//region 异常行为识别信息
|
HCNetSDK.NET_VCA_RULE_ALARM strVcaAlarm = new HCNetSDK.NET_VCA_RULE_ALARM();
|
strVcaAlarm.write();
|
Pointer pVCAInfo = strVcaAlarm.getPointer();
|
pVCAInfo.write(0, pAlarmInfo.getByteArray(0, strVcaAlarm.size()), 0, strVcaAlarm.size());
|
strVcaAlarm.read();
|
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");
|
//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 4: //region 周界入侵
|
info.setAlarmType("周界入侵报警");
|
strVcaAlarm.struRuleInfo.uEventParam.setType(HCNetSDK.NET_VCA_INTRUSION.class);
|
//图片存入minio
|
picUrl = snapPicture(info);
|
info.setPicUrl(picUrl);
|
publishMqtt(info, "camera");
|
//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;
|
default:
|
log.debug("未知异常行为事件类型:" + strVcaAlarm.struRuleInfo.wEventTypeEx);
|
break;
|
}
|
//endregion
|
break;
|
case COMM_UPLOAD_FACESNAP_RESULT:
|
log.debug("人脸抓拍报警信息(暂不解析)");
|
//region 人脸抓拍报警信息
|
HCNetSDK.NET_VCA_FACESNAP_RESULT struFaceSnap = new HCNetSDK.NET_VCA_FACESNAP_RESULT();
|
struFaceSnap.write();
|
Pointer vcaInfo = struFaceSnap.getPointer();
|
vcaInfo.write(0, pAlarmInfo.getByteArray(0, struFaceSnap.size()), 0, struFaceSnap.size());
|
struFaceSnap.read();
|
alarmTime = DateUtils.parseTime(struFaceSnap.dwAbsTime);
|
String facePicTyp;
|
switch (struFaceSnap.byUploadEventDataType) {
|
case 0:
|
facePicTyp = "二进制数据";
|
break;
|
case 1:
|
facePicTyp = "URL";
|
break;
|
default:
|
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());
|
}
|
}
|
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());
|
}
|
}
|
log.debug("【人脸抓拍报警信息】: alarmTime:" + alarmTime + " picUrl:" + picUrl + " facePicType:" + facePicTyp + " facePicUrl:" + facePicUrl);
|
FaceSnapEventInfo faceSnapEventInfo = new FaceSnapEventInfo();
|
faceSnapEventInfo.setAlarmTime(alarmTime);
|
faceSnapEventInfo.setPicUrl(picUrl);
|
publishMqtt(faceSnapEventInfo, "superbrain");
|
//endregion
|
break;
|
case COMM_SNAP_MATCH_ALARM:
|
log.debug("人脸比对报警信息");
|
//region 人脸比对报警信息
|
HCNetSDK.NET_VCA_FACESNAP_MATCH_ALARM struFaceMatchAlarm = new HCNetSDK.NET_VCA_FACESNAP_MATCH_ALARM();
|
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 = "比对失败";
|
break;
|
default:
|
contrastStatus = "未知";
|
break;
|
}
|
switch (struFaceMatchAlarm.struBlockListInfo.struBlockListInfo.byType) {
|
case 1:
|
alarmType = "陌生人报警";
|
break;
|
case 2:
|
alarmType = "人脸比对报警";
|
break;
|
default:
|
alarmType = "未知";
|
break;
|
}
|
if (struFaceMatchAlarm.dwSnapPicLen > 0 && struFaceMatchAlarm.pSnapPicBuffer != null && struFaceMatchAlarm.byPicTransType == 0) {
|
//将字节写入文件
|
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());
|
}
|
}
|
if (struFaceMatchAlarm.struBlockListInfo.dwBlockListPicLen > 0 && struFaceMatchAlarm.struBlockListInfo.pBuffer1 != null) {
|
//将字节写入文件
|
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);
|
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());
|
}
|
}
|
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();
|
}
|
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("安全帽检测报警信息");
|
//region 安全帽检测报警信息
|
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;
|
|
//处理安全帽检测上传的照片数据
|
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("检测到安全帽事件");
|
//endregion
|
break;
|
case COMM_GISINFO_UPLOAD:
|
log.debug("GPS报警信息上报(暂不解析)");
|
break;
|
case COMM_ALARMHOST_CID_ALARM:
|
log.debug("报警主机CID报告报警上报");
|
//region 报警主机报警处理
|
HCNetSDK.NET_DVR_CID_ALARM netDvrCidAlarm = new HCNetSDK.NET_DVR_CID_ALARM();
|
netDvrCidAlarm.write();
|
Pointer pCIDInfo = netDvrCidAlarm.getPointer();
|
pCIDInfo.write(0, pAlarmInfo.getByteArray(0, netDvrCidAlarm.size()), 0, netDvrCidAlarm.size());
|
netDvrCidAlarm.read();
|
//CID事件名
|
String sCIDCode = ByteUtils.bytesToStringZh(netDvrCidAlarm.sCIDCode);//CID事件名
|
//CID事件名
|
//String sCIDDescribe = ByteUtils.bytesToStringZh(netDvrCidAlarm.sCIDDescribe);//CID事件名
|
int position = ByteUtils.findIndexOfDoubleZero(netDvrCidAlarm.sCIDDescribe);
|
String sCIDDescribe;
|
if (position != -1) {
|
byte[] result = new byte[position];
|
System.arraycopy(netDvrCidAlarm.sCIDDescribe, 0, result, 0, position);
|
sCIDDescribe = ByteUtils.bytesToStringZh(result);
|
} else {
|
sCIDDescribe = ByteUtils.bytesToStringZh(netDvrCidAlarm.sCIDDescribe);
|
}
|
//触发报警的时间点
|
String struTriggerTime = DateUtils.convertDate(parseAlarmTime(netDvrCidAlarm.struTriggerTime), "yyyy-M-d H:m:s");
|
//上传报警的时间点
|
String struUploadTime = DateUtils.convertDate(parseAlarmTime(netDvrCidAlarm.struUploadTime), "yyyy-M-d H:m:s");
|
//报告类型
|
String byReportType = "";
|
switch (netDvrCidAlarm.byReportType) {
|
case 1:
|
byReportType = "防区报警";
|
break;
|
case 2:
|
byReportType = "视频报警";
|
break;
|
case 3:
|
byReportType = "软防区报警";
|
break;
|
case 4:
|
byReportType = "挟持报警";
|
break;
|
case 5:
|
byReportType = "防拆报警 ";
|
break;
|
case 6:
|
byReportType = "操作报告 ";
|
break;
|
case 7:
|
byReportType = "异常报告 ";
|
break;
|
}
|
//子系统号
|
Integer bySubSysNo = Integer.valueOf(netDvrCidAlarm.bySubSysNo);
|
//防区号 起始0
|
Integer wDefenceNo = Integer.valueOf(netDvrCidAlarm.wDefenceNo);
|
//防区名称
|
String wDefenceName = "";
|
if (!bySubSysNo.equals(-1)) {
|
CameraCmd cmd = new CameraCmd();
|
cmd.setCameraId(ardEquipExternal.getId());
|
cmd.setWZoneIndex(wDefenceNo);
|
wDefenceName = HikClientUtil.getDefenseZoneName(cmd);
|
}
|
if (sCIDDescribe.contains("恢复")) {
|
return true;
|
}
|
|
ExternalAlarmEventInfo externalAlarmEventInfo = new ExternalAlarmEventInfo();
|
externalAlarmEventInfo.setAlarmId(sCIDCode);
|
externalAlarmEventInfo.setAlarmName(sCIDDescribe);
|
externalAlarmEventInfo.setDefenseId((wDefenceNo + 1));
|
externalAlarmEventInfo.setDefenseName(wDefenceName);
|
externalAlarmEventInfo.setSubSysNo(bySubSysNo);
|
externalAlarmEventInfo.setAlarmType(byReportType);
|
externalAlarmEventInfo.setAlarmTime(struTriggerTime);
|
externalAlarmEventInfo.setAlarmHostId(ardEquipExternal.getId());
|
publishMqtt(externalAlarmEventInfo, "external");
|
//endregion
|
break;
|
case HCNetSDK.COMM_ALARM_ACS:
|
log.debug("门禁主机报警上报");
|
//region 门禁主机报警处理
|
HCNetSDK.NET_DVR_ACS_ALARM_INFO strACSInfo = new HCNetSDK.NET_DVR_ACS_ALARM_INFO();
|
strACSInfo.write();
|
Pointer acsInfo = strACSInfo.getPointer();
|
acsInfo.write(0, pAlarmInfo.getByteArray(0, strACSInfo.size()), 0, strACSInfo.size());
|
strACSInfo.read();
|
int dwMajor = strACSInfo.dwMajor;
|
if (dwMajor != 5) {
|
//只获取事件
|
// log.debug("非事件报警数据上报(暂不解析)");
|
break;
|
}
|
int dwMinor = strACSInfo.dwMinor;
|
if (dwMinor != 80 && dwMinor != 104) {
|
//只解析真人检测失败和人脸抓拍失败的次类型事件
|
break;
|
}
|
|
switch (dwMinor) {
|
case 104:
|
alarmType = "真人检测失败";
|
break;
|
case 80:
|
alarmType = "人脸抓拍失败";
|
break;
|
}
|
log.debug("门禁主机报警上传:" + alarmType);
|
alarmTime = DateUtils.convertDate(parseAlarmTime(strACSInfo.struTime), "yyyy-M-d H:m:s");
|
|
//事件图片处理
|
int 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("图片保存失败");
|
}
|
}
|
HCNetSDK.NET_DVR_ACS_EVENT_INFO struAcsEventInfo = strACSInfo.struAcsEventInfo;
|
int byType = struAcsEventInfo.byType;
|
String defenseType = "";
|
switch (byType) {
|
case 0:
|
defenseType = "即时防区";
|
break;
|
case 1:
|
defenseType = "24小时防区";
|
break;
|
case 2:
|
defenseType = "延时防区";
|
break;
|
case 3:
|
defenseType = "内部防区";
|
break;
|
case 4:
|
defenseType = "钥匙防区";
|
break;
|
case 5:
|
defenseType = "火警防区";
|
break;
|
case 6:
|
defenseType = "周界防区";
|
break;
|
case 7:
|
defenseType = "24小时无声防区";
|
break;
|
case 8:
|
defenseType = "24小时辅助防区";
|
break;
|
case 9:
|
defenseType = "24小时震动防区";
|
break;
|
case 10:
|
defenseType = "门禁紧急开门防区";
|
break;
|
case 11:
|
defenseType = "门禁紧急关门防区";
|
break;
|
default:
|
defenseType = "无";
|
break;
|
}
|
AccessControlHostEventInfo accessControlHostEventInfo = new AccessControlHostEventInfo();
|
accessControlHostEventInfo.setSerialNo(struAcsEventInfo.dwSerialNo);
|
accessControlHostEventInfo.setAlarmType(alarmType);
|
accessControlHostEventInfo.setDoorNo(struAcsEventInfo.dwDoorNo);
|
accessControlHostEventInfo.setDefenseType(defenseType);
|
accessControlHostEventInfo.setAlarmTime(alarmTime);
|
accessControlHostEventInfo.setPicUrl(picUrl);
|
accessControlHostEventInfo.setAcsId(ardEquipExternal.getId());
|
publishMqtt(accessControlHostEventInfo, "accessControl");
|
//endregion
|
break;
|
default:
|
log.debug("未知报警事件类型:lCommand:" + Integer.toHexString(lCommand));
|
break;
|
|
}
|
return true;
|
}
|
|
/**
|
* 根据给定的IP地址和端口查找ArdEquipExternal对象
|
*
|
* @param ip IP地址
|
* @param port 端口
|
* @return ArdEquipExternal对象的Optional,如果找到则有值,否则为空
|
*/
|
public static Optional<ArdEquipExternal> findArdEquipExternalByIpAndPort(String ip, int port) {
|
return ArdEquipExternalServiceImpl.ardEquipExternalList.stream()
|
.filter(equip -> equip.getIp().equals(ip) && equip.getPort() == port)
|
.findFirst();
|
}
|
|
/**
|
* 根据IP地址和端口查找ArdCamera对象。
|
*
|
* @param ip IP地址
|
* @param port 端口
|
* @return ArdCamera对象的Optional,如果找不到则为空
|
*/
|
public static Optional<ArdCameras> findArdCameraByIpAndPort(String ip, int port) {
|
return ArdCamerasServiceImpl.ardCameraList.stream()
|
.filter(camera -> camera.getIp().equals(ip) && camera.getPort() == port)
|
.findFirst();
|
}
|
|
|
/**
|
* 相机截图
|
*/
|
private String snapPicture(CameraEventInfo info) {
|
CameraCmd cmd = new CameraCmd();
|
String key = info.getCameraIp() + ":" + info.getCameraPort();
|
ArdCameras Cameras = GlobalVariable.cameraMap.get(key);
|
if (Cameras == null) {
|
return "";
|
}
|
cmd.setCameraId(Cameras.getId());
|
cmd.setChannelNum(info.getCameraChannel());
|
cmd.setBucketName("pic");
|
String filename = "alarm" + "/" + IdUtils.simpleUUID() + ".jpg";
|
cmd.setObjectName(filename);
|
String url = HikClientUtil.picCutCate(cmd);
|
return url;
|
}
|
|
/**
|
* 打印通用光电日志
|
*/
|
private void printLog(CameraEventInfo info) {
|
log.debug("【规则】" + info.getAlarmName() + "【规则id】" + info.getRuleId() + "【类型】" + info.getAlarmType() +
|
"【时间】" + info.getAlarmTime() + "【相机id】" + info.getCameraId() + "【相机】" + info.getCameraName() +
|
"【IP】" + info.getCameraIp() + "【通道】" + info.getCameraChannel() + "【型号】" + info.getCameraType() +
|
"【图片】" + info.getPicUrl() + "【坐标】" + info.getLongitude() + "," + info.getLatitude());
|
}
|
|
/**
|
* 打印报警主机事件日志
|
*/
|
private void printLog(ExternalAlarmEventInfo info) {
|
log.debug("【报警ID】" + info.getAlarmId() + "【报警名称】" + info.getAlarmName() +
|
"【防区ID】" + info.getDefenseId() + "【防区名称】" + info.getDefenseName() + "【类型】" + info.getAlarmType() +
|
"【时间】" + info.getAlarmTime() + "【报警主机ID】" + info.getAlarmHostId());
|
}
|
|
/**
|
* 打印门禁事件日志
|
*/
|
private void printLog(AccessControlHostEventInfo info) {
|
log.debug("【报警ID】" + info.getSerialNo() + "【设备编号】" +
|
"【门编号】" + info.getDoorNo() + "【事件类型】" + info.getAlarmType() +
|
"【防区类型】" + info.getDefenseType() + "【时间】" + info.getAlarmTime() +
|
"【门禁主机ID】" + info.getAcsId());
|
}
|
|
/**
|
* 发布MQTT消息
|
*
|
* @param info 消息内容
|
* @param topic 主题
|
*/
|
private <T> void publishMqtt(T info, String topic) {
|
MqttProducer.publish(2, false, topic, JSON.toJSONString(info));
|
}
|
|
/**
|
* 时间格式化
|
*/
|
private String parseAlarmTime(HCNetSDK.NET_DVR_TIME_EX netDvrTimeEx) {
|
short wYear = netDvrTimeEx.wYear;
|
byte byMonth = netDvrTimeEx.byMonth;
|
byte byDay = netDvrTimeEx.byDay;
|
byte byHour = netDvrTimeEx.byHour;
|
byte byMinute = netDvrTimeEx.byMinute;
|
byte bySecond = netDvrTimeEx.bySecond;
|
return wYear + "-" + byMonth + "-" + byDay + " " + byHour + ":" + byMinute + ":" + bySecond;
|
}
|
|
/**
|
* 时间格式化
|
*/
|
private String parseAlarmTime(HCNetSDK.NET_DVR_TIME netDvrTimeEx) {
|
int wYear = netDvrTimeEx.dwYear;
|
int byMonth = netDvrTimeEx.dwMonth;
|
int byDay = netDvrTimeEx.dwDay;
|
int byHour = netDvrTimeEx.dwHour;
|
int byMinute = netDvrTimeEx.dwMinute;
|
int bySecond = netDvrTimeEx.dwSecond;
|
return wYear + "-" + byMonth + "-" + byDay + " " + byHour + ":" + byMinute + ":" + bySecond;
|
}
|
}
|