From b96c9075fedc01cb04ff7df3c38451777fd4416a Mon Sep 17 00:00:00 2001 From: matevip <7333791@qq.com> Date: Wed, 21 Oct 2020 16:52:54 +0800 Subject: [PATCH 01/19] =?UTF-8?q?spring=20boot=20admin=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E9=92=89=E9=92=89=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vip/mate/system/aspect/PreviewAspect.java | 2 +- mate-support/mate-admin/pom.xml | 5 + .../SecurityPermitAllConfiguration.java | 10 ++ .../mate/admin/message/DingDingNotifier.java | 100 ++++++++++++++++++ .../src/main/resources/application-local.yml | 4 + .../src/main/resources/application-prod.yml | 21 +++- .../src/main/resources/application-test.yml | 21 +++- 7 files changed, 158 insertions(+), 5 deletions(-) create mode 100644 mate-support/mate-admin/src/main/java/vip/mate/admin/message/DingDingNotifier.java diff --git a/mate-platform/mate-system/src/main/java/vip/mate/system/aspect/PreviewAspect.java b/mate-platform/mate-system/src/main/java/vip/mate/system/aspect/PreviewAspect.java index 41aa34d1..d30e947d 100644 --- a/mate-platform/mate-system/src/main/java/vip/mate/system/aspect/PreviewAspect.java +++ b/mate-platform/mate-system/src/main/java/vip/mate/system/aspect/PreviewAspect.java @@ -25,7 +25,7 @@ public class PreviewAspect { @Value("${mate.preview.enable}") - private final boolean isPreview = false; + private boolean isPreview = false; private final AntPathMatcher antPathMatcher = new AntPathMatcher(); diff --git a/mate-support/mate-admin/pom.xml b/mate-support/mate-admin/pom.xml index a3282b90..4eb0d0e5 100644 --- a/mate-support/mate-admin/pom.xml +++ b/mate-support/mate-admin/pom.xml @@ -50,6 +50,11 @@ + + com.taobao + taobao-sdk + 20200415 + diff --git a/mate-support/mate-admin/src/main/java/vip/mate/admin/config/SecurityPermitAllConfiguration.java b/mate-support/mate-admin/src/main/java/vip/mate/admin/config/SecurityPermitAllConfiguration.java index b8d0e1ce..9160d058 100644 --- a/mate-support/mate-admin/src/main/java/vip/mate/admin/config/SecurityPermitAllConfiguration.java +++ b/mate-support/mate-admin/src/main/java/vip/mate/admin/config/SecurityPermitAllConfiguration.java @@ -4,6 +4,7 @@ import com.alibaba.cloud.nacos.NacosServiceManager; import com.alibaba.cloud.nacos.discovery.NacosWatch; import de.codecentric.boot.admin.server.config.AdminServerProperties; +import de.codecentric.boot.admin.server.domain.entities.InstanceRepository; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -13,6 +14,7 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; +import vip.mate.admin.message.DingDingNotifier; /** * Spring Security 自定义拦截器 @@ -58,4 +60,12 @@ public NacosWatch nacosWatch(NacosServiceManager nacosServiceManager, ObjectProvider taskScheduler) { return new NacosWatch(nacosServiceManager, properties, taskScheduler); } + + @Bean + @ConditionalOnMissingBean + @ConditionalOnProperty(value = "spring.boot.admin.notify.dingding.enabled", havingValue = "true") + public DingDingNotifier dingDingNotifier(InstanceRepository repository) { + return new DingDingNotifier(repository); + } + } diff --git a/mate-support/mate-admin/src/main/java/vip/mate/admin/message/DingDingNotifier.java b/mate-support/mate-admin/src/main/java/vip/mate/admin/message/DingDingNotifier.java new file mode 100644 index 00000000..f34b3a57 --- /dev/null +++ b/mate-support/mate-admin/src/main/java/vip/mate/admin/message/DingDingNotifier.java @@ -0,0 +1,100 @@ +package vip.mate.admin.message; + +import com.dingtalk.api.DefaultDingTalkClient; +import com.dingtalk.api.DingTalkClient; +import com.dingtalk.api.request.OapiRobotSendRequest; +import com.taobao.api.ApiException; +import de.codecentric.boot.admin.server.domain.entities.Instance; +import de.codecentric.boot.admin.server.domain.entities.InstanceRepository; +import de.codecentric.boot.admin.server.domain.events.InstanceEvent; +import de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent; +import de.codecentric.boot.admin.server.notify.AbstractStatusChangeNotifier; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import reactor.core.publisher.Mono; + +/** + * 钉钉消息通知 + * + * @author pangu + */ +@Slf4j +public class DingDingNotifier extends AbstractStatusChangeNotifier { + + /** + * 消息模板 + */ + private static final String TEMPLATE = "服务名:%s(%s) n状态:%s(%s) n服务ip:%s"; + + @Value("${spring.boot.admin.notify.dingding.token}") + private String dingdingToken; + + public DingDingNotifier(InstanceRepository repository) { + super(repository); + } + + @Override + protected Mono doNotify(InstanceEvent event, Instance instance) { + return Mono.fromRunnable(() -> { + + if (event instanceof InstanceStatusChangedEvent) { + log.info("Instance {} ({}) is {}", instance.getRegistration().getName(), event.getInstance(), + ((InstanceStatusChangedEvent) event).getStatusInfo().getStatus()); + + String status = ((InstanceStatusChangedEvent) event).getStatusInfo().getStatus(); + String messageText = null; + switch (status) { + // 健康检查没通过 + case "DOWN": + log.info("发送 健康检查没通过 的通知!"); + messageText = String.format(TEMPLATE, instance.getRegistration().getName(), event.getInstance(), ((InstanceStatusChangedEvent) event).getStatusInfo().getStatus(), "健康检查没通过", instance.getRegistration().getServiceUrl()); + this.sendMessage(messageText); + break; + // 服务离线 + case "OFFLINE": + log.info("发送 服务离线 的通知!"); + messageText = String.format(TEMPLATE, instance.getRegistration().getName(), event.getInstance(), ((InstanceStatusChangedEvent) event).getStatusInfo().getStatus(), "服务离线", instance.getRegistration().getServiceUrl()); + this.sendMessage(messageText); + break; + //服务上线 + case "UP": + log.info("发送 服务上线 的通知!"); + messageText = String.format(TEMPLATE, instance.getRegistration().getName(), event.getInstance(), ((InstanceStatusChangedEvent) event).getStatusInfo().getStatus(), "服务上线", instance.getRegistration().getServiceUrl()); + this.sendMessage(messageText); + break; + // 服务未知异常 + case "UNKNOWN": + log.info("发送 服务未知异常 的通知!"); + messageText = String.format(TEMPLATE, instance.getRegistration().getName(), event.getInstance(), ((InstanceStatusChangedEvent) event).getStatusInfo().getStatus(), "服务未知异常", instance.getRegistration().getServiceUrl()); + this.sendMessage(messageText); + break; + default: + break; + } + } else { + log.info("Instance {} ({}) {}", instance.getRegistration().getName(), event.getInstance(), + event.getType()); + } + }); + } + + /** + * 钉钉发送消息 + * + * @param messageText 消息文本 + */ + private void sendMessage(String messageText) { + DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/robot/send?access_token=" + dingdingToken); + OapiRobotSendRequest request = new OapiRobotSendRequest(); + request.setMsgtype("text"); + OapiRobotSendRequest.Text text = new OapiRobotSendRequest.Text(); + text.setContent(messageText); + request.setText(text); + + try { + client.execute(request); + } catch (ApiException e) { + log.info("[ERROR] sendMessage", e); + } + } +} diff --git a/mate-support/mate-admin/src/main/resources/application-local.yml b/mate-support/mate-admin/src/main/resources/application-local.yml index b2ad391b..94cad5eb 100644 --- a/mate-support/mate-admin/src/main/resources/application-local.yml +++ b/mate-support/mate-admin/src/main/resources/application-local.yml @@ -12,6 +12,10 @@ spring: metadata: tags: environment: local + notify: + dingding: + enabled: false + token: AA***************BB security: user: name: admin diff --git a/mate-support/mate-admin/src/main/resources/application-prod.yml b/mate-support/mate-admin/src/main/resources/application-prod.yml index b9df0c40..4133c83f 100644 --- a/mate-support/mate-admin/src/main/resources/application-prod.yml +++ b/mate-support/mate-admin/src/main/resources/application-prod.yml @@ -7,7 +7,24 @@ spring: admin: ui: title: @artifactId@-server + client: + instance: + metadata: + tags: + environment: local + notify: + dingding: + token: AA***************BB security: user: - name: "admin" - password: "admin" + name: admin + password: matecloud + +management: + endpoints: + web: + exposure: + include: "*" + endpoint: + health: + show-details: always \ No newline at end of file diff --git a/mate-support/mate-admin/src/main/resources/application-test.yml b/mate-support/mate-admin/src/main/resources/application-test.yml index b9df0c40..4133c83f 100644 --- a/mate-support/mate-admin/src/main/resources/application-test.yml +++ b/mate-support/mate-admin/src/main/resources/application-test.yml @@ -7,7 +7,24 @@ spring: admin: ui: title: @artifactId@-server + client: + instance: + metadata: + tags: + environment: local + notify: + dingding: + token: AA***************BB security: user: - name: "admin" - password: "admin" + name: admin + password: matecloud + +management: + endpoints: + web: + exposure: + include: "*" + endpoint: + health: + show-details: always \ No newline at end of file From a328fd84832b803aa66e146f859b267bbb445c37 Mon Sep 17 00:00:00 2001 From: matevip <7333791@qq.com> Date: Thu, 22 Oct 2020 06:21:21 +0800 Subject: [PATCH 02/19] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E4=B8=BA1.5.8-SNAPSHOT=E5=BF=AB=E7=85=A7=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mate-core/mate-starter-auth/pom.xml | 2 +- mate-core/mate-starter-cloud/pom.xml | 2 +- mate-core/mate-starter-common/pom.xml | 2 +- .../main/java/vip/mate/core/common/constant/MateConstant.java | 2 +- mate-core/mate-starter-database/pom.xml | 2 +- mate-core/mate-starter-dependencies/pom.xml | 4 ++-- mate-core/mate-starter-dozer/pom.xml | 2 +- mate-core/mate-starter-dubbo/pom.xml | 2 +- mate-core/mate-starter-elasticsearch/pom.xml | 2 +- mate-core/mate-starter-feign/pom.xml | 2 +- mate-core/mate-starter-file/pom.xml | 2 +- mate-core/mate-starter-gray/pom.xml | 2 +- mate-core/mate-starter-j2cache/pom.xml | 2 +- mate-core/mate-starter-jetcache/pom.xml | 2 +- mate-core/mate-starter-job/pom.xml | 2 +- mate-core/mate-starter-kafka/pom.xml | 2 +- mate-core/mate-starter-log/pom.xml | 2 +- mate-core/mate-starter-mail/pom.xml | 2 +- mate-core/mate-starter-oss/pom.xml | 2 +- mate-core/mate-starter-prometheus/pom.xml | 2 +- mate-core/mate-starter-redis/pom.xml | 2 +- mate-core/mate-starter-retrofit/pom.xml | 2 +- mate-core/mate-starter-rocketmq/pom.xml | 2 +- mate-core/mate-starter-rule/pom.xml | 2 +- mate-core/mate-starter-seata/pom.xml | 2 +- mate-core/mate-starter-security/pom.xml | 2 +- mate-core/mate-starter-sentinel/pom.xml | 2 +- mate-core/mate-starter-sharding/pom.xml | 2 +- mate-core/mate-starter-sms/pom.xml | 2 +- mate-core/mate-starter-strategy/pom.xml | 2 +- mate-core/mate-starter-web/pom.xml | 2 +- mate-core/pom.xml | 4 ++-- mate-gateway/pom.xml | 2 +- mate-mq/mate-log-producer/pom.xml | 2 +- mate-mq/mate-message-consumer/pom.xml | 2 +- mate-mq/mate-message-producer/pom.xml | 2 +- mate-mq/pom.xml | 2 +- mate-platform/mate-component-api/pom.xml | 2 +- mate-platform/mate-component/pom.xml | 2 +- mate-platform/mate-system-api/pom.xml | 2 +- mate-platform/mate-system/pom.xml | 2 +- mate-platform/pom.xml | 2 +- mate-support/mate-admin/pom.xml | 2 +- mate-support/mate-code/pom.xml | 2 +- mate-support/mate-job-admin/pom.xml | 2 +- .../jquery-slimscroll/jquery.slimscroll.min.js | 2 +- mate-support/mate-job/pom.xml | 2 +- mate-support/pom.xml | 2 +- mate-uaa/pom.xml | 2 +- pom.xml | 4 ++-- 50 files changed, 53 insertions(+), 53 deletions(-) diff --git a/mate-core/mate-starter-auth/pom.xml b/mate-core/mate-starter-auth/pom.xml index 2f7acedb..97c3ae68 100644 --- a/mate-core/mate-starter-auth/pom.xml +++ b/mate-core/mate-starter-auth/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-core/mate-starter-cloud/pom.xml b/mate-core/mate-starter-cloud/pom.xml index 518fd5f3..fa57b7e7 100644 --- a/mate-core/mate-starter-cloud/pom.xml +++ b/mate-core/mate-starter-cloud/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-core/mate-starter-common/pom.xml b/mate-core/mate-starter-common/pom.xml index 98685d79..95bef716 100644 --- a/mate-core/mate-starter-common/pom.xml +++ b/mate-core/mate-starter-common/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-core/mate-starter-common/src/main/java/vip/mate/core/common/constant/MateConstant.java b/mate-core/mate-starter-common/src/main/java/vip/mate/core/common/constant/MateConstant.java index ae0495fc..503c2af2 100644 --- a/mate-core/mate-starter-common/src/main/java/vip/mate/core/common/constant/MateConstant.java +++ b/mate-core/mate-starter-common/src/main/java/vip/mate/core/common/constant/MateConstant.java @@ -8,7 +8,7 @@ public class MateConstant { /** * 应用版本号 */ - public static final String MATE_APP_VERSION = "1.3.8"; + public static final String MATE_APP_VERSION = "1.5.8-SNAPSHOT"; /** * Spring 应用名 prop key diff --git a/mate-core/mate-starter-database/pom.xml b/mate-core/mate-starter-database/pom.xml index 14800d3f..dba7a906 100644 --- a/mate-core/mate-starter-database/pom.xml +++ b/mate-core/mate-starter-database/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-core/mate-starter-dependencies/pom.xml b/mate-core/mate-starter-dependencies/pom.xml index 2f619f3c..6357ab44 100644 --- a/mate-core/mate-starter-dependencies/pom.xml +++ b/mate-core/mate-starter-dependencies/pom.xml @@ -12,12 +12,12 @@ vip.mate mate-starter-dependencies - 1.3.8 + 1.5.8-SNAPSHOT pom MateCloud统一版本依赖 - 1.3.8 + 1.5.8-SNAPSHOT UTF-8 2.3.4.RELEASE diff --git a/mate-core/mate-starter-dozer/pom.xml b/mate-core/mate-starter-dozer/pom.xml index 6aa22e17..932311ed 100644 --- a/mate-core/mate-starter-dozer/pom.xml +++ b/mate-core/mate-starter-dozer/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-core/mate-starter-dubbo/pom.xml b/mate-core/mate-starter-dubbo/pom.xml index 7819b503..40cf0d1c 100644 --- a/mate-core/mate-starter-dubbo/pom.xml +++ b/mate-core/mate-starter-dubbo/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-core/mate-starter-elasticsearch/pom.xml b/mate-core/mate-starter-elasticsearch/pom.xml index 0f104f56..6c3fa9f3 100644 --- a/mate-core/mate-starter-elasticsearch/pom.xml +++ b/mate-core/mate-starter-elasticsearch/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-core/mate-starter-feign/pom.xml b/mate-core/mate-starter-feign/pom.xml index 45d98cb1..00a71bca 100644 --- a/mate-core/mate-starter-feign/pom.xml +++ b/mate-core/mate-starter-feign/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-core/mate-starter-file/pom.xml b/mate-core/mate-starter-file/pom.xml index 15613051..10bd3e59 100644 --- a/mate-core/mate-starter-file/pom.xml +++ b/mate-core/mate-starter-file/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-core/mate-starter-gray/pom.xml b/mate-core/mate-starter-gray/pom.xml index 18310b64..a471437b 100644 --- a/mate-core/mate-starter-gray/pom.xml +++ b/mate-core/mate-starter-gray/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-core/mate-starter-j2cache/pom.xml b/mate-core/mate-starter-j2cache/pom.xml index 923af25c..50a9c446 100644 --- a/mate-core/mate-starter-j2cache/pom.xml +++ b/mate-core/mate-starter-j2cache/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-core/mate-starter-jetcache/pom.xml b/mate-core/mate-starter-jetcache/pom.xml index f80b1159..b627179c 100644 --- a/mate-core/mate-starter-jetcache/pom.xml +++ b/mate-core/mate-starter-jetcache/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-core/mate-starter-job/pom.xml b/mate-core/mate-starter-job/pom.xml index 3ea4fc59..e654c255 100644 --- a/mate-core/mate-starter-job/pom.xml +++ b/mate-core/mate-starter-job/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 jar diff --git a/mate-core/mate-starter-kafka/pom.xml b/mate-core/mate-starter-kafka/pom.xml index 6a6e3601..b2dcab99 100644 --- a/mate-core/mate-starter-kafka/pom.xml +++ b/mate-core/mate-starter-kafka/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-core/mate-starter-log/pom.xml b/mate-core/mate-starter-log/pom.xml index fe3c6c64..593203ab 100644 --- a/mate-core/mate-starter-log/pom.xml +++ b/mate-core/mate-starter-log/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-core/mate-starter-mail/pom.xml b/mate-core/mate-starter-mail/pom.xml index 9dd5e82a..398f586e 100644 --- a/mate-core/mate-starter-mail/pom.xml +++ b/mate-core/mate-starter-mail/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-core/mate-starter-oss/pom.xml b/mate-core/mate-starter-oss/pom.xml index 4d968d0b..7572cc7b 100644 --- a/mate-core/mate-starter-oss/pom.xml +++ b/mate-core/mate-starter-oss/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-core/mate-starter-prometheus/pom.xml b/mate-core/mate-starter-prometheus/pom.xml index f93df5b2..fcbb5bab 100644 --- a/mate-core/mate-starter-prometheus/pom.xml +++ b/mate-core/mate-starter-prometheus/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-core/mate-starter-redis/pom.xml b/mate-core/mate-starter-redis/pom.xml index 6b21a162..66ae37e7 100644 --- a/mate-core/mate-starter-redis/pom.xml +++ b/mate-core/mate-starter-redis/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-core/mate-starter-retrofit/pom.xml b/mate-core/mate-starter-retrofit/pom.xml index caa28bc4..1e0ee2eb 100644 --- a/mate-core/mate-starter-retrofit/pom.xml +++ b/mate-core/mate-starter-retrofit/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-core/mate-starter-rocketmq/pom.xml b/mate-core/mate-starter-rocketmq/pom.xml index ffc72d07..e12c14bf 100644 --- a/mate-core/mate-starter-rocketmq/pom.xml +++ b/mate-core/mate-starter-rocketmq/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-core/mate-starter-rule/pom.xml b/mate-core/mate-starter-rule/pom.xml index 38830066..b1bf860f 100644 --- a/mate-core/mate-starter-rule/pom.xml +++ b/mate-core/mate-starter-rule/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-core/mate-starter-seata/pom.xml b/mate-core/mate-starter-seata/pom.xml index 3af87c8d..5d19a245 100644 --- a/mate-core/mate-starter-seata/pom.xml +++ b/mate-core/mate-starter-seata/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-core/mate-starter-security/pom.xml b/mate-core/mate-starter-security/pom.xml index aeaaf20b..6e2d66e6 100644 --- a/mate-core/mate-starter-security/pom.xml +++ b/mate-core/mate-starter-security/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-core/mate-starter-sentinel/pom.xml b/mate-core/mate-starter-sentinel/pom.xml index bccb944d..ac0062d6 100644 --- a/mate-core/mate-starter-sentinel/pom.xml +++ b/mate-core/mate-starter-sentinel/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-core/mate-starter-sharding/pom.xml b/mate-core/mate-starter-sharding/pom.xml index 0c08316a..2580c7f4 100644 --- a/mate-core/mate-starter-sharding/pom.xml +++ b/mate-core/mate-starter-sharding/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-core/mate-starter-sms/pom.xml b/mate-core/mate-starter-sms/pom.xml index c9ecf9c7..2a7032fd 100644 --- a/mate-core/mate-starter-sms/pom.xml +++ b/mate-core/mate-starter-sms/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-core/mate-starter-strategy/pom.xml b/mate-core/mate-starter-strategy/pom.xml index 0984bb2f..090deba9 100644 --- a/mate-core/mate-starter-strategy/pom.xml +++ b/mate-core/mate-starter-strategy/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-core/mate-starter-web/pom.xml b/mate-core/mate-starter-web/pom.xml index 01efa52f..53c6ac39 100644 --- a/mate-core/mate-starter-web/pom.xml +++ b/mate-core/mate-starter-web/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-core/pom.xml b/mate-core/pom.xml index b9357dc7..e1082f99 100644 --- a/mate-core/pom.xml +++ b/mate-core/pom.xml @@ -6,7 +6,7 @@ mate-core vip.mate - 1.3.8 + 1.5.8-SNAPSHOT pom @@ -43,7 +43,7 @@ - 1.3.8 + 1.5.8-SNAPSHOT 2.9.2 1.5.21 1.9.4 diff --git a/mate-gateway/pom.xml b/mate-gateway/pom.xml index 16587e42..a91973ee 100644 --- a/mate-gateway/pom.xml +++ b/mate-gateway/pom.xml @@ -5,7 +5,7 @@ matecloud vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-mq/mate-log-producer/pom.xml b/mate-mq/mate-log-producer/pom.xml index 39ade2f6..93303c67 100644 --- a/mate-mq/mate-log-producer/pom.xml +++ b/mate-mq/mate-log-producer/pom.xml @@ -5,7 +5,7 @@ mate-mq vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-mq/mate-message-consumer/pom.xml b/mate-mq/mate-message-consumer/pom.xml index aabaa083..26855d1f 100644 --- a/mate-mq/mate-message-consumer/pom.xml +++ b/mate-mq/mate-message-consumer/pom.xml @@ -5,7 +5,7 @@ mate-mq vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-mq/mate-message-producer/pom.xml b/mate-mq/mate-message-producer/pom.xml index bc9071b8..adc3d350 100644 --- a/mate-mq/mate-message-producer/pom.xml +++ b/mate-mq/mate-message-producer/pom.xml @@ -5,7 +5,7 @@ mate-mq vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-mq/pom.xml b/mate-mq/pom.xml index 55436b34..fae19371 100644 --- a/mate-mq/pom.xml +++ b/mate-mq/pom.xml @@ -5,7 +5,7 @@ matecloud vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-platform/mate-component-api/pom.xml b/mate-platform/mate-component-api/pom.xml index 71595199..ab1cf047 100644 --- a/mate-platform/mate-component-api/pom.xml +++ b/mate-platform/mate-component-api/pom.xml @@ -5,7 +5,7 @@ mate-platform vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-platform/mate-component/pom.xml b/mate-platform/mate-component/pom.xml index 471dfc3e..4e1273f6 100644 --- a/mate-platform/mate-component/pom.xml +++ b/mate-platform/mate-component/pom.xml @@ -5,7 +5,7 @@ mate-platform vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-platform/mate-system-api/pom.xml b/mate-platform/mate-system-api/pom.xml index ba626a1b..79271e76 100644 --- a/mate-platform/mate-system-api/pom.xml +++ b/mate-platform/mate-system-api/pom.xml @@ -5,7 +5,7 @@ mate-platform vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-platform/mate-system/pom.xml b/mate-platform/mate-system/pom.xml index 7a03cd63..0c624ee7 100644 --- a/mate-platform/mate-system/pom.xml +++ b/mate-platform/mate-system/pom.xml @@ -5,7 +5,7 @@ mate-platform vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-platform/pom.xml b/mate-platform/pom.xml index 850916cb..e247527b 100644 --- a/mate-platform/pom.xml +++ b/mate-platform/pom.xml @@ -5,7 +5,7 @@ matecloud vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-support/mate-admin/pom.xml b/mate-support/mate-admin/pom.xml index 4eb0d0e5..c0562fa8 100644 --- a/mate-support/mate-admin/pom.xml +++ b/mate-support/mate-admin/pom.xml @@ -5,7 +5,7 @@ mate-support vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-support/mate-code/pom.xml b/mate-support/mate-code/pom.xml index e4664710..380aac6e 100644 --- a/mate-support/mate-code/pom.xml +++ b/mate-support/mate-code/pom.xml @@ -5,7 +5,7 @@ mate-support vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-support/mate-job-admin/pom.xml b/mate-support/mate-job-admin/pom.xml index 583ea2ab..456b6937 100644 --- a/mate-support/mate-job-admin/pom.xml +++ b/mate-support/mate-job-admin/pom.xml @@ -5,7 +5,7 @@ mate-support vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-support/mate-job-admin/src/main/resources/static/adminlte/bower_components/jquery-slimscroll/jquery.slimscroll.min.js b/mate-support/mate-job-admin/src/main/resources/static/adminlte/bower_components/jquery-slimscroll/jquery.slimscroll.min.js index 7531ab35..29f59290 100644 --- a/mate-support/mate-job-admin/src/main/resources/static/adminlte/bower_components/jquery-slimscroll/jquery.slimscroll.min.js +++ b/mate-support/mate-job-admin/src/main/resources/static/adminlte/bower_components/jquery-slimscroll/jquery.slimscroll.min.js @@ -2,7 +2,7 @@ * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses. * - * Version: 1.3.8 + * Version: 1.5.8-SNAPSHOT * */ (function(e){e.fn.extend({slimScroll:function(f){var a=e.extend({width:"auto",height:"250px",size:"7px",color:"#000",position:"right",distance:"1px",start:"top",opacity:.4,alwaysVisible:!1,disableFadeOut:!1,railVisible:!1,railColor:"#333",railOpacity:.2,railDraggable:!0,railClass:"slimScrollRail",barClass:"slimScrollBar",wrapperClass:"slimScrollDiv",allowPageScroll:!1,wheelStep:20,touchScrollStep:200,borderRadius:"7px",railBorderRadius:"7px"},f);this.each(function(){function v(d){if(r){d=d||window.event; diff --git a/mate-support/mate-job/pom.xml b/mate-support/mate-job/pom.xml index b42957ca..9fb1c8cc 100644 --- a/mate-support/mate-job/pom.xml +++ b/mate-support/mate-job/pom.xml @@ -5,7 +5,7 @@ mate-support vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-support/pom.xml b/mate-support/pom.xml index 540bde50..362d52bf 100644 --- a/mate-support/pom.xml +++ b/mate-support/pom.xml @@ -5,7 +5,7 @@ matecloud vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/mate-uaa/pom.xml b/mate-uaa/pom.xml index 92d9e11d..20aaaae9 100644 --- a/mate-uaa/pom.xml +++ b/mate-uaa/pom.xml @@ -5,7 +5,7 @@ matecloud vip.mate - 1.3.8 + 1.5.8-SNAPSHOT 4.0.0 diff --git a/pom.xml b/pom.xml index 77d67aed..fc453415 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ vip.mate matecloud pom - 1.3.8 + 1.5.8-SNAPSHOT matecloud Mate Cloud - 基于Spring Cloud Alibaba实现的微服务架构 @@ -23,7 +23,7 @@ - 1.3.8 + 1.5.8-SNAPSHOT 1.8 3.8.1 UTF-8 From b236e947a65e5c49c31d7fc0f23fcb3e92796314 Mon Sep 17 00:00:00 2001 From: matevip <7333791@qq.com> Date: Thu, 22 Oct 2020 06:56:39 +0800 Subject: [PATCH 03/19] =?UTF-8?q?=E5=B0=81=E8=A3=85mongodb=E5=9F=BA?= =?UTF-8?q?=E7=A1=80=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/xxl/job/core/util/ShardingUtil.java | 2 +- mate-core/mate-starter-mongodb/pom.xml | 27 ++ .../core/mongodb/annotation/QueryField.java | 22 + .../core/mongodb/annotation/QueryType.java | 84 ++++ .../core/mongodb/service/BaseMongoDAO.java | 125 ++++++ .../core/mongodb/service/MongoDaoSupport.java | 252 +++++++++++ .../core/mongodb/util/ReflectionUtil.java | 246 +++++++++++ .../mate/core/mongodb/util/StringUtil.java | 391 ++++++++++++++++++ .../java/vip/mate/core/mongodb/vo/Page.java | 100 +++++ mate-core/pom.xml | 1 + .../vip/mate/system/mapper/SysRoleMapper.xml | 2 +- .../vip/mate/system/mapper/SysRouteMapper.xml | 2 +- .../mate/code/mapper/SysDataSourceMapper.xml | 2 +- 13 files changed, 1252 insertions(+), 4 deletions(-) create mode 100644 mate-core/mate-starter-mongodb/pom.xml create mode 100644 mate-core/mate-starter-mongodb/src/main/java/vip/mate/core/mongodb/annotation/QueryField.java create mode 100644 mate-core/mate-starter-mongodb/src/main/java/vip/mate/core/mongodb/annotation/QueryType.java create mode 100644 mate-core/mate-starter-mongodb/src/main/java/vip/mate/core/mongodb/service/BaseMongoDAO.java create mode 100644 mate-core/mate-starter-mongodb/src/main/java/vip/mate/core/mongodb/service/MongoDaoSupport.java create mode 100644 mate-core/mate-starter-mongodb/src/main/java/vip/mate/core/mongodb/util/ReflectionUtil.java create mode 100644 mate-core/mate-starter-mongodb/src/main/java/vip/mate/core/mongodb/util/StringUtil.java create mode 100644 mate-core/mate-starter-mongodb/src/main/java/vip/mate/core/mongodb/vo/Page.java diff --git a/mate-core/mate-starter-job/src/main/java/com/xxl/job/core/util/ShardingUtil.java b/mate-core/mate-starter-job/src/main/java/com/xxl/job/core/util/ShardingUtil.java index 27044832..7fa35e5b 100644 --- a/mate-core/mate-starter-job/src/main/java/com/xxl/job/core/util/ShardingUtil.java +++ b/mate-core/mate-starter-job/src/main/java/com/xxl/job/core/util/ShardingUtil.java @@ -1,7 +1,7 @@ package com.xxl.job.core.util;//package com.xxl.job.core.util; // ///** -// * sharding vo +// * sharding vip.mate.core.mongodb.vo // * @author xuxueli 2017-07-25 21:26:38 // */ //public class ShardingUtil { diff --git a/mate-core/mate-starter-mongodb/pom.xml b/mate-core/mate-starter-mongodb/pom.xml new file mode 100644 index 00000000..aebb8b2c --- /dev/null +++ b/mate-core/mate-starter-mongodb/pom.xml @@ -0,0 +1,27 @@ + + + + mate-core + vip.mate + 1.5.8-SNAPSHOT + + 4.0.0 + + mate-starter-mongodb + + + + org.springframework.boot + spring-boot-starter-data-mongodb + + + org.projectlombok + lombok + provided + + + + + \ No newline at end of file diff --git a/mate-core/mate-starter-mongodb/src/main/java/vip/mate/core/mongodb/annotation/QueryField.java b/mate-core/mate-starter-mongodb/src/main/java/vip/mate/core/mongodb/annotation/QueryField.java new file mode 100644 index 00000000..0a422a37 --- /dev/null +++ b/mate-core/mate-starter-mongodb/src/main/java/vip/mate/core/mongodb/annotation/QueryField.java @@ -0,0 +1,22 @@ +package vip.mate.core.mongodb.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * type表示查询类似,默认为equals + * attribute表示要查询的属性,默认为空串,如果为空则为字段名称 + * @link https://gitee.com/qwer.com/open-mongodb + * + * @author pangu + */ +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +public @interface QueryField { + + QueryType type() default QueryType.EQUALS; + + String attribute() default ""; +} diff --git a/mate-core/mate-starter-mongodb/src/main/java/vip/mate/core/mongodb/annotation/QueryType.java b/mate-core/mate-starter-mongodb/src/main/java/vip/mate/core/mongodb/annotation/QueryType.java new file mode 100644 index 00000000..c0e2d4e1 --- /dev/null +++ b/mate-core/mate-starter-mongodb/src/main/java/vip/mate/core/mongodb/annotation/QueryType.java @@ -0,0 +1,84 @@ +package vip.mate.core.mongodb.annotation; + +import org.springframework.data.mongodb.core.query.Criteria; + +import java.lang.reflect.Field; + +import org.springframework.util.StringUtils; + +import java.util.List; + +/** + * 查询媒介 + * 1. equals:相等 + * 2. like:mongodb的like查询 + * 3. in:用于列表的in类型查询 + * + * @author pangu + * @date 2020-10-20 + */ +public enum QueryType { + /** + * 相等 + */ + EQUALS { + @Override + public Criteria buildCriteria(QueryField queryFieldAnnotation, Field field, Object value) { + if (check(queryFieldAnnotation, field, value)) { + String queryField = getQueryFieldName(queryFieldAnnotation, field); + return Criteria.where(queryField).is(value.toString()); + } + return new Criteria(); + } + }, + /** + * mongodb的like查询 + */ + LIKE { + @Override + public Criteria buildCriteria(QueryField queryFieldAnnotation, Field field, Object value) { + if (check(queryFieldAnnotation, field, value)) { + String queryField = getQueryFieldName(queryFieldAnnotation, field); + return Criteria.where(queryField).regex(value.toString()); + } + return new Criteria(); + } + }, + /** + * 用于列表的in类型查询 + */ + IN { + @Override + public Criteria buildCriteria(QueryField queryFieldAnnotation, Field field, Object value) { + if (check(queryFieldAnnotation, field, value)) { + if (value instanceof List) { + String queryField = getQueryFieldName(queryFieldAnnotation, field); + // 此处必须转型为List,否则会在in外面多一层[] + return Criteria.where(queryField).in((List) value); + } + } + return new Criteria(); + } + }; + + private static boolean check(QueryField queryField, Field field, Object value) { + return !(queryField == null || field == null || value == null); + } + + public abstract Criteria buildCriteria(QueryField queryFieldAnnotation, Field field, Object value); + + + /** + * 如果实体bean的字段上QueryField注解没有设置attribute属性时,默认为该字段的名称 + * + * @param field + * @return + */ + private static String getQueryFieldName(QueryField queryField, Field field) { + String queryFieldValue = queryField.attribute(); + if (!StringUtils.hasText(queryFieldValue)) { + queryFieldValue = field.getName(); + } + return queryFieldValue; + } +} diff --git a/mate-core/mate-starter-mongodb/src/main/java/vip/mate/core/mongodb/service/BaseMongoDAO.java b/mate-core/mate-starter-mongodb/src/main/java/vip/mate/core/mongodb/service/BaseMongoDAO.java new file mode 100644 index 00000000..8b797454 --- /dev/null +++ b/mate-core/mate-starter-mongodb/src/main/java/vip/mate/core/mongodb/service/BaseMongoDAO.java @@ -0,0 +1,125 @@ +package vip.mate.core.mongodb.service; + +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.query.Query; +import org.springframework.data.mongodb.core.query.Update; +import vip.mate.core.mongodb.vo.Page; + +import java.util.List; + +/** + * MongoDB通用Dao + * + * @param + * @author pangu + * @date 2020-10-20 + */ +public interface BaseMongoDAO { + + /** + * 保存一个对象到mongodb + * + * @param entity + * @return + */ + public T save(T entity); + + /** + * 根据id删除对象 + * + * @param t + */ + public void deleteById(T t); + + /** + * 根据对象的属性删除 + * + * @param t + */ + public void deleteByCondition(T t); + + + /** + * 根据id进行更新 + * + * @param id + * @param t + */ + public void updateById(String id, T t); + + + /** + * 根据对象的属性查询 + * + * @param t + * @return + */ + public List findByCondition(T t); + + + /** + * 通过条件查询实体(集合) + * + * @param query + */ + public List find(Query query); + + /** + * 通过一定的条件查询一个实体 + * + * @param query + * @return + */ + public T findOne(Query query); + + /** + * 通过条件查询更新数据 + * + * @param query + * @param update + * @return + */ + public void update(Query query, Update update); + + /** + * 通过ID获取记录 + * + * @param id + * @return + */ + public T findById(String id); + + /** + * 通过ID获取记录,并且指定了集合名(表的意思) + * + * @param id + * @param collectionName 集合名 + * @return + */ + public T findById(String id, String collectionName); + + /** + * 通过条件查询,查询分页结果 + * + * @param page + * @param query + * @return + */ + public Page findPage(Page page, Query query); + + /** + * 求数据总和 + * + * @param query + * @return + */ + public long count(Query query); + + + /** + * 获取MongoDB模板操作 + * + * @return + */ + public MongoTemplate getMongoTemplate(); +} diff --git a/mate-core/mate-starter-mongodb/src/main/java/vip/mate/core/mongodb/service/MongoDaoSupport.java b/mate-core/mate-starter-mongodb/src/main/java/vip/mate/core/mongodb/service/MongoDaoSupport.java new file mode 100644 index 00000000..1d1a434b --- /dev/null +++ b/mate-core/mate-starter-mongodb/src/main/java/vip/mate/core/mongodb/service/MongoDaoSupport.java @@ -0,0 +1,252 @@ +package vip.mate.core.mongodb.service; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.query.Criteria; +import org.springframework.data.mongodb.core.query.Query; +import org.springframework.data.mongodb.core.query.Update; +import vip.mate.core.mongodb.annotation.QueryField; +import vip.mate.core.mongodb.util.ReflectionUtil; +import vip.mate.core.mongodb.vo.Page; + +import java.lang.reflect.Field; +import java.util.List; + +/** + * MongoDB通用Dao抽象实现 + * + * @param + * @author pangu + * @date 2020-10-20 + */ +public abstract class MongoDaoSupport implements BaseMongoDAO { + + @Autowired + @Qualifier("mongoTemplate") + protected MongoTemplate mongoTemplate; + + /** + * 保存一个对象到mongodb + * + * @param bean + * @return + */ + @Override + public T save(T bean) { + mongoTemplate.save(bean); + return bean; + } + + /** + * 根据id删除对象 + * + * @param t + */ + @Override + public void deleteById(T t) { + mongoTemplate.remove(t); + } + + + /** + * 根据对象的属性删除 + * + * @param t + */ + @Override + public void deleteByCondition(T t) { + Query query = buildBaseQuery(t); + mongoTemplate.remove(query, getEntityClass()); + } + + /** + * 根据id进行更新 + * + * @param id + * @param t + */ + @Override + public void updateById(String id, T t) { + Query query = new Query(); + query.addCriteria(Criteria.where("id").is(id)); + Update update = buildBaseUpdate(t); + update(query, update); + } + + /** + * 根据对象的属性查询 + * + * @param t + * @return + */ + @Override + public List findByCondition(T t) { + Query query = buildBaseQuery(t); + return mongoTemplate.find(query, getEntityClass()); + } + + /** + * 通过条件查询实体(集合) + * + * @param query + * @return + */ + @Override + public List find(Query query) { + return mongoTemplate.find(query, this.getEntityClass()); + } + + /** + * 通过一定的条件查询一个实体 + * + * @param query + * @return + */ + @Override + public T findOne(Query query) { + return mongoTemplate.findOne(query, this.getEntityClass()); + } + + /** + * 通过条件查询更新数据 + * + * @param query + * @param update + */ + @Override + public void update(Query query, Update update) { + mongoTemplate.updateMulti(query, update, this.getEntityClass()); + } + + /** + * 通过ID获取记录 + * + * @param id + * @return + */ + @Override + public T findById(String id) { + return mongoTemplate.findById(id, this.getEntityClass()); + } + + /** + * 通过ID获取记录,并且指定了集合名(表的意思) + * + * @param id + * @param collectionName + * @return + */ + @Override + public T findById(String id, String collectionName) { + return mongoTemplate.findById(id, this.getEntityClass(), collectionName); + } + + /** + * 通过条件查询,查询分页结果 + * + * @param page + * @param query + * @return + */ + @Override + public Page findPage(Page page, Query query) { + //如果没有条件 则所有全部 + query = query == null ? new Query(Criteria.where("_id").exists(true)) : query; + long count = this.count(query); + // 总数 + page.setTotalCount((int) count); + int currentPage = page.getCurrentPage(); + int pageSize = page.getPageSize(); + query.skip((currentPage - 1) * pageSize).limit(pageSize); + List rows = this.find(query); + page.build(rows); + return page; + } + + /** + * 求数据总和 + * + * @param query + * @return + */ + @Override + public long count(Query query) { + return mongoTemplate.count(query, this.getEntityClass()); + } + + /** + * 根据vo构建查询条件Query + * + * @param t + * @return + */ + private Query buildBaseQuery(T t) { + Query query = new Query(); + + Field[] fields = t.getClass().getDeclaredFields(); + for (Field field : fields) { + field.setAccessible(true); + try { + Object value = field.get(t); + if (value != null) { + QueryField queryField = field.getAnnotation(QueryField.class); + if (queryField != null) { + query.addCriteria(queryField.type().buildCriteria(queryField, field, value)); + } + } + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + return query; + } + + /** + * 根据vo构建更新条件Query + * + * @param t + * @return + */ + private Update buildBaseUpdate(T t) { + Update update = new Update(); + + Field[] fields = t.getClass().getDeclaredFields(); + for (Field field : fields) { + field.setAccessible(true); + try { + Object value = field.get(t); + if (value != null) { + update.set(field.getName(), value); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + return update; + } + + /** + * 获取需要操作的实体类class + * + * @return + */ + @SuppressWarnings("unchecked") + protected Class getEntityClass() { + // TODO 这种方式也可以 return ((Class) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]); + return ReflectionUtil.getSuperClassGenricType(getClass()); + } + + /** + * 获取MongoDB模板操作 + * + * @return + */ + @Override + public MongoTemplate getMongoTemplate() { + return mongoTemplate; + } + +} diff --git a/mate-core/mate-starter-mongodb/src/main/java/vip/mate/core/mongodb/util/ReflectionUtil.java b/mate-core/mate-starter-mongodb/src/main/java/vip/mate/core/mongodb/util/ReflectionUtil.java new file mode 100644 index 00000000..98f8194d --- /dev/null +++ b/mate-core/mate-starter-mongodb/src/main/java/vip/mate/core/mongodb/util/ReflectionUtil.java @@ -0,0 +1,246 @@ +package vip.mate.core.mongodb.util; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.data.mongodb.core.query.Update; +import org.springframework.util.Assert; +import org.springframework.util.StringUtils; + +import java.lang.reflect.*; + +/** + * 反射工具类 + *

+ * 提供访问私有变量,获取泛型类型Class, 提取集合中元素的属性, 转换字符串到对象等Util函数. + *

+ * + * @author pangu + * @date 2020-10-20 + */ +@Slf4j +public class ReflectionUtil { + + /** + * 调用Getter方法. + */ + public static Object invokeGetterMethod(Object obj, String propertyName) { + String getterMethodName = "get" + StringUtils.capitalize(propertyName); + return invokeMethod(obj, getterMethodName, new Class[]{}, new Object[]{}); + } + + /** + * 调用Setter方法.使用value的Class来查找Setter方法. + */ + public static void invokeSetterMethod(Object obj, String propertyName, Object value) { + invokeSetterMethod(obj, propertyName, value, null); + } + + /** + * 调用Setter方法. + * + * @param propertyType 用于查找Setter方法,为空时使用value的Class替代. + */ + public static void invokeSetterMethod(Object obj, String propertyName, Object value, Class propertyType) { + Class type = propertyType != null ? propertyType : value.getClass(); + String setterMethodName = "set" + StringUtils.capitalize(propertyName); + invokeMethod(obj, setterMethodName, new Class[]{type}, new Object[]{value}); + } + + /** + * 直接读取对象属性值, 无视private/protected修饰符, 不经过getter函数. + */ + public static Object getFieldValue(final Object obj, final String fieldName) { + Field field = getAccessibleField(obj, fieldName); + + if (field == null) { + throw new IllegalArgumentException("Could not find field [" + fieldName + "] on target [" + obj + "]"); + } + + Object result = null; + try { + result = field.get(obj); + } catch (IllegalAccessException e) { + log.error("不可能抛出的异常{}", e.getMessage()); + } + return result; + } + + /** + * 直接设置对象属性值, 无视private/protected修饰符, 不经过setter函数. + */ + public static void setFieldValue(final Object obj, final String fieldName, final Object value) { + Field field = getAccessibleField(obj, fieldName); + + if (field == null) { + throw new IllegalArgumentException("Could not find field [" + fieldName + "] on target [" + obj + "]"); + } + + try { + field.set(obj, value); + } catch (IllegalAccessException e) { + log.error("不可能抛出的异常:{}", e.getMessage()); + } + } + + /** + * 循环向上转型, 获取对象的DeclaredField, 并强制设置为可访问. + *

+ * 如向上转型到Object仍无法找到, 返回null. + */ + public static Field getAccessibleField(final Object obj, final String fieldName) { + Assert.notNull(obj, "object不能为空"); + Assert.hasText(fieldName, "fieldName"); + for (Class superClass = obj.getClass(); superClass != Object.class; superClass = superClass.getSuperclass()) { + try { + Field field = superClass.getDeclaredField(fieldName); + field.setAccessible(true); + return field; + } catch (NoSuchFieldException e) {//NOSONAR + // Field不在当前类定义,继续向上转型 + } + } + return null; + } + + /** + * 直接调用对象方法, 无视private/protected修饰符. + * 用于一次性调用的情况. + */ + public static Object invokeMethod(final Object obj, final String methodName, final Class[] parameterTypes, + final Object[] args) { + Method method = getAccessibleMethod(obj, methodName, parameterTypes); + if (method == null) { + throw new IllegalArgumentException("Could not find method [" + methodName + "] on target [" + obj + "]"); + } + + try { + return method.invoke(obj, args); + } catch (Exception e) { + throw convertReflectionExceptionToUnchecked(e); + } + } + + /** + * 循环向上转型, 获取对象的DeclaredMethod,并强制设置为可访问. + * 如向上转型到Object仍无法找到, 返回null. + *

+ * 用于方法需要被多次调用的情况. 先使用本函数先取得Method,然后调用Method.invoke(Object obj, Object... args) + */ + public static Method getAccessibleMethod(final Object obj, final String methodName, + final Class... parameterTypes) { + Assert.notNull(obj, "object不能为空"); + + for (Class superClass = obj.getClass(); superClass != Object.class; superClass = superClass.getSuperclass()) { + try { + Method method = superClass.getDeclaredMethod(methodName, parameterTypes); + + method.setAccessible(true); + + return method; + + } catch (NoSuchMethodException e) {//NOSONAR + // Method不在当前类定义,继续向上转型 + } + } + return null; + } + + /** + * 通过反射, 获得Class定义中声明的父类的泛型参数的类型. + * 如无法找到, 返回Object.class. + * eg. + * public UserDao extends HibernateDao + * + * @param clazz The class to introspect + * @return the first generic declaration, or Object.class if cannot be determined + */ + @SuppressWarnings({"unchecked", "rawtypes"}) + public static Class getSuperClassGenricType(final Class clazz) { + return getSuperClassGenricType(clazz, 0); + } + + /** + * 通过反射, 获得Class定义中声明的父类的泛型参数的类型. + * 如无法找到, 返回Object.class. + *

+ * 如public UserDao extends HibernateDao + * + * @param clazz clazz The class to introspect + * @param index the Index of the generic ddeclaration,start from 0. + * @return the index generic declaration, or Object.class if cannot be determined + */ + @SuppressWarnings("rawtypes") + public static Class getSuperClassGenricType(final Class clazz, final int index) { + + Type genType = clazz.getGenericSuperclass(); + + if (!(genType instanceof ParameterizedType)) { + log.warn(clazz.getSimpleName() + "'s superclass not ParameterizedType"); + return Object.class; + } + + Type[] params = ((ParameterizedType) genType).getActualTypeArguments(); + + if (index >= params.length || index < 0) { + log.warn("Index: " + index + ", Size of " + clazz.getSimpleName() + "'s Parameterized Type: " + + params.length); + return Object.class; + } + if (!(params[index] instanceof Class)) { + log.warn(clazz.getSimpleName() + " not set the actual class on superclass generic parameter"); + return Object.class; + } + + return (Class) params[index]; + } + + /** + * 将反射时的checked exception转换为unchecked exception. + */ + public static RuntimeException convertReflectionExceptionToUnchecked(Exception e) { + if (e instanceof IllegalAccessException || e instanceof IllegalArgumentException + || e instanceof NoSuchMethodException) { + return new IllegalArgumentException("Reflection Exception.", e); + } else if (e instanceof InvocationTargetException) { + return new RuntimeException("Reflection Exception.", ((InvocationTargetException) e).getTargetException()); + } else if (e instanceof RuntimeException) { + return (RuntimeException) e; + } + return new RuntimeException("Unexpected Checked Exception.", e); + } + + /** + * 根据对象获得mongodb Update语句 + * 除id字段以外,所有被赋值的字段都会成为修改项 + */ + public static Update getUpdateObj(final Object obj) { + if (obj == null) { + return null; + } + Field[] fields = obj.getClass().getDeclaredFields(); + Update update = null; + boolean isFirst = true; + for (Field field : fields) { + field.setAccessible(true); + try { + Object value = field.get(obj); + if (value != null) { + if ("id".equals(field.getName().toLowerCase()) || "serialversionuid".equals(field.getName().toLowerCase())) { + continue; + } + if (isFirst) { + update = Update.update(field.getName(), value); + isFirst = false; + } else { + update = update.set(field.getName(), value); + } + } + + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } + return update; + } +} diff --git a/mate-core/mate-starter-mongodb/src/main/java/vip/mate/core/mongodb/util/StringUtil.java b/mate-core/mate-starter-mongodb/src/main/java/vip/mate/core/mongodb/util/StringUtil.java new file mode 100644 index 00000000..05212a8d --- /dev/null +++ b/mate-core/mate-starter-mongodb/src/main/java/vip/mate/core/mongodb/util/StringUtil.java @@ -0,0 +1,391 @@ +package vip.mate.core.mongodb.util; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * String工具类 + * + * @author pangu + * @date 2020-10-20 + */ +public class StringUtil { + + private StringUtil() { + super(); + } + + /** + * 出去null和"" + * + * @param src + * @return + */ + public static String formatNull(String src) { + return (src == null || "null".equals(src)) ? "" : src; + } + + /** + * 判断字符串是否为空的正则表达式,空白字符对应的unicode编码 + */ + private static final String EMPTY_REGEX = "[\\s\\u00a0\\u2007\\u202f\\u0009-\\u000d\\u001c-\\u001f]+"; + + /** + * 验证字符串是否为空 + * + * @param input + * @return + */ + public static boolean isEmpty(String input) { + return input == null || input.equals("") || input.matches(EMPTY_REGEX); + } + + public static boolean isNotEmpty(String input) { + return !isEmpty(input); + } + + private static final String NUM_REG = "(\\+|\\-)?\\s*\\d+(\\.\\d+)?"; + + + //首字母转小写 + public static String toLowerCaseFirstOne(String s) { + if (Character.isLowerCase(s.charAt(0))) { + return s; + } else { + return (new StringBuilder()).append(Character.toLowerCase(s.charAt(0))).append(s.substring(1)).toString(); + } + } + + //首字母转大写 + public static String toUpperCaseFirstOne(String s) { + if (Character.isUpperCase(s.charAt(0))) { + return s; + } else { + return (new StringBuilder()).append(Character.toUpperCase(s.charAt(0))).append(s.substring(1)).toString(); + } + } + + + /** + * 判断是否数字 + * + * @param str + * @return + */ + public static boolean isNumber(String str) { + if (isEmpty(str)) { + return false; + } + + if (str.trim().matches(NUM_REG)) { + return true; + } + + return false; + } + + /** + * 判断是否包含有乱码的数据,如果字符串中包含有替换字符就认为是乱码 + * + * @param str + * @return + */ + public static boolean containUnreadableCode(String str) { + return contain(str, "\\ufffd"); + } + + /** + * 判读是否包含数字 + * + * @param str + * @return + */ + public static boolean containNumber(String str) { + return contain(str, "\\d"); + } + + /** + * 判断是否包含a-zA-Z_0-9 + * + * @param str + * @return + */ + public static boolean containWord(String str) { + return contain(str, "\\w"); + } + + /** + * 是否包含有标点符号 + * + * @param str + * @return + */ + public static boolean containPunct(String str) { + return contain(str, PUNCT_REG); + } + + public static boolean contain(String str, String regex) { + if (isEmpty(str) || isEmpty(regex)) { + return false; + } + + if (str.trim().matches(regex)) { + return true; + } + + Pattern pattern = Pattern.compile(regex); + Matcher matcher = pattern.matcher(str); + if (matcher.find()) { + return true; + } + + return false; + } + + /** + * 替换所有的(不区分大小写) + * + * @param input + * @param regex + * @param replacement + * @return + */ + public static String replaceAll(String input, String regex, + String replacement) { + return Pattern.compile(regex, Pattern.CASE_INSENSITIVE).matcher(input) + .replaceAll(replacement); + } + + /** + * 移除所有的空格 + * + * @param text + * @return + */ + public static String removeAllSpace(String text) { + if (isEmpty(text)) { + return text; + } + + return text.replaceAll("[ ]+", ""); + } + + private static final String PUNCT_REG = "[^a-zA-Z0-9\\u4e00-\\u9fa5]"; + + /** + * 移除字符串中的所有的中英文标点符号 + * + * @param str + * @return + */ + public static String removeAllPunct(String str) { + if (isEmpty(str)) { + return str; + } + + return str.replaceAll(PUNCT_REG, ""); + } + + /** + * 计算str中包含多少个子字符串sub + * + * @param str + * @param sub + * @return + */ + public static int countMatches(String str, String sub) { + if (isEmpty(str) || isEmpty(sub)) { + return 0; + } + + int count = 0; + int idx = 0; + while ((idx = str.indexOf(sub, idx)) != -1) { + count++; + idx += sub.length(); + } + + return count; + } + + /** + * 获得源字符串的一个子字符串 + * + * @param str :源字符串 + * @param beginIndex :开始索引(包括) + * @param endIndex :结束索引(不包括) + * @return + */ + public static String substring(String str, int beginIndex, int endIndex) { + if (isEmpty(str)) { + return str; + } + + int length = str.length(); + + if (beginIndex >= length || endIndex <= 0 || beginIndex >= endIndex) { + return null; + } + + if (beginIndex < 0) { + beginIndex = 0; + } + if (endIndex > length) { + endIndex = length; + } + + return str.substring(beginIndex, endIndex); + } + + /** + * 计算str中包含子字符串sub所在位置的前一个字符或者后一个字符和sub所组成的新字符串 + * + * @param str + * @param sub + * @return + */ + public static Set substring(String str, String sub) { + if (isEmpty(str) || isEmpty(sub)) { + return null; + } + + Set result = new HashSet(); + int idx = 0; + while ((idx = str.indexOf(sub, idx)) != -1) { + String temp = substring(str, idx - 1, idx + sub.length()); + if (!isEmpty(temp)) { + temp = removeAllPunct(temp); + if (!sub.equalsIgnoreCase(temp) && !containWord(temp)) { + result.add(temp); + } + + } + + temp = substring(str, idx, idx + sub.length() + 1); + if (!isEmpty(temp)) { + temp = removeAllPunct(temp); + if (!sub.equalsIgnoreCase(temp) && !containWord(temp)) { + result.add(temp); + } + } + + idx += sub.length(); + } + + return result; + } + + /** + * 过滤掉XML中无法解析的非法字符 + * + * @param content + * @return + */ + public static String wrapXmlContent(String content) { + if (isEmpty(content)) { + return ""; + } + + StringBuilder result = new StringBuilder(); + + for (int i = 0; i < content.length(); i++) { + char ch = content.charAt(i); + if ((ch == '\t') || (ch == '\n') || (ch == '\r') + || ((ch >= ' ') && (ch <= 55295)) + || ((ch >= 57344) && (ch <= 65533)) + || ((ch >= 65536) && (ch <= 1114111))) { + result.append(ch); + } + } + + return result.toString(); + } + + /** + * 判断字符串的长度 + * + * @param str + * @return + */ + public static boolean overLength(String str) { + if (isEmpty(str)) { + return false; + } + + return str.length() > 1 ? true : false; + } + + /** + * 字符串中含有特殊字符的处理 + * + * @param str + * @return + */ + public static String specialStr(String str) { + str = str.replaceAll("[^\\u4e00-\\u9fa5 | 0-9| a-zA-Z | \\.]+", " ") + .replaceAll("[\\.]{2,}", " ").trim(); + return str; + } + + /** + * 将特殊符号去掉,但是保留空格 + * + * @param str + * @return + */ + public static String replaceInValidateChar(String str) { + return str.replaceAll("[^a-zA-Z0-9\\u4e00-\\u9fa5\\s+]", " "); + } + + /** + * 返回字符串对应的unicode编码 + * + * @param str + * @return + */ + public static String[] toHexString(String str) { + char[] chars = str.toCharArray(); + + String[] result = new String[chars.length]; + + for (int i = 0; i < chars.length; i++) { + result[i] = Integer.toHexString((int) chars[i]); + } + + return result; + } + + public static String getUuid() { + return UUID.randomUUID().toString(); + } + + public static boolean isUrl(String src) { + String regex = "http[s]?:\\/\\/([\\w-]+\\.[\\w-]+)(\\.[\\w-])+(:\\d{2,10})?.*"; + Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); + Matcher matcher = pattern.matcher(src); + return matcher.matches(); + } + + /** + * sql 查询转义 + * + * @param str + * @return + */ + public static String escapeSql(String str) { + if (StringUtil.isNotEmpty(str)) { + StringBuffer strbuff = new StringBuffer(); + for (String s : str.split("")) { + if (s.equals("%") || s.equals("_") || s.equals("\\")) { + strbuff.append("\\"); + } + strbuff.append(s); + } + return strbuff.toString(); + } + return str; + } +} diff --git a/mate-core/mate-starter-mongodb/src/main/java/vip/mate/core/mongodb/vo/Page.java b/mate-core/mate-starter-mongodb/src/main/java/vip/mate/core/mongodb/vo/Page.java new file mode 100644 index 00000000..7c837a45 --- /dev/null +++ b/mate-core/mate-starter-mongodb/src/main/java/vip/mate/core/mongodb/vo/Page.java @@ -0,0 +1,100 @@ +package vip.mate.core.mongodb.vo; + +import java.io.Serializable; +import java.util.List; + +/** + * 分页参数实体 + * + * @param + * @author pangu + * @date 2020-10-20 + */ +public class Page implements Serializable { + + private static final long serialVersionUID = 5760097915453738435L; + public static final int DEFAULT_PAGE_SIZE = 10; + /** + * 每页显示个数 + */ + private int pageSize; + /** + * 当前页数 + */ + private int currentPage; + /** + * 总页数 + */ + private int totalPage; + /** + * 总记录数 + */ + private int totalCount; + /** + * 结果列表 + */ + private List rows; + + public Page() { + this.currentPage = 1; + this.pageSize = DEFAULT_PAGE_SIZE; + } + + public Page(int currentPage, int pageSize) { + this.currentPage = currentPage <= 0 ? 1 : currentPage; + this.pageSize = pageSize <= 0 ? 1 : pageSize; + } + + public int getPageSize() { + return pageSize; + } + + public void setPageSize(int pageSize) { + this.pageSize = pageSize; + } + + public int getCurrentPage() { + return currentPage; + } + + public void setCurrentPage(int currentPage) { + this.currentPage = currentPage; + } + + public int getTotalPage() { + return totalPage; + } + + public void setTotalPage(int totalPage) { + this.totalPage = totalPage; + } + + public int getTotalCount() { + return totalCount; + } + + public void setTotalCount(int totalCount) { + this.totalCount = totalCount; + } + + /** + * 设置结果 及总页数 + * + * @param rows + */ + public void build(List rows) { + this.setRows(rows); + int count = this.getTotalCount(); + int divisor = count / this.getPageSize(); + int remainder = count % this.getPageSize(); + this.setTotalPage(remainder == 0 ? divisor == 0 ? 1 : divisor : divisor + 1); + } + + public List getRows() { + return rows; + } + + public void setRows(List rows) { + this.rows = rows; + } +} diff --git a/mate-core/pom.xml b/mate-core/pom.xml index e1082f99..f611757b 100644 --- a/mate-core/pom.xml +++ b/mate-core/pom.xml @@ -40,6 +40,7 @@ mate-starter-strategy mate-starter-retrofit mate-starter-j2cache + mate-starter-mongodb diff --git a/mate-platform/mate-system/src/main/java/vip/mate/system/mapper/SysRoleMapper.xml b/mate-platform/mate-system/src/main/java/vip/mate/system/mapper/SysRoleMapper.xml index 0d6ccdcd..9ad817db 100644 --- a/mate-platform/mate-system/src/main/java/vip/mate/system/mapper/SysRoleMapper.xml +++ b/mate-platform/mate-system/src/main/java/vip/mate/system/mapper/SysRoleMapper.xml @@ -2,7 +2,7 @@ - + diff --git a/mate-platform/mate-system/src/main/java/vip/mate/system/mapper/SysRouteMapper.xml b/mate-platform/mate-system/src/main/java/vip/mate/system/mapper/SysRouteMapper.xml index 594bbd1f..0d4a3a36 100644 --- a/mate-platform/mate-system/src/main/java/vip/mate/system/mapper/SysRouteMapper.xml +++ b/mate-platform/mate-system/src/main/java/vip/mate/system/mapper/SysRouteMapper.xml @@ -18,7 +18,7 @@ - + diff --git a/mate-support/mate-code/src/main/java/vip/mate/code/mapper/SysDataSourceMapper.xml b/mate-support/mate-code/src/main/java/vip/mate/code/mapper/SysDataSourceMapper.xml index c1a0c77f..d7ffaed3 100644 --- a/mate-support/mate-code/src/main/java/vip/mate/code/mapper/SysDataSourceMapper.xml +++ b/mate-support/mate-code/src/main/java/vip/mate/code/mapper/SysDataSourceMapper.xml @@ -2,7 +2,7 @@ - + From c1a3617127d56527de8a96c2c2a1bcfb8b59220b Mon Sep 17 00:00:00 2001 From: matevip <7333791@qq.com> Date: Thu, 22 Oct 2020 07:03:19 +0800 Subject: [PATCH 04/19] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=9B=A0=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=8C=85=E5=90=8D=E8=80=8C=E8=A2=ABidea=E8=AF=AF?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E4=BF=AE=E6=94=B9=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/xxl/job/core/util/ShardingUtil.java | 46 ------------------- .../vip/mate/system/mapper/SysRoleMapper.xml | 2 +- .../vip/mate/system/mapper/SysRouteMapper.xml | 2 +- .../mate/code/mapper/SysDataSourceMapper.xml | 2 +- 4 files changed, 3 insertions(+), 49 deletions(-) delete mode 100644 mate-core/mate-starter-job/src/main/java/com/xxl/job/core/util/ShardingUtil.java diff --git a/mate-core/mate-starter-job/src/main/java/com/xxl/job/core/util/ShardingUtil.java b/mate-core/mate-starter-job/src/main/java/com/xxl/job/core/util/ShardingUtil.java deleted file mode 100644 index 7fa35e5b..00000000 --- a/mate-core/mate-starter-job/src/main/java/com/xxl/job/core/util/ShardingUtil.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.xxl.job.core.util;//package com.xxl.job.core.util; -// -///** -// * sharding vip.mate.core.mongodb.vo -// * @author xuxueli 2017-07-25 21:26:38 -// */ -//public class ShardingUtil { -// -// private static InheritableThreadLocal contextHolder = new InheritableThreadLocal(); -// -// public static class ShardingVO { -// -// private int index; // sharding index -// private int total; // sharding total -// -// public ShardingVO(int index, int total) { -// this.index = index; -// this.total = total; -// } -// -// public int getIndex() { -// return index; -// } -// -// public void setIndex(int index) { -// this.index = index; -// } -// -// public int getTotal() { -// return total; -// } -// -// public void setTotal(int total) { -// this.total = total; -// } -// } -// -// public static void setShardingVo(ShardingVO shardingVo){ -// contextHolder.set(shardingVo); -// } -// -// public static ShardingVO getShardingVo(){ -// return contextHolder.get(); -// } -// -//} diff --git a/mate-platform/mate-system/src/main/java/vip/mate/system/mapper/SysRoleMapper.xml b/mate-platform/mate-system/src/main/java/vip/mate/system/mapper/SysRoleMapper.xml index 9ad817db..0d6ccdcd 100644 --- a/mate-platform/mate-system/src/main/java/vip/mate/system/mapper/SysRoleMapper.xml +++ b/mate-platform/mate-system/src/main/java/vip/mate/system/mapper/SysRoleMapper.xml @@ -2,7 +2,7 @@ - + diff --git a/mate-platform/mate-system/src/main/java/vip/mate/system/mapper/SysRouteMapper.xml b/mate-platform/mate-system/src/main/java/vip/mate/system/mapper/SysRouteMapper.xml index 0d4a3a36..594bbd1f 100644 --- a/mate-platform/mate-system/src/main/java/vip/mate/system/mapper/SysRouteMapper.xml +++ b/mate-platform/mate-system/src/main/java/vip/mate/system/mapper/SysRouteMapper.xml @@ -18,7 +18,7 @@ - + diff --git a/mate-support/mate-code/src/main/java/vip/mate/code/mapper/SysDataSourceMapper.xml b/mate-support/mate-code/src/main/java/vip/mate/code/mapper/SysDataSourceMapper.xml index d7ffaed3..c1a0c77f 100644 --- a/mate-support/mate-code/src/main/java/vip/mate/code/mapper/SysDataSourceMapper.xml +++ b/mate-support/mate-code/src/main/java/vip/mate/code/mapper/SysDataSourceMapper.xml @@ -2,7 +2,7 @@ - + From 002a2bbdf2db0fe229d241c81973bbd994c32b04 Mon Sep 17 00:00:00 2001 From: matevip <7333791@qq.com> Date: Thu, 22 Oct 2020 20:08:22 +0800 Subject: [PATCH 05/19] =?UTF-8?q?mate-admin=E5=A2=9E=E5=8A=A0=E9=92=89?= =?UTF-8?q?=E9=92=89=E5=91=8A=E8=AD=A6=E7=9A=84readme=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mate-support/mate-admin/README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 mate-support/mate-admin/README.md diff --git a/mate-support/mate-admin/README.md b/mate-support/mate-admin/README.md new file mode 100644 index 00000000..3554fef5 --- /dev/null +++ b/mate-support/mate-admin/README.md @@ -0,0 +1,22 @@ +# MATE-ADMIN钉钉告警配置方案 + +## SDK下载 + +#### Java SDK 下载 +[Java SDK下载]https://open-doc.dingtalk.com/microapp/faquestions/vzbp02 + +#### 本地jar包 +项目目录:doc/lib/taobao-sdk-20200415.jar + +## 配置项 + +#### application-@spring.active@.yml + +```yaml +spring: + boot: + admin: + notify: + dingding: + token: ${Your DingDing Robot Token} +``` \ No newline at end of file From 0d0fefdcec5d734203ececf8c13ccae4aa784dcc Mon Sep 17 00:00:00 2001 From: matevip <7333791@qq.com> Date: Fri, 23 Oct 2020 14:29:58 +0800 Subject: [PATCH 06/19] =?UTF-8?q?redisson=E5=8D=87=E7=BA=A7=E8=87=B33.13.6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mate-core/mate-starter-dependencies/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mate-core/mate-starter-dependencies/pom.xml b/mate-core/mate-starter-dependencies/pom.xml index 6357ab44..c32877e9 100644 --- a/mate-core/mate-starter-dependencies/pom.xml +++ b/mate-core/mate-starter-dependencies/pom.xml @@ -67,7 +67,7 @@ 3.2.2 6.5.0 - 3.13.3 + 3.13.6 5.3.3.RELEASE 1.8.0 2.11.5 From b546c897231fa865eb2b179c6145e887c4992a28 Mon Sep 17 00:00:00 2001 From: matevip <7333791@qq.com> Date: Fri, 23 Oct 2020 22:14:00 +0800 Subject: [PATCH 07/19] =?UTF-8?q?=E5=B0=81=E8=A3=85redisson=20lock?= =?UTF-8?q?=E5=9F=BA=E7=A1=80=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mate-core/mate-starter-lock/pom.xml | 34 +++++++ .../java/vip/mate/core/lock/RedissonLock.java | 60 ++++++++++++ .../vip/mate/core/lock/RedissonManager.java | 92 +++++++++++++++++++ .../core/lock/annotation/DistributedLock.java | 29 ++++++ .../lock/annotation/EnableRedissonLock.java | 20 ++++ .../lock/aspect/DistributedLockHandler.java | 57 ++++++++++++ .../mate/core/lock/config/RedissonConfig.java | 47 ++++++++++ .../ClusterRedissonConfigStrategyImpl.java | 40 ++++++++ ...MasterslaveRedissonConfigStrategyImpl.java | 50 ++++++++++ .../strategy/RedissonConfigContext.java | 27 ++++++ .../strategy/RedissonConfigStrategy.java | 21 +++++ .../SentinelRedissonConfigStrategyImpl.java | 45 +++++++++ .../StandaloneRedissonConfigStrategyImpl.java | 38 ++++++++ .../core/lock/constant/GlobalConstant.java | 22 +++++ .../lock/constant/RedisConnectionType.java | 39 ++++++++ .../core/lock/props/RedissonProperties.java | 33 +++++++ .../main/resources/META-INF/spring.factories | 4 + mate-core/pom.xml | 1 + 18 files changed, 659 insertions(+) create mode 100644 mate-core/mate-starter-lock/pom.xml create mode 100644 mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/RedissonLock.java create mode 100644 mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/RedissonManager.java create mode 100644 mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/annotation/DistributedLock.java create mode 100644 mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/annotation/EnableRedissonLock.java create mode 100644 mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/aspect/DistributedLockHandler.java create mode 100644 mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/RedissonConfig.java create mode 100644 mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/ClusterRedissonConfigStrategyImpl.java create mode 100644 mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/MasterslaveRedissonConfigStrategyImpl.java create mode 100644 mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/RedissonConfigContext.java create mode 100644 mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/RedissonConfigStrategy.java create mode 100644 mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/SentinelRedissonConfigStrategyImpl.java create mode 100644 mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/StandaloneRedissonConfigStrategyImpl.java create mode 100644 mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/constant/GlobalConstant.java create mode 100644 mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/constant/RedisConnectionType.java create mode 100644 mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/props/RedissonProperties.java create mode 100644 mate-core/mate-starter-lock/src/main/resources/META-INF/spring.factories diff --git a/mate-core/mate-starter-lock/pom.xml b/mate-core/mate-starter-lock/pom.xml new file mode 100644 index 00000000..eeb743de --- /dev/null +++ b/mate-core/mate-starter-lock/pom.xml @@ -0,0 +1,34 @@ + + + + mate-core + vip.mate + 1.5.8-SNAPSHOT + + 4.0.0 + + mate-starter-lock + + + + org.redisson + redisson + + + org.projectlombok + lombok + provided + + + org.apache.commons + commons-lang3 + + + com.google.guava + guava + + + + \ No newline at end of file diff --git a/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/RedissonLock.java b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/RedissonLock.java new file mode 100644 index 00000000..f2d6244a --- /dev/null +++ b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/RedissonLock.java @@ -0,0 +1,60 @@ +package vip.mate.core.lock; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; +import org.redisson.api.RLock; + +import java.util.concurrent.TimeUnit; + +/** + * 分布式锁实现基于Redisson + * + * @author pangu + * @date 2020-10-22 + */ +@Slf4j +@AllArgsConstructor +@NoArgsConstructor +@Getter +@Setter +public class RedissonLock { + + RedissonManager redissonManager; + + /** + * 加锁操作 + * + * @return boolean + */ + public boolean lock(String lockName, long expireSeconds) { + RLock rLock = redissonManager.getRedisson().getLock(lockName); + boolean getLock = false; + try { + getLock = rLock.tryLock(0, expireSeconds, TimeUnit.SECONDS); + if (getLock) { + log.info("获取Redisson分布式锁[成功],lockName={}", lockName); + } else { + log.info("获取Redisson分布式锁[失败],lockName={}", lockName); + } + } catch (InterruptedException e) { + log.error("获取Redisson分布式锁[异常],lockName=" + lockName, e); + e.printStackTrace(); + return false; + } + return getLock; + } + + /** + * 解锁 + * + * @param lockName 锁名称 + */ + public void release(String lockName) { + redissonManager.getRedisson().getLock(lockName).unlock(); + } + + +} diff --git a/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/RedissonManager.java b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/RedissonManager.java new file mode 100644 index 00000000..eb5258ab --- /dev/null +++ b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/RedissonManager.java @@ -0,0 +1,92 @@ +package vip.mate.core.lock; + +import com.google.common.base.Preconditions; +import lombok.extern.slf4j.Slf4j; +import org.redisson.Redisson; +import org.redisson.config.Config; +import vip.mate.core.lock.config.strategy.*; +import vip.mate.core.lock.constant.RedisConnectionType; +import vip.mate.core.lock.props.RedissonProperties; + +/** + * Redisson核心配置,用于提供初始化的redisson实例 + * + * @author pangu + * @date 2020-10-22 + */ +@Slf4j +public class RedissonManager { + + private Config config = new Config(); + + private Redisson redisson = null; + + public RedissonManager() {} + + public RedissonManager(RedissonProperties redissonProperties) { + try { + config = RedissonConfigFactory.getInstance().createConfig(redissonProperties); + redisson = (Redisson) Redisson.create(config); + } catch (Exception e) { + log.error("Redisson init error", e); + throw new IllegalArgumentException("please input correct configurations," + + "connectionType must in standalone/sentinel/cluster/masterslave"); } + } + + public Redisson getRedisson() { + return redisson; + } + + /** + * Redisson连接方式配置工厂 + * 双重检查锁 + */ + static class RedissonConfigFactory { + + private RedissonConfigFactory() {} + + private static volatile RedissonConfigFactory factory = null; + + public static RedissonConfigFactory getInstance() { + if (factory == null) { + synchronized (Object.class) { + if (factory == null) { + factory = new RedissonConfigFactory(); + } + } + } + return factory; + } + + private Config config = new Config(); + + /** + * 根据连接类型获取对应连接方式的配置,基于策略模式 + * @param redissonProperties + * @return Config + */ + Config createConfig(RedissonProperties redissonProperties) { + Preconditions.checkNotNull(redissonProperties); + Preconditions.checkNotNull(redissonProperties.getAddress(), "redisson.lock.server.address cannot be NULL!"); + Preconditions.checkNotNull(redissonProperties.getType(), "redisson.lock.server.password cannot be NULL"); + Preconditions.checkNotNull(redissonProperties.getDatabase(), "redisson.lock.server.database cannot be NULL"); + String connectionType = redissonProperties.getType(); + /**声明配置上下文*/ + RedissonConfigContext redissonConfigContext = null; + if (connectionType.equals(RedisConnectionType.STANDALONE.getConnection_type())) { + redissonConfigContext = new RedissonConfigContext(new StandaloneRedissonConfigStrategyImpl()); + } else if (connectionType.equals(RedisConnectionType.SENTINEL.getConnection_type())) { + redissonConfigContext = new RedissonConfigContext(new SentinelRedissonConfigStrategyImpl()); + } else if (connectionType.equals(RedisConnectionType.CLUSTER.getConnection_type())) { + redissonConfigContext = new RedissonConfigContext(new ClusterRedissonConfigStrategyImpl()); + } else if (connectionType.equals(RedisConnectionType.MASTERSLAVE.getConnection_type())) { + redissonConfigContext = new RedissonConfigContext(new MasterslaveRedissonConfigStrategyImpl()); + } else { + throw new IllegalArgumentException("创建Redisson连接Config失败!当前连接方式:" + connectionType); + } + return redissonConfigContext.createRedissonConfig(redissonProperties); + } + } + + +} diff --git a/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/annotation/DistributedLock.java b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/annotation/DistributedLock.java new file mode 100644 index 00000000..587bca2e --- /dev/null +++ b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/annotation/DistributedLock.java @@ -0,0 +1,29 @@ +package vip.mate.core.lock.annotation; + +import java.lang.annotation.*; + +/** + * Redisson分布式锁注解 + * + * @author pangu + */ +@Target({ElementType.TYPE, ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +public @interface DistributedLock { + + /** + * 分布式锁名称 + * + * @return String + */ + String value() default "distributed-lock-redisson"; + + /** + * 锁超时时间,默认十秒 + * + * @return int + */ + int expireSeconds() default 10; +} diff --git a/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/annotation/EnableRedissonLock.java b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/annotation/EnableRedissonLock.java new file mode 100644 index 00000000..2e6fb21a --- /dev/null +++ b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/annotation/EnableRedissonLock.java @@ -0,0 +1,20 @@ +package vip.mate.core.lock.annotation; + +import org.springframework.context.annotation.Import; +import vip.mate.core.lock.config.RedissonConfig; + +import java.lang.annotation.*; + +/** + * 开启Redisson注解支持 + * + * @author pangu + * @date 2020-10-22 + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +@Documented +@Inherited +@Import(RedissonConfig.class) +public @interface EnableRedissonLock { +} diff --git a/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/aspect/DistributedLockHandler.java b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/aspect/DistributedLockHandler.java new file mode 100644 index 00000000..505874d1 --- /dev/null +++ b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/aspect/DistributedLockHandler.java @@ -0,0 +1,57 @@ +package vip.mate.core.lock.aspect; + +import lombok.extern.slf4j.Slf4j; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import vip.mate.core.lock.RedissonLock; +import vip.mate.core.lock.annotation.DistributedLock; + +/** + * 分布式锁解析器 + * + * @author pangu + * @date 2020-10-22 + * @link https://github.com/TaXueWWL/redis-distributed-lock + */ +@Slf4j +@Aspect +@Component +public class DistributedLockHandler { + + @Autowired + RedissonLock redissonLock; + + @Pointcut("@annotation(vip.mate.core.lock.annotation.DistributedLock)") + public void distributedLock() { + } + + @Around("@annotation(distributedLock)") + public void around(ProceedingJoinPoint joinPoint, DistributedLock distributedLock) { + log.info("[开始]执行RedisLock环绕通知,获取Redis分布式锁开始"); + //获取锁名称 + String lockName = distributedLock.value(); + //获取超时时间 + int expireSeconds = distributedLock.expireSeconds(); + + if (redissonLock.lock(lockName, expireSeconds)) { + try { + log.info("获取Redis分布式锁[成功],加锁完成,开始执行业务逻辑..."); + joinPoint.proceed(); + } catch (Throwable throwable) { + log.error("获取Redis分布式锁[异常],加锁失败", throwable); + throwable.printStackTrace(); + } finally { + redissonLock.release(lockName); + } + log.info("释放Redis分布式锁[成功],解锁完成,结束业务逻辑..."); + } else { + log.error("获取Redis分布式锁[失败]"); + } + log.info("[结束]执行RedisLock环绕通知"); + + } +} diff --git a/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/RedissonConfig.java b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/RedissonConfig.java new file mode 100644 index 00000000..65a9efa7 --- /dev/null +++ b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/RedissonConfig.java @@ -0,0 +1,47 @@ +package vip.mate.core.lock.config; + +import lombok.extern.slf4j.Slf4j; +import org.redisson.Redisson; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.annotation.Order; +import vip.mate.core.lock.RedissonLock; +import vip.mate.core.lock.RedissonManager; +import vip.mate.core.lock.props.RedissonProperties; + +/** + * Redisson自动化配置 + * + * @author pangu + * @date 2020-10-20 + */ +@Slf4j +@Configuration +@ConditionalOnClass(Redisson.class) +@EnableConfigurationProperties(RedissonProperties.class) +public class RedissonConfig { + + @Bean + @ConditionalOnMissingBean + @Order(value = 2) + public RedissonLock redissonLock(RedissonManager redissonManager) { + RedissonLock redissonLock = new RedissonLock(); + redissonLock.setRedissonManager(redissonManager); + log.info("[RedissonLock]组装完毕"); + return redissonLock; + } + + @Bean + @ConditionalOnMissingBean + @Order(value = 1) + public RedissonManager redissonManager(RedissonProperties redissonProperties) { + RedissonManager redissonManager = + new RedissonManager(redissonProperties); + log.info("[RedissonManager]组装完毕,当前连接方式:" + redissonProperties.getType() + + ",连接地址:" + redissonProperties.getAddress()); + return redissonManager; + } +} diff --git a/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/ClusterRedissonConfigStrategyImpl.java b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/ClusterRedissonConfigStrategyImpl.java new file mode 100644 index 00000000..ba54bcb2 --- /dev/null +++ b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/ClusterRedissonConfigStrategyImpl.java @@ -0,0 +1,40 @@ +package vip.mate.core.lock.config.strategy; + +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.redisson.config.Config; +import vip.mate.core.lock.constant.GlobalConstant; +import vip.mate.core.lock.props.RedissonProperties; + +/** + * 集群方式Redisson配置 + * + * @author pangu + * @date 2020-10-22 + */ +@Slf4j +public class ClusterRedissonConfigStrategyImpl implements RedissonConfigStrategy { + + @Override + public Config createRedissonConfig(RedissonProperties redissonProperties) { + Config config = new Config(); + try { + String address = redissonProperties.getAddress(); + String password = redissonProperties.getPassword(); + String[] addrTokens = address.split(","); + /**设置cluster节点的服务IP和端口*/ + for (int i = 0; i < addrTokens.length; i++) { + config.useClusterServers() + .addNodeAddress(GlobalConstant.REDIS_CONNECTION_PREFIX.getConstant_value() + addrTokens[i]); + if (StringUtils.isNotBlank(password)) { + config.useClusterServers().setPassword(password); + } + } + log.info("初始化[cluster]方式Config,redisAddress:" + address); + } catch (Exception e) { + log.error("cluster Redisson init error", e); + e.printStackTrace(); + } + return config; + } +} diff --git a/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/MasterslaveRedissonConfigStrategyImpl.java b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/MasterslaveRedissonConfigStrategyImpl.java new file mode 100644 index 00000000..b26ca09f --- /dev/null +++ b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/MasterslaveRedissonConfigStrategyImpl.java @@ -0,0 +1,50 @@ +package vip.mate.core.lock.config.strategy; + +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.redisson.config.Config; +import vip.mate.core.lock.constant.GlobalConstant; +import vip.mate.core.lock.props.RedissonProperties; + +import java.util.ArrayList; +import java.util.List; + +/** + * 主从方式Redisson配置 + * 连接方式:主节点,子节点,子节点 + *

格式为: 127.0.0.1:6379,127.0.0.1:6380,127.0.0.1:6381

+ */ +@Slf4j +public class MasterslaveRedissonConfigStrategyImpl implements RedissonConfigStrategy { + + @Override + public Config createRedissonConfig(RedissonProperties redissonProperties) { + Config config = new Config(); + try { + String address = redissonProperties.getAddress(); + String password = redissonProperties.getPassword(); + int database = redissonProperties.getDatabase(); + String[] addrTokens = address.split(","); + String masterNodeAddr = addrTokens[0]; + /**设置主节点ip*/ + config.useMasterSlaveServers().setMasterAddress(masterNodeAddr); + if (StringUtils.isNotBlank(password)) { + config.useMasterSlaveServers().setPassword(password); + } + config.useMasterSlaveServers().setDatabase(database); + /**设置从节点,移除第一个节点,默认第一个为主节点*/ + List slaveList = new ArrayList<>(); + for (String addrToken : addrTokens) { + slaveList.add(GlobalConstant.REDIS_CONNECTION_PREFIX.getConstant_value() + addrToken); + } + slaveList.remove(0); + + config.useMasterSlaveServers().addSlaveAddress((String[]) slaveList.toArray()); + log.info("初始化[MASTERSLAVE]方式Config,redisAddress:" + address); + } catch (Exception e) { + log.error("MASTERSLAVE Redisson init error", e); + e.printStackTrace(); + } + return config; + } +} diff --git a/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/RedissonConfigContext.java b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/RedissonConfigContext.java new file mode 100644 index 00000000..11bd4217 --- /dev/null +++ b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/RedissonConfigContext.java @@ -0,0 +1,27 @@ +package vip.mate.core.lock.config.strategy; + +import lombok.AllArgsConstructor; +import org.redisson.config.Config; +import vip.mate.core.lock.props.RedissonProperties; + +/** + * Redisson配置上下文,产出真正的Redisson的Config + * + * @author pangu + * @date 2020-10-22 + */ +@AllArgsConstructor +public class RedissonConfigContext { + + private final RedissonConfigStrategy redissonConfigStrategy; + + /** + * 上下文根据构造中传入的具体策略产出真实的Redisson的Config + * + * @param redissonProperties redisson配置 + * @return Config + */ + public Config createRedissonConfig(RedissonProperties redissonProperties) { + return this.redissonConfigStrategy.createRedissonConfig(redissonProperties); + } +} diff --git a/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/RedissonConfigStrategy.java b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/RedissonConfigStrategy.java new file mode 100644 index 00000000..7453942c --- /dev/null +++ b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/RedissonConfigStrategy.java @@ -0,0 +1,21 @@ +package vip.mate.core.lock.config.strategy; + +import org.redisson.config.Config; +import vip.mate.core.lock.props.RedissonProperties; + +/** + * Redisson配置构建接口 + * + * @author pangu + * @date 2020-10-22 + */ +public interface RedissonConfigStrategy { + + /** + * 根据不同的Redis配置策略创建对应的Config + * + * @param redissonProperties redisson配置 + * @return Config + */ + Config createRedissonConfig(RedissonProperties redissonProperties); +} diff --git a/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/SentinelRedissonConfigStrategyImpl.java b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/SentinelRedissonConfigStrategyImpl.java new file mode 100644 index 00000000..8138e173 --- /dev/null +++ b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/SentinelRedissonConfigStrategyImpl.java @@ -0,0 +1,45 @@ +package vip.mate.core.lock.config.strategy; + +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.redisson.config.Config; +import vip.mate.core.lock.constant.GlobalConstant; +import vip.mate.core.lock.props.RedissonProperties; + +/** + * 哨兵方式Redis连接配置 + * + * @author pangu + * @date 2020-10-22 + */ +@Slf4j +public class SentinelRedissonConfigStrategyImpl implements RedissonConfigStrategy { + + @Override + public Config createRedissonConfig(RedissonProperties redissonProperties) { + Config config = new Config(); + try { + String address = redissonProperties.getAddress(); + String password = redissonProperties.getPassword(); + int database = redissonProperties.getDatabase(); + String[] addrTokens = address.split(","); + String sentinelAliasName = addrTokens[0]; + /**设置redis配置文件sentinel.conf配置的sentinel别名*/ + config.useSentinelServers() + .setMasterName(sentinelAliasName); + config.useSentinelServers().setDatabase(database); + if (StringUtils.isNotBlank(password)) { + config.useSentinelServers().setPassword(password); + } + /**设置sentinel节点的服务IP和端口*/ + for (int i = 1; i < addrTokens.length; i++) { + config.useSentinelServers().addSentinelAddress(GlobalConstant.REDIS_CONNECTION_PREFIX.getConstant_value() + addrTokens[i]); + } + log.info("初始化[sentinel]方式Config,redisAddress:" + address); + } catch (Exception e) { + log.error("sentinel Redisson init error", e); + e.printStackTrace(); + } + return config; + } +} diff --git a/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/StandaloneRedissonConfigStrategyImpl.java b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/StandaloneRedissonConfigStrategyImpl.java new file mode 100644 index 00000000..40ae287c --- /dev/null +++ b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/StandaloneRedissonConfigStrategyImpl.java @@ -0,0 +1,38 @@ +package vip.mate.core.lock.config.strategy; + +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.redisson.config.Config; +import vip.mate.core.lock.constant.GlobalConstant; +import vip.mate.core.lock.props.RedissonProperties; + +/** + * 单机方式Redisson配置 + * + * @author pangu + * @date 2020-10-22 + */ +@Slf4j +public class StandaloneRedissonConfigStrategyImpl implements RedissonConfigStrategy { + + @Override + public Config createRedissonConfig(RedissonProperties redissonProperties) { + Config config = new Config(); + try { + String address = redissonProperties.getAddress(); + String password = redissonProperties.getPassword(); + int database = redissonProperties.getDatabase(); + String redisAddr = GlobalConstant.REDIS_CONNECTION_PREFIX.getConstant_value() + address; + config.useSingleServer().setAddress(redisAddr); + config.useSingleServer().setDatabase(database); + if (StringUtils.isNotBlank(password)) { + config.useSingleServer().setPassword(password); + } + log.info("初始化[standalone]方式Config,redisAddress:" + address); + } catch (Exception e) { + log.error("standalone Redisson init error", e); + e.printStackTrace(); + } + return config; + } +} diff --git a/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/constant/GlobalConstant.java b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/constant/GlobalConstant.java new file mode 100644 index 00000000..d2f0da28 --- /dev/null +++ b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/constant/GlobalConstant.java @@ -0,0 +1,22 @@ +package vip.mate.core.lock.constant; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 全局常量枚举 + * + * @author pangu + */ +@Getter +@AllArgsConstructor +public enum GlobalConstant { + + /** + * Redis地址连接前缀 + */ + REDIS_CONNECTION_PREFIX("redis://", "Redis地址配置前缀"); + + private final String constant_value; + private final String constant_desc; +} diff --git a/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/constant/RedisConnectionType.java b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/constant/RedisConnectionType.java new file mode 100644 index 00000000..ad4c7eb8 --- /dev/null +++ b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/constant/RedisConnectionType.java @@ -0,0 +1,39 @@ +package vip.mate.core.lock.constant; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * Redis连接方式 + *

+ * 包含:standalone-单节点部署方式 + * sentinel-哨兵部署方式 + * cluster-集群方式 + * masterslave-主从部署方式 + *

+ * + * @author xuzhanfu + */ +@Getter +@AllArgsConstructor +public enum RedisConnectionType { + /** + * 单节点部署方式 + */ + STANDALONE("standalone", "单节点部署方式"), + /** + * 哨兵部署方式 + */ + SENTINEL("sentinel", "哨兵部署方式"), + /** + * 集群部署方式 + */ + CLUSTER("cluster", "集群方式"), + /** + * 主从部署方式 + */ + MASTERSLAVE("masterslave", "主从部署方式"); + + private final String connection_type; + private final String connection_desc; +} diff --git a/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/props/RedissonProperties.java b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/props/RedissonProperties.java new file mode 100644 index 00000000..0d5914be --- /dev/null +++ b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/props/RedissonProperties.java @@ -0,0 +1,33 @@ +package vip.mate.core.lock.props; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * Redisson配置映射类 + * + * @author pangu + * @date 2020-10-22 + */ +@Data +@ConfigurationProperties(prefix = "redisson.lock.server") +public class RedissonProperties { + + /** + * redis主机地址,ip:port,有多个用半角逗号分隔 + */ + private String address; + /** + * 连接类型,支持standalone-单机节点,sentinel-哨兵,cluster-集群,masterslave-主从 + */ + private String type; + /** + * redis连接密码 + */ + private String password; + /** + * 选取数据库 + */ + private int database; + +} diff --git a/mate-core/mate-starter-lock/src/main/resources/META-INF/spring.factories b/mate-core/mate-starter-lock/src/main/resources/META-INF/spring.factories new file mode 100644 index 00000000..44a4e1e7 --- /dev/null +++ b/mate-core/mate-starter-lock/src/main/resources/META-INF/spring.factories @@ -0,0 +1,4 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + vip.mate.core.lock.config.RedissonConfig + + diff --git a/mate-core/pom.xml b/mate-core/pom.xml index f611757b..707904a0 100644 --- a/mate-core/pom.xml +++ b/mate-core/pom.xml @@ -41,6 +41,7 @@ mate-starter-retrofit mate-starter-j2cache mate-starter-mongodb + mate-starter-lock From 2d430a9b2e99ae1b710a62e318fba6a1b9ce7fc7 Mon Sep 17 00:00:00 2001 From: matevip <7333791@qq.com> Date: Sat, 24 Oct 2020 07:51:47 +0800 Subject: [PATCH 08/19] =?UTF-8?q?redisson=E5=88=86=E5=B8=83=E5=BC=8F?= =?UTF-8?q?=E9=94=81=E5=8A=9F=E8=83=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/vip/mate/core/lock/RedissonManager.java | 14 +++++++++----- .../core/lock/aspect/DistributedLockHandler.java | 16 +++++++++------- .../ClusterRedissonConfigStrategyImpl.java | 2 +- .../MasterslaveRedissonConfigStrategyImpl.java | 4 ++-- .../SentinelRedissonConfigStrategyImpl.java | 4 ++-- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/RedissonManager.java b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/RedissonManager.java index eb5258ab..755018d2 100644 --- a/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/RedissonManager.java +++ b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/RedissonManager.java @@ -21,7 +21,8 @@ public class RedissonManager { private Redisson redisson = null; - public RedissonManager() {} + public RedissonManager() { + } public RedissonManager(RedissonProperties redissonProperties) { try { @@ -30,7 +31,8 @@ public RedissonManager(RedissonProperties redissonProperties) { } catch (Exception e) { log.error("Redisson init error", e); throw new IllegalArgumentException("please input correct configurations," + - "connectionType must in standalone/sentinel/cluster/masterslave"); } + "connectionType must in standalone/sentinel/cluster/masterslave"); + } } public Redisson getRedisson() { @@ -43,7 +45,8 @@ public Redisson getRedisson() { */ static class RedissonConfigFactory { - private RedissonConfigFactory() {} + private RedissonConfigFactory() { + } private static volatile RedissonConfigFactory factory = null; @@ -62,7 +65,8 @@ public static RedissonConfigFactory getInstance() { /** * 根据连接类型获取对应连接方式的配置,基于策略模式 - * @param redissonProperties + * + * @param redissonProperties redisson配置 * @return Config */ Config createConfig(RedissonProperties redissonProperties) { @@ -71,7 +75,7 @@ Config createConfig(RedissonProperties redissonProperties) { Preconditions.checkNotNull(redissonProperties.getType(), "redisson.lock.server.password cannot be NULL"); Preconditions.checkNotNull(redissonProperties.getDatabase(), "redisson.lock.server.database cannot be NULL"); String connectionType = redissonProperties.getType(); - /**声明配置上下文*/ + // 声明配置上下文 RedissonConfigContext redissonConfigContext = null; if (connectionType.equals(RedisConnectionType.STANDALONE.getConnection_type())) { redissonConfigContext = new RedissonConfigContext(new StandaloneRedissonConfigStrategyImpl()); diff --git a/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/aspect/DistributedLockHandler.java b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/aspect/DistributedLockHandler.java index 505874d1..5974c622 100644 --- a/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/aspect/DistributedLockHandler.java +++ b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/aspect/DistributedLockHandler.java @@ -25,12 +25,14 @@ public class DistributedLockHandler { @Autowired RedissonLock redissonLock; - @Pointcut("@annotation(vip.mate.core.lock.annotation.DistributedLock)") - public void distributedLock() { - } - + /** + * 切面环绕通知 + * @param joinPoint ProceedingJoinPoint + * @param distributedLock DistributedLock + * @return Object + */ @Around("@annotation(distributedLock)") - public void around(ProceedingJoinPoint joinPoint, DistributedLock distributedLock) { + public Object around(ProceedingJoinPoint joinPoint, DistributedLock distributedLock) { log.info("[开始]执行RedisLock环绕通知,获取Redis分布式锁开始"); //获取锁名称 String lockName = distributedLock.value(); @@ -40,7 +42,7 @@ public void around(ProceedingJoinPoint joinPoint, DistributedLock distributedLoc if (redissonLock.lock(lockName, expireSeconds)) { try { log.info("获取Redis分布式锁[成功],加锁完成,开始执行业务逻辑..."); - joinPoint.proceed(); + return joinPoint.proceed(); } catch (Throwable throwable) { log.error("获取Redis分布式锁[异常],加锁失败", throwable); throwable.printStackTrace(); @@ -52,6 +54,6 @@ public void around(ProceedingJoinPoint joinPoint, DistributedLock distributedLoc log.error("获取Redis分布式锁[失败]"); } log.info("[结束]执行RedisLock环绕通知"); - + return null; } } diff --git a/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/ClusterRedissonConfigStrategyImpl.java b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/ClusterRedissonConfigStrategyImpl.java index ba54bcb2..2d2f002c 100644 --- a/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/ClusterRedissonConfigStrategyImpl.java +++ b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/ClusterRedissonConfigStrategyImpl.java @@ -22,7 +22,7 @@ public Config createRedissonConfig(RedissonProperties redissonProperties) { String address = redissonProperties.getAddress(); String password = redissonProperties.getPassword(); String[] addrTokens = address.split(","); - /**设置cluster节点的服务IP和端口*/ + // 设置cluster节点的服务IP和端口 for (int i = 0; i < addrTokens.length; i++) { config.useClusterServers() .addNodeAddress(GlobalConstant.REDIS_CONNECTION_PREFIX.getConstant_value() + addrTokens[i]); diff --git a/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/MasterslaveRedissonConfigStrategyImpl.java b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/MasterslaveRedissonConfigStrategyImpl.java index b26ca09f..86406bf5 100644 --- a/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/MasterslaveRedissonConfigStrategyImpl.java +++ b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/MasterslaveRedissonConfigStrategyImpl.java @@ -26,13 +26,13 @@ public Config createRedissonConfig(RedissonProperties redissonProperties) { int database = redissonProperties.getDatabase(); String[] addrTokens = address.split(","); String masterNodeAddr = addrTokens[0]; - /**设置主节点ip*/ + // 设置主节点ip config.useMasterSlaveServers().setMasterAddress(masterNodeAddr); if (StringUtils.isNotBlank(password)) { config.useMasterSlaveServers().setPassword(password); } config.useMasterSlaveServers().setDatabase(database); - /**设置从节点,移除第一个节点,默认第一个为主节点*/ + // 设置从节点,移除第一个节点,默认第一个为主节点 List slaveList = new ArrayList<>(); for (String addrToken : addrTokens) { slaveList.add(GlobalConstant.REDIS_CONNECTION_PREFIX.getConstant_value() + addrToken); diff --git a/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/SentinelRedissonConfigStrategyImpl.java b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/SentinelRedissonConfigStrategyImpl.java index 8138e173..5b6ad6e7 100644 --- a/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/SentinelRedissonConfigStrategyImpl.java +++ b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/strategy/SentinelRedissonConfigStrategyImpl.java @@ -24,14 +24,14 @@ public Config createRedissonConfig(RedissonProperties redissonProperties) { int database = redissonProperties.getDatabase(); String[] addrTokens = address.split(","); String sentinelAliasName = addrTokens[0]; - /**设置redis配置文件sentinel.conf配置的sentinel别名*/ + // 设置redis配置文件sentinel.conf配置的sentinel别名 config.useSentinelServers() .setMasterName(sentinelAliasName); config.useSentinelServers().setDatabase(database); if (StringUtils.isNotBlank(password)) { config.useSentinelServers().setPassword(password); } - /**设置sentinel节点的服务IP和端口*/ + // 设置sentinel节点的服务IP和端口 for (int i = 1; i < addrTokens.length; i++) { config.useSentinelServers().addSentinelAddress(GlobalConstant.REDIS_CONNECTION_PREFIX.getConstant_value() + addrTokens[i]); } From 11bb65b1b5a820c6958ae1e9b18f2d1617bd0ff3 Mon Sep 17 00:00:00 2001 From: matevip <7333791@qq.com> Date: Sat, 24 Oct 2020 09:46:42 +0800 Subject: [PATCH 09/19] =?UTF-8?q?redis=E5=B7=A5=E5=85=B7=E7=B1=BB=E7=BB=9F?= =?UTF-8?q?=E4=B8=80=E5=BC=82=E5=B8=B8=E6=97=A5=E5=BF=97=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mate/core/redis/core/RedisService.java | 50 ++++++++++--------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/mate-core/mate-starter-redis/src/main/java/vip/mate/core/redis/core/RedisService.java b/mate-core/mate-starter-redis/src/main/java/vip/mate/core/redis/core/RedisService.java index f8feb183..dff1bb14 100644 --- a/mate-core/mate-starter-redis/src/main/java/vip/mate/core/redis/core/RedisService.java +++ b/mate-core/mate-starter-redis/src/main/java/vip/mate/core/redis/core/RedisService.java @@ -16,6 +16,7 @@ */ package vip.mate.core.redis.core; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; import org.springframework.data.redis.connection.RedisConnection; @@ -39,6 +40,7 @@ * @author xuzhanfu * @date 2019-10-11 19:02 **/ +@Slf4j public class RedisService { @Autowired @@ -59,7 +61,7 @@ public Boolean expire(String key, Long time) { } return true; } catch (Exception e) { - e.printStackTrace(); + log.error("Exception: {}", e.getMessage()); return false; } } @@ -123,7 +125,7 @@ public Boolean hasKey(String key) { try { return redisTemplate.hasKey(key); } catch (Exception e) { - e.printStackTrace(); + log.error("Exception: {}", e.getMessage()); return false; } } @@ -177,7 +179,7 @@ public Boolean set(String key, Object value) { redisTemplate.opsForValue().set(key, value); return true; } catch (Exception e) { - e.printStackTrace(); + log.error("Exception: {}", e.getMessage()); return false; } } @@ -199,7 +201,7 @@ public Boolean set(String key, Object value, Long time) { } return true; } catch (Exception e) { - e.printStackTrace(); + log.error("Exception: {}", e.getMessage()); return false; } } @@ -222,7 +224,7 @@ public Boolean set(String key, Object value, Duration timeout) { } return true; } catch (Exception e) { - e.printStackTrace(); + log.error("Exception: {}", e.getMessage()); return false; } } @@ -288,7 +290,7 @@ public Boolean hmset(String key, Map map) { redisTemplate.opsForHash().putAll(key, map); return true; } catch (Exception e) { - e.printStackTrace(); + log.error("Exception: {}", e.getMessage()); return false; } } @@ -309,7 +311,7 @@ public Boolean hmset(String key, Map map, Long time) { } return true; } catch (Exception e) { - e.printStackTrace(); + log.error("Exception: {}", e.getMessage()); return false; } } @@ -327,7 +329,7 @@ public Boolean hset(String key, String item, Object value) { redisTemplate.opsForHash().put(key, item, value); return true; } catch (Exception e) { - e.printStackTrace(); + log.error("Exception: {}", e.getMessage()); return false; } } @@ -349,7 +351,7 @@ public Boolean hset(String key, String item, Object value, Long time) { } return true; } catch (Exception e) { - e.printStackTrace(); + log.error("Exception: {}", e.getMessage()); return false; } } @@ -409,7 +411,7 @@ public Set sGet(String key) { try { return redisTemplate.opsForSet().members(key); } catch (Exception e) { - e.printStackTrace(); + log.error("Exception: {}", e.getMessage()); return null; } } @@ -425,7 +427,7 @@ public Boolean sHasKey(String key, Object value) { try { return redisTemplate.opsForSet().isMember(key, value); } catch (Exception e) { - e.printStackTrace(); + log.error("Exception: {}", e.getMessage()); return false; } } @@ -441,7 +443,7 @@ public Long sSet(String key, Object... values) { try { return redisTemplate.opsForSet().add(key, values); } catch (Exception e) { - e.printStackTrace(); + log.error("Exception: {}", e.getMessage()); return 0L; } } @@ -462,7 +464,7 @@ public Long sSetAndTime(String key, Long time, Object... values) { } return count; } catch (Exception e) { - e.printStackTrace(); + log.error("Exception: {}", e.getMessage()); return 0L; } } @@ -477,7 +479,7 @@ public Long sGetSetSize(String key) { try { return redisTemplate.opsForSet().size(key); } catch (Exception e) { - e.printStackTrace(); + log.error("Exception: {}", e.getMessage()); return 0L; } } @@ -493,7 +495,7 @@ public Long setRemove(String key, Object... values) { try { return redisTemplate.opsForSet().remove(key, values); } catch (Exception e) { - e.printStackTrace(); + log.error("Exception: {}", e.getMessage()); return 0L; } } @@ -510,7 +512,7 @@ public List lGet(String key, Long start, Long end) { try { return redisTemplate.opsForList().range(key, start, end); } catch (Exception e) { - e.printStackTrace(); + log.error("Exception: {}", e.getMessage()); return null; } } @@ -525,7 +527,7 @@ public Long lGetListSize(String key) { try { return redisTemplate.opsForList().size(key); } catch (Exception e) { - e.printStackTrace(); + log.error("Exception: {}", e.getMessage()); return 0L; } } @@ -542,7 +544,7 @@ public Object lGetIndex(String key, Long index) { try { return redisTemplate.opsForList().index(key, index); } catch (Exception e) { - e.printStackTrace(); + log.error("Exception: {}", e.getMessage()); return null; } } @@ -559,7 +561,7 @@ public Boolean lSet(String key, Object value) { redisTemplate.opsForList().rightPush(key, value); return true; } catch (Exception e) { - e.printStackTrace(); + log.error("Exception: {}", e.getMessage()); return false; } } @@ -580,7 +582,7 @@ public Boolean lSet(String key, Object value, Long time) { } return true; } catch (Exception e) { - e.printStackTrace(); + log.error("Exception: {}", e.getMessage()); return false; } } @@ -597,7 +599,7 @@ public Boolean lSet(String key, List value) { redisTemplate.opsForList().rightPushAll(key, value); return true; } catch (Exception e) { - e.printStackTrace(); + log.error("Exception: {}", e.getMessage()); return false; } } @@ -618,7 +620,7 @@ public Boolean lSet(String key, List value, Long time) { } return true; } catch (Exception e) { - e.printStackTrace(); + log.error("Exception: {}", e.getMessage()); return false; } } @@ -636,7 +638,7 @@ public Boolean lUpdateIndex(String key, Long index, Object value) { redisTemplate.opsForList().set(key, index, value); return true; } catch (Exception e) { - e.printStackTrace(); + log.error("Exception: {}", e.getMessage()); return false; } } @@ -653,7 +655,7 @@ public Long lRemove(String key, Long count, Object value) { try { return redisTemplate.opsForList().remove(key, count, value); } catch (Exception e) { - e.printStackTrace(); + log.error("Exception: {}", e.getMessage()); return 0L; } } From 46de28e7f26b38f592139cf11d6155d82c60fbe9 Mon Sep 17 00:00:00 2001 From: matevip <7333791@qq.com> Date: Sat, 24 Oct 2020 10:00:51 +0800 Subject: [PATCH 10/19] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E4=B8=AD=E5=BF=83=E5=91=BD=E5=90=8D=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...tion.java => DubboFeignConfiguration.java} | 2 +- .../main/resources/META-INF/spring.factories | 2 +- ... => RibbonDiscoveryRuleConfiguration.java} | 2 +- .../main/resources/META-INF/spring.factories | 2 +- .../lock/annotation/EnableRedissonLock.java | 4 ++-- ...Config.java => RedissonConfiguration.java} | 2 +- .../main/resources/META-INF/spring.factories | 2 +- .../vip/mate/core/redis/package-info.java | 1 - .../core/redis/props/MateRedisProperties.java | 21 ++++++++++++------- ....java => IgnoreUrlPropsConfiguration.java} | 2 +- .../main/resources/META-INF/spring.factories | 2 +- .../core/sms/config/AliSmsConfiguration.java | 13 ++++++++---- .../vip/mate/uaa/config/SecurityConfig.java | 4 ++-- 13 files changed, 34 insertions(+), 25 deletions(-) rename mate-core/mate-starter-dubbo/src/main/java/vip/mate/core/dubbo/config/{DubboFeignAutoConfiguration.java => DubboFeignConfiguration.java} (97%) rename mate-core/mate-starter-gray/src/main/java/vip/mate/core/gray/config/{RibbonDiscoveryRuleConfig.java => RibbonDiscoveryRuleConfiguration.java} (95%) rename mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/{RedissonConfig.java => RedissonConfiguration.java} (97%) delete mode 100644 mate-core/mate-starter-redis/src/main/java/vip/mate/core/redis/package-info.java rename mate-core/mate-starter-security/src/main/java/vip/mate/core/security/config/{IgnoreUrlPropsConfig.java => IgnoreUrlPropsConfiguration.java} (92%) diff --git a/mate-core/mate-starter-dubbo/src/main/java/vip/mate/core/dubbo/config/DubboFeignAutoConfiguration.java b/mate-core/mate-starter-dubbo/src/main/java/vip/mate/core/dubbo/config/DubboFeignConfiguration.java similarity index 97% rename from mate-core/mate-starter-dubbo/src/main/java/vip/mate/core/dubbo/config/DubboFeignAutoConfiguration.java rename to mate-core/mate-starter-dubbo/src/main/java/vip/mate/core/dubbo/config/DubboFeignConfiguration.java index 40f29feb..6336905b 100644 --- a/mate-core/mate-starter-dubbo/src/main/java/vip/mate/core/dubbo/config/DubboFeignAutoConfiguration.java +++ b/mate-core/mate-starter-dubbo/src/main/java/vip/mate/core/dubbo/config/DubboFeignConfiguration.java @@ -27,7 +27,7 @@ @Configuration @ConditionalOnProperty(prefix = DUBBO_PREFIX, name = "enabled", matchIfMissing = true, havingValue = "true") @ConditionalOnClass(AbstractConfig.class) -public class DubboFeignAutoConfiguration { +public class DubboFeignConfiguration { @ConditionalOnProperty(prefix = DUBBO_SCAN_PREFIX, name = BASE_PACKAGES_PROPERTY_NAME) @ConditionalOnClass(ConfigurationPropertySources.class) diff --git a/mate-core/mate-starter-dubbo/src/main/resources/META-INF/spring.factories b/mate-core/mate-starter-dubbo/src/main/resources/META-INF/spring.factories index b4fa065c..1dd079d6 100644 --- a/mate-core/mate-starter-dubbo/src/main/resources/META-INF/spring.factories +++ b/mate-core/mate-starter-dubbo/src/main/resources/META-INF/spring.factories @@ -1,3 +1,3 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ - vip.mate.core.dubbo.config.DubboFeignAutoConfiguration + vip.mate.core.dubbo.config.DubboFeignConfiguration diff --git a/mate-core/mate-starter-gray/src/main/java/vip/mate/core/gray/config/RibbonDiscoveryRuleConfig.java b/mate-core/mate-starter-gray/src/main/java/vip/mate/core/gray/config/RibbonDiscoveryRuleConfiguration.java similarity index 95% rename from mate-core/mate-starter-gray/src/main/java/vip/mate/core/gray/config/RibbonDiscoveryRuleConfig.java rename to mate-core/mate-starter-gray/src/main/java/vip/mate/core/gray/config/RibbonDiscoveryRuleConfiguration.java index 3e04222d..4e35b03a 100644 --- a/mate-core/mate-starter-gray/src/main/java/vip/mate/core/gray/config/RibbonDiscoveryRuleConfig.java +++ b/mate-core/mate-starter-gray/src/main/java/vip/mate/core/gray/config/RibbonDiscoveryRuleConfiguration.java @@ -19,7 +19,7 @@ @Configuration @AutoConfigureBefore(RibbonClientConfiguration.class) @ConditionalOnProperty(value = "ribbon.filter.metadata.enabled", matchIfMissing = true) -public class RibbonDiscoveryRuleConfig { +public class RibbonDiscoveryRuleConfiguration { @Bean @ConditionalOnMissingBean diff --git a/mate-core/mate-starter-gray/src/main/resources/META-INF/spring.factories b/mate-core/mate-starter-gray/src/main/resources/META-INF/spring.factories index 1430fd9c..ce58fb37 100644 --- a/mate-core/mate-starter-gray/src/main/resources/META-INF/spring.factories +++ b/mate-core/mate-starter-gray/src/main/resources/META-INF/spring.factories @@ -1,4 +1,4 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ - vip.mate.core.gray.config.RibbonDiscoveryRuleConfig + vip.mate.core.gray.config.RibbonDiscoveryRuleConfiguration diff --git a/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/annotation/EnableRedissonLock.java b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/annotation/EnableRedissonLock.java index 2e6fb21a..319f3800 100644 --- a/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/annotation/EnableRedissonLock.java +++ b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/annotation/EnableRedissonLock.java @@ -1,7 +1,7 @@ package vip.mate.core.lock.annotation; import org.springframework.context.annotation.Import; -import vip.mate.core.lock.config.RedissonConfig; +import vip.mate.core.lock.config.RedissonConfiguration; import java.lang.annotation.*; @@ -15,6 +15,6 @@ @Target(ElementType.TYPE) @Documented @Inherited -@Import(RedissonConfig.class) +@Import(RedissonConfiguration.class) public @interface EnableRedissonLock { } diff --git a/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/RedissonConfig.java b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/RedissonConfiguration.java similarity index 97% rename from mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/RedissonConfig.java rename to mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/RedissonConfiguration.java index 65a9efa7..0d131354 100644 --- a/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/RedissonConfig.java +++ b/mate-core/mate-starter-lock/src/main/java/vip/mate/core/lock/config/RedissonConfiguration.java @@ -22,7 +22,7 @@ @Configuration @ConditionalOnClass(Redisson.class) @EnableConfigurationProperties(RedissonProperties.class) -public class RedissonConfig { +public class RedissonConfiguration { @Bean @ConditionalOnMissingBean diff --git a/mate-core/mate-starter-lock/src/main/resources/META-INF/spring.factories b/mate-core/mate-starter-lock/src/main/resources/META-INF/spring.factories index 44a4e1e7..8dbc9e32 100644 --- a/mate-core/mate-starter-lock/src/main/resources/META-INF/spring.factories +++ b/mate-core/mate-starter-lock/src/main/resources/META-INF/spring.factories @@ -1,4 +1,4 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ - vip.mate.core.lock.config.RedissonConfig + vip.mate.core.lock.config.RedissonConfiguration diff --git a/mate-core/mate-starter-redis/src/main/java/vip/mate/core/redis/package-info.java b/mate-core/mate-starter-redis/src/main/java/vip/mate/core/redis/package-info.java deleted file mode 100644 index 6fbb59f1..00000000 --- a/mate-core/mate-starter-redis/src/main/java/vip/mate/core/redis/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package vip.mate.core.redis; \ No newline at end of file diff --git a/mate-core/mate-starter-redis/src/main/java/vip/mate/core/redis/props/MateRedisProperties.java b/mate-core/mate-starter-redis/src/main/java/vip/mate/core/redis/props/MateRedisProperties.java index d3177b4a..83afbbe9 100644 --- a/mate-core/mate-starter-redis/src/main/java/vip/mate/core/redis/props/MateRedisProperties.java +++ b/mate-core/mate-starter-redis/src/main/java/vip/mate/core/redis/props/MateRedisProperties.java @@ -4,16 +4,21 @@ import lombok.Setter; import org.springframework.boot.context.properties.ConfigurationProperties; +/** + * redis配置 + * + * @author pangu + */ @Getter @Setter @ConfigurationProperties(MateRedisProperties.PREFIX) public class MateRedisProperties { - /** - * 前缀 - */ - public static final String PREFIX = "mate.lettuce.redis"; - /** - * 是否开启Lettuce - */ - private Boolean enable = true; + /** + * 前缀 + */ + public static final String PREFIX = "mate.lettuce.redis"; + /** + * 是否开启Lettuce + */ + private Boolean enable = true; } diff --git a/mate-core/mate-starter-security/src/main/java/vip/mate/core/security/config/IgnoreUrlPropsConfig.java b/mate-core/mate-starter-security/src/main/java/vip/mate/core/security/config/IgnoreUrlPropsConfiguration.java similarity index 92% rename from mate-core/mate-starter-security/src/main/java/vip/mate/core/security/config/IgnoreUrlPropsConfig.java rename to mate-core/mate-starter-security/src/main/java/vip/mate/core/security/config/IgnoreUrlPropsConfiguration.java index 82a28a4e..85dcf3d5 100644 --- a/mate-core/mate-starter-security/src/main/java/vip/mate/core/security/config/IgnoreUrlPropsConfig.java +++ b/mate-core/mate-starter-security/src/main/java/vip/mate/core/security/config/IgnoreUrlPropsConfiguration.java @@ -17,7 +17,7 @@ @RefreshScope @ConfigurationProperties(prefix = "ignore") @Component -public class IgnoreUrlPropsConfig { +public class IgnoreUrlPropsConfiguration { private List urls = new ArrayList<>(); diff --git a/mate-core/mate-starter-security/src/main/resources/META-INF/spring.factories b/mate-core/mate-starter-security/src/main/resources/META-INF/spring.factories index 593f0c70..9ffbec6a 100644 --- a/mate-core/mate-starter-security/src/main/resources/META-INF/spring.factories +++ b/mate-core/mate-starter-security/src/main/resources/META-INF/spring.factories @@ -1,5 +1,5 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ - vip.mate.core.security.config.IgnoreUrlPropsConfig,\ + vip.mate.core.security.config.IgnoreUrlPropsConfiguration,\ vip.mate.core.security.service.PermissionService diff --git a/mate-core/mate-starter-sms/src/main/java/vip/mate/core/sms/config/AliSmsConfiguration.java b/mate-core/mate-starter-sms/src/main/java/vip/mate/core/sms/config/AliSmsConfiguration.java index ed901c08..135e185f 100644 --- a/mate-core/mate-starter-sms/src/main/java/vip/mate/core/sms/config/AliSmsConfiguration.java +++ b/mate-core/mate-starter-sms/src/main/java/vip/mate/core/sms/config/AliSmsConfiguration.java @@ -8,13 +8,18 @@ import vip.mate.core.sms.core.SmsTemplate; import vip.mate.core.sms.props.SmsProperties; +/** + * 阿里短信配置 + * + * @author pangu + */ @Configuration @EnableConfigurationProperties(value = SmsProperties.class) @ConditionalOnProperty(prefix = SmsProperties.PREFIX, name = "enable", havingValue = "true") public class AliSmsConfiguration { - @Bean - public SmsTemplate aliSmsTemplate(SmsProperties smsProperties) { - return new AliSmsTemplate(smsProperties); - } + @Bean + public SmsTemplate aliSmsTemplate(SmsProperties smsProperties) { + return new AliSmsTemplate(smsProperties); + } } diff --git a/mate-uaa/src/main/java/vip/mate/uaa/config/SecurityConfig.java b/mate-uaa/src/main/java/vip/mate/uaa/config/SecurityConfig.java index 19203e67..a141e2e5 100644 --- a/mate-uaa/src/main/java/vip/mate/uaa/config/SecurityConfig.java +++ b/mate-uaa/src/main/java/vip/mate/uaa/config/SecurityConfig.java @@ -30,7 +30,7 @@ import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.web.authentication.AuthenticationFailureHandler; import org.springframework.security.web.authentication.AuthenticationSuccessHandler; -import vip.mate.core.security.config.IgnoreUrlPropsConfig; +import vip.mate.core.security.config.IgnoreUrlPropsConfiguration; import vip.mate.core.security.handle.MateAuthenticationFailureHandler; import vip.mate.core.security.handle.MateAuthenticationSuccessHandler; import vip.mate.uaa.service.impl.UserDetailsServiceImpl; @@ -49,7 +49,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired - private IgnoreUrlPropsConfig ignoreUrlPropsConfig; + private IgnoreUrlPropsConfiguration ignoreUrlPropsConfig; @Bean public PasswordEncoder passwordEncoder() { From 7d66feaab499199681fcf78d58d1d315cedf4c49 Mon Sep 17 00:00:00 2001 From: matevip <7333791@qq.com> Date: Sun, 25 Oct 2020 10:04:26 +0800 Subject: [PATCH 11/19] =?UTF-8?q?admin=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0enable=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mate-support/mate-admin/src/main/resources/application-prod.yml | 1 + mate-support/mate-admin/src/main/resources/application-test.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/mate-support/mate-admin/src/main/resources/application-prod.yml b/mate-support/mate-admin/src/main/resources/application-prod.yml index 4133c83f..94cad5eb 100644 --- a/mate-support/mate-admin/src/main/resources/application-prod.yml +++ b/mate-support/mate-admin/src/main/resources/application-prod.yml @@ -14,6 +14,7 @@ spring: environment: local notify: dingding: + enabled: false token: AA***************BB security: user: diff --git a/mate-support/mate-admin/src/main/resources/application-test.yml b/mate-support/mate-admin/src/main/resources/application-test.yml index 4133c83f..94cad5eb 100644 --- a/mate-support/mate-admin/src/main/resources/application-test.yml +++ b/mate-support/mate-admin/src/main/resources/application-test.yml @@ -14,6 +14,7 @@ spring: environment: local notify: dingding: + enabled: false token: AA***************BB security: user: From 1d2abf92e6cdf1b8158363e550dc155f9f8c0454 Mon Sep 17 00:00:00 2001 From: matevip <7333791@qq.com> Date: Mon, 26 Oct 2020 17:19:02 +0800 Subject: [PATCH 12/19] =?UTF-8?q?=E5=B0=81=E8=A3=85encrypt=E6=8A=A5?= =?UTF-8?q?=E6=96=87=E5=8A=A0=E8=A7=A3=E5=AF=86=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mate-core/mate-starter-encrypt/pom.xml | 15 +++++++++++++++ .../core/encrypt/annotation/EnableEncrypt.java | 17 +++++++++++++++++ .../vip/mate/core/encrypt/package-info.java | 1 + mate-core/pom.xml | 1 + 4 files changed, 34 insertions(+) create mode 100644 mate-core/mate-starter-encrypt/pom.xml create mode 100644 mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/annotation/EnableEncrypt.java create mode 100644 mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/package-info.java diff --git a/mate-core/mate-starter-encrypt/pom.xml b/mate-core/mate-starter-encrypt/pom.xml new file mode 100644 index 00000000..ae47c3e4 --- /dev/null +++ b/mate-core/mate-starter-encrypt/pom.xml @@ -0,0 +1,15 @@ + + + + mate-core + vip.mate + 1.5.8-SNAPSHOT + + 4.0.0 + + mate-starter-encrypt + + + \ No newline at end of file diff --git a/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/annotation/EnableEncrypt.java b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/annotation/EnableEncrypt.java new file mode 100644 index 00000000..71a42b6a --- /dev/null +++ b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/annotation/EnableEncrypt.java @@ -0,0 +1,17 @@ +package vip.mate.core.encrypt.annotation; + +import java.lang.annotation.*; + +/** + * Enable encrypt of the Spring Application Context + * 支持res和rsa的加密方式 + * + * @author pangu + * @since 1.5.8 + */ +@Target({ElementType.TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Inherited +public @interface EnableEncrypt { +} diff --git a/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/package-info.java b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/package-info.java new file mode 100644 index 00000000..a3a6a992 --- /dev/null +++ b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/package-info.java @@ -0,0 +1 @@ +package vip.mate.core.encrypt; \ No newline at end of file diff --git a/mate-core/pom.xml b/mate-core/pom.xml index 707904a0..3c10b4a5 100644 --- a/mate-core/pom.xml +++ b/mate-core/pom.xml @@ -42,6 +42,7 @@ mate-starter-j2cache mate-starter-mongodb mate-starter-lock + mate-starter-encrypt From 53813c1f4da5145d18743d0157dcda2851b241c7 Mon Sep 17 00:00:00 2001 From: matevip <7333791@qq.com> Date: Tue, 27 Oct 2020 20:47:54 +0800 Subject: [PATCH 13/19] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=B1=BB=E5=92=8C?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E6=B3=A8=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/encrypt/annotation/SeparateEncrypt.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/annotation/SeparateEncrypt.java diff --git a/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/annotation/SeparateEncrypt.java b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/annotation/SeparateEncrypt.java new file mode 100644 index 00000000..15fbd170 --- /dev/null +++ b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/annotation/SeparateEncrypt.java @@ -0,0 +1,15 @@ +package vip.mate.core.encrypt.annotation; + +import java.lang.annotation.*; + +/** + * 独立注解 + * 用于部分类和方法加密使用 + * + * @author pangu + */ +@Target({ElementType.TYPE, ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface SeparateEncrypt { +} From c3206b56f2d3a69cd618163cc28a90cf7d4afca0 Mon Sep 17 00:00:00 2001 From: matevip <7333791@qq.com> Date: Wed, 28 Oct 2020 17:40:13 +0800 Subject: [PATCH 14/19] =?UTF-8?q?=E6=96=B0=E5=A2=9Eaes=E5=92=8Cbase64?= =?UTF-8?q?=E4=B8=A4=E7=A7=8D=E5=8A=A0=E5=AF=86=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mate-core/mate-starter-encrypt/pom.xml | 18 ++ .../core/encrypt/config/EncryptFilter.java | 11 ++ .../vip/mate/core/encrypt/entity/RsaKey.java | 16 ++ .../mate/core/encrypt/enums/EncryptType.java | 34 ++++ .../encrypt/exception/EncryptException.java | 21 ++ .../core/encrypt/handler/EncryptHandler.java | 25 +++ .../core/encrypt/handler/InitHandler.java | 180 ++++++++++++++++++ .../handler/impl/AesEncryptHandler.java | 54 ++++++ .../handler/impl/Base64EncryptHandler.java | 22 +++ 9 files changed, 381 insertions(+) create mode 100644 mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/config/EncryptFilter.java create mode 100644 mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/entity/RsaKey.java create mode 100644 mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/enums/EncryptType.java create mode 100644 mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/exception/EncryptException.java create mode 100644 mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/handler/EncryptHandler.java create mode 100644 mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/handler/InitHandler.java create mode 100644 mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/handler/impl/AesEncryptHandler.java create mode 100644 mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/handler/impl/Base64EncryptHandler.java diff --git a/mate-core/mate-starter-encrypt/pom.xml b/mate-core/mate-starter-encrypt/pom.xml index ae47c3e4..8c6a384a 100644 --- a/mate-core/mate-starter-encrypt/pom.xml +++ b/mate-core/mate-starter-encrypt/pom.xml @@ -11,5 +11,23 @@ mate-starter-encrypt + + + javax.servlet + javax.servlet-api + provided + + + org.springframework + spring-web + provided + + + org.projectlombok + lombok + provided + + + \ No newline at end of file diff --git a/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/config/EncryptFilter.java b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/config/EncryptFilter.java new file mode 100644 index 00000000..1b601254 --- /dev/null +++ b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/config/EncryptFilter.java @@ -0,0 +1,11 @@ +package vip.mate.core.encrypt.config; + +import lombok.extern.slf4j.Slf4j; + +/** + * 加密过滤器 + * @author pangu + */ +@Slf4j +public class EncryptFilter { +} diff --git a/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/entity/RsaKey.java b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/entity/RsaKey.java new file mode 100644 index 00000000..aed39def --- /dev/null +++ b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/entity/RsaKey.java @@ -0,0 +1,16 @@ +package vip.mate.core.encrypt.entity; + +import lombok.Data; + +/** + * RSA公私钥实体类 + * + * @author pangu + */ +@Data +public class RsaKey { + + private String publicKey; + private String privateKey; + +} diff --git a/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/enums/EncryptType.java b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/enums/EncryptType.java new file mode 100644 index 00000000..a8428782 --- /dev/null +++ b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/enums/EncryptType.java @@ -0,0 +1,34 @@ +package vip.mate.core.encrypt.enums; + + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 加密类型枚举类 + * + * @author pangu + */ +@Getter +@AllArgsConstructor +public enum EncryptType { + + /** + * 基于Base64加密方式 + */ + BASE64("base64"), + /** + * 自定义加密方式 + */ + CUSTOM("自定义"), + /** + * AES对称加密 + */ + AES("对称加密,需指定秘钥"), + /** + * RSA非对称加密 + */ + RSA("非对称加密,需指定公钥和私钥"); + + private String describe; +} diff --git a/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/exception/EncryptException.java b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/exception/EncryptException.java new file mode 100644 index 00000000..5cafb760 --- /dev/null +++ b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/exception/EncryptException.java @@ -0,0 +1,21 @@ +package vip.mate.core.encrypt.exception; + +/** + * 加密自定义异常 + * + * @author pangu + */ +public class EncryptException extends RuntimeException { + + public EncryptException() { + super(); + } + + public EncryptException(String message) { + super(message); + } + + public EncryptException(String message, Throwable t) { + super(message, t); + } +} diff --git a/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/handler/EncryptHandler.java b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/handler/EncryptHandler.java new file mode 100644 index 00000000..7ebaa35d --- /dev/null +++ b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/handler/EncryptHandler.java @@ -0,0 +1,25 @@ +package vip.mate.core.encrypt.handler; + +/** + * 加密业务接口 + * + * @author pangu + */ +public interface EncryptHandler { + + /** + * 加密 + * + * @param content 加密内容 + * @return     byte数组 + */ + byte[] encode(byte[] content); + + /** + * 解密 + * + * @param content 加密内容 + * @return byte数组 + */ + byte[] decode(byte[] content); +} diff --git a/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/handler/InitHandler.java b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/handler/InitHandler.java new file mode 100644 index 00000000..9d9535c7 --- /dev/null +++ b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/handler/InitHandler.java @@ -0,0 +1,180 @@ +package vip.mate.core.encrypt.handler; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.BeanCreationException; +import org.springframework.core.annotation.AnnotationUtils; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; +import vip.mate.core.encrypt.annotation.SeparateEncrypt; + +import javax.servlet.FilterConfig; +import java.lang.reflect.Method; +import java.util.*; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.stream.Collectors; + +/** + * 初始化处理器 + * + * @author pangu + */ +@Slf4j +public class InitHandler { + + public static void handler(FilterConfig filterConfig, Set encryptCacheUri, AtomicBoolean isEncryptAnnotation) { + WebApplicationContext servletContext = WebApplicationContextUtils.getWebApplicationContext(filterConfig.getServletContext()); + Map restControllers = new HashMap<>(); + Map controllers = new HashMap<>(); + try { + controllers = servletContext.getBeansWithAnnotation(Controller.class); + } catch (BeanCreationException e) { + log.info(e.getMessage()); + } + try { + restControllers = servletContext.getBeansWithAnnotation(RestController.class); + } catch (BeanCreationException e) { + log.info(e.getMessage()); + } + + if (restControllers.size() > 0) { + List types = restControllers.values().stream().filter(v -> AnnotationUtils.findAnnotation(v.getClass(), SeparateEncrypt.class ) != null).collect(Collectors.toList()); + List notTypes = restControllers.values().stream().filter(v -> AnnotationUtils.findAnnotation(v.getClass(), SeparateEncrypt.class ) == null).collect(Collectors.toList()); + restcontrollerTypesHandler(types, encryptCacheUri); + restcontrollerNotTypesHandler(notTypes, encryptCacheUri); + } + if (controllers.size() > 0) { + List types = controllers.values().stream().filter(v -> AnnotationUtils.findAnnotation(v.getClass(), SeparateEncrypt.class ) != null).collect(Collectors.toList()); + List notTypes = controllers.values().stream().filter(v -> AnnotationUtils.findAnnotation(v.getClass(), SeparateEncrypt.class ) == null).collect(Collectors.toList()); + controllerTypesHandler(types, encryptCacheUri); + controllerNotTypesHandler(notTypes, encryptCacheUri); + } + + if (encryptCacheUri.size() > 0) { + isEncryptAnnotation.set(true); + } + } + + private static void controllerNotTypesHandler(List types, Set cacheUrl) { + if (types.size() > 0) { + types.stream().forEach(t -> { + Class aClass = t.getClass(); + Method[] declaredMethods = aClass.getDeclaredMethods(); + String[] finalTypeUrl = typeUrl(aClass); + List methods = Arrays.stream(declaredMethods).filter(d -> AnnotationUtils.findAnnotation(d, SeparateEncrypt.class) != null).collect(Collectors.toList()); + if (methods.size() == 0) { + return; + } + MethodHandler(methods, finalTypeUrl, cacheUrl); + }); + } + } + + private static void controllerTypesHandler(List types, Set cacheUrl) { + if (types.size() > 0) { + types.stream().forEach(t -> { + Class aClass = t.getClass(); + Method[] declaredMethods = aClass.getDeclaredMethods(); + String[] finalTypeUrl = typeUrl(aClass); + if (declaredMethods.length == 0) { + return; + } + List methods = Arrays.asList(declaredMethods); + MethodHandler(methods, finalTypeUrl, cacheUrl); + }); + } + } + + + private static void restcontrollerNotTypesHandler(List types, Set cacheUrl) { + if (types.size() > 0) { + types.stream().forEach(t -> { + Class aClass = t.getClass(); + Method[] declaredMethods = aClass.getDeclaredMethods(); + String[] finalTypeUrl = typeUrl(aClass); + List methods = Arrays.stream(declaredMethods).filter(d -> AnnotationUtils.findAnnotation(d, SeparateEncrypt.class) != null).collect(Collectors.toList()); + if (methods.size() == 0) { + return; + } + restMethodHandler(methods, finalTypeUrl, cacheUrl); + }); + } + } + + private static void restcontrollerTypesHandler(List types, Set cacheUrl) { + if (types.size() > 0) { + types.stream().forEach(t -> { + Class aClass = t.getClass(); + Method[] declaredMethods = aClass.getDeclaredMethods(); + String[] finalTypeUrl = typeUrl(aClass); + if (declaredMethods.length == 0) { + return; + } + List methods = Arrays.asList(declaredMethods); + restMethodHandler(methods, finalTypeUrl, cacheUrl); + }); + } + } + + private static String[] typeUrl(Class aClass) { + String[] typeUrl = null; + if (AnnotationUtils.findAnnotation(aClass, RequestMapping.class) != null) { + typeUrl = AnnotationUtils.findAnnotation(aClass, RequestMapping.class).value(); + } + return typeUrl; + } + + private static void restMethodHandler(List methods, String[] finalTypeUrl, Set cacheUrl) { + methods.forEach(m -> { + if (AnnotationUtils.findAnnotation(m, PostMapping.class) != null || (AnnotationUtils.findAnnotation(m, RequestMapping.class) != null + && Arrays.stream(AnnotationUtils.findAnnotation(m, RequestMapping.class).method()).allMatch(r -> !r.equals(RequestMethod.GET)))) { + urlHandler(m, finalTypeUrl, cacheUrl); + } + }); + } + + private static void MethodHandler(List methods, String[] finalTypeUrl, Set cacheUrl) { + methods.forEach(m -> { + if ((AnnotationUtils.findAnnotation(m, PostMapping.class) != null && AnnotationUtils.findAnnotation(m, ResponseBody.class) != null) || (AnnotationUtils.findAnnotation(m, RequestMapping.class) != null + && Arrays.stream(AnnotationUtils.findAnnotation(m, RequestMapping.class).method()).allMatch(r -> !r.equals(RequestMethod.GET)) && AnnotationUtils.findAnnotation(m, ResponseBody.class) != null)) { + urlHandler(m, finalTypeUrl, cacheUrl); + } + }); + } + + private static void urlHandler(Method m, String[] finalTypeUrl, Set cacheUrl) { + String[] urls = null; + if (AnnotationUtils.findAnnotation(m, PostMapping.class) != null) { + urls = AnnotationUtils.findAnnotation(m, PostMapping.class).value(); + } else { + urls = AnnotationUtils.findAnnotation(m, RequestMapping.class).value(); + } + if (urls != null) { + Arrays.stream(urls).forEach(u -> { + if (!u.startsWith("/")) { + u = "/".concat(u); + } + if (finalTypeUrl != null && finalTypeUrl.length > 0) { + String finalU = u; + Arrays.stream(finalTypeUrl).forEach(f -> { + if (!f.startsWith("/")) { + f = "/".concat(f); + } + String uri = f.concat(finalU).replaceAll("//+", "/"); + if (uri.endsWith("/")) { + uri = uri.substring(0, uri.length() - 1); + } + cacheUrl.add(uri); + }); + } else { + String uri = u.replaceAll("//+", "/"); + if (uri.endsWith("/")) { + uri = uri.substring(0, uri.length() - 1); + } + cacheUrl.add(uri); + } + }); + } + } +} diff --git a/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/handler/impl/AesEncryptHandler.java b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/handler/impl/AesEncryptHandler.java new file mode 100644 index 00000000..041419f8 --- /dev/null +++ b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/handler/impl/AesEncryptHandler.java @@ -0,0 +1,54 @@ +package vip.mate.core.encrypt.handler.impl; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.util.Base64Utils; +import vip.mate.core.encrypt.handler.EncryptHandler; + +import javax.crypto.Cipher; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; + +/** + * AES加密处理器 + * + * @author pangu + */ +@Slf4j +public class AesEncryptHandler implements EncryptHandler { + + private String secret; + + private static final String VIPARA = "0102030405060708"; + private static final String KEY_ALGORITHM = "AES"; + + @Override + public byte[] encode(byte[] content) { + try { + IvParameterSpec zeroIv = new IvParameterSpec(VIPARA.getBytes()); + SecretKeySpec key = new SecretKeySpec(secret.getBytes(), KEY_ALGORITHM); + Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); + cipher.init(Cipher.ENCRYPT_MODE, key, zeroIv); + byte[] byte_AES = cipher.doFinal(content); + return Base64Utils.encode(byte_AES); + } catch (Exception e) { + log.error(e.getMessage()); + } + return new byte[0]; + } + + @Override + public byte[] decode(byte[] content) { + try { + IvParameterSpec zeroIv = new IvParameterSpec(VIPARA.getBytes()); + SecretKeySpec key = new SecretKeySpec(secret.getBytes(), KEY_ALGORITHM); + Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); + cipher.init(Cipher.DECRYPT_MODE, key, zeroIv); + byte[] byte_content = Base64Utils.decode(content); + byte[] byte_decode = cipher.doFinal(byte_content); + return byte_decode; + } catch (Exception e) { + log.error(e.getMessage()); + } + return new byte[0]; + } +} diff --git a/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/handler/impl/Base64EncryptHandler.java b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/handler/impl/Base64EncryptHandler.java new file mode 100644 index 00000000..d43bfb5f --- /dev/null +++ b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/handler/impl/Base64EncryptHandler.java @@ -0,0 +1,22 @@ +package vip.mate.core.encrypt.handler.impl; + +import org.springframework.util.Base64Utils; +import vip.mate.core.encrypt.handler.EncryptHandler; + +/** + * Base64加密处理器 + * + * @author pangu + */ +public class Base64EncryptHandler implements EncryptHandler { + + @Override + public byte[] encode(byte[] content) { + return Base64Utils.encode(content); + } + + @Override + public byte[] decode(byte[] content) { + return Base64Utils.decode(content); + } +} From 78bf8b68306cfd5954746cc0a4cc6aab8e8c1146 Mon Sep 17 00:00:00 2001 From: matevip <7333791@qq.com> Date: Thu, 29 Oct 2020 07:21:32 +0800 Subject: [PATCH 15/19] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=8A=A0=E5=AF=86?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E7=9A=84=E5=8C=85=E8=A3=85=E5=99=A8=E5=92=8C?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../encrypt/annotation/EnableEncrypt.java | 5 + .../encrypt/config/EncryptConfiguration.java | 89 +++++++++ .../core/encrypt/config/EncryptFilter.java | 86 ++++++++- .../encrypt/config/EncryptRequestWrapper.java | 71 +++++++ .../config/EncryptResponseWrapper.java | 52 +++++ .../core/encrypt/config/WebConfiguration.java | 46 +++++ .../handler/impl/AesEncryptHandler.java | 23 +-- .../handler/impl/RsaEncryptHandler.java | 178 ++++++++++++++++++ .../main/resources/META-INF/spring.factories | 4 + 9 files changed, 542 insertions(+), 12 deletions(-) create mode 100644 mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/config/EncryptConfiguration.java create mode 100644 mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/config/EncryptRequestWrapper.java create mode 100644 mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/config/EncryptResponseWrapper.java create mode 100644 mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/config/WebConfiguration.java create mode 100644 mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/handler/impl/RsaEncryptHandler.java create mode 100644 mate-core/mate-starter-encrypt/src/main/resources/META-INF/spring.factories diff --git a/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/annotation/EnableEncrypt.java b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/annotation/EnableEncrypt.java index 71a42b6a..5ac5a7de 100644 --- a/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/annotation/EnableEncrypt.java +++ b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/annotation/EnableEncrypt.java @@ -1,5 +1,9 @@ package vip.mate.core.encrypt.annotation; +import org.springframework.context.annotation.Import; +import vip.mate.core.encrypt.config.EncryptConfiguration; +import vip.mate.core.encrypt.config.WebConfiguration; + import java.lang.annotation.*; /** @@ -13,5 +17,6 @@ @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited +@Import({EncryptConfiguration.class, WebConfiguration.class}) public @interface EnableEncrypt { } diff --git a/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/config/EncryptConfiguration.java b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/config/EncryptConfiguration.java new file mode 100644 index 00000000..cc2d8b70 --- /dev/null +++ b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/config/EncryptConfiguration.java @@ -0,0 +1,89 @@ +package vip.mate.core.encrypt.config; + +import lombok.Data; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.BeanFactoryPostProcessor; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.beans.factory.support.DefaultListableBeanFactory; +import org.springframework.beans.factory.support.GenericBeanDefinition; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.EnvironmentAware; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; +import vip.mate.core.encrypt.enums.EncryptType; +import vip.mate.core.encrypt.exception.EncryptException; +import vip.mate.core.encrypt.handler.EncryptHandler; +import vip.mate.core.encrypt.handler.impl.AesEncryptHandler; +import vip.mate.core.encrypt.handler.impl.Base64EncryptHandler; +import vip.mate.core.encrypt.handler.impl.RsaEncryptHandler; + +/** + * 加密配置 + * + * @author pangu + */ +@Data +@Configuration +@EnableAutoConfiguration +public class EncryptConfiguration implements ApplicationContextAware, BeanFactoryPostProcessor, EnvironmentAware { + private ApplicationContext applicationContext; + private Environment environment; + + @Override + public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException { + DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) configurableListableBeanFactory; + GenericBeanDefinition bean = new GenericBeanDefinition(); + EncryptType type = environment.getProperty("encrypt.type", EncryptType.class); + String secret = environment.getProperty("encrypt.secret", String.class); + String publicKey = environment.getProperty("encrypt.publicKey", String.class); + String privateKey = environment.getProperty("encrypt.privateKey", String.class); + Boolean debug = environment.getProperty("encrypt.debug", boolean.class); + if (debug != null && debug) { + return; + } + if (type == null) { + throw new EncryptException("没有定义加密类型(No encryption type is defined)"); + } + switch (type) { + case BASE64: + bean.setBeanClass(Base64EncryptHandler.class); + bean.setPrimary(true); + beanFactory.registerBeanDefinition("encryptHandler", bean); + break; + case AES: + if (secret == null || "".equals(secret.trim())) { + throw new EncryptException("没有定义秘钥(No secret key is defined)"); + } + bean.setBeanClass(AesEncryptHandler.class); + bean.getPropertyValues().add("secret", secret); + bean.setPrimary(true); + beanFactory.registerBeanDefinition("encryptHandler", bean); + break; + case RSA: + if (publicKey == null || "".equals(publicKey.trim())) { + throw new EncryptException("没有定义公钥(No publicKey is defined)"); + } + if (privateKey == null || "".equals(privateKey.trim())) { + throw new EncryptException("没有定义私钥(No privateKey is defined)"); + } + bean.setBeanClass(RsaEncryptHandler.class); + bean.getPropertyValues().add("publicKey", publicKey); + bean.getPropertyValues().add("privateKey", privateKey); + bean.setPrimary(true); + beanFactory.registerBeanDefinition("encryptHandler", bean); + break; + case CUSTOM: + try { + beanFactory.getBean(EncryptHandler.class); + } catch (Exception e) { + throw new EncryptException("没有自定义加密处理器(No custom encryption processor)"); + } + break; + default: + break; + } + } + +} diff --git a/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/config/EncryptFilter.java b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/config/EncryptFilter.java index 1b601254..3bb3b535 100644 --- a/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/config/EncryptFilter.java +++ b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/config/EncryptFilter.java @@ -1,11 +1,95 @@ package vip.mate.core.encrypt.config; import lombok.extern.slf4j.Slf4j; +import org.springframework.http.MediaType; +import vip.mate.core.encrypt.handler.EncryptHandler; +import vip.mate.core.encrypt.handler.InitHandler; + +import javax.servlet.*; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.net.URLEncoder; +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; /** * 加密过滤器 + * * @author pangu */ @Slf4j -public class EncryptFilter { +public class EncryptFilter implements Filter { + + private EncryptHandler encryptHandler; + + private static AtomicBoolean isEncryptAnnotation = new AtomicBoolean(false); + private final static Set encryptCacheUri = new HashSet<>(); + + public EncryptFilter(EncryptHandler encryptHandler) { + this.encryptHandler = encryptHandler; + } + + @Override + public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { + if (this.isEncryptAnnotation.get()) { + if (checkUri(((HttpServletRequest) servletRequest).getRequestURI())) { + this.chain(servletRequest, servletResponse, filterChain); + } else { + filterChain.doFilter(servletRequest, servletResponse); + } + } else { + HttpServletRequest request = (HttpServletRequest) servletRequest; + String contentType = request.getContentType(); + if (request.getRequestURI().startsWith("/actuator") || contentType == null || !contentType.toLowerCase().equals(MediaType.APPLICATION_JSON_VALUE)) { + filterChain.doFilter(servletRequest, servletResponse); + } else { + this.chain(servletRequest, servletResponse, filterChain); + } + } + } + + private void chain(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { + EncryptRequestWrapper request = new EncryptRequestWrapper((HttpServletRequest) servletRequest, encryptHandler); + EncryptResponseWrapper response = new EncryptResponseWrapper((HttpServletResponse) servletResponse); + filterChain.doFilter(request, response); + byte[] responseData = response.getResponseData(); + if (responseData.length == 0) { + return; + } + log.info("接收的报文:" + new String(responseData)); + byte[] encryptByte = encryptHandler.encode(URLEncoder.encode(new String(responseData), "UTF-8").getBytes()); + log.info("加密后的报文:" + new String(encryptByte)); + servletResponse.setContentLength(-1); + servletResponse.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE); + ServletOutputStream outputStream = servletResponse.getOutputStream(); + log.info("outputStream: " + outputStream.toString()); + outputStream.write(encryptByte); + outputStream.flush(); + } + + + private boolean checkUri(String uri) { + uri = uri.replaceAll("//+", "/"); + if (uri.endsWith("/")) { + uri = uri.substring(0, uri.length() - 1); + } + if (encryptCacheUri.contains(uri)) { + return true; + } + return false; + } + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + InitHandler.handler(filterConfig, encryptCacheUri, isEncryptAnnotation); + } + + + @Override + public void destroy() { + + } + } diff --git a/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/config/EncryptRequestWrapper.java b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/config/EncryptRequestWrapper.java new file mode 100644 index 00000000..8ff6794b --- /dev/null +++ b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/config/EncryptRequestWrapper.java @@ -0,0 +1,71 @@ +package vip.mate.core.encrypt.config; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.MediaType; +import vip.mate.core.encrypt.handler.EncryptHandler; + +import javax.servlet.ReadListener; +import javax.servlet.ServletException; +import javax.servlet.ServletInputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletRequestWrapper; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.net.URLDecoder; + +/** + * 加密请求包装器 + * + * @author pangu + */ +@Slf4j +public class EncryptRequestWrapper extends HttpServletRequestWrapper { + + private byte[] body; + private EncryptHandler encryptHandler; + + public EncryptRequestWrapper(HttpServletRequest request, EncryptHandler encryptHandler) throws IOException, ServletException { + super(request); + this.encryptHandler = encryptHandler; + if (!request.getContentType().toLowerCase().equals(MediaType.APPLICATION_JSON_VALUE) && !request.getContentType().toLowerCase().equals(MediaType.APPLICATION_JSON_UTF8_VALUE.toLowerCase())) { + throw new ServletException("contentType error"); + } + ServletInputStream inputStream = request.getInputStream(); + int contentLength = Integer.parseInt(request.getHeader("Content-Length")); + byte[] bytes = new byte[contentLength]; + int readCount = 0; + while (readCount < contentLength) { + readCount += inputStream.read(bytes, readCount, contentLength - readCount); + } + body = bytes; + } + + @Override + public ServletInputStream getInputStream() throws IOException { + log.info("接收到的请求密文:" + new String(body)); + byte[] decode = encryptHandler.decode(body); + String urlDecodeStr = URLDecoder.decode(new String(decode), "UTF-8"); + log.info("解密后的报文:" + urlDecodeStr); + final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(urlDecodeStr.getBytes()); + return new ServletInputStream() { + @Override + public boolean isFinished() { + return byteArrayInputStream.available() == 0; + } + + @Override + public boolean isReady() { + return true; + } + + @Override + public void setReadListener(ReadListener readListener) { + } + + @Override + public int read() throws IOException { + return byteArrayInputStream.read(); + } + }; + } +} diff --git a/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/config/EncryptResponseWrapper.java b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/config/EncryptResponseWrapper.java new file mode 100644 index 00000000..8ebd1fc6 --- /dev/null +++ b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/config/EncryptResponseWrapper.java @@ -0,0 +1,52 @@ +package vip.mate.core.encrypt.config; + +import javax.servlet.ServletOutputStream; +import javax.servlet.WriteListener; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpServletResponseWrapper; +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +/** + * 加密响应包装器 + * + * @author pangu + */ +public class EncryptResponseWrapper extends HttpServletResponseWrapper { + + private ServletOutputStream filterOutput; + private ByteArrayOutputStream output; + + public EncryptResponseWrapper(HttpServletResponse response) { + super(response); + output = new ByteArrayOutputStream(); + } + + + @Override + public ServletOutputStream getOutputStream() throws IOException { + if (filterOutput == null) { + filterOutput = new ServletOutputStream() { + @Override + public void write(int b) throws IOException { + output.write(b); + } + + @Override + public boolean isReady() { + return false; + } + + @Override + public void setWriteListener(WriteListener writeListener) { + } + }; + } + + return filterOutput; + } + + public byte[] getResponseData() { + return output.toByteArray(); + } +} diff --git a/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/config/WebConfiguration.java b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/config/WebConfiguration.java new file mode 100644 index 00000000..0ecd567e --- /dev/null +++ b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/config/WebConfiguration.java @@ -0,0 +1,46 @@ +package vip.mate.core.encrypt.config; + +import lombok.AllArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.web.servlet.FilterRegistrationBean; +import org.springframework.context.annotation.*; +import org.springframework.core.env.Environment; +import org.springframework.core.type.AnnotatedTypeMetadata; +import vip.mate.core.encrypt.handler.EncryptHandler; + +/** + * web配置 + * + * @author pangu + */ +@Configuration +@AllArgsConstructor +public class WebConfiguration { + + @Autowired(required = false) + private final EncryptHandler encryptHandler; + + Environment environment; + + + @Bean + @Conditional(DefaultCondition.class) + public FilterRegistrationBean filterRegistrationBean() { + Integer order = environment.getProperty("encrypt.order", Integer.class); + FilterRegistrationBean bean = new FilterRegistrationBean(); + bean.setFilter(new EncryptFilter(encryptHandler)); + bean.addUrlPatterns("/*"); + bean.setName("encryptFilter"); + bean.setOrder(order == null ? 0 : order); + return bean; + } + + static class DefaultCondition implements Condition { + @Override + public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) { + Environment environment = conditionContext.getEnvironment(); + Boolean debug = environment.getProperty("encrypt.debug", Boolean.class); + return debug == null || !debug; + } + } +} diff --git a/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/handler/impl/AesEncryptHandler.java b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/handler/impl/AesEncryptHandler.java index 041419f8..1be8eda9 100644 --- a/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/handler/impl/AesEncryptHandler.java +++ b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/handler/impl/AesEncryptHandler.java @@ -1,7 +1,9 @@ package vip.mate.core.encrypt.handler.impl; +import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.springframework.util.Base64Utils; +import vip.mate.core.encrypt.exception.EncryptException; import vip.mate.core.encrypt.handler.EncryptHandler; import javax.crypto.Cipher; @@ -13,42 +15,41 @@ * * @author pangu */ +@Data @Slf4j public class AesEncryptHandler implements EncryptHandler { private String secret; - private static final String VIPARA = "0102030405060708"; + private static final String IV_PARA = "0102030405060708"; private static final String KEY_ALGORITHM = "AES"; @Override public byte[] encode(byte[] content) { try { - IvParameterSpec zeroIv = new IvParameterSpec(VIPARA.getBytes()); + IvParameterSpec zeroIv = new IvParameterSpec(IV_PARA.getBytes()); SecretKeySpec key = new SecretKeySpec(secret.getBytes(), KEY_ALGORITHM); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, key, zeroIv); - byte[] byte_AES = cipher.doFinal(content); - return Base64Utils.encode(byte_AES); + byte[] byteAes = cipher.doFinal(content); + return Base64Utils.encode(byteAes); } catch (Exception e) { log.error(e.getMessage()); + throw new EncryptException("rsa加密错误", e); } - return new byte[0]; } @Override public byte[] decode(byte[] content) { try { - IvParameterSpec zeroIv = new IvParameterSpec(VIPARA.getBytes()); + IvParameterSpec zeroIv = new IvParameterSpec(IV_PARA.getBytes()); SecretKeySpec key = new SecretKeySpec(secret.getBytes(), KEY_ALGORITHM); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, key, zeroIv); - byte[] byte_content = Base64Utils.decode(content); - byte[] byte_decode = cipher.doFinal(byte_content); - return byte_decode; + byte[] byteContent = Base64Utils.decode(content); + return cipher.doFinal(byteContent); } catch (Exception e) { - log.error(e.getMessage()); + throw new EncryptException("rsa加密错误", e); } - return new byte[0]; } } diff --git a/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/handler/impl/RsaEncryptHandler.java b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/handler/impl/RsaEncryptHandler.java new file mode 100644 index 00000000..2f44f2c1 --- /dev/null +++ b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/handler/impl/RsaEncryptHandler.java @@ -0,0 +1,178 @@ +package vip.mate.core.encrypt.handler.impl; + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.springframework.util.Base64Utils; +import vip.mate.core.encrypt.entity.RsaKey; +import vip.mate.core.encrypt.exception.EncryptException; +import vip.mate.core.encrypt.handler.EncryptHandler; + +import javax.crypto.BadPaddingException; +import javax.crypto.Cipher; +import javax.crypto.IllegalBlockSizeException; +import java.io.ByteArrayOutputStream; +import java.security.*; +import java.security.interfaces.RSAPrivateKey; +import java.security.interfaces.RSAPublicKey; +import java.security.spec.PKCS8EncodedKeySpec; +import java.security.spec.X509EncodedKeySpec; +import java.util.HashMap; +import java.util.Map; + +/** + * RSA加密处理器 + * + * @author pangu + */ +@Data +@Slf4j +public class RsaEncryptHandler implements EncryptHandler { + + private static final String KEY_ALGORITHM = "RSA"; + private static final int KEY_SIZE = 1024; + private static final String PUBLIC_KEY = "RSAPublicKey"; + private static final String PRIVATE_KEY = "RSAPrivateKey"; + private static final int MAX_ENCODE_BLOCK = (KEY_SIZE / 8) - 11; + private static final int MAX_DECODE_BLOCK = KEY_SIZE / 8; + private String publicKey; + private String privateKey; + + @Override + public byte[] encode(byte[] content) { + try { + byte[] bytes = encryptByPublicKey(content, Base64Utils.decodeFromString(publicKey)); + return bytes; + } catch (Exception e) { + log.error(e.getMessage()); + throw new EncryptException("rsa加密错误", e); + } + } + + @Override + public byte[] decode(byte[] content) { + try { + byte[] bytes = decryptByPrivateKey(Base64Utils.decode(content), Base64Utils.decodeFromString(privateKey)); + return bytes; + } catch (Exception e) { + log.error(e.getMessage()); + throw new EncryptException("rsa解密错误", e); + } + } + public static RsaKey getRsaKeys() throws Exception { + Map keyMap = initKey(); + byte[] publicKey = getPublicKey(keyMap); + byte[] privateKey = getPrivateKey(keyMap); + RsaKey rsaKey = new RsaKey(); + rsaKey.setPublicKey(Base64Utils.encodeToString(publicKey)); + rsaKey.setPrivateKey(Base64Utils.encodeToString(privateKey)); + return rsaKey; + } + + private static Map initKey() throws Exception { + KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(KEY_ALGORITHM); + keyPairGenerator.initialize(KEY_SIZE); + KeyPair keyPair = keyPairGenerator.generateKeyPair(); + RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic(); + RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate(); + Map keyMap = new HashMap(); + keyMap.put(PUBLIC_KEY, publicKey); + keyMap.put(PRIVATE_KEY, privateKey); + return keyMap; + + } + + private static byte[] encryptByPrivateKey(byte[] data, byte[] key) throws Exception { + byte[] encryptedData = new byte[0]; + if (data.length == 0) { + return encryptedData; + } + try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { + PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(key); + KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); + PrivateKey privateKey = keyFactory.generatePrivate(pkcs8KeySpec); + Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm()); + cipher.init(Cipher.ENCRYPT_MODE, privateKey); + + encryptedData = Base64Utils.encode(doFinal(data, cipher, out, MAX_ENCODE_BLOCK)); + } + return encryptedData; + } + + private static byte[] encryptByPublicKey(byte[] data, byte[] key) throws Exception { + byte[] encryptedData = new byte[0]; + if (data.length == 0) { + return encryptedData; + } + try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { + KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); + X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(key); + PublicKey pubKey = keyFactory.generatePublic(x509KeySpec); + Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm()); + cipher.init(Cipher.ENCRYPT_MODE, pubKey); + + encryptedData = Base64Utils.encode(doFinal(data, cipher, out, MAX_ENCODE_BLOCK)); + } + return encryptedData; + } + + private static byte[] decryptByPrivateKey(byte[] data, byte[] key) throws Exception { + byte[] encryptedData = new byte[0]; + if (data.length == 0) { + return encryptedData; + } + try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { + PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(key); + KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); + PrivateKey privateKey = keyFactory.generatePrivate(pkcs8KeySpec); + Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm()); + cipher.init(Cipher.DECRYPT_MODE, privateKey); + + encryptedData = doFinal(data, cipher, out, MAX_DECODE_BLOCK); + } + return encryptedData; + } + + private static byte[] decryptByPublicKey(byte[] data, byte[] key) throws Exception { + byte[] encryptedData = new byte[0]; + if (data.length == 0) { + return encryptedData; + } + try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { + KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); + X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(key); + PublicKey pubKey = keyFactory.generatePublic(x509KeySpec); + Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm()); + cipher.init(Cipher.DECRYPT_MODE, pubKey); + + encryptedData = doFinal(data, cipher, out, MAX_DECODE_BLOCK); + } + return encryptedData; + } + + private static byte[] getPrivateKey(Map keyMap) { + Key key = (Key) keyMap.get(PRIVATE_KEY); + return key.getEncoded(); + } + + private static byte[] getPublicKey(Map keyMap) throws Exception { + Key key = (Key) keyMap.get(PUBLIC_KEY); + return key.getEncoded(); + } + private static byte[] doFinal(byte[] data, Cipher cipher, ByteArrayOutputStream out, int MAX_BLOCK) throws BadPaddingException, IllegalBlockSizeException { + int inputLen = data.length; + int offSet = 0; + byte[] cache; + int i = 0; + while (inputLen - offSet > 0) { + if (inputLen - offSet > MAX_BLOCK) { + cache = cipher.doFinal(data, offSet, MAX_BLOCK); + } else { + cache = cipher.doFinal(data, offSet, inputLen - offSet); + } + out.write(cache, 0, cache.length); + i++; + offSet = i * MAX_BLOCK; + } + return out.toByteArray(); + } +} diff --git a/mate-core/mate-starter-encrypt/src/main/resources/META-INF/spring.factories b/mate-core/mate-starter-encrypt/src/main/resources/META-INF/spring.factories new file mode 100644 index 00000000..bef5828e --- /dev/null +++ b/mate-core/mate-starter-encrypt/src/main/resources/META-INF/spring.factories @@ -0,0 +1,4 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + vip.mate.core.encrypt.config.WebConfiguration + + From 988ebcfad67d50ad489a78a7904ba9dd4c29a601 Mon Sep 17 00:00:00 2001 From: matevip <7333791@qq.com> Date: Fri, 30 Oct 2020 17:23:36 +0800 Subject: [PATCH 16/19] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=BD=91=E5=85=B3?= =?UTF-8?q?=E5=AF=B9=E6=9C=8D=E5=8A=A1=E6=A8=A1=E5=9D=97=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E9=89=B4=E6=9D=83=E6=93=8D=E4=BD=9C=EF=BC=8C=E7=8E=B0=E5=B7=B2?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=A8=A1=E5=9D=97=E9=89=B4=E6=9D=83=E5=92=8C?= =?UTF-8?q?=E7=BD=91=E5=85=B3=E7=BB=9F=E4=B8=80=E9=89=B4=E6=9D=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/nacos/mate-dev.yaml | 8 +- doc/nacos/mate-local.yaml | 6 ++ doc/nacos/mate-prod.yaml | 6 ++ doc/nacos/mate-test.yaml | 6 ++ .../core/cloud/props/MateUaaProperties.java | 62 ++++++++++++ .../core/common/constant/MateConstant.java | 5 + .../mate/core/common/util/ResponseUtil.java | 69 +++++++------ .../vip/mate/core/encrypt/package-info.java | 1 - .../mate/gateway/config/PreRequestConfig.java | 3 +- .../vip/mate/gateway/filter/UaaFilter.java | 96 +++++++++++++++++++ 10 files changed, 228 insertions(+), 34 deletions(-) create mode 100644 mate-core/mate-starter-cloud/src/main/java/vip/mate/core/cloud/props/MateUaaProperties.java delete mode 100644 mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/package-info.java create mode 100644 mate-gateway/src/main/java/vip/mate/gateway/filter/UaaFilter.java diff --git a/doc/nacos/mate-dev.yaml b/doc/nacos/mate-dev.yaml index cb19ffae..0012c1bd 100644 --- a/doc/nacos/mate-dev.yaml +++ b/doc/nacos/mate-dev.yaml @@ -25,4 +25,10 @@ mate: preview: enable: false tenant: - enable: false \ No newline at end of file + enable: false + uaa: + enable: false + ignore-url: + - /auth/login/** + - /auth/callback/** + - /auth/sms-code \ No newline at end of file diff --git a/doc/nacos/mate-local.yaml b/doc/nacos/mate-local.yaml index 1509e828..0cda9918 100644 --- a/doc/nacos/mate-local.yaml +++ b/doc/nacos/mate-local.yaml @@ -26,3 +26,9 @@ mate: enable: false tenant: enable: false + uaa: + enable: false + ignore-url: + - /auth/login/** + - /auth/callback/** + - /auth/sms-code diff --git a/doc/nacos/mate-prod.yaml b/doc/nacos/mate-prod.yaml index 1509e828..0012c1bd 100644 --- a/doc/nacos/mate-prod.yaml +++ b/doc/nacos/mate-prod.yaml @@ -26,3 +26,9 @@ mate: enable: false tenant: enable: false + uaa: + enable: false + ignore-url: + - /auth/login/** + - /auth/callback/** + - /auth/sms-code \ No newline at end of file diff --git a/doc/nacos/mate-test.yaml b/doc/nacos/mate-test.yaml index 1509e828..0012c1bd 100644 --- a/doc/nacos/mate-test.yaml +++ b/doc/nacos/mate-test.yaml @@ -26,3 +26,9 @@ mate: enable: false tenant: enable: false + uaa: + enable: false + ignore-url: + - /auth/login/** + - /auth/callback/** + - /auth/sms-code \ No newline at end of file diff --git a/mate-core/mate-starter-cloud/src/main/java/vip/mate/core/cloud/props/MateUaaProperties.java b/mate-core/mate-starter-cloud/src/main/java/vip/mate/core/cloud/props/MateUaaProperties.java new file mode 100644 index 00000000..9cfccfb0 --- /dev/null +++ b/mate-core/mate-starter-cloud/src/main/java/vip/mate/core/cloud/props/MateUaaProperties.java @@ -0,0 +1,62 @@ +package vip.mate.core.cloud.props; + +import lombok.Getter; +import lombok.Setter; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.cloud.context.config.annotation.RefreshScope; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * 验证权限配置 + * + * @author pangu + * @date 2020-10-28 + */ +@Setter +@RefreshScope +@ConfigurationProperties(prefix = "mate.uaa") +public class MateUaaProperties { + + /** + * 忽略URL,List列表形式 + */ + private List ignoreUrl = new ArrayList<>(); + + /** + * 是否启用网关鉴权模式 + */ + private Boolean enable = false; + + /** + * 监控中心和swagger需要访问的url + */ + private static final String[] ENDPOINTS = { + "/oauth/**", + "/actuator/**", + "/*/v2/api-docs", + "/swagger/api-docs", + "/swagger-ui.html", + "/doc.html", + "/swagger-resources/**", + "/webjars/**", + "/druid/**", + "/auth/logout", + "/auth/code" + }; + + /** + * 自定义getter方法,并将ENDPOINTS加入至忽略URL列表 + * @return List + */ + public List getIgnoreUrl() { + Collections.addAll(ignoreUrl, ENDPOINTS); + return ignoreUrl; + } + + public Boolean getEnable() { + return enable; + } +} diff --git a/mate-core/mate-starter-common/src/main/java/vip/mate/core/common/constant/MateConstant.java b/mate-core/mate-starter-common/src/main/java/vip/mate/core/common/constant/MateConstant.java index 503c2af2..1995ca8e 100644 --- a/mate-core/mate-starter-common/src/main/java/vip/mate/core/common/constant/MateConstant.java +++ b/mate-core/mate-starter-common/src/main/java/vip/mate/core/common/constant/MateConstant.java @@ -74,5 +74,10 @@ public class MateConstant { */ public static final String MATE_API_RESOURCE = "mate-api-resource"; + /** + * 权限认证的排序 + */ + public static final int MATE_UAA_FILTER_ORDER = -200; + } diff --git a/mate-core/mate-starter-common/src/main/java/vip/mate/core/common/util/ResponseUtil.java b/mate-core/mate-starter-common/src/main/java/vip/mate/core/common/util/ResponseUtil.java index 7ef15ba7..0d9e9ecd 100644 --- a/mate-core/mate-starter-common/src/main/java/vip/mate/core/common/util/ResponseUtil.java +++ b/mate-core/mate-starter-common/src/main/java/vip/mate/core/common/util/ResponseUtil.java @@ -6,42 +6,49 @@ import org.springframework.http.HttpStatus; import org.springframework.http.server.reactive.ServerHttpResponse; import reactor.core.publisher.Mono; +import vip.mate.core.common.api.Result; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +/** + * 响应工具 + * + * @author pangu + */ public class ResponseUtil { - /** - * 设置响应 - * - * @param response HttpServletResponse - * @param contentType content-type - * @param status http状态码 - * @param value 响应内容 - * @throws IOException IOException - */ - public static void responseWriter(HttpServletResponse response, String contentType, - int status, Object value) throws IOException { - response.setContentType(contentType); - response.setStatus(status); - response.getOutputStream().write(JSONObject.toJSONString(value).getBytes()); - } + /** + * 设置响应 + * + * @param response HttpServletResponse + * @param contentType content-type + * @param status http状态码 + * @param value 响应内容 + * @throws IOException IOException + */ + public static void responseWriter(HttpServletResponse response, String contentType, + int status, Object value) throws IOException { + response.setContentType(contentType); + response.setStatus(status); + response.getOutputStream().write(JSONObject.toJSONString(value).getBytes()); + } - /** - * 设置webflux模型响应 - * - * @param response ServerHttpResponse - * @param contentType content-type - * @param status http状态码 - * @param value 响应内容 - * @return Mono - */ - public static Mono webFluxResponseWriter(ServerHttpResponse response, String contentType, - HttpStatus status, Object value) { - response.setStatusCode(status); - response.getHeaders().add(HttpHeaders.CONTENT_TYPE, contentType); - DataBuffer dataBuffer = response.bufferFactory().wrap(JSONObject.toJSONString(value).getBytes()); - return response.writeWith(Mono.just(dataBuffer)); - } + /** + * 设置webflux模型响应 + * + * @param response ServerHttpResponse + * @param contentType content-type + * @param status http状态码 + * @param value 响应内容 + * @return Mono + */ + public static Mono webFluxResponseWriter(ServerHttpResponse response, String contentType, + HttpStatus status, Object value) { + response.setStatusCode(status); + response.getHeaders().add(HttpHeaders.CONTENT_TYPE, contentType); + Result result = Result.fail(status.value(), value.toString()); + DataBuffer dataBuffer = response.bufferFactory().wrap(JSONObject.toJSONString(result).getBytes()); + return response.writeWith(Mono.just(dataBuffer)); + } } diff --git a/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/package-info.java b/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/package-info.java deleted file mode 100644 index a3a6a992..00000000 --- a/mate-core/mate-starter-encrypt/src/main/java/vip/mate/core/encrypt/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package vip.mate.core.encrypt; \ No newline at end of file diff --git a/mate-gateway/src/main/java/vip/mate/gateway/config/PreRequestConfig.java b/mate-gateway/src/main/java/vip/mate/gateway/config/PreRequestConfig.java index f2482912..19b15a93 100644 --- a/mate-gateway/src/main/java/vip/mate/gateway/config/PreRequestConfig.java +++ b/mate-gateway/src/main/java/vip/mate/gateway/config/PreRequestConfig.java @@ -3,6 +3,7 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Configuration; import vip.mate.core.cloud.props.MateRequestProperties; +import vip.mate.core.cloud.props.MateUaaProperties; /** * 预请求配置 @@ -10,6 +11,6 @@ * @author pangu */ @Configuration -@EnableConfigurationProperties({MateRequestProperties.class}) +@EnableConfigurationProperties({MateRequestProperties.class, MateUaaProperties.class}) public class PreRequestConfig { } diff --git a/mate-gateway/src/main/java/vip/mate/gateway/filter/UaaFilter.java b/mate-gateway/src/main/java/vip/mate/gateway/filter/UaaFilter.java new file mode 100644 index 00000000..86d8b10b --- /dev/null +++ b/mate-gateway/src/main/java/vip/mate/gateway/filter/UaaFilter.java @@ -0,0 +1,96 @@ +package vip.mate.gateway.filter; + +import io.jsonwebtoken.Claims; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.cloud.gateway.filter.GatewayFilterChain; +import org.springframework.cloud.gateway.filter.GlobalFilter; +import org.springframework.core.Ordered; +import org.springframework.http.HttpStatus; +import org.springframework.http.server.reactive.ServerHttpResponse; +import org.springframework.stereotype.Component; +import org.springframework.util.AntPathMatcher; +import org.springframework.web.server.ServerWebExchange; +import reactor.core.publisher.Mono; +import vip.mate.core.cloud.props.MateUaaProperties; +import vip.mate.core.common.constant.MateConstant; +import vip.mate.core.common.constant.Oauth2Constant; +import vip.mate.core.common.util.ResponseUtil; +import vip.mate.core.common.util.SecurityUtil; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * 网关统一的token验证 + * + * @author pangu + */ +@Slf4j +@Component +@AllArgsConstructor +public class UaaFilter implements GlobalFilter, Ordered { + + private final MateUaaProperties mateUaaProperties; + + @Override + public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { + // 如果未启用网关验证,则跳过 + if (!mateUaaProperties.getEnable()) { + return chain.filter(exchange); + } + log.error("getIgnoreUrl:{}", mateUaaProperties.getIgnoreUrl()); + + // 如果在忽略的url里,则跳过 + String path = replacePrefix(exchange.getRequest().getURI().getPath()); + String requestUrl = exchange.getRequest().getURI().getRawPath(); + if (ignore(path) || ignore(requestUrl)) { + return chain.filter(exchange); + } + + // 验证token是否有效 + ServerHttpResponse resp = exchange.getResponse(); + String headerToken = exchange.getRequest().getHeaders().getFirst(Oauth2Constant.HEADER_TOKEN); + if (headerToken == null) { + return unauthorized(resp, "没有携带Token信息!"); + } + Claims claims = SecurityUtil.getClaims(headerToken.replace("bearer ","")); + if (claims == null) { + return unauthorized(resp, "token已过期或验证不正确!"); + } + return chain.filter(exchange); + } + + /** + * 检查是否忽略url + * @param path 路径 + * @return boolean + */ + private boolean ignore(String path) { + return mateUaaProperties.getIgnoreUrl().stream() + .map(url -> url.replace("/**", "")) + .anyMatch(path::startsWith); + } + + /** + * 移除模块前缀 + * @param path 路径 + * @return String + */ + private String replacePrefix(String path) { + if (path.startsWith("/mate")) { + return path.substring(path.indexOf("/",1)); + } + return path; + } + + private Mono unauthorized(ServerHttpResponse resp, String msg) { + return ResponseUtil.webFluxResponseWriter(resp, "application/json;charset=UTF-8", HttpStatus.UNAUTHORIZED, msg); + } + + @Override + public int getOrder() { + return MateConstant.MATE_UAA_FILTER_ORDER; + } +} From af4bc91360892a002c270359c2574650ba7bc3b5 Mon Sep 17 00:00:00 2001 From: matevip <7333791@qq.com> Date: Sat, 31 Oct 2020 09:10:44 +0800 Subject: [PATCH 17/19] =?UTF-8?q?Spring=20Boot=E5=8D=87=E7=BA=A7=E8=87=B32?= =?UTF-8?q?.3.5.RELEASE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- mate-core/mate-starter-dependencies/pom.xml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index fd73fd48..f0c19b29 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@

License Stars - SpringBoot + SpringBoot SpringCloud Spring Cloud Alibaba

@@ -34,7 +34,7 @@ QQ群:2003638

### 功能特点 -- 主体框架:采用最新的Spring Cloud Hoxton SR8, Spring Boot 2.3.4.RELEASE, Spring Cloud Alibaba 2.2.3.RELEASE版本进行系统设计; +- 主体框架:采用最新的Spring Cloud Hoxton SR8, Spring Boot 2.3.5.RELEASE, Spring Cloud Alibaba 2.2.3.RELEASE版本进行系统设计; - 统一注册:支持nacos作为注册中心,实现多配置、分群组、分命名空间、多业务模块的注册和发现功能; diff --git a/mate-core/mate-starter-dependencies/pom.xml b/mate-core/mate-starter-dependencies/pom.xml index c32877e9..5f2e6f29 100644 --- a/mate-core/mate-starter-dependencies/pom.xml +++ b/mate-core/mate-starter-dependencies/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 2.3.4.RELEASE + 2.3.5.RELEASE 4.0.0 @@ -20,7 +20,7 @@ 1.5.8-SNAPSHOT UTF-8 - 2.3.4.RELEASE + 2.3.5.RELEASE Hoxton.SR8 2.2.3.RELEASE From 12d19808ee1145b9dfb785c1babdb9f28ea9c618 Mon Sep 17 00:00:00 2001 From: matevip <7333791@qq.com> Date: Sat, 31 Oct 2020 09:36:15 +0800 Subject: [PATCH 18/19] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BD=91=E5=85=B3?= =?UTF-8?q?=E9=89=B4=E6=9D=83get=E6=96=B9=E6=B3=95bug,=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E6=8B=A6=E6=88=AATokenException?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/cloud/props/MateUaaProperties.java | 10 +- .../core/common/exception/TokenException.java | 13 +- .../vip/mate/gateway/filter/UaaFilter.java | 9 +- .../handler/ExceptionHandlerAdvice.java | 113 ++++++++++-------- .../handler/JsonErrorExceptionHandler.java | 7 +- 5 files changed, 86 insertions(+), 66 deletions(-) diff --git a/mate-core/mate-starter-cloud/src/main/java/vip/mate/core/cloud/props/MateUaaProperties.java b/mate-core/mate-starter-cloud/src/main/java/vip/mate/core/cloud/props/MateUaaProperties.java index 9cfccfb0..3b72b50b 100644 --- a/mate-core/mate-starter-cloud/src/main/java/vip/mate/core/cloud/props/MateUaaProperties.java +++ b/mate-core/mate-starter-cloud/src/main/java/vip/mate/core/cloud/props/MateUaaProperties.java @@ -1,6 +1,5 @@ package vip.mate.core.cloud.props; -import lombok.Getter; import lombok.Setter; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.cloud.context.config.annotation.RefreshScope; @@ -36,13 +35,16 @@ public class MateUaaProperties { private static final String[] ENDPOINTS = { "/oauth/**", "/actuator/**", - "/*/v2/api-docs", + "/v2/api-docs/**", + "/v2/api-docs-ext/**", "/swagger/api-docs", "/swagger-ui.html", "/doc.html", "/swagger-resources/**", "/webjars/**", "/druid/**", + "/error/**", + "/assets/**", "/auth/logout", "/auth/code" }; @@ -52,7 +54,9 @@ public class MateUaaProperties { * @return List */ public List getIgnoreUrl() { - Collections.addAll(ignoreUrl, ENDPOINTS); + if (!ignoreUrl.contains("/doc.html")) { + Collections.addAll(ignoreUrl, ENDPOINTS); + } return ignoreUrl; } diff --git a/mate-core/mate-starter-common/src/main/java/vip/mate/core/common/exception/TokenException.java b/mate-core/mate-starter-common/src/main/java/vip/mate/core/common/exception/TokenException.java index 1842e9f5..732f3a66 100644 --- a/mate-core/mate-starter-common/src/main/java/vip/mate/core/common/exception/TokenException.java +++ b/mate-core/mate-starter-common/src/main/java/vip/mate/core/common/exception/TokenException.java @@ -1,10 +1,15 @@ package vip.mate.core.common.exception; +/** + * Token处理异常 + * + * @author xuzhanfu + */ public class TokenException extends RuntimeException { - private static final long serialVersionUID = -109638013567525177L; + private static final long serialVersionUID = -109638013567525177L; - public TokenException(String message) { - super(message); - } + public TokenException(String message) { + super(message); + } } diff --git a/mate-gateway/src/main/java/vip/mate/gateway/filter/UaaFilter.java b/mate-gateway/src/main/java/vip/mate/gateway/filter/UaaFilter.java index 86d8b10b..caf69efb 100644 --- a/mate-gateway/src/main/java/vip/mate/gateway/filter/UaaFilter.java +++ b/mate-gateway/src/main/java/vip/mate/gateway/filter/UaaFilter.java @@ -9,7 +9,6 @@ import org.springframework.http.HttpStatus; import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.stereotype.Component; -import org.springframework.util.AntPathMatcher; import org.springframework.web.server.ServerWebExchange; import reactor.core.publisher.Mono; import vip.mate.core.cloud.props.MateUaaProperties; @@ -18,10 +17,6 @@ import vip.mate.core.common.util.ResponseUtil; import vip.mate.core.common.util.SecurityUtil; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - /** * 网关统一的token验证 * @@ -93,4 +88,8 @@ private Mono unauthorized(ServerHttpResponse resp, String msg) { public int getOrder() { return MateConstant.MATE_UAA_FILTER_ORDER; } + + public static void main(String[] args) { + + } } diff --git a/mate-gateway/src/main/java/vip/mate/gateway/handler/ExceptionHandlerAdvice.java b/mate-gateway/src/main/java/vip/mate/gateway/handler/ExceptionHandlerAdvice.java index f8b34c3f..d6f27064 100644 --- a/mate-gateway/src/main/java/vip/mate/gateway/handler/ExceptionHandlerAdvice.java +++ b/mate-gateway/src/main/java/vip/mate/gateway/handler/ExceptionHandlerAdvice.java @@ -11,63 +11,78 @@ import org.springframework.web.server.ResponseStatusException; import vip.mate.core.common.api.Result; import vip.mate.core.common.api.ResultCode; +import vip.mate.core.common.exception.TokenException; +/** + * 异常处理通知 + * + * @author pangu + */ @Slf4j @Component public class ExceptionHandlerAdvice { - @ExceptionHandler(value = {ResponseStatusException.class}) - public Result handle(ResponseStatusException ex) { - log.error("response status exception:{}", ex.getMessage()); - if (StringUtils.contains(ex.getMessage(), HttpStatus.NOT_FOUND.toString())){ - return Result.fail(ResultCode.NOT_FOUND, ex.getMessage()); - } else { - return Result.fail(ResultCode.ERROR); - } - } + @ExceptionHandler(value = {ResponseStatusException.class}) + public Result handle(ResponseStatusException ex) { + log.error("response status exception:{}", ex.getMessage()); + if (StringUtils.contains(ex.getMessage(), HttpStatus.NOT_FOUND.toString())) { + return Result.fail(ResultCode.NOT_FOUND, ex.getMessage()); + } else { + return Result.fail(ResultCode.ERROR); + } + } - @ExceptionHandler(value = {ConnectTimeoutException.class}) - public Result handle(ConnectTimeoutException ex) { - log.error("connect timeout exception:{}", ex.getMessage()); - return Result.fail(ResultCode.ERROR); - } + @ExceptionHandler(value = {ConnectTimeoutException.class}) + public Result handle(ConnectTimeoutException ex) { + log.error("connect timeout exception:{}", ex.getMessage()); + return Result.fail(ResultCode.ERROR); + } - @ExceptionHandler(value = {NotFoundException.class}) - @ResponseStatus(HttpStatus.NOT_FOUND) - public Result handle(NotFoundException ex) { - log.error("not found exception:{}", ex.getMessage()); - return Result.fail(ResultCode.NOT_FOUND); - } + @ExceptionHandler(value = {NotFoundException.class}) + @ResponseStatus(HttpStatus.NOT_FOUND) + public Result handle(NotFoundException ex) { + log.error("not found exception:{}", ex.getMessage()); + return Result.fail(ResultCode.NOT_FOUND); + } - @ExceptionHandler(value = {RuntimeException.class}) - @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) - public Result handle(RuntimeException ex) { - log.error("runtime exception:{}", ex.getMessage()); - return Result.fail(); - } + @ExceptionHandler(value = {RuntimeException.class}) + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) + public Result handle(RuntimeException ex) { + log.error("runtime exception:{}", ex.getMessage()); + return Result.fail(ex.getMessage()); + } - @ExceptionHandler(value = {Exception.class}) - @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) - public Result handle(Exception ex) { - log.error("exception:{}", ex.getMessage()); - return Result.fail(); - } + @ExceptionHandler(value = {TokenException.class}) + @ResponseStatus(HttpStatus.UNAUTHORIZED) + public Result handle(TokenException ex) { + log.error("runtime exception:{}", ex.getMessage()); + return Result.fail(HttpStatus.UNAUTHORIZED.value(), ex.getMessage()); + } - @ExceptionHandler(value = {Throwable.class}) - @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) - public Result handle(Throwable throwable) { - Result result = Result.fail(); - if (throwable instanceof ResponseStatusException) { - result = handle((ResponseStatusException) throwable); - } else if (throwable instanceof ConnectTimeoutException) { - result = handle((ConnectTimeoutException) throwable); - } else if (throwable instanceof NotFoundException) { - result = handle((NotFoundException) throwable); - } else if (throwable instanceof RuntimeException) { - result = handle((RuntimeException) throwable); - } else if (throwable instanceof Exception) { - result = handle((Exception) throwable); - } - return result; - } + @ExceptionHandler(value = {Exception.class}) + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) + public Result handle(Exception ex) { + log.error("exception:{}", ex.getMessage()); + return Result.fail(); + } + + @ExceptionHandler(value = {Throwable.class}) + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) + public Result handle(Throwable throwable) { + Result result = Result.fail(); + if (throwable instanceof ResponseStatusException) { + result = handle((ResponseStatusException) throwable); + } else if (throwable instanceof ConnectTimeoutException) { + result = handle((ConnectTimeoutException) throwable); + } else if (throwable instanceof NotFoundException) { + result = handle((NotFoundException) throwable); + } else if (throwable instanceof TokenException) { + result = handle((TokenException) throwable); + } else if (throwable instanceof RuntimeException) { + result = handle((RuntimeException) throwable); + } else if (throwable instanceof Exception) { + result = handle((Exception) throwable); + } + return result; + } } diff --git a/mate-gateway/src/main/java/vip/mate/gateway/handler/JsonErrorExceptionHandler.java b/mate-gateway/src/main/java/vip/mate/gateway/handler/JsonErrorExceptionHandler.java index 28a1c696..44d1f958 100644 --- a/mate-gateway/src/main/java/vip/mate/gateway/handler/JsonErrorExceptionHandler.java +++ b/mate-gateway/src/main/java/vip/mate/gateway/handler/JsonErrorExceptionHandler.java @@ -1,22 +1,17 @@ package vip.mate.gateway.handler; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.web.ErrorProperties; import org.springframework.boot.autoconfigure.web.ResourceProperties; import org.springframework.boot.autoconfigure.web.reactive.error.DefaultErrorWebExceptionHandler; import org.springframework.boot.web.reactive.error.ErrorAttributes; import org.springframework.context.ApplicationContext; -import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.reactive.function.server.*; -import org.springframework.web.server.ResponseStatusException; import reactor.core.publisher.Mono; -import java.io.FileNotFoundException; -import java.util.HashMap; import java.util.Map; /** @@ -48,6 +43,8 @@ public JsonErrorExceptionHandler(ErrorAttributes errorAttributes, // } else if (error instanceof ResponseStatusException // && StringUtils.contains(error.getMessage(), HttpStatus.NOT_FOUND.toString())) { // code = HttpStatus.NOT_FOUND.value(); +// } else if (error instanceof TokenException) { +// code = HttpStatus.UNAUTHORIZED.value(); // } // Map errorAttributes = new HashMap<>(8); // errorAttributes.put("message", error.getMessage()); From 5caf4e20b837f78d67236cd0d1201e836036fe40 Mon Sep 17 00:00:00 2001 From: matevip <7333791@qq.com> Date: Sat, 31 Oct 2020 09:42:32 +0800 Subject: [PATCH 19/19] =?UTF-8?q?=E5=8F=91=E5=B8=831.5.8=E6=AD=A3=E5=BC=8F?= =?UTF-8?q?=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mate-core/mate-starter-auth/pom.xml | 2 +- mate-core/mate-starter-cloud/pom.xml | 2 +- mate-core/mate-starter-common/pom.xml | 2 +- .../main/java/vip/mate/core/common/constant/MateConstant.java | 2 +- mate-core/mate-starter-database/pom.xml | 2 +- mate-core/mate-starter-dependencies/pom.xml | 4 ++-- mate-core/mate-starter-dozer/pom.xml | 2 +- mate-core/mate-starter-dubbo/pom.xml | 2 +- mate-core/mate-starter-elasticsearch/pom.xml | 2 +- mate-core/mate-starter-encrypt/pom.xml | 2 +- mate-core/mate-starter-feign/pom.xml | 2 +- mate-core/mate-starter-file/pom.xml | 2 +- mate-core/mate-starter-gray/pom.xml | 2 +- mate-core/mate-starter-j2cache/pom.xml | 2 +- mate-core/mate-starter-jetcache/pom.xml | 2 +- mate-core/mate-starter-job/pom.xml | 2 +- mate-core/mate-starter-kafka/pom.xml | 2 +- mate-core/mate-starter-lock/pom.xml | 2 +- mate-core/mate-starter-log/pom.xml | 2 +- mate-core/mate-starter-mail/pom.xml | 2 +- mate-core/mate-starter-mongodb/pom.xml | 2 +- mate-core/mate-starter-oss/pom.xml | 2 +- mate-core/mate-starter-prometheus/pom.xml | 2 +- mate-core/mate-starter-redis/pom.xml | 2 +- mate-core/mate-starter-retrofit/pom.xml | 2 +- mate-core/mate-starter-rocketmq/pom.xml | 2 +- mate-core/mate-starter-rule/pom.xml | 2 +- mate-core/mate-starter-seata/pom.xml | 2 +- mate-core/mate-starter-security/pom.xml | 2 +- mate-core/mate-starter-sentinel/pom.xml | 2 +- mate-core/mate-starter-sharding/pom.xml | 2 +- mate-core/mate-starter-sms/pom.xml | 2 +- mate-core/mate-starter-strategy/pom.xml | 2 +- mate-core/mate-starter-web/pom.xml | 2 +- mate-core/pom.xml | 4 ++-- mate-gateway/pom.xml | 2 +- mate-mq/mate-log-producer/pom.xml | 2 +- mate-mq/mate-message-consumer/pom.xml | 2 +- mate-mq/mate-message-producer/pom.xml | 2 +- mate-mq/pom.xml | 2 +- mate-platform/mate-component-api/pom.xml | 2 +- mate-platform/mate-component/pom.xml | 2 +- mate-platform/mate-system-api/pom.xml | 2 +- mate-platform/mate-system/pom.xml | 2 +- mate-platform/pom.xml | 2 +- mate-support/mate-admin/pom.xml | 2 +- mate-support/mate-code/pom.xml | 2 +- mate-support/mate-job-admin/pom.xml | 2 +- .../jquery-slimscroll/jquery.slimscroll.min.js | 2 +- mate-support/mate-job/pom.xml | 2 +- mate-support/pom.xml | 2 +- mate-uaa/pom.xml | 2 +- pom.xml | 4 ++-- 53 files changed, 56 insertions(+), 56 deletions(-) diff --git a/mate-core/mate-starter-auth/pom.xml b/mate-core/mate-starter-auth/pom.xml index 97c3ae68..51305343 100644 --- a/mate-core/mate-starter-auth/pom.xml +++ b/mate-core/mate-starter-auth/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-core/mate-starter-cloud/pom.xml b/mate-core/mate-starter-cloud/pom.xml index fa57b7e7..56a135d6 100644 --- a/mate-core/mate-starter-cloud/pom.xml +++ b/mate-core/mate-starter-cloud/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-core/mate-starter-common/pom.xml b/mate-core/mate-starter-common/pom.xml index 95bef716..0616702d 100644 --- a/mate-core/mate-starter-common/pom.xml +++ b/mate-core/mate-starter-common/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-core/mate-starter-common/src/main/java/vip/mate/core/common/constant/MateConstant.java b/mate-core/mate-starter-common/src/main/java/vip/mate/core/common/constant/MateConstant.java index 1995ca8e..4bf8639e 100644 --- a/mate-core/mate-starter-common/src/main/java/vip/mate/core/common/constant/MateConstant.java +++ b/mate-core/mate-starter-common/src/main/java/vip/mate/core/common/constant/MateConstant.java @@ -8,7 +8,7 @@ public class MateConstant { /** * 应用版本号 */ - public static final String MATE_APP_VERSION = "1.5.8-SNAPSHOT"; + public static final String MATE_APP_VERSION = "1.5.8"; /** * Spring 应用名 prop key diff --git a/mate-core/mate-starter-database/pom.xml b/mate-core/mate-starter-database/pom.xml index dba7a906..8c7381d3 100644 --- a/mate-core/mate-starter-database/pom.xml +++ b/mate-core/mate-starter-database/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-core/mate-starter-dependencies/pom.xml b/mate-core/mate-starter-dependencies/pom.xml index 5f2e6f29..f4e74883 100644 --- a/mate-core/mate-starter-dependencies/pom.xml +++ b/mate-core/mate-starter-dependencies/pom.xml @@ -12,12 +12,12 @@ vip.mate mate-starter-dependencies - 1.5.8-SNAPSHOT + 1.5.8 pom MateCloud统一版本依赖 - 1.5.8-SNAPSHOT + 1.5.8 UTF-8 2.3.5.RELEASE diff --git a/mate-core/mate-starter-dozer/pom.xml b/mate-core/mate-starter-dozer/pom.xml index 932311ed..3cb05a92 100644 --- a/mate-core/mate-starter-dozer/pom.xml +++ b/mate-core/mate-starter-dozer/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-core/mate-starter-dubbo/pom.xml b/mate-core/mate-starter-dubbo/pom.xml index 40cf0d1c..d223bbce 100644 --- a/mate-core/mate-starter-dubbo/pom.xml +++ b/mate-core/mate-starter-dubbo/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-core/mate-starter-elasticsearch/pom.xml b/mate-core/mate-starter-elasticsearch/pom.xml index 6c3fa9f3..c3d468bc 100644 --- a/mate-core/mate-starter-elasticsearch/pom.xml +++ b/mate-core/mate-starter-elasticsearch/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-core/mate-starter-encrypt/pom.xml b/mate-core/mate-starter-encrypt/pom.xml index 8c6a384a..bdc58ad3 100644 --- a/mate-core/mate-starter-encrypt/pom.xml +++ b/mate-core/mate-starter-encrypt/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-core/mate-starter-feign/pom.xml b/mate-core/mate-starter-feign/pom.xml index 00a71bca..70d1f134 100644 --- a/mate-core/mate-starter-feign/pom.xml +++ b/mate-core/mate-starter-feign/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-core/mate-starter-file/pom.xml b/mate-core/mate-starter-file/pom.xml index 10bd3e59..98058261 100644 --- a/mate-core/mate-starter-file/pom.xml +++ b/mate-core/mate-starter-file/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-core/mate-starter-gray/pom.xml b/mate-core/mate-starter-gray/pom.xml index a471437b..3a798174 100644 --- a/mate-core/mate-starter-gray/pom.xml +++ b/mate-core/mate-starter-gray/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-core/mate-starter-j2cache/pom.xml b/mate-core/mate-starter-j2cache/pom.xml index 50a9c446..967d9a43 100644 --- a/mate-core/mate-starter-j2cache/pom.xml +++ b/mate-core/mate-starter-j2cache/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-core/mate-starter-jetcache/pom.xml b/mate-core/mate-starter-jetcache/pom.xml index b627179c..fde819fb 100644 --- a/mate-core/mate-starter-jetcache/pom.xml +++ b/mate-core/mate-starter-jetcache/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-core/mate-starter-job/pom.xml b/mate-core/mate-starter-job/pom.xml index e654c255..bc6d8d14 100644 --- a/mate-core/mate-starter-job/pom.xml +++ b/mate-core/mate-starter-job/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 jar diff --git a/mate-core/mate-starter-kafka/pom.xml b/mate-core/mate-starter-kafka/pom.xml index b2dcab99..e28b032a 100644 --- a/mate-core/mate-starter-kafka/pom.xml +++ b/mate-core/mate-starter-kafka/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-core/mate-starter-lock/pom.xml b/mate-core/mate-starter-lock/pom.xml index eeb743de..ff92edc7 100644 --- a/mate-core/mate-starter-lock/pom.xml +++ b/mate-core/mate-starter-lock/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-core/mate-starter-log/pom.xml b/mate-core/mate-starter-log/pom.xml index 593203ab..7a1442d6 100644 --- a/mate-core/mate-starter-log/pom.xml +++ b/mate-core/mate-starter-log/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-core/mate-starter-mail/pom.xml b/mate-core/mate-starter-mail/pom.xml index 398f586e..38ab620f 100644 --- a/mate-core/mate-starter-mail/pom.xml +++ b/mate-core/mate-starter-mail/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-core/mate-starter-mongodb/pom.xml b/mate-core/mate-starter-mongodb/pom.xml index aebb8b2c..5557ce45 100644 --- a/mate-core/mate-starter-mongodb/pom.xml +++ b/mate-core/mate-starter-mongodb/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-core/mate-starter-oss/pom.xml b/mate-core/mate-starter-oss/pom.xml index 7572cc7b..d59dd9b1 100644 --- a/mate-core/mate-starter-oss/pom.xml +++ b/mate-core/mate-starter-oss/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-core/mate-starter-prometheus/pom.xml b/mate-core/mate-starter-prometheus/pom.xml index fcbb5bab..ca69c9e5 100644 --- a/mate-core/mate-starter-prometheus/pom.xml +++ b/mate-core/mate-starter-prometheus/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-core/mate-starter-redis/pom.xml b/mate-core/mate-starter-redis/pom.xml index 66ae37e7..319ee6a4 100644 --- a/mate-core/mate-starter-redis/pom.xml +++ b/mate-core/mate-starter-redis/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-core/mate-starter-retrofit/pom.xml b/mate-core/mate-starter-retrofit/pom.xml index 1e0ee2eb..6fd51bed 100644 --- a/mate-core/mate-starter-retrofit/pom.xml +++ b/mate-core/mate-starter-retrofit/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-core/mate-starter-rocketmq/pom.xml b/mate-core/mate-starter-rocketmq/pom.xml index e12c14bf..5146c7e1 100644 --- a/mate-core/mate-starter-rocketmq/pom.xml +++ b/mate-core/mate-starter-rocketmq/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-core/mate-starter-rule/pom.xml b/mate-core/mate-starter-rule/pom.xml index b1bf860f..aa32bebf 100644 --- a/mate-core/mate-starter-rule/pom.xml +++ b/mate-core/mate-starter-rule/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-core/mate-starter-seata/pom.xml b/mate-core/mate-starter-seata/pom.xml index 5d19a245..e574fbf1 100644 --- a/mate-core/mate-starter-seata/pom.xml +++ b/mate-core/mate-starter-seata/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-core/mate-starter-security/pom.xml b/mate-core/mate-starter-security/pom.xml index 6e2d66e6..8a19dc8f 100644 --- a/mate-core/mate-starter-security/pom.xml +++ b/mate-core/mate-starter-security/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-core/mate-starter-sentinel/pom.xml b/mate-core/mate-starter-sentinel/pom.xml index ac0062d6..beb8ace4 100644 --- a/mate-core/mate-starter-sentinel/pom.xml +++ b/mate-core/mate-starter-sentinel/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-core/mate-starter-sharding/pom.xml b/mate-core/mate-starter-sharding/pom.xml index 2580c7f4..8c9a3d3f 100644 --- a/mate-core/mate-starter-sharding/pom.xml +++ b/mate-core/mate-starter-sharding/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-core/mate-starter-sms/pom.xml b/mate-core/mate-starter-sms/pom.xml index 2a7032fd..47045837 100644 --- a/mate-core/mate-starter-sms/pom.xml +++ b/mate-core/mate-starter-sms/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-core/mate-starter-strategy/pom.xml b/mate-core/mate-starter-strategy/pom.xml index 090deba9..eefcd9f3 100644 --- a/mate-core/mate-starter-strategy/pom.xml +++ b/mate-core/mate-starter-strategy/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-core/mate-starter-web/pom.xml b/mate-core/mate-starter-web/pom.xml index 53c6ac39..2d6e8e29 100644 --- a/mate-core/mate-starter-web/pom.xml +++ b/mate-core/mate-starter-web/pom.xml @@ -5,7 +5,7 @@ mate-core vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-core/pom.xml b/mate-core/pom.xml index 3c10b4a5..0d20bceb 100644 --- a/mate-core/pom.xml +++ b/mate-core/pom.xml @@ -6,7 +6,7 @@ mate-core vip.mate - 1.5.8-SNAPSHOT + 1.5.8 pom @@ -46,7 +46,7 @@ - 1.5.8-SNAPSHOT + 1.5.8 2.9.2 1.5.21 1.9.4 diff --git a/mate-gateway/pom.xml b/mate-gateway/pom.xml index a91973ee..6e18eada 100644 --- a/mate-gateway/pom.xml +++ b/mate-gateway/pom.xml @@ -5,7 +5,7 @@ matecloud vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-mq/mate-log-producer/pom.xml b/mate-mq/mate-log-producer/pom.xml index 93303c67..18a77a56 100644 --- a/mate-mq/mate-log-producer/pom.xml +++ b/mate-mq/mate-log-producer/pom.xml @@ -5,7 +5,7 @@ mate-mq vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-mq/mate-message-consumer/pom.xml b/mate-mq/mate-message-consumer/pom.xml index 26855d1f..6295c3fa 100644 --- a/mate-mq/mate-message-consumer/pom.xml +++ b/mate-mq/mate-message-consumer/pom.xml @@ -5,7 +5,7 @@ mate-mq vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-mq/mate-message-producer/pom.xml b/mate-mq/mate-message-producer/pom.xml index adc3d350..b642404e 100644 --- a/mate-mq/mate-message-producer/pom.xml +++ b/mate-mq/mate-message-producer/pom.xml @@ -5,7 +5,7 @@ mate-mq vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-mq/pom.xml b/mate-mq/pom.xml index fae19371..b242614a 100644 --- a/mate-mq/pom.xml +++ b/mate-mq/pom.xml @@ -5,7 +5,7 @@ matecloud vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-platform/mate-component-api/pom.xml b/mate-platform/mate-component-api/pom.xml index ab1cf047..f2d32bf7 100644 --- a/mate-platform/mate-component-api/pom.xml +++ b/mate-platform/mate-component-api/pom.xml @@ -5,7 +5,7 @@ mate-platform vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-platform/mate-component/pom.xml b/mate-platform/mate-component/pom.xml index 4e1273f6..00391f0f 100644 --- a/mate-platform/mate-component/pom.xml +++ b/mate-platform/mate-component/pom.xml @@ -5,7 +5,7 @@ mate-platform vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-platform/mate-system-api/pom.xml b/mate-platform/mate-system-api/pom.xml index 79271e76..28f80a3f 100644 --- a/mate-platform/mate-system-api/pom.xml +++ b/mate-platform/mate-system-api/pom.xml @@ -5,7 +5,7 @@ mate-platform vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-platform/mate-system/pom.xml b/mate-platform/mate-system/pom.xml index 0c624ee7..d5b7434f 100644 --- a/mate-platform/mate-system/pom.xml +++ b/mate-platform/mate-system/pom.xml @@ -5,7 +5,7 @@ mate-platform vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-platform/pom.xml b/mate-platform/pom.xml index e247527b..9a9e16ae 100644 --- a/mate-platform/pom.xml +++ b/mate-platform/pom.xml @@ -5,7 +5,7 @@ matecloud vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-support/mate-admin/pom.xml b/mate-support/mate-admin/pom.xml index c0562fa8..0baf3f0c 100644 --- a/mate-support/mate-admin/pom.xml +++ b/mate-support/mate-admin/pom.xml @@ -5,7 +5,7 @@ mate-support vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-support/mate-code/pom.xml b/mate-support/mate-code/pom.xml index 380aac6e..38daf3b0 100644 --- a/mate-support/mate-code/pom.xml +++ b/mate-support/mate-code/pom.xml @@ -5,7 +5,7 @@ mate-support vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-support/mate-job-admin/pom.xml b/mate-support/mate-job-admin/pom.xml index 456b6937..de190793 100644 --- a/mate-support/mate-job-admin/pom.xml +++ b/mate-support/mate-job-admin/pom.xml @@ -5,7 +5,7 @@ mate-support vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-support/mate-job-admin/src/main/resources/static/adminlte/bower_components/jquery-slimscroll/jquery.slimscroll.min.js b/mate-support/mate-job-admin/src/main/resources/static/adminlte/bower_components/jquery-slimscroll/jquery.slimscroll.min.js index 29f59290..2f1b8d3d 100644 --- a/mate-support/mate-job-admin/src/main/resources/static/adminlte/bower_components/jquery-slimscroll/jquery.slimscroll.min.js +++ b/mate-support/mate-job-admin/src/main/resources/static/adminlte/bower_components/jquery-slimscroll/jquery.slimscroll.min.js @@ -2,7 +2,7 @@ * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses. * - * Version: 1.5.8-SNAPSHOT + * Version: 1.5.8 * */ (function(e){e.fn.extend({slimScroll:function(f){var a=e.extend({width:"auto",height:"250px",size:"7px",color:"#000",position:"right",distance:"1px",start:"top",opacity:.4,alwaysVisible:!1,disableFadeOut:!1,railVisible:!1,railColor:"#333",railOpacity:.2,railDraggable:!0,railClass:"slimScrollRail",barClass:"slimScrollBar",wrapperClass:"slimScrollDiv",allowPageScroll:!1,wheelStep:20,touchScrollStep:200,borderRadius:"7px",railBorderRadius:"7px"},f);this.each(function(){function v(d){if(r){d=d||window.event; diff --git a/mate-support/mate-job/pom.xml b/mate-support/mate-job/pom.xml index 9fb1c8cc..19b704bb 100644 --- a/mate-support/mate-job/pom.xml +++ b/mate-support/mate-job/pom.xml @@ -5,7 +5,7 @@ mate-support vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-support/pom.xml b/mate-support/pom.xml index 362d52bf..4c9c2593 100644 --- a/mate-support/pom.xml +++ b/mate-support/pom.xml @@ -5,7 +5,7 @@ matecloud vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/mate-uaa/pom.xml b/mate-uaa/pom.xml index 20aaaae9..f4704992 100644 --- a/mate-uaa/pom.xml +++ b/mate-uaa/pom.xml @@ -5,7 +5,7 @@ matecloud vip.mate - 1.5.8-SNAPSHOT + 1.5.8 4.0.0 diff --git a/pom.xml b/pom.xml index fc453415..38479b38 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ vip.mate matecloud pom - 1.5.8-SNAPSHOT + 1.5.8 matecloud Mate Cloud - 基于Spring Cloud Alibaba实现的微服务架构 @@ -23,7 +23,7 @@ - 1.5.8-SNAPSHOT + 1.5.8 1.8 3.8.1 UTF-8