diff --git a/src/main/java/cn/iocoder/dashboard/framework/redis/core/util/RedisStreamUtils.java b/src/main/java/cn/iocoder/dashboard/framework/redis/core/util/RedisStreamUtils.java deleted file mode 100644 index 590c84209..000000000 --- a/src/main/java/cn/iocoder/dashboard/framework/redis/core/util/RedisStreamUtils.java +++ /dev/null @@ -1,29 +0,0 @@ -package cn.iocoder.dashboard.framework.redis.core.util; - -import cn.iocoder.dashboard.modules.system.redis.stream.sms.SmsSendMessage; -import org.springframework.data.redis.connection.stream.StreamRecords; -import org.springframework.data.redis.core.RedisTemplate; - -/** - * Redis 消息工具类 - * - * @author 芋道源码 - */ -public class RedisStreamUtils { - - public static final String KEY_SMS_SEND = "stream_sms_send"; - - public static final String GROUP_SMS_SEND = "group_sms_send"; - - /** - * 发送 Redis 消息,基于 Redis pub/sub 实现 - * - * @param redisTemplate Redis 操作模板 - * @param message 消息 - */ - public static void sendChannelMessage(RedisTemplate redisTemplate, SmsSendMessage message) { - - redisTemplate.opsForStream().add(StreamRecords.newRecord().ofObject(message).withStreamKey(KEY_SMS_SEND)); - } - -} diff --git a/src/main/java/cn/iocoder/dashboard/framework/sms/core/SmsClientFactory.java b/src/main/java/cn/iocoder/dashboard/framework/sms/core/SmsClientFactory.java index d55c7cb99..bd41cc2ee 100644 --- a/src/main/java/cn/iocoder/dashboard/framework/sms/core/SmsClientFactory.java +++ b/src/main/java/cn/iocoder/dashboard/framework/sms/core/SmsClientFactory.java @@ -102,7 +102,7 @@ public class SmsClientFactory { public String getTemplateApiIdByCode(String templateCode) { SmsTemplateProperty smsTemplateProperty = templatePropertyMap.get(templateCode); if (smsTemplateProperty == null) { - throw new ServiceException(SMS_TEMPLATE_NOT_FOUND); + throw new ServiceException(SMS_TEMPLATE_NOT_EXISTS); } return smsTemplateProperty.getApiTemplateId(); } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/SmsChannelController.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/SmsChannelController.java index ddc492c23..415e47405 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/SmsChannelController.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/SmsChannelController.java @@ -5,7 +5,7 @@ import cn.iocoder.dashboard.common.pojo.PageResult; import cn.iocoder.dashboard.modules.system.controller.sms.vo.req.SmsChannelCreateReqVO; import cn.iocoder.dashboard.modules.system.controller.sms.vo.req.SmsChannelPageReqVO; import cn.iocoder.dashboard.modules.system.controller.sms.vo.resp.SmsChannelEnumRespVO; -import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.sms.SysSmsChannelDO; +import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsChannelDO; import cn.iocoder.dashboard.modules.system.service.sms.SysSmsChannelService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/SmsDefaultCallbackController.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/SmsDefaultCallbackController.java index 0a33e8b0e..3d4661076 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/SmsDefaultCallbackController.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/sms/SmsDefaultCallbackController.java @@ -1,19 +1,14 @@ package cn.iocoder.dashboard.modules.system.controller.sms; -import cn.iocoder.dashboard.framework.sms.core.SmsBody; -import cn.iocoder.dashboard.modules.system.redis.stream.sms.SmsSendStreamProducer; import cn.iocoder.dashboard.modules.system.service.sms.SysSmsService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import javax.servlet.ServletRequest; -import java.util.Arrays; -import java.util.Map; /** * 短信默认回调接口 diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/convert/sms/SmsChannelConvert.java b/src/main/java/cn/iocoder/dashboard/modules/system/convert/sms/SmsChannelConvert.java index ad272218e..833c1919c 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/convert/sms/SmsChannelConvert.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/convert/sms/SmsChannelConvert.java @@ -7,7 +7,7 @@ import cn.iocoder.dashboard.modules.system.controller.sms.vo.SmsChannelAllVO; import cn.iocoder.dashboard.modules.system.controller.sms.vo.req.SmsChannelCreateReqVO; import cn.iocoder.dashboard.modules.system.controller.sms.vo.resp.SmsChannelEnumRespVO; import cn.iocoder.dashboard.modules.system.controller.user.vo.user.SysUserUpdateReqVO; -import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.sms.SysSmsChannelDO; +import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsChannelDO; import com.baomidou.mybatisplus.core.metadata.IPage; import org.mapstruct.Mapper; import org.mapstruct.Mapping; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/convert/sms/SmsTemplateConvert.java b/src/main/java/cn/iocoder/dashboard/modules/system/convert/sms/SmsTemplateConvert.java index febac15fc..2ff680028 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/convert/sms/SmsTemplateConvert.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/convert/sms/SmsTemplateConvert.java @@ -3,8 +3,8 @@ package cn.iocoder.dashboard.modules.system.convert.sms; import cn.iocoder.dashboard.common.pojo.PageResult; import cn.iocoder.dashboard.framework.sms.core.property.SmsTemplateProperty; import cn.iocoder.dashboard.modules.system.controller.sms.vo.SmsTemplateVO; -import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.sms.SysSmsChannelDO; -import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.sms.SysSmsTemplateDO; +import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsChannelDO; +import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsTemplateDO; import com.baomidou.mybatisplus.core.metadata.IPage; import org.mapstruct.Mapper; import org.mapstruct.Mapping; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/sms/SysSmsChannelDO.java b/src/main/java/cn/iocoder/dashboard/modules/system/dal/dataobject/sms/SysSmsChannelDO.java similarity index 94% rename from src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/sms/SysSmsChannelDO.java rename to src/main/java/cn/iocoder/dashboard/modules/system/dal/dataobject/sms/SysSmsChannelDO.java index d38c1bc07..48acf346f 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/sms/SysSmsChannelDO.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/dal/dataobject/sms/SysSmsChannelDO.java @@ -1,4 +1,4 @@ -package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.sms; +package cn.iocoder.dashboard.modules.system.dal.dataobject.sms; import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO; import com.baomidou.mybatisplus.annotation.TableName; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/sms/SysSmsQueryLogDO.java b/src/main/java/cn/iocoder/dashboard/modules/system/dal/dataobject/sms/SysSmsQueryLogDO.java similarity index 95% rename from src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/sms/SysSmsQueryLogDO.java rename to src/main/java/cn/iocoder/dashboard/modules/system/dal/dataobject/sms/SysSmsQueryLogDO.java index ebb170ded..8a5d413bc 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/sms/SysSmsQueryLogDO.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/dal/dataobject/sms/SysSmsQueryLogDO.java @@ -1,4 +1,4 @@ -package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.sms; +package cn.iocoder.dashboard.modules.system.dal.dataobject.sms; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/sms/SysSmsSendLogDO.java b/src/main/java/cn/iocoder/dashboard/modules/system/dal/dataobject/sms/SysSmsSendLogDO.java similarity index 93% rename from src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/sms/SysSmsSendLogDO.java rename to src/main/java/cn/iocoder/dashboard/modules/system/dal/dataobject/sms/SysSmsSendLogDO.java index f85416dba..4bbe5f23e 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/sms/SysSmsSendLogDO.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/dal/dataobject/sms/SysSmsSendLogDO.java @@ -1,4 +1,4 @@ -package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.sms; +package cn.iocoder.dashboard.modules.system.dal.dataobject.sms; import cn.iocoder.dashboard.modules.system.enums.sms.SmsSendStatusEnum; import com.baomidou.mybatisplus.annotation.TableName; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/sms/SysSmsTemplateDO.java b/src/main/java/cn/iocoder/dashboard/modules/system/dal/dataobject/sms/SysSmsTemplateDO.java similarity index 75% rename from src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/sms/SysSmsTemplateDO.java rename to src/main/java/cn/iocoder/dashboard/modules/system/dal/dataobject/sms/SysSmsTemplateDO.java index 3e8cdc25c..929e79440 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/sms/SysSmsTemplateDO.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/dal/dataobject/sms/SysSmsTemplateDO.java @@ -1,11 +1,14 @@ -package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.sms; +package cn.iocoder.dashboard.modules.system.dal.dataobject.sms; +import cn.iocoder.dashboard.common.enums.CommonStatusEnum; import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; import lombok.Data; import lombok.EqualsAndHashCode; -import java.util.Date; +import java.util.List; /** * 短信模板 @@ -44,7 +47,7 @@ public class SysSmsTemplateDO extends BaseDO { private String bizCode; /** - * 编码 + * 模板编码 */ private String code; @@ -66,7 +69,8 @@ public class SysSmsTemplateDO extends BaseDO { /** * 参数数组(自动根据内容生成) */ - private String params; + @TableField(typeHandler = JacksonTypeHandler.class) + private List params; /** * 备注 @@ -74,7 +78,9 @@ public class SysSmsTemplateDO extends BaseDO { private String remark; /** - * 启用状态(0正常 1停用) + * 启用状态 + * + * 枚举 {@link CommonStatusEnum} */ private Integer status; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/sms/SysSmsChannelMapper.java b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/sms/SysSmsChannelMapper.java index 43b7fe743..e601ebc5c 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/sms/SysSmsChannelMapper.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/sms/SysSmsChannelMapper.java @@ -1,10 +1,10 @@ -package cn.iocoder.dashboard.modules.system.dal.mysql.dao.sms; +package cn.iocoder.dashboard.modules.system.dal.mysql.sms; import cn.hutool.core.util.StrUtil; import cn.iocoder.dashboard.common.enums.CommonStatusEnum; import cn.iocoder.dashboard.framework.mybatis.core.util.MyBatisUtils; import cn.iocoder.dashboard.modules.system.controller.sms.vo.req.SmsChannelPageReqVO; -import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.sms.SysSmsChannelDO; +import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsChannelDO; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/sms/SysSmsQueryLogMapper.java b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/sms/SysSmsQueryLogMapper.java index 535afa667..d02ceec8c 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/sms/SysSmsQueryLogMapper.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/sms/SysSmsQueryLogMapper.java @@ -1,7 +1,7 @@ -package cn.iocoder.dashboard.modules.system.dal.mysql.dao.sms; +package cn.iocoder.dashboard.modules.system.dal.mysql.sms; import cn.iocoder.dashboard.common.enums.DefaultBitFieldEnum; -import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.sms.SysSmsQueryLogDO; +import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsQueryLogDO; import cn.iocoder.dashboard.modules.system.enums.sms.SmsSendStatusEnum; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/sms/SysSmsSendLogMapper.java b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/sms/SysSmsSendLogMapper.java index eebb48fcc..3a5c7fbb8 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/sms/SysSmsSendLogMapper.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/sms/SysSmsSendLogMapper.java @@ -1,6 +1,6 @@ -package cn.iocoder.dashboard.modules.system.dal.mysql.dao.sms; +package cn.iocoder.dashboard.modules.system.dal.mysql.sms; -import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.sms.SysSmsSendLogDO; +import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsSendLogDO; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Mapper; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/sms/SysSmsTemplateMapper.java b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/sms/SysSmsTemplateMapper.java index b24c630d4..3cfc898b3 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/sms/SysSmsTemplateMapper.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/sms/SysSmsTemplateMapper.java @@ -1,15 +1,18 @@ -package cn.iocoder.dashboard.modules.system.dal.mysql.dao.sms; - +package cn.iocoder.dashboard.modules.system.dal.mysql.sms; import cn.iocoder.dashboard.common.enums.CommonStatusEnum; -import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.sms.SysSmsTemplateDO; +import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsTemplateDO; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.mapper.BaseMapper; import org.apache.ibatis.annotations.Mapper; import java.util.List; @Mapper -public interface SysSmsTemplateMapper extends BaseMapper { +public interface SysSmsTemplateMapper extends BaseMapperX { + + default SysSmsTemplateDO selectOneByCode(String code) { + return selectOne("code", code); + } /** * 根据短信渠道id查询短信模板集合 diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/enums/SysErrorCodeConstants.java b/src/main/java/cn/iocoder/dashboard/modules/system/enums/SysErrorCodeConstants.java index ca4c11a05..94db1c2f6 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/enums/SysErrorCodeConstants.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/enums/SysErrorCodeConstants.java @@ -79,11 +79,15 @@ public interface SysErrorCodeConstants { ErrorCode FILE_IS_EMPTY= new ErrorCode(1002009003, "文件为空"); - // ========== 消息 1003001000 ========== + // ========== 短信模板 1002010000 ========== + ErrorCode SMS_TEMPLATE_NOT_EXISTS = new ErrorCode(1002010000, "短信模板不存在"); + + // ========== 短信发送 1002011000 ========== + ErrorCode SMS_SEND_MOBILE_NOT_EXISTS = new ErrorCode(1002011000, "手机号不存在"); + ErrorCode SMS_CHANNEL_NOT_INIT = new ErrorCode(1003001001, "短信渠道没有初始化, 请调用SmsClientWrapper#initSmsClient()或SmsClientWrapper#addSmsClient"); ErrorCode SMS_CHANNEL_NOT_FOUND = new ErrorCode(1003001002, "没有短信渠道信息, 请初始化sms_channel表数据。"); - ErrorCode SMS_TEMPLATE_NOT_FOUND = new ErrorCode(1003001003, "没有短信模板信息, 请初始化sms_template表数据。"); ErrorCode SMS_SENDER_NOT_FOUND = new ErrorCode(1003001004, "没有找到对应的短信发送对象,请检查sms_channel表和sms_template表数据"); ErrorCode INVALID_CHANNEL_CODE = new ErrorCode(1003001005, "非法的短信渠道code,请检查sms_channel表的code值是否与SmsChannelEnum中的code值一致。"); ErrorCode PARAM_VALUE_IS_NULL = new ErrorCode(1003001006, "参数【{}】不能为空"); diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/consumer/dept/SysDeptRefreshConsumer.java b/src/main/java/cn/iocoder/dashboard/modules/system/mq/consumer/dept/SysDeptRefreshConsumer.java similarity index 82% rename from src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/consumer/dept/SysDeptRefreshConsumer.java rename to src/main/java/cn/iocoder/dashboard/modules/system/mq/consumer/dept/SysDeptRefreshConsumer.java index 7e4852dff..e6fa5a98d 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/consumer/dept/SysDeptRefreshConsumer.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/mq/consumer/dept/SysDeptRefreshConsumer.java @@ -1,7 +1,7 @@ -package cn.iocoder.dashboard.modules.system.redis.mq.consumer.dept; +package cn.iocoder.dashboard.modules.system.mq.consumer.dept; import cn.iocoder.dashboard.framework.redis.core.pubsub.AbstractChannelMessageListener; -import cn.iocoder.dashboard.modules.system.redis.mq.message.dept.SysDeptRefreshMessage; +import cn.iocoder.dashboard.modules.system.mq.message.dept.SysDeptRefreshMessage; import cn.iocoder.dashboard.modules.system.service.dept.SysDeptService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/consumer/dict/SysDictDataRefreshConsumer.java b/src/main/java/cn/iocoder/dashboard/modules/system/mq/consumer/dict/SysDictDataRefreshConsumer.java similarity index 82% rename from src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/consumer/dict/SysDictDataRefreshConsumer.java rename to src/main/java/cn/iocoder/dashboard/modules/system/mq/consumer/dict/SysDictDataRefreshConsumer.java index 87c898984..12bf134a3 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/consumer/dict/SysDictDataRefreshConsumer.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/mq/consumer/dict/SysDictDataRefreshConsumer.java @@ -1,7 +1,7 @@ -package cn.iocoder.dashboard.modules.system.redis.mq.consumer.dict; +package cn.iocoder.dashboard.modules.system.mq.consumer.dict; import cn.iocoder.dashboard.framework.redis.core.pubsub.AbstractChannelMessageListener; -import cn.iocoder.dashboard.modules.system.redis.mq.message.dict.SysDictDataRefreshMessage; +import cn.iocoder.dashboard.modules.system.mq.message.dict.SysDictDataRefreshMessage; import cn.iocoder.dashboard.modules.system.service.dict.SysDictDataService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/consumer/permission/SysMenuRefreshConsumer.java b/src/main/java/cn/iocoder/dashboard/modules/system/mq/consumer/permission/SysMenuRefreshConsumer.java similarity index 81% rename from src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/consumer/permission/SysMenuRefreshConsumer.java rename to src/main/java/cn/iocoder/dashboard/modules/system/mq/consumer/permission/SysMenuRefreshConsumer.java index 5f4442769..36152424c 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/consumer/permission/SysMenuRefreshConsumer.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/mq/consumer/permission/SysMenuRefreshConsumer.java @@ -1,7 +1,7 @@ -package cn.iocoder.dashboard.modules.system.redis.mq.consumer.permission; +package cn.iocoder.dashboard.modules.system.mq.consumer.permission; import cn.iocoder.dashboard.framework.redis.core.pubsub.AbstractChannelMessageListener; -import cn.iocoder.dashboard.modules.system.redis.mq.message.permission.SysMenuRefreshMessage; +import cn.iocoder.dashboard.modules.system.mq.message.permission.SysMenuRefreshMessage; import cn.iocoder.dashboard.modules.system.service.permission.SysMenuService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/consumer/permission/SysRoleMenuRefreshConsumer.java b/src/main/java/cn/iocoder/dashboard/modules/system/mq/consumer/permission/SysRoleMenuRefreshConsumer.java similarity index 82% rename from src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/consumer/permission/SysRoleMenuRefreshConsumer.java rename to src/main/java/cn/iocoder/dashboard/modules/system/mq/consumer/permission/SysRoleMenuRefreshConsumer.java index 60861ba58..6927e1464 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/consumer/permission/SysRoleMenuRefreshConsumer.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/mq/consumer/permission/SysRoleMenuRefreshConsumer.java @@ -1,7 +1,7 @@ -package cn.iocoder.dashboard.modules.system.redis.mq.consumer.permission; +package cn.iocoder.dashboard.modules.system.mq.consumer.permission; import cn.iocoder.dashboard.framework.redis.core.pubsub.AbstractChannelMessageListener; -import cn.iocoder.dashboard.modules.system.redis.mq.message.permission.SysRoleMenuRefreshMessage; +import cn.iocoder.dashboard.modules.system.mq.message.permission.SysRoleMenuRefreshMessage; import cn.iocoder.dashboard.modules.system.service.permission.SysPermissionService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/consumer/permission/SysRoleRefreshConsumer.java b/src/main/java/cn/iocoder/dashboard/modules/system/mq/consumer/permission/SysRoleRefreshConsumer.java similarity index 81% rename from src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/consumer/permission/SysRoleRefreshConsumer.java rename to src/main/java/cn/iocoder/dashboard/modules/system/mq/consumer/permission/SysRoleRefreshConsumer.java index 0a71fca7e..a5e77f7e5 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/consumer/permission/SysRoleRefreshConsumer.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/mq/consumer/permission/SysRoleRefreshConsumer.java @@ -1,7 +1,7 @@ -package cn.iocoder.dashboard.modules.system.redis.mq.consumer.permission; +package cn.iocoder.dashboard.modules.system.mq.consumer.permission; import cn.iocoder.dashboard.framework.redis.core.pubsub.AbstractChannelMessageListener; -import cn.iocoder.dashboard.modules.system.redis.mq.message.permission.SysRoleRefreshMessage; +import cn.iocoder.dashboard.modules.system.mq.message.permission.SysRoleRefreshMessage; import cn.iocoder.dashboard.modules.system.service.permission.SysRoleService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/redis/stream/sms/SmsSendStreamConsumer.java b/src/main/java/cn/iocoder/dashboard/modules/system/mq/consumer/sms/SmsSendStreamConsumer.java similarity index 96% rename from src/main/java/cn/iocoder/dashboard/modules/system/redis/stream/sms/SmsSendStreamConsumer.java rename to src/main/java/cn/iocoder/dashboard/modules/system/mq/consumer/sms/SmsSendStreamConsumer.java index 0ab531b43..bbd5de462 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/redis/stream/sms/SmsSendStreamConsumer.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/mq/consumer/sms/SmsSendStreamConsumer.java @@ -1,4 +1,4 @@ -package cn.iocoder.dashboard.modules.system.redis.stream.sms; +package cn.iocoder.dashboard.modules.system.mq.consumer.sms; import cn.iocoder.dashboard.framework.sms.client.AbstractSmsClient; import cn.iocoder.dashboard.framework.sms.core.SmsBody; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/message/dept/SysDeptRefreshMessage.java b/src/main/java/cn/iocoder/dashboard/modules/system/mq/message/dept/SysDeptRefreshMessage.java similarity index 81% rename from src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/message/dept/SysDeptRefreshMessage.java rename to src/main/java/cn/iocoder/dashboard/modules/system/mq/message/dept/SysDeptRefreshMessage.java index 0c069e319..a78b1250f 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/message/dept/SysDeptRefreshMessage.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/mq/message/dept/SysDeptRefreshMessage.java @@ -1,4 +1,4 @@ -package cn.iocoder.dashboard.modules.system.redis.mq.message.dept; +package cn.iocoder.dashboard.modules.system.mq.message.dept; import cn.iocoder.dashboard.framework.redis.core.pubsub.ChannelMessage; import lombok.Data; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/message/dict/SysDictDataRefreshMessage.java b/src/main/java/cn/iocoder/dashboard/modules/system/mq/message/dict/SysDictDataRefreshMessage.java similarity index 82% rename from src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/message/dict/SysDictDataRefreshMessage.java rename to src/main/java/cn/iocoder/dashboard/modules/system/mq/message/dict/SysDictDataRefreshMessage.java index 2d4342423..7fad277c4 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/message/dict/SysDictDataRefreshMessage.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/mq/message/dict/SysDictDataRefreshMessage.java @@ -1,4 +1,4 @@ -package cn.iocoder.dashboard.modules.system.redis.mq.message.dict; +package cn.iocoder.dashboard.modules.system.mq.message.dict; import cn.iocoder.dashboard.framework.redis.core.pubsub.ChannelMessage; import lombok.Data; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/message/permission/SysMenuRefreshMessage.java b/src/main/java/cn/iocoder/dashboard/modules/system/mq/message/permission/SysMenuRefreshMessage.java similarity index 80% rename from src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/message/permission/SysMenuRefreshMessage.java rename to src/main/java/cn/iocoder/dashboard/modules/system/mq/message/permission/SysMenuRefreshMessage.java index 8f72705ee..159682a98 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/message/permission/SysMenuRefreshMessage.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/mq/message/permission/SysMenuRefreshMessage.java @@ -1,4 +1,4 @@ -package cn.iocoder.dashboard.modules.system.redis.mq.message.permission; +package cn.iocoder.dashboard.modules.system.mq.message.permission; import cn.iocoder.dashboard.framework.redis.core.pubsub.ChannelMessage; import lombok.Data; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/message/permission/SysRoleMenuRefreshMessage.java b/src/main/java/cn/iocoder/dashboard/modules/system/mq/message/permission/SysRoleMenuRefreshMessage.java similarity index 81% rename from src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/message/permission/SysRoleMenuRefreshMessage.java rename to src/main/java/cn/iocoder/dashboard/modules/system/mq/message/permission/SysRoleMenuRefreshMessage.java index b1c303dbe..491c9b0d2 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/message/permission/SysRoleMenuRefreshMessage.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/mq/message/permission/SysRoleMenuRefreshMessage.java @@ -1,4 +1,4 @@ -package cn.iocoder.dashboard.modules.system.redis.mq.message.permission; +package cn.iocoder.dashboard.modules.system.mq.message.permission; import cn.iocoder.dashboard.framework.redis.core.pubsub.ChannelMessage; import lombok.Data; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/message/permission/SysRoleRefreshMessage.java b/src/main/java/cn/iocoder/dashboard/modules/system/mq/message/permission/SysRoleRefreshMessage.java similarity index 80% rename from src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/message/permission/SysRoleRefreshMessage.java rename to src/main/java/cn/iocoder/dashboard/modules/system/mq/message/permission/SysRoleRefreshMessage.java index ac46d181e..b99401021 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/message/permission/SysRoleRefreshMessage.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/mq/message/permission/SysRoleRefreshMessage.java @@ -1,4 +1,4 @@ -package cn.iocoder.dashboard.modules.system.redis.mq.message.permission; +package cn.iocoder.dashboard.modules.system.mq.message.permission; import cn.iocoder.dashboard.framework.redis.core.pubsub.ChannelMessage; import lombok.Data; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/producer/dept/SysDeptProducer.java b/src/main/java/cn/iocoder/dashboard/modules/system/mq/producer/dept/SysDeptProducer.java similarity index 80% rename from src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/producer/dept/SysDeptProducer.java rename to src/main/java/cn/iocoder/dashboard/modules/system/mq/producer/dept/SysDeptProducer.java index 3ce859fa4..4ad7db4b8 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/producer/dept/SysDeptProducer.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/mq/producer/dept/SysDeptProducer.java @@ -1,7 +1,7 @@ -package cn.iocoder.dashboard.modules.system.redis.mq.producer.dept; +package cn.iocoder.dashboard.modules.system.mq.producer.dept; import cn.iocoder.dashboard.framework.redis.core.util.RedisMessageUtils; -import cn.iocoder.dashboard.modules.system.redis.mq.message.dept.SysDeptRefreshMessage; +import cn.iocoder.dashboard.modules.system.mq.message.dept.SysDeptRefreshMessage; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Component; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/producer/dict/SysDictDataProducer.java b/src/main/java/cn/iocoder/dashboard/modules/system/mq/producer/dict/SysDictDataProducer.java similarity index 80% rename from src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/producer/dict/SysDictDataProducer.java rename to src/main/java/cn/iocoder/dashboard/modules/system/mq/producer/dict/SysDictDataProducer.java index af9daae84..2ccfc51d2 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/producer/dict/SysDictDataProducer.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/mq/producer/dict/SysDictDataProducer.java @@ -1,7 +1,7 @@ -package cn.iocoder.dashboard.modules.system.redis.mq.producer.dict; +package cn.iocoder.dashboard.modules.system.mq.producer.dict; import cn.iocoder.dashboard.framework.redis.core.util.RedisMessageUtils; -import cn.iocoder.dashboard.modules.system.redis.mq.message.dict.SysDictDataRefreshMessage; +import cn.iocoder.dashboard.modules.system.mq.message.dict.SysDictDataRefreshMessage; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Component; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/producer/permission/SysMenuProducer.java b/src/main/java/cn/iocoder/dashboard/modules/system/mq/producer/permission/SysMenuProducer.java similarity index 79% rename from src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/producer/permission/SysMenuProducer.java rename to src/main/java/cn/iocoder/dashboard/modules/system/mq/producer/permission/SysMenuProducer.java index 9a760ad2d..6d664c725 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/producer/permission/SysMenuProducer.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/mq/producer/permission/SysMenuProducer.java @@ -1,7 +1,7 @@ -package cn.iocoder.dashboard.modules.system.redis.mq.producer.permission; +package cn.iocoder.dashboard.modules.system.mq.producer.permission; import cn.iocoder.dashboard.framework.redis.core.util.RedisMessageUtils; -import cn.iocoder.dashboard.modules.system.redis.mq.message.permission.SysMenuRefreshMessage; +import cn.iocoder.dashboard.modules.system.mq.message.permission.SysMenuRefreshMessage; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Component; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/producer/permission/SysPermissionProducer.java b/src/main/java/cn/iocoder/dashboard/modules/system/mq/producer/permission/SysPermissionProducer.java similarity index 79% rename from src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/producer/permission/SysPermissionProducer.java rename to src/main/java/cn/iocoder/dashboard/modules/system/mq/producer/permission/SysPermissionProducer.java index 67a4769a1..f9eded668 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/producer/permission/SysPermissionProducer.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/mq/producer/permission/SysPermissionProducer.java @@ -1,7 +1,7 @@ -package cn.iocoder.dashboard.modules.system.redis.mq.producer.permission; +package cn.iocoder.dashboard.modules.system.mq.producer.permission; import cn.iocoder.dashboard.framework.redis.core.util.RedisMessageUtils; -import cn.iocoder.dashboard.modules.system.redis.mq.message.permission.SysRoleMenuRefreshMessage; +import cn.iocoder.dashboard.modules.system.mq.message.permission.SysRoleMenuRefreshMessage; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Component; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/producer/permission/SysRoleProducer.java b/src/main/java/cn/iocoder/dashboard/modules/system/mq/producer/permission/SysRoleProducer.java similarity index 79% rename from src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/producer/permission/SysRoleProducer.java rename to src/main/java/cn/iocoder/dashboard/modules/system/mq/producer/permission/SysRoleProducer.java index f1be4b87b..e11945dfe 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/producer/permission/SysRoleProducer.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/mq/producer/permission/SysRoleProducer.java @@ -1,7 +1,7 @@ -package cn.iocoder.dashboard.modules.system.redis.mq.producer.permission; +package cn.iocoder.dashboard.modules.system.mq.producer.permission; import cn.iocoder.dashboard.framework.redis.core.util.RedisMessageUtils; -import cn.iocoder.dashboard.modules.system.redis.mq.message.permission.SysRoleRefreshMessage; +import cn.iocoder.dashboard.modules.system.mq.message.permission.SysRoleRefreshMessage; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Component; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/mq/producer/sms/SmsSendStreamProducer.java b/src/main/java/cn/iocoder/dashboard/modules/system/mq/producer/sms/SmsSendStreamProducer.java new file mode 100644 index 000000000..891a844cc --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/system/mq/producer/sms/SmsSendStreamProducer.java @@ -0,0 +1,42 @@ +package cn.iocoder.dashboard.modules.system.mq.producer.sms; + +import cn.iocoder.dashboard.framework.redis.core.util.RedisMessageUtils; +import cn.iocoder.dashboard.modules.system.mq.message.sms.SysSmsSendMessage; +import lombok.extern.slf4j.Slf4j; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.Map; + +/** + * 短信发送流消息监听器 + * + * @author zzf + * @date 2021/3/9 16:35 + */ +@Slf4j +@Component +public class SmsSendStreamProducer { + + @Resource + private StringRedisTemplate stringRedisTemplate; + + /** + * 发送短信 Message + * + * @param mobile 手机号 + * @param templateCode 短信模板编号 + * @param templateParams 短信模板参数 + * @param userId 用户编号 + * @param userType 用户类型 + */ + public void sendSmsSendMessage(String mobile, String templateCode, Map templateParams, + Integer userId, Integer userType) { + SysSmsSendMessage message = new SysSmsSendMessage(); + message.setMobile(mobile).setTemplateCode(templateCode).setTemplateParams(templateParams); + message.setUserId(userId).setUserType(userType); + RedisMessageUtils.sendStreamMessage(stringRedisTemplate, message); + } + +} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/consumer/sms/SmsSendConsumer.java b/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/consumer/sms/SmsSendConsumer.java deleted file mode 100644 index db8d727ad..000000000 --- a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/consumer/sms/SmsSendConsumer.java +++ /dev/null @@ -1,56 +0,0 @@ -//package cn.iocoder.dashboard.modules.system.redis.mq.consumer.sms; -// -//import cn.iocoder.dashboard.framework.redis.core.pubsub.AbstractChannelMessageListener; -//import cn.iocoder.dashboard.framework.sms.client.AbstractSmsClient; -//import cn.iocoder.dashboard.framework.sms.core.SmsResult; -//import cn.iocoder.dashboard.modules.system.redis.mq.message.dept.SysDeptRefreshMessage; -//import cn.iocoder.dashboard.modules.system.redis.stream.sms.SmsSendMessage; -//import cn.iocoder.dashboard.modules.system.service.sms.SysSmsChannelService; -//import cn.iocoder.dashboard.modules.system.service.sms.SysSmsQueryLogService; -//import lombok.extern.slf4j.Slf4j; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.data.redis.connection.stream.Consumer; -//import org.springframework.data.redis.connection.stream.ObjectRecord; -//import org.springframework.data.redis.connection.stream.ReadOffset; -//import org.springframework.data.redis.connection.stream.StreamOffset; -//import org.springframework.data.redis.core.StringRedisTemplate; -//import org.springframework.stereotype.Component; -// -//import javax.annotation.Resource; -// -///** -// * 针对 {@link SysDeptRefreshMessage} 的消费者 -// * -// * @author 芋道源码 -// */ -//@Component -//@Slf4j -//public class SmsSendConsumer extends AbstractChannelMessageListener { -// -// @Resource -// private SysSmsChannelService smsChannelService; -// -// @Resource -// private SysSmsQueryLogService smsQueryLogService; -// -// @Autowired -// StringRedisTemplate redisTemplate; -// -// @Override -// public void onMessage(SmsSendMessage message) { -// -// redisTemplate.opsForStream().add(ObjectRecord.create("String", message)); -// -// redisTemplate.opsForStream().read(Consumer.from("",""), StreamOffset.create("", ReadOffset.lastConsumed())); -// -// -// -// log.info("[onMessage][收到 发送短信 消息], content: " + message.toString()); -// AbstractSmsClient smsClient = smsChannelService.getSmsClient(message.getSmsBody().getTemplateCode()); -// String templateApiId = smsChannelService.getSmsTemplateApiIdByCode(message.getSmsBody().getTemplateCode()); -// -// SmsResult result = smsClient.send(templateApiId, message.getSmsBody(), message.getTargetPhone()); -// smsQueryLogService.afterSendLog(message.getSmsBody().getSmsLogId(), result); -// } -// -//} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/producer/sms/SmsProducer.java b/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/producer/sms/SmsProducer.java deleted file mode 100644 index 3e4681715..000000000 --- a/src/main/java/cn/iocoder/dashboard/modules/system/redis/mq/producer/sms/SmsProducer.java +++ /dev/null @@ -1,31 +0,0 @@ -//package cn.iocoder.dashboard.modules.system.redis.mq.producer.sms; -// -//import cn.iocoder.dashboard.framework.redis.core.util.RedisMessageUtils; -//import cn.iocoder.dashboard.framework.sms.core.SmsBody; -//import cn.iocoder.dashboard.modules.system.redis.stream.sms.SmsSendMessage; -//import org.springframework.data.redis.core.StringRedisTemplate; -//import org.springframework.stereotype.Component; -// -//import javax.annotation.Resource; -// -///** -// * 短信的 Producer -// */ -//@Component -//public class SmsProducer { -// -// @Resource -// private StringRedisTemplate stringRedisTemplate; -// -// /** -// * 发送 {@link SmsSendMessage} 消息 -// */ -// public void sendSmsSendMessage(SmsBody smsBody, String targetPhone) { -// SmsSendMessage message = new SmsSendMessage(); -// message.setSmsBody(smsBody); -// message.setTargetPhone(targetPhone); -// // TODO FROM 芋艿 TO ZZF:这块等未来改哈。这个方法目前是广播消费,会导致每个节点都发送一次。等后续封装出 redis stream 消息 -// RedisMessageUtils.sendChannelMessage(stringRedisTemplate, message); -// } -// -//} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/redis/stream/StreamConsumerRunner.java b/src/main/java/cn/iocoder/dashboard/modules/system/redis/stream/StreamConsumerRunner.java deleted file mode 100644 index 7cd9d2486..000000000 --- a/src/main/java/cn/iocoder/dashboard/modules/system/redis/stream/StreamConsumerRunner.java +++ /dev/null @@ -1,93 +0,0 @@ -package cn.iocoder.dashboard.modules.system.redis.stream; - -import cn.iocoder.dashboard.framework.redis.core.util.RedisStreamUtils; -import cn.iocoder.dashboard.modules.system.redis.stream.sms.SmsSendMessage; -import cn.iocoder.dashboard.modules.system.redis.stream.sms.SmsSendStreamConsumer; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.DisposableBean; -import org.springframework.boot.ApplicationArguments; -import org.springframework.boot.ApplicationRunner; -import org.springframework.data.redis.connection.RedisConnectionFactory; -import org.springframework.data.redis.connection.stream.*; -import org.springframework.data.redis.core.StringRedisTemplate; -import org.springframework.data.redis.serializer.StringRedisSerializer; -import org.springframework.data.redis.stream.StreamMessageListenerContainer; -import org.springframework.data.redis.stream.StreamMessageListenerContainer.StreamMessageListenerContainerOptions; -import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; -import org.springframework.stereotype.Component; -import org.springframework.util.ErrorHandler; - -import javax.annotation.Resource; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.time.Duration; - - -@Slf4j -@Component -public class StreamConsumerRunner implements ApplicationRunner, DisposableBean { - - @Resource - RedisConnectionFactory redisConnectionFactory; - - @Resource - ThreadPoolTaskExecutor threadPoolTaskExecutor; - - @Resource - SmsSendStreamConsumer streamMessageListener; - - @Resource - StringRedisTemplate stringRedisTemplate; - - private StreamMessageListenerContainer> streamMessageListenerContainer; - - @Override - public void run(ApplicationArguments args) throws UnknownHostException { - - StreamInfo.XInfoGroups groups = stringRedisTemplate.opsForStream().groups(RedisStreamUtils.KEY_SMS_SEND); - if (groups.isEmpty()) { - stringRedisTemplate.opsForStream().createGroup(RedisStreamUtils.KEY_SMS_SEND, RedisStreamUtils.GROUP_SMS_SEND); - } - - - // 创建配置对象 - StreamMessageListenerContainerOptions> streamMessageListenerContainerOptions = StreamMessageListenerContainerOptions - .builder() - // 一次性最多拉取多少条消息 - .batchSize(10) - // 执行消息轮询的执行器 - .executor(this.threadPoolTaskExecutor) - // 消息消费异常的handler - .errorHandler(new ErrorHandler() { - @Override - public void handleError(Throwable t) { - // throw new RuntimeException(t); - t.printStackTrace(); - } - }) - // 超时时间,设置为0,表示不超时(超时后会抛出异常) - .pollTimeout(Duration.ZERO) - // 序列化器 - .serializer(new StringRedisSerializer()) - .targetType(SmsSendMessage.class) - .build(); - - // 根据配置对象创建监听容器对象 - StreamMessageListenerContainer> streamMessageListenerContainer = StreamMessageListenerContainer - .create(this.redisConnectionFactory, streamMessageListenerContainerOptions); - - // 使用监听容器对象开始监听消费(使用的是手动确认方式) - streamMessageListenerContainer.receive(Consumer.from(RedisStreamUtils.GROUP_SMS_SEND, InetAddress.getLocalHost().getHostName()), - StreamOffset.create(RedisStreamUtils.KEY_SMS_SEND, ReadOffset.lastConsumed()), this.streamMessageListener); - - this.streamMessageListenerContainer = streamMessageListenerContainer; - // 启动监听 - this.streamMessageListenerContainer.start(); - - } - - @Override - public void destroy() throws Exception { - this.streamMessageListenerContainer.stop(); - } -} \ No newline at end of file diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/redis/stream/sms/SmsSendMessage.java b/src/main/java/cn/iocoder/dashboard/modules/system/redis/stream/sms/SmsSendMessage.java deleted file mode 100644 index a8aeff23f..000000000 --- a/src/main/java/cn/iocoder/dashboard/modules/system/redis/stream/sms/SmsSendMessage.java +++ /dev/null @@ -1,16 +0,0 @@ -package cn.iocoder.dashboard.modules.system.redis.stream.sms; - -import cn.iocoder.dashboard.framework.sms.core.SmsBody; -import lombok.Data; - -/** - * 部门数据刷新 Message - */ -@Data -public class SmsSendMessage { - - private SmsBody smsBody; - - private String targetPhone; - -} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/redis/stream/sms/SmsSendStreamProducer.java b/src/main/java/cn/iocoder/dashboard/modules/system/redis/stream/sms/SmsSendStreamProducer.java deleted file mode 100644 index 069534251..000000000 --- a/src/main/java/cn/iocoder/dashboard/modules/system/redis/stream/sms/SmsSendStreamProducer.java +++ /dev/null @@ -1,35 +0,0 @@ -package cn.iocoder.dashboard.modules.system.redis.stream.sms; - -import cn.iocoder.dashboard.framework.redis.core.util.RedisStreamUtils; -import cn.iocoder.dashboard.framework.sms.core.SmsBody; -import lombok.extern.slf4j.Slf4j; -import org.springframework.data.redis.core.StringRedisTemplate; -import org.springframework.stereotype.Component; - -import javax.annotation.Resource; - -/** - * 短信发送流消息监听器 - * - * @author zzf - * @date 2021/3/9 16:35 - */ -@Slf4j -@Component -public class SmsSendStreamProducer { - - @Resource - private StringRedisTemplate stringRedisTemplate; - - /** - * 发送 {@link SmsSendMessage} 消息 - */ - public void sendSmsSendMessage(SmsBody smsBody, String targetPhone) { - SmsSendMessage message = new SmsSendMessage(); - message.setSmsBody(smsBody); - message.setTargetPhone(targetPhone); - - RedisStreamUtils.sendChannelMessage(stringRedisTemplate, message); - } - -} \ No newline at end of file diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/dept/impl/SysDeptServiceImpl.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/dept/impl/SysDeptServiceImpl.java index e87e92a9b..96e3d1ad0 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/dept/impl/SysDeptServiceImpl.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/dept/impl/SysDeptServiceImpl.java @@ -11,7 +11,7 @@ import cn.iocoder.dashboard.modules.system.convert.dept.SysDeptConvert; import cn.iocoder.dashboard.modules.system.dal.mysql.dept.SysDeptMapper; import cn.iocoder.dashboard.modules.system.dal.dataobject.dept.SysDeptDO; import cn.iocoder.dashboard.modules.system.enums.dept.DeptIdEnum; -import cn.iocoder.dashboard.modules.system.redis.mq.producer.dept.SysDeptProducer; +import cn.iocoder.dashboard.modules.system.mq.producer.dept.SysDeptProducer; import cn.iocoder.dashboard.modules.system.service.dept.SysDeptService; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMultimap; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/dict/impl/SysDictDataServiceImpl.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/dict/impl/SysDictDataServiceImpl.java index 461d1ab21..7f24cbff4 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/dict/impl/SysDictDataServiceImpl.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/dict/impl/SysDictDataServiceImpl.java @@ -12,7 +12,7 @@ import cn.iocoder.dashboard.modules.system.convert.dict.SysDictDataConvert; import cn.iocoder.dashboard.modules.system.dal.dataobject.dict.SysDictDataDO; import cn.iocoder.dashboard.modules.system.dal.dataobject.dict.SysDictTypeDO; import cn.iocoder.dashboard.modules.system.dal.mysql.dict.SysDictDataMapper; -import cn.iocoder.dashboard.modules.system.redis.mq.producer.dict.SysDictDataProducer; +import cn.iocoder.dashboard.modules.system.mq.producer.dict.SysDictDataProducer; import cn.iocoder.dashboard.modules.system.service.dict.SysDictDataService; import cn.iocoder.dashboard.modules.system.service.dict.SysDictTypeService; import com.google.common.annotations.VisibleForTesting; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysMenuServiceImpl.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysMenuServiceImpl.java index 6b93d9d48..ec4ea5a9b 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysMenuServiceImpl.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysMenuServiceImpl.java @@ -11,7 +11,7 @@ import cn.iocoder.dashboard.modules.system.dal.mysql.permission.SysMenuMapper; import cn.iocoder.dashboard.modules.system.dal.dataobject.permission.SysMenuDO; import cn.iocoder.dashboard.modules.system.enums.permission.MenuIdEnum; import cn.iocoder.dashboard.modules.system.enums.permission.MenuTypeEnum; -import cn.iocoder.dashboard.modules.system.redis.mq.producer.permission.SysMenuProducer; +import cn.iocoder.dashboard.modules.system.mq.producer.permission.SysMenuProducer; import cn.iocoder.dashboard.modules.system.service.permission.SysMenuService; import cn.iocoder.dashboard.modules.system.service.permission.SysPermissionService; import cn.iocoder.dashboard.util.collection.CollectionUtils; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysPermissionServiceImpl.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysPermissionServiceImpl.java index 5cf15879b..9116d3e55 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysPermissionServiceImpl.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysPermissionServiceImpl.java @@ -3,7 +3,6 @@ package cn.iocoder.dashboard.modules.system.service.permission.impl; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.ArrayUtil; -import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.dashboard.framework.security.core.util.SecurityFrameworkUtils; import cn.iocoder.dashboard.modules.system.dal.mysql.permission.SysRoleMenuMapper; import cn.iocoder.dashboard.modules.system.dal.mysql.permission.SysUserRoleMapper; @@ -11,7 +10,7 @@ import cn.iocoder.dashboard.modules.system.dal.dataobject.permission.SysMenuDO; import cn.iocoder.dashboard.modules.system.dal.dataobject.permission.SysRoleDO; import cn.iocoder.dashboard.modules.system.dal.dataobject.permission.SysRoleMenuDO; import cn.iocoder.dashboard.modules.system.dal.dataobject.permission.SysUserRoleDO; -import cn.iocoder.dashboard.modules.system.redis.mq.producer.permission.SysPermissionProducer; +import cn.iocoder.dashboard.modules.system.mq.producer.permission.SysPermissionProducer; import cn.iocoder.dashboard.modules.system.service.permission.SysMenuService; import cn.iocoder.dashboard.modules.system.service.permission.SysPermissionService; import cn.iocoder.dashboard.modules.system.service.permission.SysRoleService; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysRoleServiceImpl.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysRoleServiceImpl.java index 1d627b8b3..e79813636 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysRoleServiceImpl.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/permission/impl/SysRoleServiceImpl.java @@ -15,7 +15,7 @@ import cn.iocoder.dashboard.modules.system.dal.mysql.permission.SysRoleMapper; import cn.iocoder.dashboard.modules.system.dal.dataobject.permission.SysRoleDO; import cn.iocoder.dashboard.modules.system.enums.permission.RoleCodeEnum; import cn.iocoder.dashboard.modules.system.enums.permission.SysRoleTypeEnum; -import cn.iocoder.dashboard.modules.system.redis.mq.producer.permission.SysRoleProducer; +import cn.iocoder.dashboard.modules.system.mq.producer.permission.SysRoleProducer; import cn.iocoder.dashboard.modules.system.service.permission.SysPermissionService; import cn.iocoder.dashboard.modules.system.service.permission.SysRoleService; import com.google.common.collect.ImmutableMap; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/SysSmsChannelService.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/SysSmsChannelService.java index 3ce83fe78..5224adb9a 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/SysSmsChannelService.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/SysSmsChannelService.java @@ -2,14 +2,12 @@ package cn.iocoder.dashboard.modules.system.service.sms; import cn.iocoder.dashboard.common.pojo.PageResult; import cn.iocoder.dashboard.framework.sms.client.AbstractSmsClient; -import cn.iocoder.dashboard.framework.sms.core.SmsResultDetail; import cn.iocoder.dashboard.modules.system.controller.sms.vo.SmsChannelAllVO; import cn.iocoder.dashboard.modules.system.controller.sms.vo.req.SmsChannelCreateReqVO; import cn.iocoder.dashboard.modules.system.controller.sms.vo.req.SmsChannelPageReqVO; import cn.iocoder.dashboard.modules.system.controller.sms.vo.resp.SmsChannelEnumRespVO; -import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.sms.SysSmsChannelDO; +import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsChannelDO; -import javax.servlet.ServletRequest; import java.util.List; /** diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/SysSmsService.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/SysSmsService.java index 93a467d62..cccd64c31 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/SysSmsService.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/SysSmsService.java @@ -1,13 +1,8 @@ package cn.iocoder.dashboard.modules.system.service.sms; -import cn.hutool.core.collection.CollectionUtil; -import cn.hutool.core.util.ArrayUtil; -import cn.iocoder.dashboard.framework.sms.core.SmsBody; -import cn.iocoder.dashboard.framework.sms.core.enums.SmsChannelEnum; - import javax.servlet.ServletRequest; -import java.util.Arrays; import java.util.List; +import java.util.Map; /** * 短信Service接口 @@ -18,39 +13,11 @@ import java.util.List; */ public interface SysSmsService { - /** - * 发送消息 - * - * @param smsBody 消息内容 - * @param targetPhones 发送对象手机号列表 - */ - default void send(SmsBody smsBody, List targetPhones) { - if (CollectionUtil.isEmpty(targetPhones)) { - return; - } - targetPhones.forEach(s -> this.send(smsBody, s)); - } + void sendSingleSms(String mobile, Long userId, Integer userType, + String templateCode, Map templateParams); - /** - * 发送消息 - * - * @param smsBody 消息内容 - * @param targetPhone 发送对象手机号 - */ - void send(SmsBody smsBody, String targetPhone); - - /** - * 发送消息 - * - * @param smsBody 消息内容 - * @param targetPhones 发送对象手机号数组 - */ - default void send(SmsBody smsBody, String... targetPhones) { - if (ArrayUtil.isEmpty(targetPhones)) { - return; - } - send(smsBody, Arrays.asList(targetPhones)); - } + void sendBatchSms(List mobiles, List userIds, Integer userType, + String templateCode, Map templateParams); /** * 处理短信发送回调函数 diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/SysSmsTemplateService.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/SysSmsTemplateService.java index 8ba74b2f6..137291a47 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/SysSmsTemplateService.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/SysSmsTemplateService.java @@ -1,10 +1,21 @@ package cn.iocoder.dashboard.modules.system.service.sms; +import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsTemplateDO; + /** - * 短信渠道Service接口 + * 短信模板 Service 接口 * * @author zzf * @date 2021/1/25 9:24 */ public interface SysSmsTemplateService { + + /** + * 获得短信模板 + * + * @param code 模板编码 + * @return 短信模板 + */ + SysSmsTemplateDO getSmsTemplateByCode(String code); + } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SysSmsChannelServiceImpl.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SysSmsChannelServiceImpl.java index 6ecd7681b..6026320f9 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SysSmsChannelServiceImpl.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SysSmsChannelServiceImpl.java @@ -8,7 +8,6 @@ import cn.iocoder.dashboard.framework.sms.core.enums.SmsChannelEnum; import cn.iocoder.dashboard.framework.sms.core.property.SmsChannelProperty; import cn.iocoder.dashboard.framework.sms.core.property.SmsTemplateProperty; import cn.iocoder.dashboard.modules.system.controller.sms.vo.SmsChannelAllVO; -import cn.iocoder.dashboard.modules.system.controller.sms.vo.SmsTemplateVO; import cn.iocoder.dashboard.modules.system.controller.sms.vo.req.SmsChannelCreateReqVO; import cn.iocoder.dashboard.modules.system.controller.sms.vo.req.SmsChannelPageReqVO; import cn.iocoder.dashboard.modules.system.controller.sms.vo.resp.SmsChannelEnumRespVO; @@ -16,10 +15,9 @@ import cn.iocoder.dashboard.modules.system.convert.sms.SmsChannelConvert; import cn.iocoder.dashboard.modules.system.convert.sms.SmsTemplateConvert; import cn.iocoder.dashboard.modules.system.dal.mysql.dao.sms.SysSmsChannelMapper; import cn.iocoder.dashboard.modules.system.dal.mysql.dao.sms.SysSmsTemplateMapper; -import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.sms.SysSmsChannelDO; -import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.sms.SysSmsTemplateDO; +import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsChannelDO; +import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsTemplateDO; import cn.iocoder.dashboard.modules.system.service.sms.SysSmsChannelService; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SysSmsQueryLogServiceImpl.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SysSmsQueryLogServiceImpl.java index a08a7bb76..42d7d3550 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SysSmsQueryLogServiceImpl.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SysSmsQueryLogServiceImpl.java @@ -6,7 +6,7 @@ import cn.iocoder.dashboard.framework.sms.core.SmsResult; import cn.iocoder.dashboard.framework.sms.core.SmsResultDetail; import cn.iocoder.dashboard.framework.sms.core.property.SmsChannelProperty; import cn.iocoder.dashboard.modules.system.dal.mysql.dao.sms.SysSmsQueryLogMapper; -import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.sms.SysSmsQueryLogDO; +import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsQueryLogDO; import cn.iocoder.dashboard.modules.system.enums.sms.SmsSendStatusEnum; import cn.iocoder.dashboard.modules.system.service.sms.SysSmsQueryLogService; import org.springframework.stereotype.Service; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SysSmsSendLogServiceImpl.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SysSmsSendLogServiceImpl.java index c58ce5ca7..8cb5772ac 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SysSmsSendLogServiceImpl.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SysSmsSendLogServiceImpl.java @@ -2,11 +2,10 @@ package cn.iocoder.dashboard.modules.system.service.sms.impl; import cn.hutool.core.collection.CollectionUtil; import cn.iocoder.dashboard.framework.sms.client.AbstractSmsClient; -import cn.iocoder.dashboard.framework.sms.core.SmsResultDetail; -import cn.iocoder.dashboard.modules.system.dal.mysql.dao.sms.SysSmsQueryLogMapper; -import cn.iocoder.dashboard.modules.system.dal.mysql.dao.sms.SysSmsSendLogMapper; -import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.sms.SysSmsQueryLogDO; -import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.sms.SysSmsSendLogDO; +import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsQueryLogDO; +import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsSendLogDO; +import cn.iocoder.dashboard.modules.system.dal.mysql.sms.SysSmsQueryLogMapper; +import cn.iocoder.dashboard.modules.system.dal.mysql.sms.SysSmsSendLogMapper; import cn.iocoder.dashboard.modules.system.enums.sms.SmsSendStatusEnum; import cn.iocoder.dashboard.modules.system.service.sms.SysSmsChannelService; import cn.iocoder.dashboard.modules.system.service.sms.SysSmsSendLogService; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SysSmsServiceImpl.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SysSmsServiceImpl.java index c679a8c81..6bb0657ee 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SysSmsServiceImpl.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SysSmsServiceImpl.java @@ -1,17 +1,29 @@ package cn.iocoder.dashboard.modules.system.service.sms.impl; +import cn.hutool.core.util.StrUtil; +import cn.iocoder.dashboard.common.enums.UserTypeEnum; import cn.iocoder.dashboard.framework.sms.client.AbstractSmsClient; import cn.iocoder.dashboard.framework.sms.core.SmsBody; import cn.iocoder.dashboard.framework.sms.core.SmsClientFactory; import cn.iocoder.dashboard.framework.sms.core.SmsResultDetail; -import cn.iocoder.dashboard.modules.system.redis.stream.sms.SmsSendStreamProducer; +import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsTemplateDO; +import cn.iocoder.dashboard.modules.system.dal.dataobject.user.SysUserDO; +import cn.iocoder.dashboard.modules.system.mq.producer.sms.SmsSendStreamProducer; import cn.iocoder.dashboard.modules.system.service.sms.SysSmsChannelService; import cn.iocoder.dashboard.modules.system.service.sms.SysSmsQueryLogService; import cn.iocoder.dashboard.modules.system.service.sms.SysSmsService; +import cn.iocoder.dashboard.modules.system.service.sms.SysSmsTemplateService; +import cn.iocoder.dashboard.modules.system.service.user.SysUserService; import org.springframework.stereotype.Service; import javax.annotation.Resource; import javax.servlet.ServletRequest; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +import static cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.*; /** * 短信日志Service实现类 @@ -22,9 +34,15 @@ import javax.servlet.ServletRequest; @Service public class SysSmsServiceImpl implements SysSmsService { + @Resource + private SysSmsTemplateService smsTemplateService; + @Resource + private SysUserService userService; + @Resource private SysSmsChannelService channelService; + @Resource private SysSmsQueryLogService logService; @@ -34,6 +52,54 @@ public class SysSmsServiceImpl implements SysSmsService { @Resource private SmsClientFactory smsClientFactory; + @Override + public void sendSingleSms(String mobile, Long userId, Integer userType, + String templateCode, Map templateParams) { + // 校验短信模板是否存在 + SysSmsTemplateDO template = this.checkSmsTemplateExists(templateCode); + // 校验手机号码是否存在 + mobile = this.checkMobile(mobile, userId, userType); + } + + @Override + public void sendBatchSms(List mobiles, List userIds, Integer userType, + String templateCode, Map templateParams) { + // 校验短信模板是否存在 + SysSmsTemplateDO template = this.checkSmsTemplateExists(templateCode); + } + + private SysSmsTemplateDO checkSmsTemplateExists(String templateCode) { + SysSmsTemplateDO template = smsTemplateService.getSmsTemplateByCode(templateCode); + if (template == null) { + throw exception(SMS_TEMPLATE_NOT_EXISTS); + } + return template; + } + + private String checkMobile(String mobile, Long userId, Integer userType) { + mobile = getMobile(mobile, userId, userType); + if (StrUtil.isEmpty(mobile)) { + throw exception(SMS_SEND_MOBILE_NOT_EXISTS); + } + return mobile; + } + + private String getMobile(String mobile, Long userId, Integer userType) { + // 如果已经有手机号,则直接返回 + if (StrUtil.isNotEmpty(mobile)) { + return mobile; + } + // 没有手机号,则基于 userId 检索 + if (userId == null || userType == null) { + return null; + } + if (Objects.equals(userType, UserTypeEnum.ADMIN.getValue())) { + SysUserDO user = userService.getUser(userId); + return user != null ? user.getMobile() : null; + } + return null; + } + @Override public void send(SmsBody smsBody, String targetPhone) { AbstractSmsClient client = channelService.getSmsClient(smsBody.getTemplateCode()); diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SysSmsTemplateServiceImpl.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SysSmsTemplateServiceImpl.java index 0bf7ca1a0..ccbb26079 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SysSmsTemplateServiceImpl.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/impl/SysSmsTemplateServiceImpl.java @@ -1,8 +1,12 @@ package cn.iocoder.dashboard.modules.system.service.sms.impl; +import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsTemplateDO; +import cn.iocoder.dashboard.modules.system.dal.mysql.sms.SysSmsTemplateMapper; import cn.iocoder.dashboard.modules.system.service.sms.SysSmsTemplateService; import org.springframework.stereotype.Service; +import javax.annotation.Resource; + /** * 短信模板Service实现类 * @@ -11,4 +15,13 @@ import org.springframework.stereotype.Service; */ @Service public class SysSmsTemplateServiceImpl implements SysSmsTemplateService { + + @Resource + private SysSmsTemplateMapper smsTemplateMapper; + + @Override + public SysSmsTemplateDO getSmsTemplateByCode(String code) { + return smsTemplateMapper.selectOneByCode(code); + } + } diff --git a/src/test/java/cn/iocoder/dashboard/modules/system/service/dept/SysDeptServiceTest.java b/src/test/java/cn/iocoder/dashboard/modules/system/service/dept/SysDeptServiceTest.java index f3db031aa..373665546 100644 --- a/src/test/java/cn/iocoder/dashboard/modules/system/service/dept/SysDeptServiceTest.java +++ b/src/test/java/cn/iocoder/dashboard/modules/system/service/dept/SysDeptServiceTest.java @@ -8,7 +8,7 @@ import cn.iocoder.dashboard.modules.system.controller.dept.vo.dept.SysDeptUpdate import cn.iocoder.dashboard.modules.system.dal.dataobject.dept.SysDeptDO; import cn.iocoder.dashboard.modules.system.dal.mysql.dept.SysDeptMapper; import cn.iocoder.dashboard.modules.system.enums.dept.DeptIdEnum; -import cn.iocoder.dashboard.modules.system.redis.mq.producer.dept.SysDeptProducer; +import cn.iocoder.dashboard.modules.system.mq.producer.dept.SysDeptProducer; import cn.iocoder.dashboard.modules.system.service.dept.impl.SysDeptServiceImpl; import cn.iocoder.dashboard.util.collection.ArrayUtils; import cn.iocoder.dashboard.util.object.ObjectUtils; diff --git a/src/test/java/cn/iocoder/dashboard/modules/system/service/dict/SysDictDataServiceTest.java b/src/test/java/cn/iocoder/dashboard/modules/system/service/dict/SysDictDataServiceTest.java index bfd1d9781..2874285e4 100644 --- a/src/test/java/cn/iocoder/dashboard/modules/system/service/dict/SysDictDataServiceTest.java +++ b/src/test/java/cn/iocoder/dashboard/modules/system/service/dict/SysDictDataServiceTest.java @@ -10,7 +10,7 @@ import cn.iocoder.dashboard.modules.system.controller.dict.vo.data.SysDictDataUp import cn.iocoder.dashboard.modules.system.dal.dataobject.dict.SysDictDataDO; import cn.iocoder.dashboard.modules.system.dal.dataobject.dict.SysDictTypeDO; import cn.iocoder.dashboard.modules.system.dal.mysql.dict.SysDictDataMapper; -import cn.iocoder.dashboard.modules.system.redis.mq.producer.dict.SysDictDataProducer; +import cn.iocoder.dashboard.modules.system.mq.producer.dict.SysDictDataProducer; import cn.iocoder.dashboard.modules.system.service.dict.impl.SysDictDataServiceImpl; import cn.iocoder.dashboard.util.collection.ArrayUtils; import cn.iocoder.dashboard.util.object.ObjectUtils;