mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
feat(coal): 支持 SSE 服务端推送
- 在 CoalWashingDailyAnalysisService 中添加 SSE 广播消息 - 在 AuthFilter 和 ResourceFilter 中优化 SSE 请求的处理逻辑
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -42,6 +42,7 @@ public class ResourceFilter extends OncePerRequestFilter {
|
||||
if (RequestUtils.isSse(request)){
|
||||
|
||||
doFilter(request, response, filterChain);
|
||||
return;
|
||||
}
|
||||
|
||||
Optional<ResourceDto> resource =
|
||||
|
||||
Reference in New Issue
Block a user