diff --git a/src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java b/src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java index 9703c828e..f39cd8e60 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java @@ -1,5 +1,6 @@ package com.genersoft.iot.vmp.conf; +import com.genersoft.iot.vmp.service.bean.AlarmType; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.core.annotation.Order; @@ -240,5 +241,10 @@ public class UserSetting { */ private boolean snapByPullStream = false; + /** + * 报警订阅白名单,设置后只有在此列表中的上级平台才会接收报警订阅消息,默认不设置则不限制 + */ + private List allowedAlarmType = new ArrayList<>(); + } diff --git a/src/main/java/com/genersoft/iot/vmp/conf/security/JwtUtils.java b/src/main/java/com/genersoft/iot/vmp/conf/security/JwtUtils.java index c67895018..a23ba857d 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/security/JwtUtils.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/security/JwtUtils.java @@ -104,7 +104,7 @@ public class JwtUtils implements InitializingBean { } String jwkFile = userSetting.getJwkFile(); if (jwkFile == null || jwkFile.trim().isEmpty()) { - log.error("[API AUTH] JWK文件路径未配置!使用默认配置路径:./config/jwk.json"); + log.warn("[API AUTH] JWK文件路径未配置!使用默认配置路径:./config/jwk.json"); jwkFile = "config" + File.separator + "jwk.json"; // 默认外部路径 return createAndPersistDefaultRsaKey(jwkFile); } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/SseController.java b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/SseController.java deleted file mode 100644 index 8e97295df..000000000 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/SseController.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.genersoft.iot.vmp.gb28181.controller; - -import com.genersoft.iot.vmp.gb28181.session.SseSessionManager; -import io.swagger.v3.oas.annotations.tags.Tag; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; - -import jakarta.annotation.Resource; -import jakarta.servlet.http.HttpServletResponse; -import java.io.IOException; - - -/** - * SSE 推送. - * - * @author lawrencehj - * @author xiaoQQya - * @since 2021/01/20 - */ -@Tag(name = "SSE 推送") -@RestController -@RequestMapping("/api") -public class SseController { - - @Resource - private SseSessionManager sseSessionManager; - - /** - * SSE 推送. - * - * @param browserId 浏览器ID - */ - @GetMapping("/emit") - public SseEmitter emit(HttpServletResponse response, @RequestParam String browserId) throws IOException, InterruptedException { -// response.setContentType("text/event-stream"); -// response.setCharacterEncoding("utf-8"); - return sseSessionManager.conect(browserId); - } -} diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/session/SseSessionManager.java b/src/main/java/com/genersoft/iot/vmp/gb28181/session/SseSessionManager.java deleted file mode 100644 index 15effe05d..000000000 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/session/SseSessionManager.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.genersoft.iot.vmp.gb28181.session; - -import com.genersoft.iot.vmp.conf.DynamicTask; -import com.genersoft.iot.vmp.gb28181.event.alarm.DeviceAlarmEvent; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.scheduling.annotation.Async; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; -import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -@Component -@Slf4j -public class SseSessionManager { - - private static final Map sseSessionMap = new ConcurrentHashMap<>(); - - @Autowired - private DynamicTask dynamicTask; - - public SseEmitter conect(String browserId) { - SseEmitter sseEmitter = new SseEmitter(0L); - sseEmitter.onError((err) -> { - log.error("[SSE推送] 连接错误, 浏览器 ID: {}, {}", browserId, err.getMessage()); - sseSessionMap.remove(browserId); - sseEmitter.completeWithError(err); - }); - -// sseEmitter.onTimeout(() -> { -// log.info("[SSE推送] 连接超时, 浏览器 ID: {}", browserId); -// sseSessionMap.remove(browserId); -// sseEmitter.complete(); -// dynamicTask.stop(key); -// }); - - sseEmitter.onCompletion(() -> { - log.info("[SSE推送] 连接结束, 浏览器 ID: {}", browserId); - sseSessionMap.remove(browserId); - }); - - sseSessionMap.put(browserId, sseEmitter); - - log.info("[SSE推送] 连接已建立, 浏览器 ID: {}, 当前在线数: {}", browserId, sseSessionMap.size()); - return sseEmitter; - } - - @Scheduled(fixedRate = 1000) //每1秒执行一次 - public void execute() { - if (sseSessionMap.isEmpty()) { - return; - } - sendForAll("keepalive", "alive"); - } - - @Async - @org.springframework.context.event.EventListener - public void onApplicationEvent(DeviceAlarmEvent event) { - event.getDeviceAlarmList().forEach( - notify -> sendForAll("message", notify) - ); - } - - - public void sendForAll(String event, Object data) { - for (String browserId : sseSessionMap.keySet()) { - SseEmitter sseEmitter = sseSessionMap.get(browserId); - if (sseEmitter == null) { - continue; - } - ; - try { - sseEmitter.send(SseEmitter.event().name(event).data(data)); - } catch (Exception e) { - log.error("[SSE推送] 发送失败: {}", e.getMessage()); - sseSessionMap.remove(browserId); - sseEmitter.completeWithError(e); - } - } - } -} diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/AlarmServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/AlarmServiceImpl.java index de601bd0f..8b41a9c6a 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/AlarmServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/AlarmServiceImpl.java @@ -77,6 +77,10 @@ public class AlarmServiceImpl implements IAlarmService { log.info("收到设备报警事件,数量:{}", event.getDeviceAlarmList().size()); for (DeviceAlarmNotify notify : event.getDeviceAlarmList()) { Alarm alarm = Alarm.buildFromDeviceAlarmNotify(notify); + if (!userSetting.getAllowedAlarmType().isEmpty() && !userSetting.getAllowedAlarmType().contains(alarm.getAlarmType())) { + log.debug("报警类型不在允许的范围内,alarmType:{},alarmId:{}", alarm.getAlarmType(), alarm.getId()); + continue; + } String key = notify.getDeviceId() + notify.getChannelId(); DeviceChannel deviceChannel = channelCache.get(key, k -> deviceChannelService.getOneForSource(notify.getDeviceId(), notify.getChannelId())); if (deviceChannel == null) { diff --git a/src/main/resources/配置详情.yml b/src/main/resources/配置详情.yml index 8ad5f7432..6cb938536 100644 --- a/src/main/resources/配置详情.yml +++ b/src/main/resources/配置详情.yml @@ -270,6 +270,9 @@ user-settings: alarm-catch-size: 10000 # 是否使用拉流的方式获取快照,默认false,避免流量大规模消耗,开启后则使用拉流的方式获取快照 snap-by-pull-stream: true + # 是否使用拉流的方式获取快照,默认false,避免流量大规模消耗,开启后则使用拉流的方式获取快照 + allowed-alarm-type: + - IntrusionDetection # 关闭在线文档(生产环境建议关闭) springdoc: