增加Salon短信供应商全局切换
发布 Nacos 配置 / publish (push) Successful in 32s

This commit is contained in:
2026-09-06 21:41:09 +08:00
parent dc46ff359b
commit 3401c2f5e5
6 changed files with 165 additions and 1 deletions
@@ -68,4 +68,6 @@ public interface MessageHubPushConfigService {
* @return MessageHubPushConfigDO result consumed by the caller or returned to the frontend
*/
MessageHubPushConfigDO getEnabledConfig(String sceneCode);
void switchSmsProvider(UserDO currentUser, String provider);
}
@@ -26,6 +26,12 @@ import java.util.stream.Collectors;
* Beginner guide: follow the call chain Controller -> Service -> ServiceImpl -> Mapper/support class.
*/
public class MessageHubPushConfigServiceImpl implements MessageHubPushConfigService {
private static final String SPUG_PROVIDER = "SPUG";
private static final String ALIYUN_PROVIDER = "ALIYUN_SMS_VERIFY";
private static final long ALIYUN_CHANNEL_ID = 314055468907909120L;
private static final List<String> SMS_SCENES = List.of(
"USER_REGISTER_SMS_CODE", "USER_LOGIN_SMS_CODE", "USER_RESET_PASSWORD_SMS_CODE",
"USER_BIND_PHONE_SMS_CODE", "USER_CHANGE_PHONE_SMS_CODE", "USER_CHANGE_PASSWORD_SMS_CODE");
/**
* Variable `configMapper`: Spring-injected collaborator used by this class to finish database access, validation, or downstream calls.
*/
@@ -214,6 +220,48 @@ public class MessageHubPushConfigServiceImpl implements MessageHubPushConfigServ
.last("LIMIT 1"));
}
@Override
@Transactional(rollbackFor = Exception.class)
public void switchSmsProvider(UserDO currentUser, String provider) {
ensurePlatformAdmin(currentUser);
String normalizedProvider = normalizeSmsProvider(provider);
String templateCode = SPUG_PROVIDER.equals(normalizedProvider) ? "SPUG_SMS_VERIFY_1" : null;
String sendMethod = normalizedProvider;
Long channelId = SPUG_PROVIDER.equals(normalizedProvider) ? null : ALIYUN_CHANNEL_ID;
List<MessageHubPushConfigDO> configs = configMapper.selectList(new LambdaQueryWrapper<MessageHubPushConfigDO>()
.in(MessageHubPushConfigDO::getSceneCode, SMS_SCENES)
.eq(MessageHubPushConfigDO::getPlatform, "SMS")
.eq(MessageHubPushConfigDO::getIsDelete, 0));
if (configs.size() != SMS_SCENES.size()) {
throw new IllegalStateException("短信场景配置不完整,无法切换供应商");
}
for (MessageHubPushConfigDO config : configs) {
String sceneTemplate = templateCode == null ? aliyunTemplate(config.getSceneCode()) : templateCode;
config.setTemplateCode(sceneTemplate);
config.setChannelId(channelId);
config.setSendMethod(sendMethod);
configMapper.updateById(config);
}
}
private String normalizeSmsProvider(String provider) {
String value = normalizeUpper(provider, "");
if (!SPUG_PROVIDER.equals(value) && !ALIYUN_PROVIDER.equals(value)) {
throw new IllegalArgumentException("短信供应商仅支持 SPUG 或 ALIYUN_SMS_VERIFY");
}
return value;
}
private String aliyunTemplate(String sceneCode) {
return switch (sceneCode) {
case "USER_REGISTER_SMS_CODE", "USER_LOGIN_SMS_CODE" -> "100001";
case "USER_CHANGE_PHONE_SMS_CODE" -> "100002";
case "USER_RESET_PASSWORD_SMS_CODE", "USER_CHANGE_PASSWORD_SMS_CODE" -> "100003";
case "USER_BIND_PHONE_SMS_CODE" -> "100004";
default -> throw new IllegalArgumentException("不支持的短信场景: " + sceneCode);
};
}
/**
* Run business method `apply`.
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
@@ -8,6 +8,7 @@ import com.xiaowang.jacyucloudsalon.core.modules.system.mapper.SystemParameterCo
import com.xiaowang.jacyucloudsalon.core.modules.system.service.SystemParameterConfigService;
import com.xiaowang.jacyucloudsalon.core.modules.system.support.AdminDefaultPasswordSupport;
import com.xiaowang.jacyucloudsalon.core.modules.system.vo.SystemParameterConfigVO;
import com.xiaowang.jacyucloudsalon.core.modules.integration.service.MessageHubPushConfigService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -30,6 +31,7 @@ public class SystemParameterConfigServiceImpl implements SystemParameterConfigSe
* Usage: reference this field from the owning layer and pass validated inputs before reading or updating related state.
*/
private final SystemParameterConfigMapper configMapper;
private final MessageHubPushConfigService messageHubPushConfigService;
@Override
/**
@@ -81,6 +83,9 @@ public class SystemParameterConfigServiceImpl implements SystemParameterConfigSe
} else {
configMapper.updateById(config);
}
if ("SMS".equals(group) && "SMS_PROVIDER".equals(key)) {
messageHubPushConfigService.switchSmsProvider(currentUser, config.getConfigValue());
}
return true;
}