From b4607bc6d5a42f6c849ff77bcd8400eed4ddf179 Mon Sep 17 00:00:00 2001 From: koushenhai <2413176044@qq.com> Date: Mon, 23 Dec 2024 21:28:16 +0800 Subject: [PATCH] =?UTF-8?q?feat():=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81[?= =?UTF-8?q?=E5=8F=91=E9=80=81=E9=AA=8C=E8=AF=81=E7=A0=81]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gateway/web/RoutersControllerV3.java | 4 +- .../laokou/common/i18n/dto/DomainEvent.java | 6 +-- .../AbstractSendCaptchaEventHandler.java | 50 ------------------- .../handler/SendMailCaptchaEventHandler.java | 49 +++++++++--------- .../SendMobileCaptchaEventHandler.java | 48 +++++++++--------- .../auth/command/CaptchaSendCmdExe.java | 5 +- .../laokou/auth/ability/DomainService.java | 4 +- .../laokou/auth/factory/DomainFactory.java | 4 +- .../java/org/laokou/auth/model/AuthA.java | 21 +++++--- .../java/org/laokou/auth/model/Constant.java | 2 + .../auth/common/constant/MqConstant.java | 2 - 11 files changed, 78 insertions(+), 117 deletions(-) delete mode 100644 laokou-service/laokou-auth/laokou-auth-adapter/src/main/java/org/laokou/auth/consumer/handler/AbstractSendCaptchaEventHandler.java diff --git a/laokou-cloud/laokou-gateway/src/main/java/org/laokou/gateway/web/RoutersControllerV3.java b/laokou-cloud/laokou-gateway/src/main/java/org/laokou/gateway/web/RoutersControllerV3.java index f4957b810c..a8fe9228d1 100644 --- a/laokou-cloud/laokou-gateway/src/main/java/org/laokou/gateway/web/RoutersControllerV3.java +++ b/laokou-cloud/laokou-gateway/src/main/java/org/laokou/gateway/web/RoutersControllerV3.java @@ -45,14 +45,14 @@ public class RoutersControllerV3 { @Api @PostMapping @Operation(summary = "保存路由", description = "保存路由") - public Flux saveRouter() { + public Flux saveV3() { return nacosRouteDefinitionRepository.saveRouters(); } @Api @DeleteMapping @Operation(summary = "删除路由", description = "删除路由") - public Mono removeRouter() { + public Mono removeV3() { return nacosRouteDefinitionRepository.removeRouters(); } diff --git a/laokou-common/laokou-common-i18n/src/main/java/org/laokou/common/i18n/dto/DomainEvent.java b/laokou-common/laokou-common-i18n/src/main/java/org/laokou/common/i18n/dto/DomainEvent.java index 1e76d489bd..4cb0c2cd38 100644 --- a/laokou-common/laokou-common-i18n/src/main/java/org/laokou/common/i18n/dto/DomainEvent.java +++ b/laokou-common/laokou-common-i18n/src/main/java/org/laokou/common/i18n/dto/DomainEvent.java @@ -102,12 +102,12 @@ public DomainEvent() { this.version = 0; } - public DomainEvent(Long eventId, Long tenantId, Long userId, Long aggregateId, String topic, String tag, - int version, String payload, EventType type, String sourcePrefix) { + public DomainEvent(Long id, Long tenantId, Long userId, Long aggregateId, String topic, String tag, int version, + String payload, EventType type, String sourcePrefix) { + super.id = id; this.payload = payload; this.type = StringUtil.convertUnder(type.name().toLowerCase()); this.sourcePrefix = sourcePrefix; - super.id = eventId; this.tenantId = tenantId; this.userId = userId; this.aggregateId = aggregateId; diff --git a/laokou-service/laokou-auth/laokou-auth-adapter/src/main/java/org/laokou/auth/consumer/handler/AbstractSendCaptchaEventHandler.java b/laokou-service/laokou-auth/laokou-auth-adapter/src/main/java/org/laokou/auth/consumer/handler/AbstractSendCaptchaEventHandler.java deleted file mode 100644 index edc143aee6..0000000000 --- a/laokou-service/laokou-auth/laokou-auth-adapter/src/main/java/org/laokou/auth/consumer/handler/AbstractSendCaptchaEventHandler.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2022-2024 KCloud-Platform-IoT Author or Authors. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package org.laokou.auth.consumer.handler; - -/** - * @author laokou - */ -public abstract class AbstractSendCaptchaEventHandler { - - // protected AbstractSendCaptchaEventHandler(DomainEventPublisher - // domainEventPublisher) { - // super(domainEventPublisher); - // } - - // @Override - // protected void handleDomainEvent(DefaultDomainEvent domainEvent) { - // SendCaptchaEvent event = (SendCaptchaEvent) domainEvent; - // NoticeMessageEvent noticeMessageEvent = new - // NoticeMessageEvent(LAOKOU_LOG_TOPIC, NOTICE_TAG, SEND_NOTICE, - // event.getServiceId(), event.getSourcePrefix(), event.getAggregateId(), - // event.getTenantId()); - // rocketMQDomainEventPublisher.publish(noticeMessageEvent, - // SendMessageType.ONE_WAY); - // } - - // @Override - // protected DefaultDomainEvent convert(String msg) { - // return JacksonUtil.toBean(msg, SendCaptchaEvent.class); - // } - - /* - * protected abstract NoticeLog getNoticeLog(SendCaptchaEvent event); - */ - -} diff --git a/laokou-service/laokou-auth/laokou-auth-adapter/src/main/java/org/laokou/auth/consumer/handler/SendMailCaptchaEventHandler.java b/laokou-service/laokou-auth/laokou-auth-adapter/src/main/java/org/laokou/auth/consumer/handler/SendMailCaptchaEventHandler.java index 8e6233afed..c1f1308fab 100644 --- a/laokou-service/laokou-auth/laokou-auth-adapter/src/main/java/org/laokou/auth/consumer/handler/SendMailCaptchaEventHandler.java +++ b/laokou-service/laokou-auth/laokou-auth-adapter/src/main/java/org/laokou/auth/consumer/handler/SendMailCaptchaEventHandler.java @@ -17,34 +17,37 @@ package org.laokou.auth.consumer.handler; +import io.micrometer.common.lang.NonNullApi; +import lombok.extern.slf4j.Slf4j; +import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; +import org.laokou.common.domain.handler.AbstractDomainEventHandler; import org.laokou.common.domain.support.DomainEventPublisher; -import org.laokou.common.mail.service.MailService; -import org.laokou.common.redis.utils.RedisUtil; +import org.laokou.common.i18n.dto.DomainEvent; +import org.springframework.stereotype.Component; + +import static org.apache.rocketmq.spring.annotation.ConsumeMode.CONCURRENTLY; +import static org.apache.rocketmq.spring.annotation.MessageModel.CLUSTERING; +import static org.laokou.auth.common.constant.MqConstant.LAOKOU_MAIL_CAPTCHA_CONSUMER_GROUP; +import static org.laokou.auth.common.constant.MqConstant.MAIL_TAG; +import static org.laokou.auth.model.Constant.LAOKOU_CAPTCHA_TOPIC; /** * @author laokou */ -// @Slf4j -// @Component -// @NonNullApi -// @RocketMQMessageListener(consumerGroup = LAOKOU_MAIL_CAPTCHA_CONSUMER_GROUP, topic = -// LAOKOU_CAPTCHA_TOPIC, -// selectorExpression = MAIL_TAG, messageModel = CLUSTERING, consumeMode = CONCURRENTLY) -public class SendMailCaptchaEventHandler { - - private final MailService mailService; - - private final RedisUtil redisUtil; - - public SendMailCaptchaEventHandler(DomainEventPublisher domainEventPublisher, MailService mailService, - RedisUtil redisUtil) { - // super(domainEventPublisher); - this.mailService = mailService; - this.redisUtil = redisUtil; +@Slf4j +@Component +@NonNullApi +@RocketMQMessageListener(consumerGroup = LAOKOU_MAIL_CAPTCHA_CONSUMER_GROUP, topic = LAOKOU_CAPTCHA_TOPIC, + selectorExpression = MAIL_TAG, messageModel = CLUSTERING, consumeMode = CONCURRENTLY) +public class SendMailCaptchaEventHandler extends AbstractDomainEventHandler { + + public SendMailCaptchaEventHandler(DomainEventPublisher rocketMQDomainEventPublisher) { + super(rocketMQDomainEventPublisher); + } + + @Override + protected void handleDomainEvent(DomainEvent domainEvent) { + } - /* - * @Override protected NoticeLog getNoticeLog(SendCaptchaEvent event) { return - * mailService.send(event.getUuid(), 5); } - */ } diff --git a/laokou-service/laokou-auth/laokou-auth-adapter/src/main/java/org/laokou/auth/consumer/handler/SendMobileCaptchaEventHandler.java b/laokou-service/laokou-auth/laokou-auth-adapter/src/main/java/org/laokou/auth/consumer/handler/SendMobileCaptchaEventHandler.java index b00de8f68a..3413c495c5 100644 --- a/laokou-service/laokou-auth/laokou-auth-adapter/src/main/java/org/laokou/auth/consumer/handler/SendMobileCaptchaEventHandler.java +++ b/laokou-service/laokou-auth/laokou-auth-adapter/src/main/java/org/laokou/auth/consumer/handler/SendMobileCaptchaEventHandler.java @@ -17,35 +17,37 @@ package org.laokou.auth.consumer.handler; +import io.micrometer.common.lang.NonNullApi; +import lombok.extern.slf4j.Slf4j; +import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; +import org.laokou.common.domain.handler.AbstractDomainEventHandler; import org.laokou.common.domain.support.DomainEventPublisher; -import org.laokou.common.redis.utils.RedisUtil; -import org.laokou.common.sms.service.SmsService; +import org.laokou.common.i18n.dto.DomainEvent; +import org.springframework.stereotype.Component; + +import static org.apache.rocketmq.spring.annotation.ConsumeMode.CONCURRENTLY; +import static org.apache.rocketmq.spring.annotation.MessageModel.CLUSTERING; +import static org.laokou.auth.common.constant.MqConstant.LAOKOU_MOBILE_CAPTCHA_CONSUMER_GROUP; +import static org.laokou.auth.common.constant.MqConstant.MOBILE_TAG; +import static org.laokou.auth.model.Constant.LAOKOU_CAPTCHA_TOPIC; /** * @author laokou */ -// @Slf4j -// @Component -// @NonNullApi -// @RocketMQMessageListener(consumerGroup = LAOKOU_MOBILE_CAPTCHA_CONSUMER_GROUP, topic = -// LAOKOU_CAPTCHA_TOPIC, -// selectorExpression = MOBILE_TAG, messageModel = CLUSTERING, consumeMode = CONCURRENTLY) -public class SendMobileCaptchaEventHandler { - - private final SmsService smsService; - - private final RedisUtil redisUtil; - - public SendMobileCaptchaEventHandler(DomainEventPublisher domainEventPublisher, SmsService smsService, - RedisUtil redisUtil) { - // super(domainEventPublisher); - this.smsService = smsService; - this.redisUtil = redisUtil; +@Slf4j +@Component +@NonNullApi +@RocketMQMessageListener(consumerGroup = LAOKOU_MOBILE_CAPTCHA_CONSUMER_GROUP, topic = LAOKOU_CAPTCHA_TOPIC, + selectorExpression = MOBILE_TAG, messageModel = CLUSTERING, consumeMode = CONCURRENTLY) +public class SendMobileCaptchaEventHandler extends AbstractDomainEventHandler { + + public SendMobileCaptchaEventHandler(DomainEventPublisher rocketMQDomainEventPublisher) { + super(rocketMQDomainEventPublisher); } - // @Override - // protected NoticeLog getNoticeLog(SendCaptchaEvent event) { - // return smsService.send(event.getUuid(), 5); - // } + @Override + protected void handleDomainEvent(DomainEvent domainEvent) { + + } } diff --git a/laokou-service/laokou-auth/laokou-auth-app/src/main/java/org/laokou/auth/command/CaptchaSendCmdExe.java b/laokou-service/laokou-auth/laokou-auth-app/src/main/java/org/laokou/auth/command/CaptchaSendCmdExe.java index 78d93513a8..d2d475cbd5 100644 --- a/laokou-service/laokou-auth/laokou-auth-app/src/main/java/org/laokou/auth/command/CaptchaSendCmdExe.java +++ b/laokou-service/laokou-auth/laokou-auth-app/src/main/java/org/laokou/auth/command/CaptchaSendCmdExe.java @@ -25,6 +25,7 @@ import org.laokou.auth.factory.DomainFactory; import org.laokou.auth.model.AuthA; import org.laokou.auth.service.extensionpoint.CaptchaParamValidatorExtPt; +import org.laokou.common.core.utils.IdGenerator; import org.laokou.common.domain.support.DomainEventPublisher; import org.laokou.common.extension.BizScenario; import org.laokou.common.extension.ExtensionExecutor; @@ -54,9 +55,9 @@ public void executeVoid(CaptchaSendCmd cmd) { extensionExecutor.executeVoid(CaptchaParamValidatorExtPt.class, BizScenario.valueOf(co.getTag(), USE_CASE_CAPTCHA, SCENARIO), extension -> extension.validate(co.getUuid())); - AuthA auth = DomainFactory.getAuth(); + AuthA auth = DomainFactory.getAuth(IdGenerator.defaultSnowflakeId()); // 创建验证码 - domainService.createCaptcha(auth, CaptchaConvertor.toEntity(co)); + domainService.createCaptcha(IdGenerator.defaultSnowflakeId(), auth, CaptchaConvertor.toEntity(co)); // 发布事件 auth.releaseEvents().forEach(item -> rocketMQDomainEventPublisher.publish(item, SendMessageType.ASYNC)); } diff --git a/laokou-service/laokou-auth/laokou-auth-domain/src/main/java/org/laokou/auth/ability/DomainService.java b/laokou-service/laokou-auth/laokou-auth-domain/src/main/java/org/laokou/auth/ability/DomainService.java index f67158056b..a4874dc4ee 100644 --- a/laokou-service/laokou-auth/laokou-auth-domain/src/main/java/org/laokou/auth/ability/DomainService.java +++ b/laokou-service/laokou-auth/laokou-auth-domain/src/main/java/org/laokou/auth/ability/DomainService.java @@ -55,13 +55,13 @@ public void createLoginLog(LoginLogE loginLog) { loginLogGateway.create(loginLog); } - public void createCaptcha(AuthA auth, CaptchaE captcha) { + public void createCaptcha(Long eventId, AuthA auth, CaptchaE captcha) { // 获取验证码信息 auth.getCaptcha(captcha); // 校验租户 checkTenant(auth); // 创建验证码 - auth.createCaptcha(); + auth.createCaptcha(eventId); } public void auth(AuthA auth, InfoV info) { diff --git a/laokou-service/laokou-auth/laokou-auth-domain/src/main/java/org/laokou/auth/factory/DomainFactory.java b/laokou-service/laokou-auth/laokou-auth-domain/src/main/java/org/laokou/auth/factory/DomainFactory.java index 7c7ee4ff97..a73fdcc832 100644 --- a/laokou-service/laokou-auth/laokou-auth-domain/src/main/java/org/laokou/auth/factory/DomainFactory.java +++ b/laokou-service/laokou-auth/laokou-auth-domain/src/main/java/org/laokou/auth/factory/DomainFactory.java @@ -79,8 +79,8 @@ public class DomainFactory { */ private static final String TENANT_CODE = "tenant_code"; - public static AuthA getAuth() { - return new AuthA(); + public static AuthA getAuth(Long aggregateId) { + return new AuthA(aggregateId); } public static AuthA getMailAuth(Long aggregateId, HttpServletRequest request) { diff --git a/laokou-service/laokou-auth/laokou-auth-domain/src/main/java/org/laokou/auth/model/AuthA.java b/laokou-service/laokou-auth/laokou-auth-domain/src/main/java/org/laokou/auth/model/AuthA.java index f77ba6edb8..c5134807e9 100644 --- a/laokou-service/laokou-auth/laokou-auth-domain/src/main/java/org/laokou/auth/model/AuthA.java +++ b/laokou-service/laokou-auth/laokou-auth-domain/src/main/java/org/laokou/auth/model/AuthA.java @@ -21,6 +21,8 @@ import org.laokou.auth.ability.validator.CaptchaValidator; import org.laokou.auth.ability.validator.PasswordValidator; import org.laokou.auth.dto.domainevent.LoginEvent; +import org.laokou.auth.dto.domainevent.SendCaptchaEvent; +import org.laokou.common.i18n.common.constant.EventType; import org.laokou.common.i18n.common.exception.GlobalException; import org.laokou.common.i18n.common.exception.SystemException; import org.laokou.common.i18n.dto.AggregateRoot; @@ -31,8 +33,7 @@ import java.util.*; -import static org.laokou.auth.model.Constant.LAOKOU_LOG_TOPIC; -import static org.laokou.auth.model.Constant.LOGIN_TAG; +import static org.laokou.auth.model.Constant.*; import static org.laokou.auth.model.GrantType.*; import static org.laokou.common.i18n.common.constant.EventType.LOGIN_EVENT; import static org.laokou.common.i18n.common.constant.StringConstant.EMPTY; @@ -107,7 +108,8 @@ public class AuthA extends AggregateRoot { */ private CaptchaE captchaE; - public AuthA() { + public AuthA(Long id) { + super.id = id; this.username = EMPTY; this.password = EMPTY; this.tenantCode = EMPTY; @@ -115,9 +117,9 @@ public AuthA() { this.captcha = new CaptchaV(EMPTY, EMPTY); } - public AuthA(Long aggregateId, String username, String password, String tenantCode, GrantType grantType, - String uuid, String captcha) { - super.id = aggregateId; + public AuthA(Long id, String username, String password, String tenantCode, GrantType grantType, String uuid, + String captcha) { + super.id = id; this.username = username; this.password = password; this.tenantCode = tenantCode; @@ -141,8 +143,11 @@ public void createUserByAuthorizationCode() { this.user = new UserE(this.username, EMPTY, EMPTY); } - public void createCaptcha() { - version++; + public void createCaptcha(Long eventId) { + addEvent(new DomainEvent(eventId, tenantId, null, super.id, LAOKOU_CAPTCHA_TOPIC, captchaE.getTag(), + super.version, JacksonUtil.toJsonStr(new SendCaptchaEvent(captchaE.getUuid())), + EventType.SEND_CAPTCHA_EVENT, sourcePrefix)); + super.version++; } public void getExtInfo(InfoV info) { diff --git a/laokou-service/laokou-auth/laokou-auth-domain/src/main/java/org/laokou/auth/model/Constant.java b/laokou-service/laokou-auth/laokou-auth-domain/src/main/java/org/laokou/auth/model/Constant.java index 7afa08918c..c64c704f20 100644 --- a/laokou-service/laokou-auth/laokou-auth-domain/src/main/java/org/laokou/auth/model/Constant.java +++ b/laokou-service/laokou-auth/laokou-auth-domain/src/main/java/org/laokou/auth/model/Constant.java @@ -26,4 +26,6 @@ public final class Constant { public static final String LAOKOU_LOG_TOPIC = "laokou_log_topic"; + public static final String LAOKOU_CAPTCHA_TOPIC = "laokou_captcha_topic"; + } diff --git a/laokou-service/laokou-auth/laokou-auth-infrastructure/src/main/java/org/laokou/auth/common/constant/MqConstant.java b/laokou-service/laokou-auth/laokou-auth-infrastructure/src/main/java/org/laokou/auth/common/constant/MqConstant.java index 676dd75cd9..70d726643a 100644 --- a/laokou-service/laokou-auth/laokou-auth-infrastructure/src/main/java/org/laokou/auth/common/constant/MqConstant.java +++ b/laokou-service/laokou-auth/laokou-auth-infrastructure/src/main/java/org/laokou/auth/common/constant/MqConstant.java @@ -26,8 +26,6 @@ public final class MqConstant { public static final String MOBILE_TAG = "mobileCaptcha"; - public static final String LAOKOU_CAPTCHA_TOPIC = "laokou_captcha_topic"; - public static final String LAOKOU_MAIL_CAPTCHA_CONSUMER_GROUP = "laokou_mail_captcha_consumer_group"; public static final String LAOKOU_MOBILE_CAPTCHA_CONSUMER_GROUP = "laokou_mobile_captcha_consumer_group";