From a0f99040d02d9eaba8ee13250150b2148a026877 Mon Sep 17 00:00:00 2001 From: bjang03 Date: Thu, 16 May 2024 15:12:59 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BB=A3=E7=A0=81=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/config/WinWebAutoConfiguration.java | 3 --- .../web/config}/ModuleAuthenInterceptor.java | 6 ++---- .../web/config/MyCommandLineRunner.java | 2 +- .../web/config/SystemWebConfiguration.java | 13 ++++++++++++- .../module/system/job/ModuleLicencesJob.java | 2 +- .../mq/consumer/licences/LicencesConsumer.java | 6 +++++- .../mq/message/licences/LicencesMessage.java | 17 +++++++++++++++-- .../mq/producer/licences/LicencesProducer.java | 9 ++++----- .../service/licences/LicencesServiceImpl.java | 10 ++++------ .../module/system}/util/ModuleAuthenUtils.java | 2 +- 10 files changed, 45 insertions(+), 25 deletions(-) rename {win-framework/win-spring-boot-starter-web/src/main/java/com/win/framework/web/core/filter => win-module-system/win-module-system-biz/src/main/java/com/win/module/system/framework/web/config}/ModuleAuthenInterceptor.java (92%) rename {win-framework/win-spring-boot-starter-web/src/main/java/com/win/framework/web/core => win-module-system/win-module-system-biz/src/main/java/com/win/module/system}/util/ModuleAuthenUtils.java (97%) diff --git a/win-framework/win-spring-boot-starter-web/src/main/java/com/win/framework/web/config/WinWebAutoConfiguration.java b/win-framework/win-spring-boot-starter-web/src/main/java/com/win/framework/web/config/WinWebAutoConfiguration.java index 979d72d..4b1d27c 100644 --- a/win-framework/win-spring-boot-starter-web/src/main/java/com/win/framework/web/config/WinWebAutoConfiguration.java +++ b/win-framework/win-spring-boot-starter-web/src/main/java/com/win/framework/web/config/WinWebAutoConfiguration.java @@ -5,7 +5,6 @@ import com.win.framework.common.enums.WebFilterOrderEnum; import com.win.framework.web.constant.Constant; import com.win.framework.web.core.filter.CacheRequestBodyFilter; import com.win.framework.web.core.filter.DemoFilter; -import com.win.framework.web.core.filter.ModuleAuthenInterceptor; import com.win.framework.web.core.filter.MyI18nInterceptor; import com.win.framework.web.core.handler.GlobalExceptionHandler; import com.win.framework.web.core.handler.GlobalResponseBodyHandler; @@ -152,8 +151,6 @@ public class WinWebAutoConfiguration implements WebMvcConfigurer { @Override public void addInterceptors(InterceptorRegistry registry) { - registry.addInterceptor(new ModuleAuthenInterceptor()).addPathPatterns("/**");// 模块权限拦截器 张斌 2024-05-15 10:29 - // 注册拦截器 MyI18nInterceptor myHandlerInterceptor = new MyI18nInterceptor(); InterceptorRegistration loginRegistry = registry.addInterceptor(myHandlerInterceptor); diff --git a/win-framework/win-spring-boot-starter-web/src/main/java/com/win/framework/web/core/filter/ModuleAuthenInterceptor.java b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/framework/web/config/ModuleAuthenInterceptor.java similarity index 92% rename from win-framework/win-spring-boot-starter-web/src/main/java/com/win/framework/web/core/filter/ModuleAuthenInterceptor.java rename to win-module-system/win-module-system-biz/src/main/java/com/win/module/system/framework/web/config/ModuleAuthenInterceptor.java index 50261a4..bd680f8 100644 --- a/win-framework/win-spring-boot-starter-web/src/main/java/com/win/framework/web/core/filter/ModuleAuthenInterceptor.java +++ b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/framework/web/config/ModuleAuthenInterceptor.java @@ -1,10 +1,9 @@ -package com.win.framework.web.core.filter; +package com.win.module.system.framework.web.config; import cn.hutool.crypto.digest.MD5; import cn.hutool.json.JSONObject; -import com.win.framework.common.exception.enums.GlobalErrorCodeConstants; import com.win.framework.common.pojo.CommonResult; -import com.win.framework.web.core.util.ModuleAuthenUtils; +import com.win.module.system.util.ModuleAuthenUtils; import lombok.Cleanup; import lombok.extern.slf4j.Slf4j; import org.springframework.web.servlet.HandlerInterceptor; @@ -12,7 +11,6 @@ import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.io.OutputStream; import java.io.PrintWriter; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; diff --git a/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/framework/web/config/MyCommandLineRunner.java b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/framework/web/config/MyCommandLineRunner.java index 4fc2f49..4161e06 100644 --- a/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/framework/web/config/MyCommandLineRunner.java +++ b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/framework/web/config/MyCommandLineRunner.java @@ -1,6 +1,6 @@ package com.win.module.system.framework.web.config; -import com.win.framework.web.core.util.ModuleAuthenUtils; +import com.win.module.system.util.ModuleAuthenUtils; import org.springframework.boot.CommandLineRunner; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; diff --git a/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/framework/web/config/SystemWebConfiguration.java b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/framework/web/config/SystemWebConfiguration.java index 895f238..8e8e72b 100644 --- a/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/framework/web/config/SystemWebConfiguration.java +++ b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/framework/web/config/SystemWebConfiguration.java @@ -1,9 +1,13 @@ package com.win.module.system.framework.web.config; import com.win.framework.swagger.config.WinSwaggerAutoConfiguration; +import com.win.framework.web.core.filter.MyI18nInterceptor; import org.springdoc.core.GroupedOpenApi; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.InterceptorRegistration; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; /** * system 模块的 web 组件的 Configuration @@ -11,7 +15,8 @@ import org.springframework.context.annotation.Configuration; * @author 闻荫源码 */ @Configuration(proxyBeanMethods = false) -public class SystemWebConfiguration { + +public class SystemWebConfiguration implements WebMvcConfigurer { /** * system 模块的 API 分组 @@ -20,5 +25,11 @@ public class SystemWebConfiguration { public GroupedOpenApi systemGroupedOpenApi() { return WinSwaggerAutoConfiguration.buildGroupedOpenApi("system"); } + @Override + public void addInterceptors(InterceptorRegistry registry) { + + registry.addInterceptor(new ModuleAuthenInterceptor()).addPathPatterns("/**");// 模块权限拦截器 张斌 2024-05-15 10:29 + + } } diff --git a/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/job/ModuleLicencesJob.java b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/job/ModuleLicencesJob.java index 182cc40..766c3da 100644 --- a/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/job/ModuleLicencesJob.java +++ b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/job/ModuleLicencesJob.java @@ -1,6 +1,6 @@ package com.win.module.system.job; -import com.win.framework.web.core.util.ModuleAuthenUtils; +import com.win.module.system.util.ModuleAuthenUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.scheduling.annotation.EnableScheduling; diff --git a/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/mq/consumer/licences/LicencesConsumer.java b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/mq/consumer/licences/LicencesConsumer.java index d136221..d99b008 100644 --- a/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/mq/consumer/licences/LicencesConsumer.java +++ b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/mq/consumer/licences/LicencesConsumer.java @@ -5,5 +5,9 @@ import com.win.module.system.mq.message.licences.LicencesMessage; import org.springframework.stereotype.Component; @Component -public class LicencesConsumer { +public class LicencesConsumer extends AbstractStreamMessageListener{ + @Override + public void onMessage(LicencesMessage message) { + System.out.println(message); + } } diff --git a/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/mq/message/licences/LicencesMessage.java b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/mq/message/licences/LicencesMessage.java index 91f9ecd..d98e996 100644 --- a/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/mq/message/licences/LicencesMessage.java +++ b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/mq/message/licences/LicencesMessage.java @@ -1,8 +1,21 @@ package com.win.module.system.mq.message.licences; import com.win.framework.mq.core.stream.AbstractStreamMessage; +import lombok.Data; +import lombok.EqualsAndHashCode; -public class LicencesMessage{ +import java.util.Map; + +import static com.win.module.system.util.ModuleAuthenUtils.LICENCES_UPDATE_MESSAGE; + +@Data +@EqualsAndHashCode(callSuper = true) +public class LicencesMessage extends AbstractStreamMessage{ private String secretKey; - private String data; + private Map data; + + @Override + public String getStreamKey() { + return LICENCES_UPDATE_MESSAGE; + } } diff --git a/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/mq/producer/licences/LicencesProducer.java b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/mq/producer/licences/LicencesProducer.java index c79971f..083b5db 100644 --- a/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/mq/producer/licences/LicencesProducer.java +++ b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/mq/producer/licences/LicencesProducer.java @@ -1,11 +1,13 @@ package com.win.module.system.mq.producer.licences; import com.win.framework.mq.core.RedisMQTemplate; +import com.win.module.system.mq.message.licences.LicencesMessage; import com.win.module.system.mq.message.mail.MailSendMessage; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import javax.annotation.Resource; +import java.util.Map; /** * 模块权限 Producer @@ -19,11 +21,8 @@ public class LicencesProducer { @Resource private RedisMQTemplate redisMQTemplate; - public void sendMessage(Long sendLogId, String mail, Long accountId, - String nickname, String title, String content) { - MailSendMessage message = new MailSendMessage() - .setLogId(sendLogId).setMail(mail).setAccountId(accountId) - .setNickname(nickname).setTitle(title).setContent(content); + public void sendMessage(String secretKey, Map data) { + LicencesMessage message = new LicencesMessage().setSecretKey(secretKey).setData(data); redisMQTemplate.send(message); } diff --git a/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/licences/LicencesServiceImpl.java b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/licences/LicencesServiceImpl.java index 0ea62b3..578ed8f 100644 --- a/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/licences/LicencesServiceImpl.java +++ b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/service/licences/LicencesServiceImpl.java @@ -5,12 +5,11 @@ import cn.hutool.crypto.digest.MD5; import cn.hutool.extra.qrcode.QrCodeUtil; import cn.hutool.extra.qrcode.QrConfig; import cn.hutool.json.JSONObject; -import com.win.framework.web.core.util.ModuleAuthenUtils; import com.win.module.system.controller.licences.vo.GenerateLicenceReqVO; import com.win.module.system.mq.producer.licences.LicencesProducer; +import com.win.module.system.util.ModuleAuthenUtils; import lombok.Data; import org.apache.calcite.util.Util; -import org.springframework.data.redis.connection.stream.ObjectRecord; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -62,11 +61,10 @@ public class LicencesServiceImpl implements LicencesService { //todo 需迁移至mq订阅逻辑中 ModuleAuthenUtils.secretKey = licences.getSecretKey(); ModuleAuthenUtils.module = licences.getData(); - - redisTemplate.opsForValue().set(ModuleAuthenUtils.LICENCES_REDIS_KEY,new JSONObject(licences).toString()); + String licencesStr = new JSONObject(licences).toString(); + redisTemplate.opsForValue().set(ModuleAuthenUtils.LICENCES_REDIS_KEY,licencesStr); //todo 更新到redis并使用发布订阅通知其他pods拉取过滤路径 - redisTemplate.opsForStream().add(ObjectRecord.create("stream:queue:licences",1)); -// redisTemplate.convertAndSend(ModuleAuthenUtils.LICENCES_UPDATE_MESSAGE, ModuleAuthenUtils.module.toString()); + licencesProducer.sendMessage(licences.getSecretKey(),licences.getData()); } catch (Exception e) { throw exception(500, e); } diff --git a/win-framework/win-spring-boot-starter-web/src/main/java/com/win/framework/web/core/util/ModuleAuthenUtils.java b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/util/ModuleAuthenUtils.java similarity index 97% rename from win-framework/win-spring-boot-starter-web/src/main/java/com/win/framework/web/core/util/ModuleAuthenUtils.java rename to win-module-system/win-module-system-biz/src/main/java/com/win/module/system/util/ModuleAuthenUtils.java index f0d9095..ab003c1 100644 --- a/win-framework/win-spring-boot-starter-web/src/main/java/com/win/framework/web/core/util/ModuleAuthenUtils.java +++ b/win-module-system/win-module-system-biz/src/main/java/com/win/module/system/util/ModuleAuthenUtils.java @@ -1,4 +1,4 @@ -package com.win.framework.web.core.util; +package com.win.module.system.util; import cn.hutool.core.codec.Base64; import cn.hutool.json.JSONObject;