diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/dal/dataobject/sms/SysSmsQueryLogDO.java b/src/main/java/cn/iocoder/dashboard/modules/system/dal/dataobject/sms/SysSmsQueryLogDO.java deleted file mode 100644 index 05681d744..000000000 --- a/src/main/java/cn/iocoder/dashboard/modules/system/dal/dataobject/sms/SysSmsQueryLogDO.java +++ /dev/null @@ -1,140 +0,0 @@ -package cn.iocoder.dashboard.modules.system.dal.dataobject.sms; - -import cn.iocoder.dashboard.common.enums.UserTypeEnum; -import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO; -import cn.iocoder.dashboard.modules.system.enums.sms.SysSmsSendFailureTypeEnum; -import cn.iocoder.dashboard.modules.system.enums.sms.SysSmsSendStatusEnum; -import cn.iocoder.dashboard.modules.system.enums.sms.SysSmsTemplateTypeEnum; -import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.experimental.Accessors; - -import java.util.Date; -import java.util.Map; - -/** - * 短信发送日志 - * - * @author zzf - * @since 2021-01-25 - */ -@Data -@EqualsAndHashCode -@Accessors(chain = true) -@TableName(value = "sms_query_log", autoResultMap = true) -public class SysSmsQueryLogDO extends BaseDO { - - /** - * 自增编号 - */ - private Long id; - - // ========= 渠道相关字段 ========= - - /** - * 短信渠道编号 - * - * 关联 {@link SysSmsChannelDO#getId()} - */ - private Long channelId; - /** - * 短信渠道编码 - * - * 冗余 {@link SysSmsChannelDO#getCode()} - */ - private String channelCode; - /** - * 实际渠道模板唯一标识 - */ - private String apiTemplateId; - - // ========= 模板相关字段 ========= - - /** - * 短信模板编号 - * - * 关联 {@link} - */ - private String templateCode; - /** - * 短信类型 - * - * 枚举 {@link SysSmsTemplateTypeEnum} - */ - private Integer templateType; - /** - * 基于 {@link SysSmsTemplateDO#getContent()} 格式化后的内容 - */ - private String templateContent; - /** - * 基于 {@link SysSmsTemplateDO#getParams()} 输入后的内容 - */ - private Map templateParams; - - // ========= 手机相关字段 ========= - - /** - * 手机号 - */ - private String mobile; - /** - * 用户编号 - */ - private Integer userId; - /** - * 用户类型 - * - * 枚举 {@link UserTypeEnum} - */ - private Integer userType; - - // ========= 发送相关字段 ========= - - /** - * 发送状态 - * - * 枚举 {@link SysSmsSendStatusEnum} - */ - private Integer sendStatus; - /** - * 发送失败的类型 - * - * 枚举 {@link SysSmsSendFailureTypeEnum} - */ - private Integer sendFailureType; - /** - * 发送成功时间 - */ - private Date sendTime; - /** - * 短信 API 发送失败的类型 - * - * 由于第三方的错误码可能是字符串,所以使用 String 类型 - */ - private String apiSendFailureType; - /** - * 短信 API 发送失败的提示 - */ - private String apiSendFailureMsg; - /** - * 短信 API 发送返回的唯一请求 ID - * - * 用于和短信 API 进行定位于排错 - */ - private String apiRequestId; - /** - * 短信 API 发送返回的序号 - * - * 用于和短信 API 平台的发送记录关联 - */ - private String apiSerialNo; - - // ========= 接收相关字段 ========= - - /** - * 是否获取过结果[0否 1是] - */ - private Integer gotResult; - -} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/dal/dataobject/sms/SysSmsSendLogDO.java b/src/main/java/cn/iocoder/dashboard/modules/system/dal/dataobject/sms/SysSmsSendLogDO.java index e85edf74a..28c9f510f 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/dal/dataobject/sms/SysSmsSendLogDO.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/dal/dataobject/sms/SysSmsSendLogDO.java @@ -1,66 +1,148 @@ package cn.iocoder.dashboard.modules.system.dal.dataobject.sms; +import cn.iocoder.dashboard.common.enums.UserTypeEnum; +import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.dashboard.modules.system.enums.sms.SysSmsSendFailureTypeEnum; import cn.iocoder.dashboard.modules.system.enums.sms.SysSmsSendStatusEnum; import com.baomidou.mybatisplus.annotation.TableName; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.experimental.Accessors; +import lombok.*; -import java.io.Serializable; import java.util.Date; +import java.util.Map; /** - * 短信日志 + * 短信发送日志 * * @author zzf * @since 2021-01-25 */ -@Data -@EqualsAndHashCode -@Accessors(chain = true) @TableName(value = "sms_send_log", autoResultMap = true) -public class SysSmsSendLogDO implements Serializable { +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class SysSmsSendLogDO extends BaseDO { /** * 自增编号 */ private Long id; + // ========= 渠道相关字段 ========= + /** - * 短信渠道编码(来自枚举类) + * 短信渠道编号 + * + * 关联 {@link SysSmsChannelDO#getId()} + */ + private Long channelId; + /** + * 短信渠道编码 + * + * 冗余 {@link SysSmsChannelDO#getCode()} */ private String channelCode; - /** - * 短信渠道id - */ - private Long channelId; + // ========= 模板相关字段 ========= /** - * 模板id + * 短信模板编号 + * + * 关联 {@link SysSmsTemplateDO#getId()} + */ + private Long templateId; + /** + * 模板编码 + * + * 冗余 {@link SysSmsTemplateDO#getCode()} */ private String templateCode; + /** + * 短信类型 + * + * 冗余 {@link SysSmsTemplateDO#getType()} + */ + private Integer templateType; + /** + * 基于 {@link SysSmsTemplateDO#getContent()} 格式化后的内容 + */ + private String templateContent; + /** + * 基于 {@link SysSmsTemplateDO#getParams()} 输入后的内容 + */ + private Map templateParams; + /** + * 短信 API 的模板编号 + * + * 冗余 {@link SysSmsTemplateDO#getApiTemplateId()} + */ + private String apiTemplateId; + + // ========= 手机相关字段 ========= /** * 手机号 */ - private String phone; - + private String mobile; /** - * 备注 + * 用户编号 */ - private String remark; + private Long userId; + /** + * 用户类型 + * + * 枚举 {@link UserTypeEnum} + */ + private Integer userType; + + // ========= 发送相关字段 ========= /** * 发送状态 * - * @see SysSmsSendStatusEnum + * 枚举 {@link SysSmsSendStatusEnum} */ private Integer sendStatus; - /** - * 发送时间 + * 发送失败的类型 + * + * 枚举 {@link SysSmsSendFailureTypeEnum} + */ + private Integer sendFailureType; + /** + * 发送成功时间 */ private Date sendTime; + /** + * 短信 API 发送失败的类型 + * + * 由于第三方的错误码可能是字符串,所以使用 String 类型 + */ + private String apiSendFailureType; + /** + * 短信 API 发送失败的提示 + */ + private String apiSendFailureMsg; + /** + * 短信 API 发送返回的唯一请求 ID + * + * 用于和短信 API 进行定位于排错 + */ + private String apiRequestId; + /** + * 短信 API 发送返回的序号 + * + * 用于和短信 API 平台的发送记录关联 + */ + private String apiSerialNo; + + // ========= 接收相关字段 ========= + + /** + * 是否获取过结果[0否 1是] + */ + private Integer gotResult; } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/dal/dataobject/sms/SysSmsSendLogDOX.java b/src/main/java/cn/iocoder/dashboard/modules/system/dal/dataobject/sms/SysSmsSendLogDOX.java new file mode 100644 index 000000000..31d491d91 --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/system/dal/dataobject/sms/SysSmsSendLogDOX.java @@ -0,0 +1,66 @@ +package cn.iocoder.dashboard.modules.system.dal.dataobject.sms; + +import cn.iocoder.dashboard.modules.system.enums.sms.SysSmsSendStatusEnum; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +import java.io.Serializable; +import java.util.Date; + +/** + * 短信日志 + * + * @author zzf + * @since 2021-01-25 + */ +@Data +@EqualsAndHashCode +@Accessors(chain = true) +@TableName(value = "sms_send_log", autoResultMap = true) +public class SysSmsSendLogDOX implements Serializable { + + /** + * 自增编号 + */ + private Long id; + + /** + * 短信渠道编码(来自枚举类) + */ + private String channelCode; + + /** + * 短信渠道id + */ + private Long channelId; + + /** + * 模板id + */ + private String templateCode; + + /** + * 手机号 + */ + private String phone; + + /** + * 备注 + */ + private String remark; + + /** + * 发送状态 + * + * @see SysSmsSendStatusEnum + */ + private Integer sendStatus; + + /** + * 发送时间 + */ + private Date sendTime; + +} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/dal/dataobject/sms/SysSmsTemplateDO.java b/src/main/java/cn/iocoder/dashboard/modules/system/dal/dataobject/sms/SysSmsTemplateDO.java index 2efd9ae8e..ba2b9940e 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/dal/dataobject/sms/SysSmsTemplateDO.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/dal/dataobject/sms/SysSmsTemplateDO.java @@ -51,6 +51,8 @@ public class SysSmsTemplateDO extends BaseDO { private String name; /** * 内容 + * + * 内容的参数,使用 {} 包括,例如说 {name} */ private String content; /** @@ -62,6 +64,10 @@ public class SysSmsTemplateDO extends BaseDO { * 备注 */ private String remark; + /** + * 短信 API 的模板编号 + */ + private String apiTemplateId; // ========= 渠道相关字段 ========= @@ -77,9 +83,5 @@ public class SysSmsTemplateDO extends BaseDO { * 冗余 {@link SysSmsChannelDO#getCode()} */ private String channelCode; - /** - * 短信 API 的模板编号 - */ - private String apiTemplateId; } 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 917a013a6..d1cf63efa 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.sms; import cn.iocoder.dashboard.common.enums.DefaultBitFieldEnum; -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.enums.sms.SysSmsSendStatusEnum; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; @@ -10,15 +10,15 @@ import org.apache.ibatis.annotations.Mapper; import java.util.List; @Mapper -public interface SysSmsQueryLogMapper extends BaseMapper { +public interface SysSmsQueryLogMapper extends BaseMapper { /** * 查询还没有获取发送结果的短信请求信息 */ - default List selectNoResultQueryLogList() { - return this.selectList(new LambdaQueryWrapper() - .eq(SysSmsQueryLogDO::getSendStatus, SysSmsSendStatusEnum.QUERY_SUCCESS) - .eq(SysSmsQueryLogDO::getGotResult, DefaultBitFieldEnum.NO) + default List selectNoResultQueryLogList() { + return this.selectList(new LambdaQueryWrapper() + .eq(SysSmsSendLogDO::getSendStatus, SysSmsSendStatusEnum.QUERY_SUCCESS) + .eq(SysSmsSendLogDO::getGotResult, DefaultBitFieldEnum.NO) ); } @@ -26,9 +26,9 @@ public interface SysSmsQueryLogMapper extends BaseMapper { /** * 根据APIId修改对象 */ - default boolean updateByApiId(SysSmsQueryLogDO queryLogDO, String apiId) { - return update(queryLogDO, new LambdaQueryWrapper() - .eq(SysSmsQueryLogDO::getApiId, apiId) + default boolean updateByApiId(SysSmsSendLogDO queryLogDO, String apiId) { + return update(queryLogDO, new LambdaQueryWrapper() + .eq(SysSmsSendLogDO::getApiId, apiId) ) > 0; } } diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/SysSmsQueryLogService.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/SysSmsQueryLogService.java index e5ec2fa3c..858bf977a 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/SysSmsQueryLogService.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/SysSmsQueryLogService.java @@ -5,8 +5,6 @@ import cn.iocoder.dashboard.framework.sms.core.SmsBody; import cn.iocoder.dashboard.framework.sms.core.SmsResult; import cn.iocoder.dashboard.framework.sms.core.SmsResultDetail; -import java.util.List; - /** * 短信请求日志服务接口 * @@ -14,6 +12,7 @@ import java.util.List; * @date 2021/1/25 9:24 */ public interface SysSmsQueryLogService { + /** * 发送短信前的日志处理 * @@ -22,10 +21,6 @@ public interface SysSmsQueryLogService { * @param client 短信客户端 * @return 生成的日志id */ - // TODO FROM 芋艿 to ZZF: async 是针对发送的方式,对于日志不一定需要关心。这样,短信日志,实际就发送前插入,发送后更新结果. - // 这里只用于记录状态,毕竟异步可能推送失败,此时日志可记录该状态。 - - // TODO FROM 芋艿 to ZZF:短信日志,群发的情况,应该是每个手机一条哈。虽然是群发,但是可能部分成功,部分失败;对应到短信平台,实际也是多条。 void beforeSendLog(SmsBody smsBody, String targetPhone, AbstractSmsClient client); /** diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/SysSmsSendLogService.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/SysSmsSendLogService.java index fe6f5e973..e36dd1f5c 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/SysSmsSendLogService.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/sms/SysSmsSendLogService.java @@ -1,5 +1,9 @@ package cn.iocoder.dashboard.modules.system.service.sms; +import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsTemplateDO; + +import java.util.Map; + /** * 短信发送日志服务接口 * @@ -8,6 +12,9 @@ package cn.iocoder.dashboard.modules.system.service.sms; */ public interface SysSmsSendLogService { + Long createSmsSendLog(String mobile, Long userId, Integer userType, + SysSmsTemplateDO template, String templateContent, Map templateParams); + void getAndSaveSmsSendLog(); } 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 137291a47..5faeeddcb 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 @@ -2,6 +2,8 @@ package cn.iocoder.dashboard.modules.system.service.sms; import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsTemplateDO; +import java.util.Map; + /** * 短信模板 Service 接口 * @@ -18,4 +20,13 @@ public interface SysSmsTemplateService { */ SysSmsTemplateDO getSmsTemplateByCode(String code); + /** + * 格式化短信内容 + * + * @param content 短信模板的内容 + * @param params 内容的参数 + * @return 格式化后的内容 + */ + String formatSmsTemplateContent(String content, Map params); + } 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 78935dba6..6aefcbb65 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.dataobject.sms.SysSmsQueryLogDO; +import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsSendLogDO; import cn.iocoder.dashboard.modules.system.enums.sms.SysSmsSendStatusEnum; import cn.iocoder.dashboard.modules.system.service.sms.SysSmsQueryLogService; import org.springframework.stereotype.Service; @@ -27,7 +27,7 @@ public class SysSmsQueryLogServiceImpl implements SysSmsQueryLogService { @Override public void beforeSendLog(SmsBody smsBody, String targetPhone, AbstractSmsClient client) { - SysSmsQueryLogDO smsLog = new SysSmsQueryLogDO(); + SysSmsSendLogDO smsLog = new SysSmsSendLogDO(); SmsChannelProperty property = client.getProperty(); smsLog.setChannelCode(property.getCode()) @@ -43,7 +43,7 @@ public class SysSmsQueryLogServiceImpl implements SysSmsQueryLogService { @Override public void afterSendLog(Long logId, SmsResult result) { - SysSmsQueryLogDO smsLog = new SysSmsQueryLogDO(); + SysSmsSendLogDO smsLog = new SysSmsSendLogDO(); smsLog.setId(logId); smsLog.setApiId(result.getApiId()); smsLog.setSendStatus(SysSmsSendStatusEnum.QUERY_FAIL.getStatus()); @@ -53,7 +53,7 @@ public class SysSmsQueryLogServiceImpl implements SysSmsQueryLogService { @Override public void updateSendLogByResultDetail(SmsResultDetail smsResultDetail) { - SysSmsQueryLogDO queryLogDO = new SysSmsQueryLogDO(); + SysSmsSendLogDO queryLogDO = new SysSmsSendLogDO(); queryLogDO.setSendStatus(smsResultDetail.getSendStatus()); queryLogDO.setSendTime(smsResultDetail.getSendTime()); queryLogDO.setRemark(smsResultDetail.getMessage()); 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 320c0a7bd..e8295a5cf 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,8 +2,9 @@ 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.modules.system.dal.dataobject.sms.SysSmsQueryLogDO; import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsSendLogDO; +import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsSendLogDOX; +import cn.iocoder.dashboard.modules.system.dal.dataobject.sms.SysSmsTemplateDO; 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.SysSmsSendStatusEnum; @@ -15,6 +16,7 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.List; +import java.util.Map; /** * 短信发送日志服务实现类 @@ -41,18 +43,36 @@ public class SysSmsSendLogServiceImpl implements SysSmsSendLogService { private static final long SCHEDULER_PERIOD = 5 * 60 * 1000L; + @Override + public Long createSmsSendLog(String mobile, Long userId, Integer userType, + SysSmsTemplateDO template, String templateContent, Map templateParams) { + SysSmsSendLogDO.SysSmsSendLogDOBuilder logBuilder = SysSmsSendLogDO.builder(); + // 设置手机相关字段 + logBuilder.mobile(mobile).userId(userId).userType(userType); + // 设置模板相关字段 + logBuilder.templateId(template.getId()).templateCode(template.getCode()).templateType(template.getType()); + logBuilder.templateContent(templateContent).templateParams(templateParams).apiTemplateId(template.getApiTemplateId()); + // 设置渠道相关字段 + logBuilder.channelId(template.getChannelId()).channelCode(template.getChannelCode()); + + // 插入数据库 + SysSmsSendLogDO logDO = logBuilder.build(); + smsSendLogMapper.insert(logDO); + return logDO.getId(); + } + @Override public void getAndSaveSmsSendLog() { - List noResultQueryLogList = smsQueryLogMapper.selectNoResultQueryLogList(); + List noResultQueryLogList = smsQueryLogMapper.selectNoResultQueryLogList(); if (CollectionUtil.isEmpty(noResultQueryLogList)) { return; } //用于添加的发送日志对象 - SysSmsSendLogDO insertSendLog = new SysSmsSendLogDO(); + SysSmsSendLogDOX insertSendLog = new SysSmsSendLogDOX(); //用于修改状态的请求日志对象 - SysSmsQueryLogDO updateQueryLog = new SysSmsQueryLogDO(); + SysSmsSendLogDO updateQueryLog = new SysSmsSendLogDO(); noResultQueryLogList.forEach(queryLog -> { AbstractSmsClient smsClient = smsChannelService.getSmsClient(queryLog.getTemplateCode()); @@ -94,7 +114,7 @@ public class SysSmsSendLogServiceImpl implements SysSmsSendLogService { }); } - private void queryLog2SendLong(SysSmsSendLogDO insertSendLog, SysSmsQueryLogDO queryLog) { + private void queryLog2SendLong(SysSmsSendLogDOX insertSendLog, SysSmsSendLogDO queryLog) { insertSendLog.setChannelCode(queryLog.getChannelCode()); insertSendLog.setChannelId(queryLog.getChannelId()); insertSendLog.setTemplateCode(queryLog.getTemplateCode()); 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 64f9e3c8c..dde2580a4 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 @@ -11,10 +11,7 @@ import cn.iocoder.dashboard.framework.sms.core.SmsResultDetail; 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.sms.*; import cn.iocoder.dashboard.modules.system.service.user.SysUserService; import org.springframework.stereotype.Service; @@ -40,6 +37,9 @@ public class SysSmsServiceImpl implements SysSmsService { @Resource private SysSmsTemplateService smsTemplateService; + @Resource + private SysSmsSendLogService smsSendLogService; + @Resource private SysUserService userService; @@ -63,7 +63,13 @@ public class SysSmsServiceImpl implements SysSmsService { SysSmsTemplateDO template = this.checkSmsTemplateValid(templateCode, templateParams); // 校验手机号码是否存在 mobile = this.checkMobile(mobile, userId, userType); - // + + // 创建发送日志 + String content = smsTemplateService.formatSmsTemplateContent(template.getContent(), templateParams); + Long sendLogId = smsSendLogService.createSmsSendLog(mobile, userId, userType, template, content, templateParams); + + // 发送 MQ 消息 + } @Override @@ -73,6 +79,11 @@ public class SysSmsServiceImpl implements SysSmsService { SysSmsTemplateDO template = this.checkSmsTemplateValid(templateCode, templateParams); } + @Override + public void doSendSms() { + + } + private SysSmsTemplateDO checkSmsTemplateValid(String templateCode, Map templateParams) { // 短信模板不存在 SysSmsTemplateDO template = smsTemplateService.getSmsTemplateByCode(templateCode); 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 ccbb26079..c5c1a5127 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,11 +1,13 @@ package cn.iocoder.dashboard.modules.system.service.sms.impl; +import cn.hutool.core.util.StrUtil; 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; +import java.util.Map; /** * 短信模板Service实现类 @@ -24,4 +26,9 @@ public class SysSmsTemplateServiceImpl implements SysSmsTemplateService { return smsTemplateMapper.selectOneByCode(code); } + @Override + public String formatSmsTemplateContent(String content, Map params) { + return StrUtil.format(content, params); + } + }