去除 system、infra 模块,对 member 模块的依赖

This commit is contained in:
YunaiV 2022-04-10 11:31:08 +08:00
parent e33b2f0dd3
commit ae85fe8aaf
6 changed files with 69 additions and 20 deletions

View File

@ -19,11 +19,6 @@
</description>
<dependencies>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-member-api</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-system-api</artifactId>

View File

@ -23,11 +23,6 @@
<artifactId>yudao-module-system-api</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-member-api</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-infra-api</artifactId>

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -0,0 +1,4 @@
/**
* yudao-module-member 模块的适配解除 yudao-module-system 对它们的依赖
*/
package cn.iocoder.yudao.module.system.service.member;

View File

@ -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<String, Object> 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<SmsSendRespDTO> 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<SmsReceiveRespDTO> receiveResults = smsClient.parseSmsReceiveStatus(text);
if (CollUtil.isEmpty(receiveResults)) {