feat(coal): 支持 SSE 服务端推送

- 在 CoalWashingDailyAnalysisService 中添加 SSE 广播消息
- 在 AuthFilter 和 ResourceFilter 中优化 SSE 请求的处理逻辑
This commit is contained in:
2025-03-12 21:04:57 +08:00
parent f6b13159f2
commit 5cd2bd8282
3 changed files with 19 additions and 6 deletions

View File

@@ -154,6 +154,7 @@ public class CoalWashingDailyAnalysisService
entity.setName(productService.get(entity.getProduct().getId()).getName());
}
this.repository.save(entity);
sseService.broadcast("coalWashingDailyAnalysis." + entity.getId(), ImmutableMap.of("id", entity.getId(), "event", "update"));
return getById(entity.getId());
}
@@ -182,6 +183,7 @@ public class CoalWashingDailyAnalysisService
entity.setName(productService.get(entity.getProduct().getId()).getName());
}
this.repository.save(entity);
sseService.broadcast("coalWashingDailyAnalysis." + entity.getId(), ImmutableMap.of("id", entity.getId(), "event", "update"));
return getById(entity.getId());
}

View File

@@ -59,6 +59,11 @@ public class AuthFilter extends OncePerRequestFilter {
@Nullable
private static Optional<ResourceDto> getResourceDto(
HttpServletRequest request, HttpServletResponse response) {
if (RequestUtils.isSse(request)){
return Optional.empty();
}
Optional<ResourceDto> resource =
Optional.ofNullable(
(ResourceDto) request.getAttribute(Constants.HTTP_ATTR_RESOURCE));
@@ -146,16 +151,21 @@ public class AuthFilter extends OncePerRequestFilter {
stopWatch.start("hasResource");
boolean hasPermission = userService.hasResource(user, resource.get().getId()) && !RequestUtils.isSse(request);
if (!RequestUtils.isSse(request)) {
stopWatch.stop();
boolean hasPermission = userService.hasResource(user, resource.get().getId());
if (!hasPermission) {
stopWatch.stop();
RequestUtils.writeResponse(
new BizException("invalidAccess", "当前资源未授权,请联系机构管理员处理。"), response);
} else {
if (!hasPermission) {
RequestUtils.writeResponse(
new BizException("invalidAccess", "当前资源未授权,请联系机构管理员处理。"), response);
} else {
doFilter(request, response, filterChain);
}
}else {
doFilter(request, response, filterChain);
}
} catch (Exception e) {

View File

@@ -42,6 +42,7 @@ public class ResourceFilter extends OncePerRequestFilter {
if (RequestUtils.isSse(request)){
doFilter(request, response, filterChain);
return;
}
Optional<ResourceDto> resource =