diff --git a/yudao-module-infra/yudao-module-infra-impl/pom.xml b/yudao-module-infra/yudao-module-infra-impl/pom.xml index 19c9a1472..6c10ddd0b 100644 --- a/yudao-module-infra/yudao-module-infra-impl/pom.xml +++ b/yudao-module-infra/yudao-module-infra-impl/pom.xml @@ -19,11 +19,6 @@ - - cn.iocoder.boot - yudao-module-member-api - ${revision} - cn.iocoder.boot yudao-module-system-api diff --git a/yudao-module-system/yudao-module-system-impl/pom.xml b/yudao-module-system/yudao-module-system-impl/pom.xml index b297830b5..db2fce8b5 100644 --- a/yudao-module-system/yudao-module-system-impl/pom.xml +++ b/yudao-module-system/yudao-module-system-impl/pom.xml @@ -23,11 +23,6 @@ yudao-module-system-api ${revision} - - cn.iocoder.boot - yudao-module-member-api - ${revision} - cn.iocoder.boot yudao-module-infra-api diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/member/MemberService.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/member/MemberService.java new file mode 100644 index 000000000..d96352b15 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/member/MemberService.java @@ -0,0 +1,18 @@ +package cn.iocoder.yudao.module.system.service.member; + +/** + * Member Service 接口 + * + * @author 芋道源码 + */ +public interface MemberService { + + /** + * 获得会员用户的手机号码 + * + * @param id 会员用户编号 + * @return 手机号码 + */ + String getMemberUserMobile(Long id); + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/member/MemberServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/member/MemberServiceImpl.java new file mode 100644 index 000000000..676a95a4e --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/member/MemberServiceImpl.java @@ -0,0 +1,41 @@ +package cn.iocoder.yudao.module.system.service.member; + +import cn.hutool.core.util.ClassUtil; +import cn.hutool.core.util.ReflectUtil; +import cn.hutool.extra.spring.SpringUtil; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +/** + * Member Service 实现类 + * + * @author 芋道源码 + */ +@Service +public class MemberServiceImpl implements MemberService { + + @Value("${yudao.info.base-package}") + private String basePackage; + + private volatile Object memberUserApi; + + @Override + public String getMemberUserMobile(Long id) { + if (id == null) { + return null; + } + Object user = ReflectUtil.invoke(getMemberUserApi(), "getUser", id); + if (user == null) { + return null; + } + return ReflectUtil.invoke(user, "getMobile"); + } + + private Object getMemberUserApi() { + if (memberUserApi == null) { + memberUserApi = SpringUtil.getBean(ClassUtil.loadClass(String.format("%s.module.member.api.user.MemberUserApi", basePackage))); + } + return memberUserApi; + } + +} diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/member/package-info.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/member/package-info.java new file mode 100644 index 000000000..ce080b410 --- /dev/null +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/member/package-info.java @@ -0,0 +1,4 @@ +/** + * yudao-module-member 模块的适配,解除 yudao-module-system 对它们的依赖 + */ +package cn.iocoder.yudao.module.system.service.member; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsSendServiceImpl.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsSendServiceImpl.java index 538e0f925..608985454 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsSendServiceImpl.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsSendServiceImpl.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.system.service.sms; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.lang.Assert; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; @@ -10,16 +11,14 @@ import cn.iocoder.yudao.framework.sms.core.client.SmsClientFactory; import cn.iocoder.yudao.framework.sms.core.client.SmsCommonResult; import cn.iocoder.yudao.framework.sms.core.client.dto.SmsReceiveRespDTO; import cn.iocoder.yudao.framework.sms.core.client.dto.SmsSendRespDTO; -import cn.iocoder.yudao.module.member.api.user.MemberUserApi; -import cn.iocoder.yudao.module.member.api.user.dto.UserRespDTO; import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; import cn.iocoder.yudao.module.system.mq.message.sms.SmsSendMessage; import cn.iocoder.yudao.module.system.mq.producer.sms.SmsProducer; +import cn.iocoder.yudao.module.system.service.member.MemberService; import cn.iocoder.yudao.module.system.service.user.AdminUserService; import com.google.common.annotations.VisibleForTesting; import org.springframework.stereotype.Service; -import org.springframework.util.Assert; import javax.annotation.Resource; import java.util.List; @@ -40,7 +39,7 @@ public class SmsSendServiceImpl implements SmsSendService { @Resource private AdminUserService adminUserService; @Resource - private MemberUserApi memberUserApi; + private MemberService memberService; @Resource private SmsTemplateService smsTemplateService; @@ -70,10 +69,7 @@ public class SmsSendServiceImpl implements SmsSendService { public Long sendSingleSmsToMember(String mobile, Long userId, String templateCode, Map templateParams) { // 如果 mobile 为空,则加载用户编号对应的手机号 if (StrUtil.isEmpty(mobile)) { - UserRespDTO user = memberUserApi.getUser(userId); - if (user != null) { - mobile = user.getMobile(); - } + mobile = memberService.getMemberUserMobile(userId); } // 执行发送 return this.sendSingleSms(mobile, userId, UserTypeEnum.MEMBER.getValue(), templateCode, templateParams); @@ -146,7 +142,7 @@ public class SmsSendServiceImpl implements SmsSendService { public void doSendSms(SmsSendMessage message) { // 获得渠道对应的 SmsClient 客户端 SmsClient smsClient = smsClientFactory.getSmsClient(message.getChannelId()); - Assert.notNull(smsClient, String.format("短信客户端(%d) 不存在", message.getChannelId())); + Assert.notNull(smsClient, "短信客户端({}) 不存在", message.getChannelId()); // 发送短信 SmsCommonResult sendResult = smsClient.sendSms(message.getLogId(), message.getMobile(), message.getApiTemplateId(), message.getTemplateParams()); @@ -159,7 +155,7 @@ public class SmsSendServiceImpl implements SmsSendService { public void receiveSmsStatus(String channelCode, String text) throws Throwable { // 获得渠道对应的 SmsClient 客户端 SmsClient smsClient = smsClientFactory.getSmsClient(channelCode); - Assert.notNull(smsClient, String.format("短信客户端(%s) 不存在", channelCode)); + Assert.notNull(smsClient, "短信客户端({}) 不存在", channelCode); // 解析内容 List receiveResults = smsClient.parseSmsReceiveStatus(text); if (CollUtil.isEmpty(receiveResults)) {