diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/convert/package-info.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/convert/package-info.java new file mode 100644 index 000000000..230bbc092 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/convert/package-info.java @@ -0,0 +1,6 @@ +/** + * 提供 POJO 类的实体转换 + * + * 目前使用 MapStruct 框架 + */ +package cn.iocoder.yudao.coreservice.modules.member.convert; diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md new file mode 100644 index 000000000..8153487b7 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/convert/《芋道 Spring Boot 对象转换 MapStruct 入门》.md @@ -0,0 +1 @@ + diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/dal/dataobject/user/MbrUserDO.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/dal/dataobject/user/MbrUserDO.java similarity index 95% rename from yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/dal/dataobject/user/MbrUserDO.java rename to yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/dal/dataobject/user/MbrUserDO.java index f8976723e..57221f614 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/dal/dataobject/user/MbrUserDO.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/dal/dataobject/user/MbrUserDO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.userserver.modules.member.dal.dataobject.user; +package cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/dal/mysql/user/MbrUserCoreMapper.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/dal/mysql/user/MbrUserCoreMapper.java new file mode 100644 index 000000000..27c0c9509 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/dal/mysql/user/MbrUserCoreMapper.java @@ -0,0 +1,10 @@ +package cn.iocoder.yudao.coreservice.modules.member.dal.mysql.user; + +import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface MbrUserCoreMapper extends BaseMapperX { + +} diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/service/user/MbrUserCoreService.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/service/user/MbrUserCoreService.java new file mode 100644 index 000000000..934413956 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/service/user/MbrUserCoreService.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.coreservice.modules.member.service.user; + +import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; + +/** + * 前台用户 Core Service 接口 + * + * @author 芋道源码 + */ +public interface MbrUserCoreService { + /** + * 通过用户 ID 查询用户 + * + * @param id 用户ID + * @return 用户对象信息 + */ + MbrUserDO getUser(Long id); + +} diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/service/user/impl/MbrUserCoreServiceImpl.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/service/user/impl/MbrUserCoreServiceImpl.java new file mode 100644 index 000000000..08ee22c76 --- /dev/null +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/member/service/user/impl/MbrUserCoreServiceImpl.java @@ -0,0 +1,28 @@ +package cn.iocoder.yudao.coreservice.modules.member.service.user.impl; + +import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; +import cn.iocoder.yudao.coreservice.modules.member.dal.mysql.user.MbrUserCoreMapper; +import cn.iocoder.yudao.coreservice.modules.member.service.user.MbrUserCoreService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +/** + * User Core Service 实现类 + * + * @author 芋道源码 + */ +@Service +@Slf4j +public class MbrUserCoreServiceImpl implements MbrUserCoreService { + + @Resource + private MbrUserCoreMapper userCoreMapper; + + @Override + public MbrUserDO getUser(Long id) { + return userCoreMapper.selectById(id); + } + +} diff --git a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/impl/SysSmsCoreServiceImpl.java b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/impl/SysSmsCoreServiceImpl.java index 12720ddbc..3893ba340 100644 --- a/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/impl/SysSmsCoreServiceImpl.java +++ b/yudao-core-service/src/main/java/cn/iocoder/yudao/coreservice/modules/system/service/sms/impl/SysSmsCoreServiceImpl.java @@ -2,6 +2,8 @@ package cn.iocoder.yudao.coreservice.modules.system.service.sms.impl; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; +import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; +import cn.iocoder.yudao.coreservice.modules.member.service.user.MbrUserCoreService; import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.sms.SysSmsTemplateDO; import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; import cn.iocoder.yudao.coreservice.modules.system.mq.message.sms.SysSmsSendMessage; @@ -41,6 +43,8 @@ public class SysSmsCoreServiceImpl implements SysSmsCoreService { @Resource private SysUserCoreService sysUserCoreService; @Resource + private MbrUserCoreService mbrUserCoreService; + @Resource private SysSmsTemplateCoreService smsTemplateCoreService; @Resource private SysSmsLogCoreService smsLogCoreService; @@ -66,7 +70,15 @@ public class SysSmsCoreServiceImpl implements SysSmsCoreService { @Override public Long sendSingleSmsToMember(String mobile, Long userId, String templateCode, Map templateParams) { - throw new UnsupportedOperationException("暂时不支持该操作,感兴趣可以实现该功能哟!"); + // 如果 mobile 为空,则加载用户编号对应的手机号 + if (StrUtil.isEmpty(mobile)) { + MbrUserDO user = mbrUserCoreService.getUser(userId); + if (user != null) { + mobile = user.getMobile(); + } + } + // 执行发送 + return this.sendSingleSms(mobile, userId, UserTypeEnum.MEMBER.getValue(), templateCode, templateParams); } @Override diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/dal/mysql/user/MbrUserMapper.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/dal/mysql/user/MbrUserMapper.java index 7ab5128dc..35546f1d8 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/dal/mysql/user/MbrUserMapper.java +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/dal/mysql/user/MbrUserMapper.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.userserver.modules.member.dal.mysql.user; +import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.userserver.modules.member.dal.dataobject.user.MbrUserDO; import org.apache.ibatis.annotations.Mapper; /** diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/service/user/MbrUserService.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/service/user/MbrUserService.java index 886fa012f..2d5466865 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/service/user/MbrUserService.java +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/service/user/MbrUserService.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.userserver.modules.member.service.user; +import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; import cn.iocoder.yudao.framework.common.validation.Mobile; -import cn.iocoder.yudao.userserver.modules.member.dal.dataobject.user.MbrUserDO; /** * 前台用户 Service 接口 diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/service/user/impl/MbrUserServiceImpl.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/service/user/impl/MbrUserServiceImpl.java index 51faf189c..71fb9dd88 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/service/user/impl/MbrUserServiceImpl.java +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/member/service/user/impl/MbrUserServiceImpl.java @@ -1,10 +1,8 @@ package cn.iocoder.yudao.userserver.modules.member.service.user.impl; import cn.hutool.core.util.IdUtil; -import cn.hutool.core.util.RandomUtil; -import cn.hutool.core.util.StrUtil; +import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.userserver.modules.member.dal.dataobject.user.MbrUserDO; import cn.iocoder.yudao.userserver.modules.member.dal.mysql.user.MbrUserMapper; import cn.iocoder.yudao.userserver.modules.member.service.user.MbrUserService; import lombok.extern.slf4j.Slf4j; diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/SysAuthController.http b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/SysAuthController.http index e02af92a1..c9cadedcc 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/SysAuthController.http +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/controller/auth/SysAuthController.http @@ -12,7 +12,7 @@ POST {{userServerUrl}}/send-sms-code Content-Type: application/json { - "mobile": "15601691301", + "mobile": "15601691399", "scene": 1 } diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/convert/auth/SysAuthConvert.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/convert/auth/SysAuthConvert.java index 474b3368c..f2af81257 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/convert/auth/SysAuthConvert.java +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/convert/auth/SysAuthConvert.java @@ -1,8 +1,8 @@ package cn.iocoder.yudao.userserver.modules.system.convert.auth; +import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.security.core.LoginUser; -import cn.iocoder.yudao.userserver.modules.member.dal.dataobject.user.MbrUserDO; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/enums/sms/SysSmsTemplateCodeConstants.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/enums/sms/SysSmsTemplateCodeConstants.java new file mode 100644 index 000000000..5529a0741 --- /dev/null +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/enums/sms/SysSmsTemplateCodeConstants.java @@ -0,0 +1,15 @@ +package cn.iocoder.yudao.userserver.modules.system.enums.sms; + +/** + * yudao-user-server 使用到的短信模板的 Code 编码的枚举 + * + * @author 芋道源码 + */ +public interface SysSmsTemplateCodeConstants { + + /** + * 前台用户短信登录 + */ + String USER_SMS_LOGIN = "user-sms-login"; + +} diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/auth/impl/SysAuthServiceImpl.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/auth/impl/SysAuthServiceImpl.java index 1baaa24a3..0199c078e 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/auth/impl/SysAuthServiceImpl.java +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/auth/impl/SysAuthServiceImpl.java @@ -1,6 +1,9 @@ package cn.iocoder.yudao.userserver.modules.system.service.auth.impl; import cn.hutool.core.lang.Assert; +import cn.iocoder.yudao.coreservice.modules.member.dal.dataobject.user.MbrUserDO; +import cn.iocoder.yudao.coreservice.modules.system.enums.logger.SysLoginLogTypeEnum; +import cn.iocoder.yudao.coreservice.modules.system.enums.logger.SysLoginResultEnum; import cn.iocoder.yudao.coreservice.modules.system.service.auth.SysUserSessionCoreService; import cn.iocoder.yudao.coreservice.modules.system.service.logger.SysLoginLogCoreService; import cn.iocoder.yudao.coreservice.modules.system.service.logger.dto.SysLoginLogCreateReqDTO; @@ -9,15 +12,12 @@ import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.common.util.monitor.TracerUtils; import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; import cn.iocoder.yudao.framework.security.core.LoginUser; +import cn.iocoder.yudao.userserver.modules.member.service.user.MbrUserService; import cn.iocoder.yudao.userserver.modules.system.controller.auth.vo.SysAuthLoginReqVO; import cn.iocoder.yudao.userserver.modules.system.controller.auth.vo.SysAuthSmsLoginReqVO; import cn.iocoder.yudao.userserver.modules.system.convert.auth.SysAuthConvert; -import cn.iocoder.yudao.userserver.modules.member.dal.dataobject.user.MbrUserDO; import cn.iocoder.yudao.userserver.modules.system.enums.sms.SysSmsSceneEnum; import cn.iocoder.yudao.userserver.modules.system.service.auth.SysAuthService; -import cn.iocoder.yudao.userserver.modules.member.service.user.MbrUserService; -import cn.iocoder.yudao.coreservice.modules.system.enums.logger.SysLoginLogTypeEnum; -import cn.iocoder.yudao.coreservice.modules.system.enums.logger.SysLoginResultEnum; import cn.iocoder.yudao.userserver.modules.system.service.sms.SysSmsCodeService; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Lazy; diff --git a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/sms/impl/SysSmsCodeServiceImpl.java b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/sms/impl/SysSmsCodeServiceImpl.java index de81048b1..6ad132aa5 100644 --- a/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/sms/impl/SysSmsCodeServiceImpl.java +++ b/yudao-user-server/src/main/java/cn/iocoder/yudao/userserver/modules/system/service/sms/impl/SysSmsCodeServiceImpl.java @@ -1,7 +1,10 @@ package cn.iocoder.yudao.userserver.modules.system.service.sms.impl; +import cn.hutool.core.map.MapUtil; +import cn.iocoder.yudao.coreservice.modules.system.service.sms.SysSmsCoreService; import cn.iocoder.yudao.userserver.modules.system.dal.dataobject.sms.SysSmsCodeDO; import cn.iocoder.yudao.userserver.modules.system.dal.mysql.sms.SysSmsCodeMapper; +import cn.iocoder.yudao.userserver.modules.system.enums.sms.SysSmsTemplateCodeConstants; import cn.iocoder.yudao.userserver.modules.system.framework.sms.SmsCodeProperties; import cn.iocoder.yudao.userserver.modules.system.service.sms.SysSmsCodeService; import org.springframework.stereotype.Service; @@ -29,12 +32,16 @@ public class SysSmsCodeServiceImpl implements SysSmsCodeService { @Resource private SysSmsCodeMapper smsCodeMapper; + @Resource + private SysSmsCoreService smsCoreService; + @Override public void sendSmsCode(String mobile, Integer scene, String createIp) { // 创建验证码 String code = this.createSmsCode(mobile, scene, createIp); // 发送验证码 - // TODO 芋艿:重要,发送短信验证码 + smsCoreService.sendSingleSmsToMember(mobile, null, SysSmsTemplateCodeConstants.USER_SMS_LOGIN, + MapUtil.of("code", code)); } private String createSmsCode(String mobile, Integer scene, String ip) {