diff --git a/src/main/java/cn/lihongjie/coal/coalWashingDailyAnalysis/service/CoalWashingDailyAnalysisService.java b/src/main/java/cn/lihongjie/coal/coalWashingDailyAnalysis/service/CoalWashingDailyAnalysisService.java index f07ffa2e..694554d7 100644 --- a/src/main/java/cn/lihongjie/coal/coalWashingDailyAnalysis/service/CoalWashingDailyAnalysisService.java +++ b/src/main/java/cn/lihongjie/coal/coalWashingDailyAnalysis/service/CoalWashingDailyAnalysisService.java @@ -127,7 +127,7 @@ public class CoalWashingDailyAnalysisService } this.repository.save(entity); - sseService.broadcast("coalWashingDailyAnalysis." + entity.getId(), ImmutableMap.of("id", entity.getId(), "event", "update")); + sseService.broadcast("coalWashingDailyAnalysis." + entity.getId(), ImmutableMap.of("id", entity.getId(), "event", "update", "sessionId", Ctx.getSessionIdMd5())); return getById(entity.getId()); } @@ -154,7 +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", "updateKfItems")); + sseService.broadcast("coalWashingDailyAnalysis." + entity.getId(), ImmutableMap.of("id", entity.getId(), "event", "updateKfItems", "sessionId", Ctx.getSessionIdMd5())); return getById(entity.getId()); } @@ -183,7 +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", "updateMain")); + sseService.broadcast("coalWashingDailyAnalysis." + entity.getId(), ImmutableMap.of("id", entity.getId(), "event", "updateMain", "sessionId", Ctx.getSessionIdMd5())); return getById(entity.getId()); } diff --git a/src/main/java/cn/lihongjie/coal/common/Ctx.java b/src/main/java/cn/lihongjie/coal/common/Ctx.java index 15694ea6..ec413acd 100644 --- a/src/main/java/cn/lihongjie/coal/common/Ctx.java +++ b/src/main/java/cn/lihongjie/coal/common/Ctx.java @@ -6,6 +6,7 @@ import cn.lihongjie.coal.user.dto.UserDto; import lombok.Getter; import lombok.experimental.UtilityClass; +import org.apache.commons.codec.digest.DigestUtils; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; @@ -13,8 +14,7 @@ import org.springframework.security.core.context.SecurityContextHolder; @UtilityClass public class Ctx { - @Getter - private static ConfigurableApplicationContext context; + @Getter private static ConfigurableApplicationContext context; public static String getUserId() { if (!isLoggedIn()) { @@ -35,14 +35,21 @@ public class Ctx { return getAuthentication().getSessionId(); } + public static String getSessionIdMd5() { + if (!isLoggedIn()) { + return ""; + } + String sessionId = getAuthentication().getSessionId(); + + if (sessionId == null) return ""; + return DigestUtils.md5Hex(sessionId); + } + private static SessionService.MyAuthentication getAuthentication() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); - if( ! (authentication instanceof SessionService.MyAuthentication)) - return null; + if (!(authentication instanceof SessionService.MyAuthentication)) return null; - - return (SessionService.MyAuthentication) - authentication; + return (SessionService.MyAuthentication) authentication; } public static boolean isOrgAdmin() { @@ -59,7 +66,7 @@ public class Ctx { if (!isLoggedIn()) { return null; } - return getAuthentication().getUser(); + return getAuthentication().getUser(); } public static void setContext(ConfigurableApplicationContext context) { diff --git a/src/main/java/cn/lihongjie/coal/sse/service/SseService.java b/src/main/java/cn/lihongjie/coal/sse/service/SseService.java index 2b0d95f4..8a6b8d74 100644 --- a/src/main/java/cn/lihongjie/coal/sse/service/SseService.java +++ b/src/main/java/cn/lihongjie/coal/sse/service/SseService.java @@ -58,7 +58,9 @@ public class SseService { @SneakyThrows public void broadcast(String s, Object event) { - + + + RTopic topic = redissonClient.getTopic(s);