From b11443475114cacb529130a04d45c7c9981ff375 Mon Sep 17 00:00:00 2001 From: zhanghua <314079846@qq.com> Date: 星期三, 09 十月 2024 22:00:16 +0800 Subject: [PATCH] 大华报警sdk --- ycl-platform/src/main/java/com/ycl/service/video/IVideoAlarmReportService.java | 5 ycl-platform/src/main/java/com/ycl/task/SynchronizeDHAlarm.java | 71 +++++++++++ ycl-platform/src/main/resources/application-prod.yml | 2 ycl-platform/src/main/java/com/ycl/service/video/impl/IVideoPointService.java | 1 ycl-platform/src/main/java/com/ycl/PlatformApplication.java | 1 ycl-platform/src/main/java/com/ycl/entity/video/VideoAlarmReport.java | 3 ycl-platform/src/main/java/com/dahua/netsdk/lib/callback/impl/AnalyzerDataCB.java | 184 +++++++++++------------------- ycl-platform/src/main/java/com/ycl/common/constant/GlobalQueue.java | 22 +++ ycl-platform/src/main/java/com/ycl/service/video/impl/VideoAlarmReportServiceImpl.java | 10 + ycl-platform/src/test/java/com/ycl/sccgplatform/Test1.java | 9 + 10 files changed, 191 insertions(+), 117 deletions(-) diff --git a/ycl-platform/src/main/java/com/dahua/netsdk/lib/callback/impl/AnalyzerDataCB.java b/ycl-platform/src/main/java/com/dahua/netsdk/lib/callback/impl/AnalyzerDataCB.java index 4db7b06..c436f9e 100644 --- a/ycl-platform/src/main/java/com/dahua/netsdk/lib/callback/impl/AnalyzerDataCB.java +++ b/ycl-platform/src/main/java/com/dahua/netsdk/lib/callback/impl/AnalyzerDataCB.java @@ -8,6 +8,7 @@ import java.util.List; import java.util.Objects; +import com.alibaba.druid.util.StringUtils; import com.alibaba.fastjson.JSON; import com.dahua.netsdk.lib.Utils; import com.dahua.netsdk.lib.enumeration.EM_EVENT_IVS_TYPE; @@ -15,14 +16,22 @@ import com.sun.jna.Pointer; import com.dahua.netsdk.lib.NetSDKLib; import com.dahua.netsdk.lib.ToolKits; +import com.ycl.common.constant.GlobalQueue; import com.ycl.entity.video.VideoAlarmReport; import com.ycl.entity.video.VideoPoint; import com.ycl.service.caseHandler.IViolationsService; +import com.ycl.service.caseHandler.impl.ViolationsServiceImpl; import com.ycl.service.oss.OssService; +import com.ycl.service.oss.impl.OssServiceImpl; +import com.ycl.service.redis.RedisService; import com.ycl.service.video.IVideoAlarmReportService; import com.ycl.service.video.impl.IVideoPointService; +import com.ycl.service.video.impl.VideoAlarmReportServiceImpl; +import com.ycl.service.video.impl.VideoPointServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; + +import javax.annotation.Resource; /** * 鏅鸿兘鎶ヨ浜嬩欢鍥炶皟 @@ -30,23 +39,10 @@ @Component public class AnalyzerDataCB implements NetSDKLib.fAnalyzerDataCallBack { - - @Autowired - private OssService ossService; - - @Autowired - private IVideoPointService videoPointService; - - @Autowired - private IVideoAlarmReportService videoAlarmReportService; - - @Autowired - private IViolationsService violationsService; - private final File picturePath; private static AnalyzerDataCB instance; - private AnalyzerDataCB() { + public AnalyzerDataCB() { picturePath = new File("./AnalyzerPicture/"); if (!picturePath.exists()) { picturePath.mkdirs(); @@ -102,7 +98,7 @@ ToolKits.GetPointerData(pAlarmInfo, msg); String Picture = picturePath + "\\" + System.currentTimeMillis() + ".jpg"; ToolKits.savePicture(pBuffer, 0, dwBufSize, Picture); - System.out.println(" 鏂楁浜嬩欢 鏃堕棿(UTC)锛�" + msg.UTC + " 閫氶亾鍙�:" + msg.nChannelID); +// System.out.println(" 鏂楁浜嬩欢 鏃堕棿(UTC)锛�" + msg.UTC + " 閫氶亾鍙�:" + msg.nChannelID); break; } case EVENT_IVS_RIOTERDETECTION: // 鑱氫紬浜嬩欢 @@ -119,15 +115,15 @@ { NetSDKLib.DEV_EVENT_MANNUM_DETECTION_INFO msg = new NetSDKLib.DEV_EVENT_MANNUM_DETECTION_INFO(); ToolKits.GetPointerData(pAlarmInfo, msg); - System.out.println(" 绔嬩綋瑙嗚鍖哄煙鍐呬汉鏁扮粺璁′簨浠� 鏃堕棿(UTC)锛�" + msg.UTC + " 閫氶亾鍙�:" + msg.nChannelID + " 鍖哄煙浜哄憳鍒楄〃鏁伴噺:" - + msg.nManListCount + " 浜哄憳韬珮:" + msg.stuManList[0].nStature); +// System.out.println(" 绔嬩綋瑙嗚鍖哄煙鍐呬汉鏁扮粺璁′簨浠� 鏃堕棿(UTC)锛�" + msg.UTC + " 閫氶亾鍙�:" + msg.nChannelID + " 鍖哄煙浜哄憳鍒楄〃鏁伴噺:" +// + msg.nManListCount + " 浜哄憳韬珮:" + msg.stuManList[0].nStature); break; } case EVENT_IVS_CROWDDETECTION: /// < 浜虹兢瀵嗗害妫�娴嬩簨浠� { NetSDKLib.DEV_EVENT_CROWD_DETECTION_INFO msg = new NetSDKLib.DEV_EVENT_CROWD_DETECTION_INFO(); ToolKits.GetPointerData(pAlarmInfo, msg); - System.out.println(" 浜虹兢瀵嗗害妫�娴嬩簨浠� 鏃堕棿(UTC)锛�" + msg.UTC + " 閫氶亾鍙�:" + msg.nChannelID); +// System.out.println(" 浜虹兢瀵嗗害妫�娴嬩簨浠� 鏃堕棿(UTC)锛�" + msg.UTC + " 閫氶亾鍙�:" + msg.nChannelID); break; } case EVENT_IVS_CITY_MOTORPARKING: /// 1 鍩庡競鏈哄姩杞﹁繚鍋滀簨浠� @@ -135,20 +131,16 @@ NetSDKLib.DEV_EVENT_CITY_MOTORPARKING_INFO info = new NetSDKLib.DEV_EVENT_CITY_MOTORPARKING_INFO(); ToolKits.GetPointerData(pAlarmInfo, info); - videoAlarmReport.setAlarmObj(JSON.toJSONString(info)); + // videoAlarmReport.setAlarmObj(JSON.toJSONString(info)); videoAlarmReport.setAlarmTime(LocalDateTime.of(info.UTC.dwYear, info.UTC.dwMonth, info.UTC.dwDay, info.UTC.dwHour, info.UTC.dwMinute, info.UTC.dwSecond)); - VideoPoint videoPoint = videoPointService.getByChannelId(info.nChannelID); videoAlarmReport.setChannel(String.valueOf(info.nChannelID)); videoAlarmReport.setAlarmId(String.valueOf(info.nEventID)); - videoAlarmReport.setAlarmName("闈炴満鍔ㄨ溅涔卞仠鏀�"); - if (videoPoint != null) { - videoAlarmReport.setPlatResourceId(videoPoint.getPlatResourceId()); - } + videoAlarmReport.setAlarmName("鏈哄姩杞︿贡鍋滄斁"); stuFileInfo = info.stuFileInfo; - System.out.println(" 鍩庡競鏈哄姩杞﹁繚鍋滀簨浠� 鏃堕棿(UTC)锛�" + info.UTC + " 閫氶亾鍙�:" + info.nChannelID + "杩濆仠鎸佺画鏃堕暱(鍗曚綅绉�)锛�" - + info.nParkingDuration + "妫�娴嬪埌鐨勭墿浣撲釜鏁�:" + info.nObjectNum); +// System.out.println(" 鍩庡競鏈哄姩杞﹁繚鍋滀簨浠� 鏃堕棿(UTC)锛�" + info.UTC + " 閫氶亾鍙�:" + info.nChannelID + "杩濆仠鎸佺画鏃堕暱(鍗曚綅绉�)锛�" +// + info.nParkingDuration + "妫�娴嬪埌鐨勭墿浣撲釜鏁�:" + info.nObjectNum); // if (stuFileInfo != null) { // 淇濆瓨鍥剧墖 // String bigPicture = picturePath + File.separator @@ -191,20 +183,17 @@ NetSDKLib.DEV_EVENT_CITY_NONMOTORPARKING_INFO info = new NetSDKLib.DEV_EVENT_CITY_NONMOTORPARKING_INFO(); ToolKits.GetPointerData(pAlarmInfo, info); - videoAlarmReport.setAlarmObj(JSON.toJSONString(info)); +// System.out.println(JSON.toJSONString(info)); +// videoAlarmReport.setAlarmObj(JSON.toJSONString(info)); videoAlarmReport.setAlarmTime(LocalDateTime.of(info.UTC.dwYear, info.UTC.dwMonth, info.UTC.dwDay, info.UTC.dwHour, info.UTC.dwMinute, info.UTC.dwSecond)); - VideoPoint videoPoint = videoPointService.getByChannelId(info.nChannelID); videoAlarmReport.setChannel(String.valueOf(info.nChannelID)); videoAlarmReport.setAlarmId(String.valueOf(info.nEventID)); videoAlarmReport.setAlarmName("闈炴満鍔ㄨ溅涔卞仠鏀�"); - if (videoPoint != null) { - videoAlarmReport.setPlatResourceId(videoPoint.getPlatResourceId()); - } stuFileInfo = info.stuFileInfo; - System.out.println( - " 鍩庡競闈炴満鍔ㄨ溅杩濆仠浜嬩欢 鏃堕棿(UTC)锛�" + info.UTC + " 閫氶亾鍙�:" + info.nChannelID + "妫�娴嬪埌鐨勭墿浣撲釜鏁�:" + info.nObjectNum); +// System.out.println( +// " 鍩庡競闈炴満鍔ㄨ溅杩濆仠浜嬩欢 鏃堕棿(UTC)锛�" + info.UTC + " 閫氶亾鍙�:" + info.nChannelID + "妫�娴嬪埌鐨勭墿浣撲釜鏁�:" + info.nObjectNum); break; } case EVENT_IVS_HOLD_UMBRELLA: /// 6 杩濊鎾戜紴妫�娴嬩簨浠� @@ -212,20 +201,16 @@ NetSDKLib.DEV_EVENT_HOLD_UMBRELLA_INFO info = new NetSDKLib.DEV_EVENT_HOLD_UMBRELLA_INFO(); ToolKits.GetPointerData(pAlarmInfo, info); - videoAlarmReport.setAlarmObj(JSON.toJSONString(info)); +// videoAlarmReport.setAlarmObj(JSON.toJSONString(info)); videoAlarmReport.setAlarmTime(LocalDateTime.of(info.UTC.dwYear, info.UTC.dwMonth, info.UTC.dwDay, info.UTC.dwHour, info.UTC.dwMinute, info.UTC.dwSecond)); - VideoPoint videoPoint = videoPointService.getByChannelId(info.nChannelID); videoAlarmReport.setChannel(String.valueOf(info.nChannelID)); videoAlarmReport.setAlarmId(String.valueOf(info.nEventID)); videoAlarmReport.setAlarmName("杩濊鎾戜紴"); - if (videoPoint != null) { - videoAlarmReport.setPlatResourceId(videoPoint.getPlatResourceId()); - } stuFileInfo = info.stuFileInfo; - System.out.println( - " 杩濊鎾戜紴妫�娴嬩簨浠� 鏃堕棿(UTC)锛�" + info.UTC + " 閫氶亾鍙�:" + info.nChannelID + "杩濇硶鎸佺画鏃堕暱(鍗曚綅绉�)" + info.nViolationDuration); +// System.out.println( +// " 杩濊鎾戜紴妫�娴嬩簨浠� 鏃堕棿(UTC)锛�" + info.UTC + " 閫氶亾鍙�:" + info.nChannelID + "杩濇硶鎸佺画鏃堕暱(鍗曚綅绉�)" + info.nViolationDuration); break; } case EVENT_IVS_SHOPPRESENCE: /// 7 鍗犻亾缁忚惀 @@ -233,20 +218,16 @@ NetSDKLib.DEV_EVENT_SHOPPRESENCE_INFO info = new NetSDKLib.DEV_EVENT_SHOPPRESENCE_INFO(); ToolKits.GetPointerData(pAlarmInfo, info); - videoAlarmReport.setAlarmObj(JSON.toJSONString(info)); +// videoAlarmReport.setAlarmObj(JSON.toJSONString(info)); videoAlarmReport.setAlarmTime(LocalDateTime.of(info.UTC.dwYear, info.UTC.dwMonth, info.UTC.dwDay, info.UTC.dwHour, info.UTC.dwMinute, info.UTC.dwSecond)); - VideoPoint videoPoint = videoPointService.getByChannelId(info.nChannelID); videoAlarmReport.setChannel(String.valueOf(info.nChannelID)); videoAlarmReport.setAlarmId(String.valueOf(info.nEventID)); videoAlarmReport.setAlarmName("鍗犻亾缁忚惀"); - if (videoPoint != null) { - videoAlarmReport.setPlatResourceId(videoPoint.getPlatResourceId()); - } stuFileInfo = info.stuFileInfo; - System.out.println(" 鍗犻亾缁忚惀妫�娴嬩簨浠� 鏃堕棿(UTC)锛�" + info.UTC + " 閫氶亾鍙�:" + info.nChannelID + "杩濇硶鎸佺画鏃堕暱(鍗曚綅绉�)" - + info.nViolationDuration + "妫�娴嬪埌鐨勭墿浣撲釜鏁�" + info.nObjectNum); +// System.out.println(" 鍗犻亾缁忚惀妫�娴嬩簨浠� 鏃堕棿(UTC)锛�" + info.UTC + " 閫氶亾鍙�:" + info.nChannelID + "杩濇硶鎸佺画鏃堕暱(鍗曚綅绉�)" +// + info.nViolationDuration + "妫�娴嬪埌鐨勭墿浣撲釜鏁�" + info.nObjectNum); break; } case EVENT_IVS_DUSTBIN_OVER_FLOW: /// 9 鍨冨溇妗舵弧婧㈡娴嬩簨浠� @@ -254,20 +235,16 @@ NetSDKLib.DEV_EVENT_DUSTBIN_OVER_FLOW_INFO info = new NetSDKLib.DEV_EVENT_DUSTBIN_OVER_FLOW_INFO(); ToolKits.GetPointerData(pAlarmInfo, info); - videoAlarmReport.setAlarmObj(JSON.toJSONString(info)); +// videoAlarmReport.setAlarmObj(JSON.toJSONString(info)); videoAlarmReport.setAlarmTime(LocalDateTime.of(info.UTC.dwYear, info.UTC.dwMonth, info.UTC.dwDay, info.UTC.dwHour, info.UTC.dwMinute, info.UTC.dwSecond)); - VideoPoint videoPoint = videoPointService.getByChannelId(info.nChannelID); videoAlarmReport.setChannel(String.valueOf(info.nChannelID)); videoAlarmReport.setAlarmId(String.valueOf(info.nEventID)); videoAlarmReport.setAlarmName("鍨冨溇绠辨弧婧�"); - if (videoPoint != null) { - videoAlarmReport.setPlatResourceId(videoPoint.getPlatResourceId()); - } stuFileInfo = info.stuFileInfo; - System.out.println(" 鍨冨溇妗舵弧婧㈡娴嬩簨浠� 鏃堕棿(UTC)锛�" + info.UTC + " 閫氶亾鍙�:" + info.nChannelID + "杩濇硶鎸佺画鏃堕暱(鍗曚綅绉�)" - + info.nViolationDuration + "妫�娴嬪埌鐨勭墿浣撲釜鏁�" + info.nObjectNum); +// System.out.println(" 鍨冨溇妗舵弧婧㈡娴嬩簨浠� 鏃堕棿(UTC)锛�" + info.UTC + " 閫氶亾鍙�:" + info.nChannelID + "杩濇硶鎸佺画鏃堕暱(鍗曚綅绉�)" +// + info.nViolationDuration + "妫�娴嬪埌鐨勭墿浣撲釜鏁�" + info.nObjectNum); break; } case EVENT_IVS_GARBAGE_PLASTICBAG: /// 10 鎵撳寘鍨冨溇 @@ -275,20 +252,16 @@ NetSDKLib.DEV_EVENT_GARBAGE_EXPOSURE_INFO info = new NetSDKLib.DEV_EVENT_GARBAGE_EXPOSURE_INFO(); ToolKits.GetPointerData(pAlarmInfo, info); - videoAlarmReport.setAlarmObj(JSON.toJSONString(info)); +// videoAlarmReport.setAlarmObj(JSON.toJSONString(info)); videoAlarmReport.setAlarmTime(LocalDateTime.of(info.UTC.dwYear, info.UTC.dwMonth, info.UTC.dwDay, info.UTC.dwHour, info.UTC.dwMinute, info.UTC.dwSecond)); - VideoPoint videoPoint = videoPointService.getByChannelId(info.nChannelID); videoAlarmReport.setChannel(String.valueOf(info.nChannelID)); videoAlarmReport.setAlarmId(String.valueOf(info.nEventID)); videoAlarmReport.setAlarmName("鎵撳寘鍨冨溇"); - if (videoPoint != null) { - videoAlarmReport.setPlatResourceId(videoPoint.getPlatResourceId()); - } stuFileInfo = info.stuFileInfo; - System.out.println(" 鎵撳寘鍨冨溇妫�娴嬩簨浠� 鏃堕棿(UTC)锛�" + info.UTC + " 閫氶亾鍙�:" + info.nChannelID + "杩濇硶鎸佺画鏃堕暱(鍗曚綅绉�)" - + info.nViolationDuration + "妫�娴嬪埌鐨勭墿浣撲釜鏁�" + info.nObjectNum); +// System.out.println(" 鎵撳寘鍨冨溇妫�娴嬩簨浠� 鏃堕棿(UTC)锛�" + info.UTC + " 閫氶亾鍙�:" + info.nChannelID + "杩濇硶鎸佺画鏃堕暱(鍗曚綅绉�)" +// + info.nViolationDuration + "妫�娴嬪埌鐨勭墿浣撲釜鏁�" + info.nObjectNum); break; } case EVENT_IVS_DOOR_FRONT_DIRTY: /// < 闂ㄥ墠鑴忎贡妫�娴嬩簨浠� @@ -296,8 +269,8 @@ NetSDKLib.DEV_EVENT_DOOR_FRONT_DIRTY_INFO msg = new NetSDKLib.DEV_EVENT_DOOR_FRONT_DIRTY_INFO(); ToolKits.GetPointerData(pAlarmInfo, msg); stuFileInfo = msg.stuFileInfo; - System.out.println(" 闂ㄥ墠鑴忎贡妫�娴嬩簨浠� 鏃堕棿(UTC)锛�" + msg.UTC + " 閫氶亾鍙�:" + msg.nChannelID + "杩濇硶鎸佺画鏃堕暱(鍗曚綅绉�)" - + msg.nViolationDuration + "妫�娴嬪埌鐨勭墿浣撲釜鏁�" + msg.nObjectNum); +// System.out.println(" 闂ㄥ墠鑴忎贡妫�娴嬩簨浠� 鏃堕棿(UTC)锛�" + msg.UTC + " 閫氶亾鍙�:" + msg.nChannelID + "杩濇硶鎸佺画鏃堕暱(鍗曚綅绉�)" +// + msg.nViolationDuration + "妫�娴嬪埌鐨勭墿浣撲釜鏁�" + msg.nObjectNum); break; } case EVENT_IVS_GARBAGE_EXPOSURE: /// 11 鍨冨溇鏆撮湶妫�娴嬩簨浠� @@ -305,20 +278,16 @@ NetSDKLib.DEV_EVENT_GARBAGE_EXPOSURE_INFO info = new NetSDKLib.DEV_EVENT_GARBAGE_EXPOSURE_INFO(); ToolKits.GetPointerData(pAlarmInfo, info); - videoAlarmReport.setAlarmObj(JSON.toJSONString(info)); +// videoAlarmReport.setAlarmObj(JSON.toJSONString(info)); videoAlarmReport.setAlarmTime(LocalDateTime.of(info.UTC.dwYear, info.UTC.dwMonth, info.UTC.dwDay, info.UTC.dwHour, info.UTC.dwMinute, info.UTC.dwSecond)); - VideoPoint videoPoint = videoPointService.getByChannelId(info.nChannelID); videoAlarmReport.setChannel(String.valueOf(info.nChannelID)); videoAlarmReport.setAlarmId(String.valueOf(info.nEventID)); videoAlarmReport.setAlarmName("鏆撮湶鍨冨溇"); - if (videoPoint != null) { - videoAlarmReport.setPlatResourceId(videoPoint.getPlatResourceId()); - } stuFileInfo = info.stuFileInfo; - System.out.println(" 鍨冨溇鏆撮湶妫�娴嬩簨浠� 鏃堕棿(UTC)锛�" + info.UTC + " 閫氶亾鍙�:" + info.nChannelID + "杩濇硶鎸佺画鏃堕暱(鍗曚綅绉�)" - + info.nViolationDuration + "妫�娴嬪埌鐨勭墿浣撲釜鏁�" + info.nObjectNum); +// System.out.println(" 鍨冨溇鏆撮湶妫�娴嬩簨浠� 鏃堕棿(UTC)锛�" + info.UTC + " 閫氶亾鍙�:" + info.nChannelID + "杩濇硶鎸佺画鏃堕暱(鍗曚綅绉�)" +// + info.nViolationDuration + "妫�娴嬪埌鐨勭墿浣撲釜鏁�" + info.nObjectNum); break; } case EVENT_IVS_VIOLENT_THROW_DETECTION: /// < 鏆村姏鎶涚墿浜嬩欢浜嬩欢 @@ -330,8 +299,8 @@ ToolKits.savePicture(pBuffer, msg.stuSceneImage.nOffSet, msg.stuSceneImage.nLength, bigPicture); } stuFileInfo = msg.stuFileInfo; - System.out.println(" 鏆村姏鎶涚墿浜嬩欢浜嬩欢 鏃堕棿(UTC)锛�" + msg.UTC + " 閫氶亾鍙�:" + msg.nChannelID + "鏆村姏鎶涚墿妫�娴嬪尯鍩熷悕绉�" - + new String(msg.szRegionName, Charset.forName(Utils.getPlatformEncode()))); +// System.out.println(" 鏆村姏鎶涚墿浜嬩欢浜嬩欢 鏃堕棿(UTC)锛�" + msg.UTC + " 閫氶亾鍙�:" + msg.nChannelID + "鏆村姏鎶涚墿妫�娴嬪尯鍩熷悕绉�" +// + new String(msg.szRegionName, Charset.forName(Utils.getPlatformEncode()))); break; } case EVENT_IVS_SHOP_WINDOW_POST:// 姗辩獥寮犺创浜嬩欢 @@ -339,9 +308,9 @@ DEV_EVENT_SHOP_WINDOW_POST_INFO info = new DEV_EVENT_SHOP_WINDOW_POST_INFO(); ToolKits.GetPointerData(pAlarmInfo, info); stuFileInfo = info.stuFileInfo; - System.out.println(" 姗辩獥寮犺创浜嬩欢 鏃堕棿(UTC)锛�" + info.UTC + " 閫氶亾鍙�:" + info.nChannelID + " 鍟嗛摵鍦板潃: " - + new String(info.szShopAddress, Charset.forName(Utils.getPlatformEncode())).trim() + " 杩濇硶鎸佺画鏃堕棿: " - + info.nViolationDuration + " 妫�娴嬪埌鐨勭墿浣撴暟閲�: " + info.nObjectNum); +// System.out.println(" 姗辩獥寮犺创浜嬩欢 鏃堕棿(UTC)锛�" + info.UTC + " 閫氶亾鍙�:" + info.nChannelID + " 鍟嗛摵鍦板潃: " +// + new String(info.szShopAddress, Charset.forName(Utils.getPlatformEncode())).trim() + " 杩濇硶鎸佺画鏃堕棿: " +// + info.nViolationDuration + " 妫�娴嬪埌鐨勭墿浣撴暟閲�: " + info.nObjectNum); for (int i = 0; i < info.nObjectNum; i++) { stPicInfo = info.stuObjects[i].stPicInfo; if (stPicInfo != null && stPicInfo.dwFileLenth > 0) { @@ -360,20 +329,16 @@ DEV_EVENT_STREET_SUNCURE_INFO info = new DEV_EVENT_STREET_SUNCURE_INFO(); ToolKits.GetPointerData(pAlarmInfo, info); - videoAlarmReport.setAlarmObj(JSON.toJSONString(info)); +// videoAlarmReport.setAlarmObj(JSON.toJSONString(info)); videoAlarmReport.setAlarmTime(LocalDateTime.of(info.UTC.dwYear, info.UTC.dwMonth, info.UTC.dwDay, info.UTC.dwHour, info.UTC.dwMinute, info.UTC.dwSecond)); - VideoPoint videoPoint = videoPointService.getByChannelId(info.nChannelID); videoAlarmReport.setChannel(String.valueOf(info.nChannelID)); videoAlarmReport.setAlarmId(String.valueOf(info.nEventID)); videoAlarmReport.setAlarmName("娌胯鏅炬寕"); - if (videoPoint != null) { - videoAlarmReport.setPlatResourceId(videoPoint.getPlatResourceId()); - } stuFileInfo = info.stuFileInfo; - System.out.println(" 娌胯鏅炬檼浜嬩欢 鏃堕棿(UTC)锛�" + info.UTC + " 閫氶亾鍙�:" + info.nChannelID + " 杩濇硶鎸佺画鏃堕棿: " - + info.nViolationDuration + " 妫�娴嬪埌鐨勭墿浣撴暟閲�: " + info.nObjectNum); +// System.out.println(" 娌胯鏅炬檼浜嬩欢 鏃堕棿(UTC)锛�" + info.UTC + " 閫氶亾鍙�:" + info.nChannelID + " 杩濇硶鎸佺画鏃堕棿: " +// + info.nViolationDuration + " 妫�娴嬪埌鐨勭墿浣撴暟閲�: " + info.nObjectNum); break; } @@ -382,20 +347,16 @@ DEV_EVENT_OUTDOOR_ADVERTISEMENT_INFO info = new DEV_EVENT_OUTDOOR_ADVERTISEMENT_INFO(); ToolKits.GetPointerData(pAlarmInfo, info); - videoAlarmReport.setAlarmObj(JSON.toJSONString(info)); +// videoAlarmReport.setAlarmObj(JSON.toJSONString(info)); videoAlarmReport.setAlarmTime(LocalDateTime.of(info.UTC.dwYear, info.UTC.dwMonth, info.UTC.dwDay, info.UTC.dwHour, info.UTC.dwMinute, info.UTC.dwSecond)); - VideoPoint videoPoint = videoPointService.getByChannelId(info.nChannelID); videoAlarmReport.setChannel(String.valueOf(info.nChannelID)); videoAlarmReport.setAlarmId(String.valueOf(info.nEventID)); videoAlarmReport.setAlarmName("杩濊鎴峰骞垮憡"); - if (videoPoint != null) { - videoAlarmReport.setPlatResourceId(videoPoint.getPlatResourceId()); - } stuFileInfo = info.stuFileInfo; - System.out.println(" 鎴峰骞垮憡浜嬩欢 鏃堕棿(UTC)锛�" + info.UTC + " 閫氶亾鍙�:" + info.nChannelID + " 杩濇硶鎸佺画鏃堕棿: " - + info.nViolationDuration + " 妫�娴嬪埌鐨勭墿浣撴暟閲�: " + info.nObjectNum); +// System.out.println(" 鎴峰骞垮憡浜嬩欢 鏃堕棿(UTC)锛�" + info.UTC + " 閫氶亾鍙�:" + info.nChannelID + " 杩濇硶鎸佺画鏃堕棿: " +// + info.nViolationDuration + " 妫�娴嬪埌鐨勭墿浣撴暟閲�: " + info.nObjectNum); break; @@ -404,20 +365,16 @@ { DEV_EVENT_HUDDLE_MATERIAL_INFO info = new DEV_EVENT_HUDDLE_MATERIAL_INFO(); ToolKits.GetPointerData(pAlarmInfo, info); - videoAlarmReport.setAlarmObj(JSON.toJSONString(info)); +// videoAlarmReport.setAlarmObj(JSON.toJSONString(info)); videoAlarmReport.setAlarmTime(LocalDateTime.of(info.UTC.dwYear, info.UTC.dwMonth, info.UTC.dwDay, info.UTC.dwHour, info.UTC.dwMinute, info.UTC.dwSecond)); - VideoPoint videoPoint = videoPointService.getByChannelId(info.nChannelID); videoAlarmReport.setChannel(String.valueOf(info.nChannelID)); videoAlarmReport.setAlarmId(String.valueOf(info.nEventID)); videoAlarmReport.setAlarmName("涔卞爢鐗╂枡"); - if (videoPoint != null) { - videoAlarmReport.setPlatResourceId(videoPoint.getPlatResourceId()); - } stuFileInfo = info.stuFileInfo; - System.out.println(" 涔卞爢鐗╂枡妫�娴嬩簨浠� 鏃堕棿(UTC)锛�" + info.UTC + " 閫氶亾鍙�:" + info.nChannelID + " 杩濇硶鎸佺画鏃堕棿: " - + info.nViolationDuration + " 妫�娴嬪埌鐨勭墿浣撴暟閲�: " + info.nObjectNum); +// System.out.println(" 涔卞爢鐗╂枡妫�娴嬩簨浠� 鏃堕棿(UTC)锛�" + info.UTC + " 閫氶亾鍙�:" + info.nChannelID + " 杩濇硶鎸佺画鏃堕棿: " +// + info.nViolationDuration + " 妫�娴嬪埌鐨勭墿浣撴暟閲�: " + info.nObjectNum); // for (int i = 0; i < info.nObjectNum; i++) { // stPicInfo = info.stuObjects[i].stPicInfo; // if (stPicInfo != null && stPicInfo.dwFileLenth > 0) { @@ -439,17 +396,17 @@ ToolKits.GetPointerDataToStruct(pAlarmInfo, 0, trashEvent); String date = trashEvent.UTC.toStringTime(); - System.out.println("nChannelID = " + trashEvent.nChannelID); - System.out.println("szName(GBK) = " + new String(trashEvent.szName, Charset.forName("GBK"))); - System.out.println("szName(UTF-8) = " + new String(trashEvent.szName, Charset.forName("UTF-8"))); - System.out.println("nImageInfoNum = " + trashEvent.nImageInfoNum); - System.out.println("UTC = " + trashEvent.UTC.toStringTime()); +// System.out.println("nChannelID = " + trashEvent.nChannelID); +// System.out.println("szName(GBK) = " + new String(trashEvent.szName, Charset.forName("GBK"))); +// System.out.println("szName(UTF-8) = " + new String(trashEvent.szName, Charset.forName("UTF-8"))); +// System.out.println("nImageInfoNum = " + trashEvent.nImageInfoNum); +// System.out.println("UTC = " + trashEvent.UTC.toStringTime()); // save the picture String imageName = "trashEvent_" + trashEvent.UTC.toStringTitle() + ".jpg"; String savePath = picturePath + "/" + imageName; ToolKits.savePicture(pBuffer, dwBufSize, savePath); - System.out.println("save picture to " + savePath); +// System.out.println("save picture to " + savePath); break; } @@ -471,21 +428,16 @@ // stuFileInfo.bFileType, stuFileInfo.nGroupId); // ToolKits.savePicture(pBuffer, stPicInfo.dwOffSet, stPicInfo.dwFileLenth, smallPicture); // } - try { - - String extension = "jpg"; - String picData = ossService.uploadImages(new ByteArrayInputStream(pBuffer.getByteArray(stPicInfo.dwOffSet, dwBufSize)), extension); - videoAlarmReport.setPicData(picData); - - } catch (Exception ex) { - System.out.println("淇濆瓨鍥剧墖閿欒锛�" + ex.getMessage()); - } +// try { + byte[] bytes = pBuffer.getByteArray(0, dwBufSize); + videoAlarmReport.setPicByte(bytes); +// } catch (Exception ex) { +// System.out.println("淇濆瓨鍥剧墖閿欒锛�"); +// System.out.println(ex); +// } } - videoAlarmReportService.save(videoAlarmReport); - - List<VideoAlarmReport> videoAlarmReports = new ArrayList<>(); - videoAlarmReports.add(videoAlarmReport); - violationsService.saveFromVideo(videoAlarmReports); + if (!StringUtils.isEmpty(videoAlarmReport.getAlarmName())) + GlobalQueue.add(videoAlarmReport); return 0; } diff --git a/ycl-platform/src/main/java/com/ycl/PlatformApplication.java b/ycl-platform/src/main/java/com/ycl/PlatformApplication.java index 8982fea..2e2b512 100644 --- a/ycl-platform/src/main/java/com/ycl/PlatformApplication.java +++ b/ycl-platform/src/main/java/com/ycl/PlatformApplication.java @@ -7,6 +7,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.core.env.Environment; diff --git a/ycl-platform/src/main/java/com/ycl/common/constant/GlobalQueue.java b/ycl-platform/src/main/java/com/ycl/common/constant/GlobalQueue.java new file mode 100644 index 0000000..31b8927 --- /dev/null +++ b/ycl-platform/src/main/java/com/ycl/common/constant/GlobalQueue.java @@ -0,0 +1,22 @@ +package com.ycl.common.constant; + +import com.ycl.entity.video.VideoAlarmReport; + +import java.util.LinkedList; +import java.util.Queue; + +public class GlobalQueue { + private static Queue<VideoAlarmReport> queue = new LinkedList<>(); + + public static synchronized void add(VideoAlarmReport item) { + queue.add(item); + } + + public static synchronized VideoAlarmReport dequeue() { + return queue.poll(); + } + + public static synchronized int size() { + return queue.size(); + } +} diff --git a/ycl-platform/src/main/java/com/ycl/entity/video/VideoAlarmReport.java b/ycl-platform/src/main/java/com/ycl/entity/video/VideoAlarmReport.java index 77d88b9..a5e5980 100644 --- a/ycl-platform/src/main/java/com/ycl/entity/video/VideoAlarmReport.java +++ b/ycl-platform/src/main/java/com/ycl/entity/video/VideoAlarmReport.java @@ -87,4 +87,7 @@ @ApiModelProperty("绠楁硶妫�鍑哄璞″湪鍥剧墖涓殑鍧愭爣") @TableField("alarm_obj") private String alarmObj; + + @TableField(exist = false) + private byte[] picByte; } diff --git a/ycl-platform/src/main/java/com/ycl/service/video/IVideoAlarmReportService.java b/ycl-platform/src/main/java/com/ycl/service/video/IVideoAlarmReportService.java index 518a330..d9f3c99 100644 --- a/ycl-platform/src/main/java/com/ycl/service/video/IVideoAlarmReportService.java +++ b/ycl-platform/src/main/java/com/ycl/service/video/IVideoAlarmReportService.java @@ -5,6 +5,9 @@ import com.ycl.dto.video.HKAlarmParam; import com.ycl.entity.video.VideoAlarmReport; +import java.time.LocalDateTime; +import java.util.List; + /** * 瑙嗛鎶ヨ鎺ㄩ�佽褰曡〃(UmsVideoAlarmReport)琛ㄦ湇鍔℃帴鍙� * @@ -23,4 +26,6 @@ void save(AlarmParam alarmParam); void saveFromHK(HKAlarmParam alarmParam); + + List<VideoAlarmReport> findByChannelAndAlarmNameAndTime(String channel, String alarmName, LocalDateTime alarmTime); } diff --git a/ycl-platform/src/main/java/com/ycl/service/video/impl/IVideoPointService.java b/ycl-platform/src/main/java/com/ycl/service/video/impl/IVideoPointService.java index bdc516f..78db8cb 100644 --- a/ycl-platform/src/main/java/com/ycl/service/video/impl/IVideoPointService.java +++ b/ycl-platform/src/main/java/com/ycl/service/video/impl/IVideoPointService.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.ycl.entity.video.VideoPoint; import com.ycl.vo.equipment.VideoPointVo; +import org.springframework.stereotype.Component; import java.util.List; diff --git a/ycl-platform/src/main/java/com/ycl/service/video/impl/VideoAlarmReportServiceImpl.java b/ycl-platform/src/main/java/com/ycl/service/video/impl/VideoAlarmReportServiceImpl.java index 0d822f5..d790b02 100644 --- a/ycl-platform/src/main/java/com/ycl/service/video/impl/VideoAlarmReportServiceImpl.java +++ b/ycl-platform/src/main/java/com/ycl/service/video/impl/VideoAlarmReportServiceImpl.java @@ -26,6 +26,7 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.Instant; +import java.time.LocalDateTime; import java.time.ZoneId; import java.util.ArrayList; import java.util.Date; @@ -226,6 +227,15 @@ } } + @Override + public List<VideoAlarmReport> findByChannelAndAlarmNameAndTime(String channel, String alarmName, LocalDateTime alarmTime) { + + LambdaQueryWrapper<VideoAlarmReport> queryWrapper = new LambdaQueryWrapper<VideoAlarmReport>() + .eq(VideoAlarmReport::getChannel, channel).eq(VideoAlarmReport::getAlarmName, alarmName) + .between(VideoAlarmReport::getAlarmTime, alarmTime.plusMinutes(-3), alarmTime.plusMinutes(3)); + return this.list(queryWrapper); + } + private List<VideoAlarmReport> getByAlarmId(String alarmId) { LambdaQueryWrapper<VideoAlarmReport> queryWrapper = new LambdaQueryWrapper<VideoAlarmReport>().eq(VideoAlarmReport::getAlarmId, alarmId); return this.list(queryWrapper); diff --git a/ycl-platform/src/main/java/com/ycl/task/SynchronizeDHAlarm.java b/ycl-platform/src/main/java/com/ycl/task/SynchronizeDHAlarm.java new file mode 100644 index 0000000..7ad52dd --- /dev/null +++ b/ycl-platform/src/main/java/com/ycl/task/SynchronizeDHAlarm.java @@ -0,0 +1,71 @@ +package com.ycl.task; + +import com.ycl.common.constant.GlobalQueue; +import com.ycl.entity.video.VideoAlarmReport; +import com.ycl.entity.video.VideoPoint; +import com.ycl.service.caseHandler.IViolationsService; +import com.ycl.service.oss.OssService; +import com.ycl.service.video.IVideoAlarmReportService; +import com.ycl.service.video.impl.IVideoPointService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +@Component +public class SynchronizeDHAlarm { + + @Autowired + private OssService ossService; + + @Autowired + private IVideoPointService videoPointService; + + @Autowired + private IVideoAlarmReportService videoAlarmReportService; + + @Autowired + private IViolationsService violationsService; + + @Scheduled(cron = "0 */1 * * * ?") + @Transactional(rollbackFor = Exception.class) + public void scheduledTask() { + + while (GlobalQueue.size() > 0) { + try { + VideoAlarmReport videoAlarmReport = GlobalQueue.dequeue(); + + List<VideoAlarmReport> list = videoAlarmReportService.findByChannelAndAlarmNameAndTime(videoAlarmReport.getChannel(), videoAlarmReport.getAlarmName(), videoAlarmReport.getAlarmTime()); + if (list.size() == 0) { + System.out.println("----------------寮�濮嬩繚瀛樻姤璀︿俊鎭�:" + videoAlarmReport.getAlarmName()); + VideoPoint videoPoint = videoPointService.getByChannelId(Integer.parseInt(videoAlarmReport.getChannel())); + + if (videoPoint != null) { + videoAlarmReport.setPlatResourceId(videoPoint.getPlatResourceId()); + } + if (videoAlarmReport.getPicByte() != null) { + String extension = "jpg"; + InputStream inputStream = new ByteArrayInputStream(videoAlarmReport.getPicByte()); + String picData = ossService.uploadImages(inputStream, extension); + + videoAlarmReport.setPicData(picData); + } + videoAlarmReportService.save(videoAlarmReport); + + List<VideoAlarmReport> videoAlarmReports = new ArrayList<>(); + videoAlarmReports.add(videoAlarmReport); + violationsService.saveFromVideo(videoAlarmReports); + + } + } catch (Exception ex) { + System.out.println("------------淇濆瓨鎶ヨ淇℃伅寮傚父锛�"); + + } + } + } +} diff --git a/ycl-platform/src/main/resources/application-prod.yml b/ycl-platform/src/main/resources/application-prod.yml index dc74543..ce662ad 100644 --- a/ycl-platform/src/main/resources/application-prod.yml +++ b/ycl-platform/src/main/resources/application-prod.yml @@ -1,5 +1,5 @@ server: - port: 28082 + port: 8082 tomcat: uri-encoding: UTF-8 servlet: diff --git a/ycl-platform/src/test/java/com/ycl/sccgplatform/Test1.java b/ycl-platform/src/test/java/com/ycl/sccgplatform/Test1.java index 39e59a6..c8ecadb 100644 --- a/ycl-platform/src/test/java/com/ycl/sccgplatform/Test1.java +++ b/ycl-platform/src/test/java/com/ycl/sccgplatform/Test1.java @@ -1,5 +1,6 @@ package com.ycl.sccgplatform; +import com.dahua.netsdk.lib.callback.impl.AnalyzerDataCB; import com.ycl.common.util.UtilNumber; import com.ycl.entity.dingding.DingUserInfo; import com.ycl.entity.user.UmsAdmin; @@ -9,6 +10,7 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.ComponentScan; import javax.annotation.Resource; import javax.xml.bind.DatatypeConverter; @@ -17,6 +19,7 @@ import java.net.URL; import java.util.*; +@ComponentScan("com.dahua.netsdk") @SpringBootTest public class Test1 { @@ -91,8 +94,14 @@ fis.close(); } + @Autowired + AnalyzerDataCB analyzerDataCB; + @Test void alarmTest() { + + analyzerDataCB.invoke(null, 0, null, null, 0, null, 0, null); + // AlarmDataCB cbMessage = new AlarmDataCB(); // String m_strIp = "172.28.194.177"; // int m_nPort = 37777; -- Gitblit v1.8.0