refactor(system): 重构短信配置功能模块

This commit is contained in:
2025-03-19 22:31:20 +08:00
parent 6b17742a1b
commit 394b93ead5
37 changed files with 517 additions and 1005 deletions

View File

@@ -13,17 +13,16 @@
<description>系统管理模块(存放系统管理相关业务功能,例如:部门管理、角色管理、用户管理等)</description>
<dependencies>
<!-- 公共模块(存放公共工具类,公共配置等) -->
<!-- 公共模块 -->
<dependency>
<groupId>top.continew</groupId>
<artifactId>continew-common</artifactId>
</dependency>
<!-- SMS4J短信聚合框架轻松集成多家短信服务解决接入多个短信 SDK 的繁琐流程) -->
<dependency>
<groupId>org.dromara.sms4j</groupId>
<artifactId>sms4j-spring-boot-starter</artifactId>
<version>3.3.4</version>
</dependency>
</dependencies>
</project>

View File

@@ -16,30 +16,33 @@
package top.continew.admin.system.config.sms;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.sms4j.core.factory.SmsFactory;
import org.dromara.sms4j.core.proxy.SmsProxyFactory;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
/**
* 短信配置加载器
*
* @author luoqiz
* @author Charles7c
* @since 2025/03/15 22:15
*/
@Slf4j
@Component
public class SmsBlendConfig {
@RequiredArgsConstructor
public class SmsConfigLoader implements ApplicationRunner {
@Resource
SmsJdbcReadConfig config;
private final SmsReadConfigDatabaseImpl smsReadConfig;
private final SmsLogProcessor smsLogProcessor;
@Resource
private SmsRecordProcessor smsRecordProcessor;
@EventListener
public void init(ContextRefreshedEvent event) {
log.info("初始化短信配置");
// 创建SmsBlend 短信实例
SmsFactory.createSmsBlend(config);
SmsProxyFactory.addPreProcessor(smsRecordProcessor);
log.info("初始化短信配置完成");
@Override
public void run(ApplicationArguments args) {
SmsFactory.createSmsBlend(smsReadConfig);
SmsProxyFactory.addPreProcessor(smsLogProcessor);
log.debug("短信配置初始化完成");
}
}

View File

@@ -16,73 +16,67 @@
package top.continew.admin.system.config.sms;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.json.JSONUtil;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import lombok.RequiredArgsConstructor;
import org.dromara.sms4j.api.entity.SmsResponse;
import org.dromara.sms4j.api.proxy.CoreMethodProcessor;
import org.springframework.stereotype.Component;
import top.continew.admin.system.model.req.SmsRecordReq;
import top.continew.admin.system.service.SmsRecordService;
import top.continew.admin.common.enums.SuccessFailureStatusEnum;
import top.continew.admin.system.model.req.SmsLogReq;
import top.continew.admin.system.service.SmsLogService;
import java.lang.reflect.Method;
import java.util.LinkedHashMap;
import java.util.List;
@Slf4j
/**
* 短信日志处理器
*
* @author luoqiz
* @author Charles7c
* @since 2025/03/15 22:15
*/
@Component
public class SmsRecordProcessor implements CoreMethodProcessor {
@RequiredArgsConstructor
public class SmsLogProcessor implements CoreMethodProcessor {
@Resource
private SmsRecordService smsRecordService;
private final SmsLogService smsLogService;
@Override
public Object[] preProcessor(Method method, Object source, Object[] param) {
return CoreMethodProcessor.super.preProcessor(method, source, param);
public Object postProcessor(SmsResponse result, Object[] param) {
if (NumberUtil.isNumber(result.getConfigId())) {
SmsLogReq req = new SmsLogReq();
req.setConfigId(Long.parseLong(result.getConfigId()));
req.setPhone(param[0].toString());
req.setParams(JSONUtil.toJsonStr(param[1]));
req.setStatus(result.isSuccess() ? SuccessFailureStatusEnum.SUCCESS : SuccessFailureStatusEnum.FAILURE);
req.setResMsg(JSONUtil.toJsonStr(result.getData()));
smsLogService.add(req);
}
return CoreMethodProcessor.super.postProcessor(result, param);
}
@Override
public void sendMessagePreProcess(String phone, Object message) {
System.out.println("发送短信前处理" + phone + message);
// do nothing
}
@Override
public void sendMessageByTemplatePreProcess(String phone,
String templateId,
LinkedHashMap<String, String> messages) {
log.debug("发送短信前处理 sendMessageByTemplatePreProcess " + phone + templateId + JSONUtil.toJsonPrettyStr(messages));
// do nothing
}
@Override
public void massTextingPreProcess(List<String> phones, String message) {
log.debug("发送短信前处理 massTextingPreProcess " + JSONUtil.toJsonPrettyStr(phones) + message);
// do nothing
}
@Override
public void massTextingByTemplatePreProcess(List<String> phones,
String templateId,
LinkedHashMap<String, String> messages) {
log.debug("发送短信前处理 massTextingByTemplatePreProcess " + JSONUtil.toJsonPrettyStr(phones) + JSONUtil
.toJsonPrettyStr(messages));
}
@Override
public Object postProcessor(SmsResponse result, Object[] param) {
SmsRecordReq record = new SmsRecordReq();
record.setConfigId(Long.parseLong(result.getConfigId()));
record.setPhone(param[0].toString());
record.setParams(JSONUtil.toJsonPrettyStr(param[1]));
record.setStatus(result.isSuccess());
record.setResMsg(JSONUtil.toJsonPrettyStr(result.getData()));
smsRecordService.add(record);
return CoreMethodProcessor.super.postProcessor(result, param);
}
@Override
public void exceptionHandleProcessor(Method method,
Object source,
Object[] param,
Exception exception) throws RuntimeException {
CoreMethodProcessor.super.exceptionHandleProcessor(method, source, param, exception);
// do nothing
}
}

View File

@@ -16,48 +16,49 @@
package top.continew.admin.system.config.sms;
import jakarta.annotation.Resource;
import cn.hutool.core.collection.CollUtil;
import lombok.RequiredArgsConstructor;
import org.dromara.sms4j.core.datainterface.SmsReadConfig;
import org.dromara.sms4j.provider.config.BaseConfig;
import org.springframework.stereotype.Component;
import top.continew.admin.system.config.sms.utils.SmsConvertUtils;
import top.continew.admin.common.enums.DisEnableStatusEnum;
import top.continew.admin.system.model.query.SmsConfigQuery;
import top.continew.admin.system.model.resp.SmsConfigDetailResp;
import top.continew.admin.system.model.resp.SmsConfigResp;
import top.continew.admin.system.service.SmsConfigService;
import top.continew.starter.extension.crud.model.query.SortQuery;
import java.util.ArrayList;
import java.util.List;
/**
* 短信配置读取-数据源实现
*
* @author luoqiz
* @author Charles7c
* @since 2025/03/15 22:15
*/
@Component
public class SmsJdbcReadConfig implements SmsReadConfig {
@RequiredArgsConstructor
public class SmsReadConfigDatabaseImpl implements SmsReadConfig {
@Resource
private SmsConfigService smsConfigService;
private final SmsConfigService smsConfigService;
@Override
public BaseConfig getSupplierConfig(String configId) {
Long id = Long.parseLong(configId);
SmsConfigDetailResp smsConfig = smsConfigService.get(id);
if (smsConfig == null || !smsConfig.getIsEnable()) {
SmsConfigResp smsConfig = smsConfigService.get(id);
if (DisEnableStatusEnum.DISABLE.equals(smsConfig.getStatus())) {
return null;
}
return SmsConvertUtils.smsConfig2BaseConfig(smsConfig);
return smsConfig.getSupplier().toBaseConfig(smsConfig);
}
@Override
public List<BaseConfig> getSupplierConfigList() {
SmsConfigQuery smsConfigQuery = new SmsConfigQuery();
smsConfigQuery.setIsEnable(true);
SortQuery sortQuery = new SortQuery();
sortQuery.setSort(new String[] {"id", "desc"});
List<SmsConfigResp> smsConfigList = smsConfigService.list(smsConfigQuery, sortQuery);
List<BaseConfig> baseConfigList = new ArrayList<>();
for (SmsConfigResp smsConfigResp : smsConfigList) {
baseConfigList.add(SmsConvertUtils.smsConfig2BaseConfig(smsConfigResp));
SmsConfigQuery query = new SmsConfigQuery();
query.setStatus(DisEnableStatusEnum.ENABLE);
List<SmsConfigResp> list = smsConfigService.list(query, null);
if (CollUtil.isEmpty(list)) {
return List.of();
}
return baseConfigList;
return list.stream().map(smsConfig -> smsConfig.getSupplier().toBaseConfig(smsConfig)).toList();
}
}

View File

@@ -1,31 +0,0 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.continew.admin.system.config.sms.event;
import lombok.Data;
import top.continew.admin.common.enums.MethodTypeEnum;
import java.io.Serializable;
@Data
public class SmsEventMessage implements Serializable {
private static final long serialVersionUID = 1L;
private final MethodTypeEnum type;
private final String configId;
}

View File

@@ -1,44 +0,0 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.continew.admin.system.config.sms.event;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
@Configuration
public class SmsRedisConfig {
public static final String SysSmsChannel = "system:sms:topic";
@Bean
RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory,
MessageListenerAdapter listenerAdapter) {
RedisMessageListenerContainer container = new RedisMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
container.addMessageListener(listenerAdapter, new ChannelTopic(SysSmsChannel));
return container;
}
@Bean
MessageListenerAdapter listenerAdapter(SmsRedisMessageSubscriber subscriber) {
return new MessageListenerAdapter(subscriber, "onMessage");
}
}

View File

@@ -1,35 +0,0 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.continew.admin.system.config.sms.event;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class SmsRedisMessagePublisher {
@Resource
private RedisTemplate redisTemplate;
public void publish(String channel, SmsEventMessage message) {
redisTemplate.convertAndSend(channel, message);
log.debug("Message published to Redis channel [" + channel + "]: " + message);
}
}

View File

@@ -1,68 +0,0 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.continew.admin.system.config.sms.event;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.dromara.sms4j.core.factory.SmsFactory;
import org.dromara.sms4j.provider.config.BaseConfig;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import top.continew.admin.system.config.sms.SmsJdbcReadConfig;
@Slf4j
@Component
public class SmsRedisMessageSubscriber implements MessageListener {
@Resource
private RedisTemplate redisTemplate;
@Resource
private SmsJdbcReadConfig smsJdbcReadConfig;
@Override
public void onMessage(Message message, byte[] pattern) {
byte[] body = message.getBody();
SmsEventMessage msg = (SmsEventMessage)redisTemplate.getValueSerializer().deserialize(body);
switch (msg.getType()) {
case ADD:
BaseConfig config = smsJdbcReadConfig.getSupplierConfig(msg.getConfigId());
if (config != null) {
SmsFactory.createSmsBlend(config);
}
break;
case UPDATE:
BaseConfig updateConfig = smsJdbcReadConfig.getSupplierConfig(msg.getConfigId());
// 若是存在该配置,则先删除
if (SmsFactory.getSmsBlend(msg.getConfigId()) != null) {
SmsFactory.unregister(msg.getConfigId());
}
if (updateConfig != null) {
SmsFactory.createSmsBlend(updateConfig);
}
break;
case DELETE:
SmsFactory.unregister(msg.getConfigId());
break;
default:
break;
}
}
}

View File

@@ -1,94 +0,0 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.continew.admin.system.config.sms.utils;
import org.dromara.sms4j.aliyun.config.AlibabaConfig;
import org.dromara.sms4j.cloopen.config.CloopenConfig;
import org.dromara.sms4j.comm.constant.SupplierConstant;
import org.dromara.sms4j.ctyun.config.CtyunConfig;
import org.dromara.sms4j.provider.config.BaseConfig;
import top.continew.admin.system.model.resp.SmsConfigDetailResp;
import top.continew.admin.system.model.resp.SmsConfigResp;
public class SmsConvertUtils {
public static BaseConfig smsConfig2BaseConfig(SmsConfigResp smsConfig) {
switch (smsConfig.getSupplier()) {
case SupplierConstant.ALIBABA: {
AlibabaConfig alibabaConfig = new AlibabaConfig();
alibabaConfig.setConfigId(smsConfig.getId().toString());
alibabaConfig.setAccessKeyId(smsConfig.getAccessKeyId());
alibabaConfig.setAccessKeySecret(smsConfig.getAccessKeySecret());
alibabaConfig.setSignature(smsConfig.getSignature());
alibabaConfig.setTemplateId(smsConfig.getTemplateId());
return alibabaConfig;
}
case SupplierConstant.CLOOPEN: {
CloopenConfig config = new CloopenConfig();
config.setConfigId(smsConfig.getId().toString());
config.setAccessKeyId(smsConfig.getAccessKeyId());
config.setAccessKeySecret(smsConfig.getAccessKeySecret());
config.setSignature(smsConfig.getSignature());
config.setTemplateId(smsConfig.getTemplateId());
return config;
}
case SupplierConstant.CTYUN: {
CtyunConfig config = new CtyunConfig();
config.setConfigId(smsConfig.getId().toString());
config.setAccessKeyId(smsConfig.getAccessKeyId());
config.setAccessKeySecret(smsConfig.getAccessKeySecret());
config.setSignature(smsConfig.getSignature());
config.setTemplateId(smsConfig.getTemplateId());
return config;
}
}
throw new RuntimeException("短信配置有错误,未知的供应商");
}
public static BaseConfig smsConfig2BaseConfig(SmsConfigDetailResp smsConfig) {
switch (smsConfig.getSupplier()) {
case SupplierConstant.ALIBABA: {
AlibabaConfig alibabaConfig = new AlibabaConfig();
alibabaConfig.setConfigId(smsConfig.getId().toString());
alibabaConfig.setAccessKeyId(smsConfig.getAccessKeyId());
alibabaConfig.setAccessKeySecret(smsConfig.getAccessKeySecret());
alibabaConfig.setSignature(smsConfig.getSignature());
alibabaConfig.setTemplateId(smsConfig.getTemplateId());
return alibabaConfig;
}
case SupplierConstant.CLOOPEN: {
CloopenConfig config = new CloopenConfig();
config.setConfigId(smsConfig.getId().toString());
config.setAccessKeyId(smsConfig.getAccessKeyId());
config.setAccessKeySecret(smsConfig.getAccessKeySecret());
config.setSignature(smsConfig.getSignature());
config.setTemplateId(smsConfig.getTemplateId());
return config;
}
case SupplierConstant.CTYUN: {
CtyunConfig config = new CtyunConfig();
config.setConfigId(smsConfig.getId().toString());
config.setAccessKeyId(smsConfig.getAccessKeyId());
config.setAccessKeySecret(smsConfig.getAccessKeySecret());
config.setSignature(smsConfig.getSignature());
config.setTemplateId(smsConfig.getTemplateId());
return config;
}
}
throw new RuntimeException("短信配置有错误,未知的供应商");
}
}

View File

@@ -18,21 +18,72 @@ package top.continew.admin.system.enums;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.dromara.sms4j.aliyun.config.AlibabaConfig;
import org.dromara.sms4j.cloopen.config.CloopenConfig;
import org.dromara.sms4j.comm.constant.SupplierConstant;
import org.dromara.sms4j.ctyun.config.CtyunConfig;
import org.dromara.sms4j.provider.config.BaseConfig;
import top.continew.admin.system.model.resp.SmsConfigResp;
import top.continew.starter.core.enums.BaseEnum;
/**
* 菜单类型枚举
* 短信厂商枚举
*
* @author luoqiz
* @author Charles7c
* @since 2023/2/15 20:12
* @since 2025/03/15 22:15
*/
@Getter
@RequiredArgsConstructor
public enum SmsSupplierEnum implements BaseEnum<String> {
ALIBABA(SupplierConstant.ALIBABA, "阿里云"), CLOOPEN(SupplierConstant.CLOOPEN, "容联云"),
CTYUN(SupplierConstant.CTYUN, "天翼云"),
/**
* 阿里云
*/
ALIBABA(SupplierConstant.ALIBABA, "阿里云") {
@Override
public BaseConfig toBaseConfig(SmsConfigResp smsConfig) {
AlibabaConfig config = new AlibabaConfig();
config.setConfigId(smsConfig.getId().toString());
config.setAccessKeyId(smsConfig.getAccessKey());
config.setAccessKeySecret(smsConfig.getSecretKey());
config.setSignature(smsConfig.getSignature());
config.setTemplateId(smsConfig.getTemplateId());
return config;
}
},
/**
* 容联云
*/
CLOOPEN(SupplierConstant.CLOOPEN, "容联云") {
@Override
public BaseConfig toBaseConfig(SmsConfigResp smsConfig) {
CloopenConfig config = new CloopenConfig();
config.setConfigId(smsConfig.getId().toString());
config.setAccessKeyId(smsConfig.getAccessKey());
config.setAccessKeySecret(smsConfig.getSecretKey());
config.setSignature(smsConfig.getSignature());
config.setTemplateId(smsConfig.getTemplateId());
return config;
}
},
/**
* 天翼云
*/
CTYUN(SupplierConstant.CTYUN, "天翼云") {
@Override
public BaseConfig toBaseConfig(SmsConfigResp smsConfig) {
CtyunConfig config = new CtyunConfig();
config.setConfigId(smsConfig.getId().toString());
config.setAccessKeyId(smsConfig.getAccessKey());
config.setAccessKeySecret(smsConfig.getSecretKey());
config.setSignature(smsConfig.getSignature());
config.setTemplateId(smsConfig.getTemplateId());
return config;
}
},
// EMAY(SupplierConstant.EMAY, "亿美软通"), HUAWEI(SupplierConstant.HUAWEI, "华为云短信"),
// JDCLOUD(SupplierConstant.JDCLOUD, "京东云短信"), NETEASE(SupplierConstant.NETEASE, "网易云信"),
// TENCENT(SupplierConstant.TENCENT, "腾讯云短信"), UNISMS(SupplierConstant.UNISMS, "合一短信"),
@@ -47,4 +98,12 @@ public enum SmsSupplierEnum implements BaseEnum<String> {
private final String value;
private final String description;
/**
* 转换为 BaseConfig
*
* @param smsConfig 短信配置
* @return BaseConfig
*/
public abstract BaseConfig toBaseConfig(SmsConfigResp smsConfig);
}

View File

@@ -20,7 +20,7 @@ import top.continew.starter.data.mp.base.BaseMapper;
import top.continew.admin.system.model.entity.SmsConfigDO;
/**
* 短信服务配置 Mapper
* 短信配置 Mapper
*
* @author luoqiz
* @since 2025/03/15 18:41

View File

@@ -17,12 +17,12 @@
package top.continew.admin.system.mapper;
import top.continew.starter.data.mp.base.BaseMapper;
import top.continew.admin.system.model.entity.SmsRecordDO;
import top.continew.admin.system.model.entity.SmsLogDO;
/**
* 短信记录 Mapper
* 短信日志 Mapper
*
* @author luoqiz
* @since 2025/03/15 22:15
*/
public interface SmsRecordMapper extends BaseMapper<SmsRecordDO> {}
public interface SmsLogMapper extends BaseMapper<SmsLogDO> {}

View File

@@ -18,15 +18,18 @@ package top.continew.admin.system.model.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import top.continew.admin.common.enums.DisEnableStatusEnum;
import top.continew.admin.common.model.entity.BaseDO;
import top.continew.admin.system.enums.SmsSupplierEnum;
import top.continew.starter.security.crypto.annotation.FieldEncrypt;
import java.io.Serial;
/**
* 短信服务配置实体
* 短信配置实体
*
* @author luoqiz
* @author Charles7c
* @since 2025/03/15 18:41
*/
@Data
@@ -42,20 +45,20 @@ public class SmsConfigDO extends BaseDO {
private String name;
/**
* 厂商名称标识
* 厂商
*/
private String supplier;
private SmsSupplierEnum supplier;
/**
* Access Key 或 API Key
* Access Key
*/
private String accessKeyId;
private String accessKey;
/**
* Access Secret 或 API Secret
* Secret Key
*/
@FieldEncrypt
private String accessKeySecret;
private String secretKey;
/**
* 短信签名
@@ -73,17 +76,17 @@ public class SmsConfigDO extends BaseDO {
private Integer weight;
/**
* 短信自动重试间隔时间(秒)
* 重试间隔(单位:秒)
*/
private Integer retryInterval;
/**
* 短信重试次数
* 重试次数
*/
private Integer maxRetries;
/**
* 当前厂商的发送数量上限
* 发送上限
*/
private Integer maximum;
@@ -93,7 +96,7 @@ public class SmsConfigDO extends BaseDO {
private String supplierConfig;
/**
* 是否启用
* 状态
*/
private Boolean isEnable;
private DisEnableStatusEnum status;
}

View File

@@ -16,29 +16,29 @@
package top.continew.admin.system.model.entity;
import lombok.Data;
import com.baomidou.mybatisplus.annotation.TableName;
import top.continew.admin.common.model.entity.BaseDO;
import lombok.Data;
import top.continew.admin.common.enums.SuccessFailureStatusEnum;
import top.continew.admin.common.model.entity.BaseCreateDO;
import java.io.Serial;
/**
* 短信记录实体
* 短信日志实体
*
* @author luoqiz
* @author Charles7c
* @since 2025/03/15 22:15
*/
@Data
@TableName("sys_sms_record")
public class SmsRecordDO extends BaseDO {
@TableName("sys_sms_log")
public class SmsLogDO extends BaseCreateDO {
@Serial
private static final long serialVersionUID = 1L;
/**
* 配置id
* 配置 ID
*/
private Long configId;
@@ -55,7 +55,7 @@ public class SmsRecordDO extends BaseDO {
/**
* 发送状态
*/
private Boolean status;
private SuccessFailureStatusEnum status;
/**
* 返回数据

View File

@@ -18,6 +18,8 @@ package top.continew.admin.system.model.query;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import top.continew.admin.common.enums.DisEnableStatusEnum;
import top.continew.admin.system.enums.SmsSupplierEnum;
import top.continew.starter.data.core.annotation.Query;
import top.continew.starter.data.core.enums.QueryType;
@@ -25,13 +27,14 @@ import java.io.Serial;
import java.io.Serializable;
/**
* 短信服务配置查询条件
* 短信配置查询条件
*
* @author luoqiz
* @author Charles7c
* @since 2025/03/15 18:41
*/
@Data
@Schema(description = "短信服务配置查询条件")
@Schema(description = "短信配置查询条件")
public class SmsConfigQuery implements Serializable {
@Serial
@@ -40,42 +43,27 @@ public class SmsConfigQuery implements Serializable {
/**
* 名称
*/
@Schema(description = "名称")
@Schema(description = "名称", example = "短信配置1")
@Query(type = QueryType.LIKE)
private String name;
/**
* 厂商名称标识
* 厂商
*/
@Schema(description = "厂商名称标识")
@Query(type = QueryType.EQ)
private String supplier;
@Schema(description = "厂商", example = "cloopen")
@Query
private SmsSupplierEnum supplier;
/**
* Access Key 或 API Key
* Access Key
*/
@Schema(description = "Access Key 或 API Key")
@Query(type = QueryType.EQ)
private String accessKeyId;
@Schema(description = "Access Key", example = "7aaf0708674db3ee05676ecbc2f31b7b")
@Query
private String accessKey;
/**
* 短信签名
* 状态
*/
@Schema(description = "短信签名")
@Query(type = QueryType.EQ)
private String signature;
/**
* 模板 ID
*/
@Schema(description = "模板 ID")
@Query(type = QueryType.EQ)
private String templateId;
/**
* 是否启用
*/
@Schema(description = "是否启用")
@Query(type = QueryType.EQ)
private Boolean isEnable;
@Schema(description = "状态", example = "1")
private DisEnableStatusEnum status;
}

View File

@@ -18,43 +18,44 @@ package top.continew.admin.system.model.query;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import top.continew.admin.common.enums.SuccessFailureStatusEnum;
import top.continew.starter.data.core.annotation.Query;
import top.continew.starter.data.core.enums.QueryType;
import java.io.Serial;
import java.io.Serializable;
/**
* 短信记录查询条件
* 短信日志查询条件
*
* @author luoqiz
* @author Charles7c
* @since 2025/03/15 22:15
*/
@Data
@Schema(description = "短信记录查询条件")
public class SmsRecordQuery implements Serializable {
@Schema(description = "短信日志查询条件")
public class SmsLogQuery implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 配置id
* 配置 ID
*/
@Schema(description = "配置id")
@Query(type = QueryType.EQ)
@Schema(description = "配置 ID", example = "1")
@Query
private Long configId;
/**
* 手机号
*/
@Schema(description = "手机号")
@Query(type = QueryType.EQ)
@Schema(description = "手机号", example = "18888888888")
@Query
private String phone;
/**
* 发送状态
*/
@Schema(description = "发送状态")
@Query(type = QueryType.EQ)
private Boolean status;
@Schema(description = "发送状态", example = "1")
@Query
private SuccessFailureStatusEnum status;
}

View File

@@ -23,18 +23,21 @@ import lombok.Data;
import io.swagger.v3.oas.annotations.media.Schema;
import org.hibernate.validator.constraints.Length;
import top.continew.admin.common.enums.DisEnableStatusEnum;
import top.continew.admin.system.enums.SmsSupplierEnum;
import java.io.Serial;
import java.io.Serializable;
/**
* 创建或修改短信服务配置参数
* 创建或修改短信配置参数
*
* @author luoqiz
* @author Charles7c
* @since 2025/03/15 18:41
*/
@Data
@Schema(description = "创建或修改短信服务配置参数")
@Schema(description = "创建或修改短信配置参数")
public class SmsConfigReq implements Serializable {
@Serial
@@ -43,86 +46,83 @@ public class SmsConfigReq implements Serializable {
/**
* 名称
*/
@Schema(description = "名称")
@Schema(description = "名称", example = "短信配置1")
@NotBlank(message = "名称不能为空")
@Length(max = 255, message = "名称长度不能超过 {max} 个字符")
@Length(max = 100, message = "名称长度不能超过 {max} 个字符")
private String name;
/**
* 厂商名称标识
* 厂商
*/
@Schema(description = "厂商名称标识")
@NotBlank(message = "厂商名称标识不能为空")
@Length(max = 50, message = "厂商名称标识长度不能超过 {max} 个字符")
private String supplier;
@Schema(description = "厂商", example = "cloopen")
@NotNull(message = "厂商无效")
private SmsSupplierEnum supplier;
/**
* Access Key 或 API Key
* Access Key
*/
@Schema(description = "Access Key 或 API Key")
@NotBlank(message = "Access Key 或 API Key不能为空")
@Length(max = 255, message = "Access Key 或 API Key长度不能超过 {max} 个字符")
private String accessKeyId;
@Schema(description = "Access Key", example = "7aaf0708674db3ee05676ecbc2f31b7b")
@NotBlank(message = "Access Key 不能为空")
@Length(max = 255, message = "Access Key 长度不能超过 {max} 个字符")
private String accessKey;
/**
* Access Secret 或 API Secret
* Secret Key
*/
@Schema(description = "Access Secret 或 API Secret")
@NotBlank(message = "Access Secret 或 API Secret不能为空")
@Length(max = 255, message = "Access Secret 或 API Secret长度不能超过 {max} 个字符")
private String accessKeySecret;
@Schema(description = "Secret Key", example = "7fd47ade9ae54cddb222222sdsdss57be")
@NotBlank(message = "Secret Key 不能为空")
@Length(max = 255, message = "Secret Key 长度不能超过 {max} 个字符")
private String secretKey;
/**
* 短信签名
*/
@Schema(description = "短信签名")
@NotBlank(message = "短信签名不能为空")
@Schema(description = "短信签名", example = "")
@Length(max = 100, message = "短信签名长度不能超过 {max} 个字符")
private String signature;
/**
* 模板 ID
*/
@Schema(description = "模板 ID")
@NotBlank(message = "模板 ID不能为空")
@Length(max = 50, message = "模板 ID长度不能超过 {max} 个字符")
@Schema(description = "模板 ID", example = "1")
@NotBlank(message = "模板 ID 不能为空")
@Length(max = 50, message = "模板 ID 长度不能超过 {max} 个字符")
private String templateId;
/**
* 负载均衡权重
*/
@Schema(description = "负载均衡权重")
@Schema(description = "负载均衡权重", example = "1")
private Integer weight;
/**
* 短信自动重试间隔时间(秒)
* 重试间隔(单位:秒)
*/
@Schema(description = "短信自动重试间隔时间(秒)")
@Schema(description = "重试间隔(单位:秒)", example = "5")
private Integer retryInterval;
/**
* 短信重试次数
* 重试次数
*/
@Schema(description = "短信重试次数")
@Schema(description = "重试次数", example = "0")
private Integer maxRetries;
/**
* 当前厂商的发送数量上限
* 发送上限
*/
@Schema(description = "当前厂商的发送数量上限")
@Schema(description = "发送上限")
private Integer maximum;
/**
* 各个厂商独立配置
*/
@Schema(description = "各个厂商独立配置")
@Length(max = 10000, message = "各个厂商独立配置长度不能超过 {max} 个字符")
@Schema(description = "各个厂商独立配置", example = "")
@Length(max = 65535, message = "各个厂商独立配置长度不能超过 {max} 个字符")
private String supplierConfig;
/**
* 是否启用
* 状态
*/
@Schema(description = "是否启用")
@NotNull(message = "是否启用不能为空")
private Boolean isEnable;
@Schema(description = "状态", example = "1")
private DisEnableStatusEnum status;
}

View File

@@ -14,69 +14,49 @@
* limitations under the License.
*/
package top.continew.admin.system.model.resp;
package top.continew.admin.system.model.req;
import lombok.Data;
import io.swagger.v3.oas.annotations.media.Schema;
import top.continew.admin.common.model.resp.BaseResp;
import top.continew.admin.common.enums.SuccessFailureStatusEnum;
import java.io.Serial;
import java.time.*;
import java.io.Serializable;
/**
* 短信记录信息
* 创建或修改短信日志参数
*
* @author luoqiz
* @author Charles7c
* @since 2025/03/15 22:15
*/
@Data
@Schema(description = "短信记录信息")
public class SmsRecordResp extends BaseResp {
public class SmsLogReq implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 配置id
* 配置 ID
*/
@Schema(description = "配置id")
private Long configId;
/**
* 手机号
*/
@Schema(description = "手机号")
private String phone;
/**
* 参数配置
*/
@Schema(description = "参数配置")
private String params;
/**
* 发送状态
*/
@Schema(description = "发送状态")
private Boolean status;
private SuccessFailureStatusEnum status;
/**
* 返回数据
*/
@Schema(description = "返回数据")
private String resMsg;
/**
* 修改人
*/
@Schema(description = "修改人")
private Long updateUser;
/**
* 修改时间
*/
@Schema(description = "修改时间")
private LocalDateTime updateTime;
}

View File

@@ -1,76 +0,0 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.continew.admin.system.model.req;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import java.io.Serial;
import java.io.Serializable;
/**
* 创建或修改短信记录参数
*
* @author luoqiz
* @since 2025/03/15 22:15
*/
@Data
@Schema(description = "创建或修改短信记录参数")
public class SmsRecordReq implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 配置id
*/
@Schema(description = "配置id")
@NotNull(message = "配置id不能为空")
private Long configId;
/**
* 手机号
*/
@Schema(description = "手机号")
@NotBlank(message = "手机号不能为空")
@Length(max = 25, message = "手机号长度不能超过 {max} 个字符")
private String phone;
/**
* 参数配置
*/
@Schema(description = "参数配置")
private String params;
/**
* 发送状态
*/
@Schema(description = "发送状态")
@NotNull(message = "发送状态不能为空")
private Boolean status;
/**
* 返回数据
*/
@Schema(description = "返回数据")
@NotBlank(message = "返回数据不能为空")
@Length(max = 2048, message = "返回数据长度不能超过 {max} 个字符")
private String resMsg;
}

View File

@@ -1,126 +0,0 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.continew.admin.system.model.resp;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import top.continew.admin.common.model.resp.BaseDetailResp;
import top.continew.starter.security.mask.annotation.JsonMask;
import java.io.Serial;
/**
* 短信服务配置详情信息
*
* @author luoqiz
* @since 2025/03/15 18:41
*/
@Data
@ExcelIgnoreUnannotated
@Schema(description = "短信服务配置详情信息")
public class SmsConfigDetailResp extends BaseDetailResp {
@Serial
private static final long serialVersionUID = 1L;
/**
* 名称
*/
@Schema(description = "名称")
@ExcelProperty(value = "名称")
private String name;
/**
* 厂商名称标识
*/
@Schema(description = "厂商名称标识")
@ExcelProperty(value = "厂商名称标识")
private String supplier;
/**
* Access Key 或 API Key
*/
@Schema(description = "Access Key 或 API Key")
@ExcelProperty(value = "Access Key 或 API Key")
private String accessKeyId;
/**
* Access Secret 或 API Secret
*/
@Schema(description = "Access Secret 或 API Secret")
@ExcelProperty(value = "Access Secret 或 API Secret")
@JsonMask(left = 4, right = 4, character = '*')
private String accessKeySecret;
/**
* 短信签名
*/
@Schema(description = "短信签名")
@ExcelProperty(value = "短信签名")
private String signature;
/**
* 模板 ID
*/
@Schema(description = "模板 ID")
@ExcelProperty(value = "模板 ID")
private String templateId;
/**
* 负载均衡权重
*/
@Schema(description = "负载均衡权重")
@ExcelProperty(value = "负载均衡权重")
private Integer weight;
/**
* 短信自动重试间隔时间(秒)
*/
@Schema(description = "短信自动重试间隔时间(秒)")
@ExcelProperty(value = "短信自动重试间隔时间(秒)")
private Integer retryInterval;
/**
* 短信重试次数
*/
@Schema(description = "短信重试次数")
@ExcelProperty(value = "短信重试次数")
private Integer maxRetries;
/**
* 当前厂商的发送数量上限
*/
@Schema(description = "当前厂商的发送数量上限")
@ExcelProperty(value = "当前厂商的发送数量上限")
private Integer maximum;
/**
* 各个厂商独立配置
*/
@Schema(description = "各个厂商独立配置")
@ExcelProperty(value = "各个厂商独立配置")
private String supplierConfig;
/**
* 是否启用
*/
@Schema(description = "是否启用")
@ExcelProperty(value = "是否启用")
private Boolean isEnable;
}

View File

@@ -16,23 +16,29 @@
package top.continew.admin.system.model.resp;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import top.continew.admin.common.model.resp.BaseResp;
import top.continew.admin.common.enums.DisEnableStatusEnum;
import top.continew.admin.common.model.resp.BaseDetailResp;
import top.continew.admin.system.enums.SmsSupplierEnum;
import top.continew.starter.file.excel.converter.ExcelBaseEnumConverter;
import top.continew.starter.security.mask.annotation.JsonMask;
import java.io.Serial;
import java.time.LocalDateTime;
/**
* 短信服务配置信息
* 短信配置信息
*
* @author luoqiz
* @author Charles7c
* @since 2025/03/15 18:41
*/
@Data
@Schema(description = "短信服务配置信息")
public class SmsConfigResp extends BaseResp {
@ExcelIgnoreUnannotated
@Schema(description = "短信配置信息")
public class SmsConfigResp extends BaseDetailResp {
@Serial
private static final long serialVersionUID = 1L;
@@ -40,85 +46,85 @@ public class SmsConfigResp extends BaseResp {
/**
* 名称
*/
@Schema(description = "名称")
@Schema(description = "名称", example = "短信配置1")
@ExcelProperty(value = "名称")
private String name;
/**
* 厂商名称标识
* 厂商
*/
@Schema(description = "厂商名称标识")
private String supplier;
@Schema(description = "厂商", example = "cloopen")
@ExcelProperty(value = "厂商")
private SmsSupplierEnum supplier;
/**
* Access Key 或 API Key
* Access Key
*/
@Schema(description = "Access Key 或 API Key")
private String accessKeyId;
@Schema(description = "Access Key", example = "7aaf0708674db3ee05676ecbc2f31b7b")
@ExcelProperty(value = "Access Key")
private String accessKey;
/**
* Access Secret 或 API Secret
* Secret Key
*/
@Schema(description = "Access Secret 或 API Secret")
@JsonMask(left = 4, right = 4, character = '*')
private String accessKeySecret;
@Schema(description = "Secret Key", example = "7fd4************************57be")
@ExcelProperty(value = "Secret Key")
@JsonMask(left = 4, right = 4)
private String secretKey;
/**
* 短信签名
*/
@Schema(description = "短信签名")
@Schema(description = "短信签名", example = "")
@ExcelProperty(value = "短信签名")
private String signature;
/**
* 模板 ID
*/
@Schema(description = "模板 ID")
@Schema(description = "模板 ID", example = "1")
@ExcelProperty(value = "模板 ID")
private String templateId;
/**
* 负载均衡权重
*/
@Schema(description = "负载均衡权重")
@Schema(description = "负载均衡权重", example = "1")
@ExcelProperty(value = "负载均衡权重")
private Integer weight;
/**
* 短信自动重试间隔时间(秒)
* 重试间隔(单位:秒)
*/
@Schema(description = "短信自动重试间隔时间(秒)")
@Schema(description = "重试间隔(单位:秒)", example = "5")
@ExcelProperty(value = "重试间隔(单位:秒)")
private Integer retryInterval;
/**
* 短信重试次数
* 重试次数
*/
@Schema(description = "短信重试次数")
@Schema(description = "重试次数", example = "0")
@ExcelProperty(value = "重试次数")
private Integer maxRetries;
/**
* 当前厂商的发送数量上限
* 发送上限
*/
@Schema(description = "当前厂商的发送数量上限")
@Schema(description = "发送上限")
@ExcelProperty(value = "发送上限")
private Integer maximum;
/**
* 各个厂商独立配置
*/
@Schema(description = "各个厂商独立配置")
@Schema(description = "各个厂商独立配置", example = "")
@ExcelProperty(value = "各个厂商独立配置")
private String supplierConfig;
/**
* 是否启用
* 状态
*/
@Schema(description = "是否启用")
private Boolean isEnable;
/**
* 修改人
*/
@Schema(description = "修改人")
private Long updateUser;
/**
* 修改时间
*/
@Schema(description = "修改时间")
private LocalDateTime updateTime;
@Schema(description = "状态", example = "1")
@ExcelProperty(value = "状态", converter = ExcelBaseEnumConverter.class)
private DisEnableStatusEnum status;
}

View File

@@ -20,35 +20,38 @@ import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import top.continew.admin.common.model.resp.BaseDetailResp;
import top.continew.admin.common.enums.SuccessFailureStatusEnum;
import top.continew.admin.common.model.resp.BaseResp;
import top.continew.starter.file.excel.converter.ExcelBaseEnumConverter;
import java.io.Serial;
/**
* 短信记录详情信息
* 短信日志信息
*
* @author luoqiz
* @author Charles7c
* @since 2025/03/15 22:15
*/
@Data
@ExcelIgnoreUnannotated
@Schema(description = "短信记录详情信息")
public class SmsRecordDetailResp extends BaseDetailResp {
@Schema(description = "短信日志信息")
public class SmsLogResp extends BaseResp {
@Serial
private static final long serialVersionUID = 1L;
/**
* 配置id
* 配置 ID
*/
@Schema(description = "配置id")
@ExcelProperty(value = "配置id")
@Schema(description = "配置 ID", example = "")
@ExcelProperty(value = "配置 ID")
private Long configId;
/**
* 手机号
*/
@Schema(description = "手机号")
@Schema(description = "手机号", example = "18888888888")
@ExcelProperty(value = "手机号")
private String phone;
@@ -62,9 +65,9 @@ public class SmsRecordDetailResp extends BaseDetailResp {
/**
* 发送状态
*/
@Schema(description = "发送状态")
@ExcelProperty(value = "发送状态")
private Boolean status;
@Schema(description = "发送状态", example = "1")
@ExcelProperty(value = "发送状态", converter = ExcelBaseEnumConverter.class)
private SuccessFailureStatusEnum status;
/**
* 返回数据

View File

@@ -16,16 +16,15 @@
package top.continew.admin.system.service;
import top.continew.starter.extension.crud.service.BaseService;
import top.continew.admin.system.model.query.SmsConfigQuery;
import top.continew.admin.system.model.req.SmsConfigReq;
import top.continew.admin.system.model.resp.SmsConfigDetailResp;
import top.continew.admin.system.model.resp.SmsConfigResp;
import top.continew.starter.extension.crud.service.BaseService;
/**
* 短信服务配置业务接口
* 短信配置业务接口
*
* @author luoqiz
* @since 2025/03/15 18:41
*/
public interface SmsConfigService extends BaseService<SmsConfigResp, SmsConfigDetailResp, SmsConfigQuery, SmsConfigReq> {}
public interface SmsConfigService extends BaseService<SmsConfigResp, SmsConfigResp, SmsConfigQuery, SmsConfigReq> {}

View File

@@ -16,16 +16,15 @@
package top.continew.admin.system.service;
import top.continew.admin.system.model.query.SmsLogQuery;
import top.continew.admin.system.model.req.SmsLogReq;
import top.continew.admin.system.model.resp.SmsLogResp;
import top.continew.starter.extension.crud.service.BaseService;
import top.continew.admin.system.model.query.SmsRecordQuery;
import top.continew.admin.system.model.req.SmsRecordReq;
import top.continew.admin.system.model.resp.SmsRecordDetailResp;
import top.continew.admin.system.model.resp.SmsRecordResp;
/**
* 短信记录业务接口
* 短信日志业务接口
*
* @author luoqiz
* @since 2025/03/15 22:15
*/
public interface SmsRecordService extends BaseService<SmsRecordResp, SmsRecordDetailResp, SmsRecordQuery, SmsRecordReq> {}
public interface SmsLogService extends BaseService<SmsLogResp, SmsLogResp, SmsLogQuery, SmsLogReq> {}

View File

@@ -16,18 +16,16 @@
package top.continew.admin.system.service.impl;
import jakarta.annotation.Resource;
import cn.hutool.core.bean.BeanUtil;
import lombok.RequiredArgsConstructor;
import org.dromara.sms4j.core.factory.SmsFactory;
import org.dromara.sms4j.provider.config.BaseConfig;
import org.springframework.stereotype.Service;
import top.continew.admin.common.enums.MethodTypeEnum;
import top.continew.admin.system.config.sms.event.SmsEventMessage;
import top.continew.admin.system.config.sms.event.SmsRedisConfig;
import top.continew.admin.system.config.sms.event.SmsRedisMessagePublisher;
import top.continew.admin.system.enums.SmsSupplierEnum;
import top.continew.admin.system.mapper.SmsConfigMapper;
import top.continew.admin.system.model.entity.SmsConfigDO;
import top.continew.admin.system.model.query.SmsConfigQuery;
import top.continew.admin.system.model.req.SmsConfigReq;
import top.continew.admin.system.model.resp.SmsConfigDetailResp;
import top.continew.admin.system.model.resp.SmsConfigResp;
import top.continew.admin.system.service.SmsConfigService;
import top.continew.starter.extension.crud.service.BaseServiceImpl;
@@ -35,39 +33,55 @@ import top.continew.starter.extension.crud.service.BaseServiceImpl;
import java.util.List;
/**
* 短信服务配置业务实现
* 短信配置业务实现
*
* @author luoqiz
* @since 2025/03/15 18:41
*/
@Service
@RequiredArgsConstructor
public class SmsConfigServiceImpl extends BaseServiceImpl<SmsConfigMapper, SmsConfigDO, SmsConfigResp, SmsConfigDetailResp, SmsConfigQuery, SmsConfigReq> implements SmsConfigService {
@Resource
private SmsRedisMessagePublisher smsRedisMessagePublisher;
public class SmsConfigServiceImpl extends BaseServiceImpl<SmsConfigMapper, SmsConfigDO, SmsConfigResp, SmsConfigResp, SmsConfigQuery, SmsConfigReq> implements SmsConfigService {
@Override
protected void afterAdd(SmsConfigReq req, SmsConfigDO entity) {
super.afterAdd(req, entity);
smsRedisMessagePublisher.publish(SmsRedisConfig.SysSmsChannel, new SmsEventMessage(MethodTypeEnum.ADD, entity
.getId()
.toString()));
public void afterAdd(SmsConfigReq req, SmsConfigDO entity) {
this.load(entity);
}
@Override
protected void afterUpdate(SmsConfigReq req, SmsConfigDO entity) {
super.afterUpdate(req, entity);
smsRedisMessagePublisher.publish(SmsRedisConfig.SysSmsChannel, new SmsEventMessage(MethodTypeEnum.UPDATE, entity
.getId()
.toString()));
public void afterUpdate(SmsConfigReq req, SmsConfigDO entity) {
// 重新加载配置
// 先卸载
this.unload(entity.getId().toString());
// 再加载
this.load(entity);
}
@Override
protected void afterDelete(List<Long> ids) {
super.afterDelete(ids);
public void afterDelete(List<Long> ids) {
for (Long id : ids) {
smsRedisMessagePublisher.publish(SmsRedisConfig.SysSmsChannel, new SmsEventMessage(MethodTypeEnum.DELETE, id
.toString()));
this.unload(id.toString());
}
}
/**
* 加载配置
*
* @param entity 配置信息
*/
private void load(SmsConfigDO entity) {
SmsSupplierEnum supplier = entity.getSupplier();
BaseConfig config = supplier.toBaseConfig(BeanUtil.toBean(entity, SmsConfigResp.class));
SmsFactory.createSmsBlend(config);
}
/**
* 卸载配置
*
* @param configId 配置 ID
*/
private void unload(String configId) {
if (SmsFactory.getSmsBlend(configId) != null) {
SmsFactory.unregister(configId);
}
}
}

View File

@@ -16,25 +16,20 @@
package top.continew.admin.system.service.impl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import top.continew.admin.system.mapper.SmsLogMapper;
import top.continew.admin.system.model.entity.SmsLogDO;
import top.continew.admin.system.model.query.SmsLogQuery;
import top.continew.admin.system.model.req.SmsLogReq;
import top.continew.admin.system.model.resp.SmsLogResp;
import top.continew.admin.system.service.SmsLogService;
import top.continew.starter.extension.crud.service.BaseServiceImpl;
import top.continew.admin.system.mapper.SmsRecordMapper;
import top.continew.admin.system.model.entity.SmsRecordDO;
import top.continew.admin.system.model.query.SmsRecordQuery;
import top.continew.admin.system.model.req.SmsRecordReq;
import top.continew.admin.system.model.resp.SmsRecordDetailResp;
import top.continew.admin.system.model.resp.SmsRecordResp;
import top.continew.admin.system.service.SmsRecordService;
/**
* 短信记录业务实现
* 短信日志业务实现
*
* @author luoqiz
* @since 2025/03/15 22:15
*/
@Service
@RequiredArgsConstructor
public class SmsRecordServiceImpl extends BaseServiceImpl<SmsRecordMapper, SmsRecordDO, SmsRecordResp, SmsRecordDetailResp, SmsRecordQuery, SmsRecordReq> implements SmsRecordService {}
public class SmsLogServiceImpl extends BaseServiceImpl<SmsLogMapper, SmsLogDO, SmsLogResp, SmsLogResp, SmsLogQuery, SmsLogReq> implements SmsLogService {}

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="top.continew.admin.system.mapper.SmsRecordMapper">
<mapper namespace="top.continew.admin.system.mapper.SmsLogMapper">
</mapper>