|
|
@@ -1,63 +0,0 @@
|
|
|
-package cn.iocoder.yudao.module.pms.hik;
|
|
|
-
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.http.MediaType;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
-
|
|
|
-/**
|
|
|
- * 海康ISAPI JSON格式告警事件接收控制器
|
|
|
- */
|
|
|
-@Slf4j
|
|
|
-@RestController
|
|
|
-@RequestMapping("/hikvision/alarm")
|
|
|
-public class HikAlarmController {
|
|
|
-
|
|
|
- /**
|
|
|
- * 接收海康巡检融合超脑推送的JSON格式告警事件
|
|
|
- * 接口地址需配置到海康平台:http://你的服务器IP:端口/hikvision/alarm/receive-json
|
|
|
- */
|
|
|
- @PostMapping(value = "/receive-json", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
- public HikAlarmResponse receiveJsonAlarm(@RequestBody HikAlarmEvent alarmEvent) {
|
|
|
- try {
|
|
|
- // 1. 打印告警日志,便于调试和排查问题
|
|
|
- log.info("接收到海康JSON格式告警事件:{}", alarmEvent);
|
|
|
-
|
|
|
- // 2. 核心业务处理(可抽离到Service层,异步处理)
|
|
|
- processAlarmEvent(alarmEvent);
|
|
|
-
|
|
|
- // 3. 快速返回成功响应(必须立即返回,避免设备超时重试)
|
|
|
- return HikAlarmResponse.success();
|
|
|
- } catch (Exception e) {
|
|
|
- // 异常时记录日志,返回失败响应
|
|
|
- log.error("处理海康JSON告警事件失败", e);
|
|
|
- return HikAlarmResponse.fail();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 告警事件业务处理逻辑(示例)
|
|
|
- * 可扩展:入库、消息队列推送、前端通知等
|
|
|
- */
|
|
|
- private void processAlarmEvent(HikAlarmEvent alarmEvent) {
|
|
|
- // 示例1:根据告警类型区分处理
|
|
|
- switch (alarmEvent.getEventType()) {
|
|
|
- case "VMD":
|
|
|
- log.info("【移动侦测告警】设备:{},时间:{}", alarmEvent.getDeviceName(), alarmEvent.getDateTime());
|
|
|
- break;
|
|
|
- case "LINEDETECT":
|
|
|
- log.info("【越界告警】设备:{},通道:{}", alarmEvent.getDeviceID(), alarmEvent.getChannelID());
|
|
|
- break;
|
|
|
- default:
|
|
|
- log.info("【未知类型告警】类型:{},描述:{}", alarmEvent.getEventType(), alarmEvent.getDescription());
|
|
|
- }
|
|
|
-
|
|
|
- // 示例2:告警入库(实际项目中可调用Service层操作数据库)
|
|
|
- // alarmService.saveAlarm(alarmEvent);
|
|
|
-
|
|
|
- // 示例3:异步推送至消息队列(避免阻塞响应)
|
|
|
- // rabbitTemplate.convertAndSend("hik-alarm-queue", alarmEvent);
|
|
|
- }
|
|
|
-}
|