Merge pull request 'Dev' (#47) from dev into sit
Reviewed-on: http://wcy111.top:3000/xiaowang/JayuCloud/pulls/47
This commit was merged in pull request #47.
This commit is contained in:
+2
@@ -68,4 +68,6 @@ public interface MessageHubPushConfigService {
|
|||||||
* @return MessageHubPushConfigDO result consumed by the caller or returned to the frontend
|
* @return MessageHubPushConfigDO result consumed by the caller or returned to the frontend
|
||||||
*/
|
*/
|
||||||
MessageHubPushConfigDO getEnabledConfig(String sceneCode);
|
MessageHubPushConfigDO getEnabledConfig(String sceneCode);
|
||||||
|
|
||||||
|
void switchSmsProvider(UserDO currentUser, String provider);
|
||||||
}
|
}
|
||||||
|
|||||||
+48
@@ -26,6 +26,12 @@ import java.util.stream.Collectors;
|
|||||||
* Beginner guide: follow the call chain Controller -> Service -> ServiceImpl -> Mapper/support class.
|
* Beginner guide: follow the call chain Controller -> Service -> ServiceImpl -> Mapper/support class.
|
||||||
*/
|
*/
|
||||||
public class MessageHubPushConfigServiceImpl implements MessageHubPushConfigService {
|
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.
|
* 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"));
|
.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`.
|
* 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.
|
* Call guide: pass the named parameters below from the controller or caller; the method validates them and returns the business result.
|
||||||
|
|||||||
+5
@@ -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.service.SystemParameterConfigService;
|
||||||
import com.xiaowang.jacyucloudsalon.core.modules.system.support.AdminDefaultPasswordSupport;
|
import com.xiaowang.jacyucloudsalon.core.modules.system.support.AdminDefaultPasswordSupport;
|
||||||
import com.xiaowang.jacyucloudsalon.core.modules.system.vo.SystemParameterConfigVO;
|
import com.xiaowang.jacyucloudsalon.core.modules.system.vo.SystemParameterConfigVO;
|
||||||
|
import com.xiaowang.jacyucloudsalon.core.modules.integration.service.MessageHubPushConfigService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
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.
|
* Usage: reference this field from the owning layer and pass validated inputs before reading or updating related state.
|
||||||
*/
|
*/
|
||||||
private final SystemParameterConfigMapper configMapper;
|
private final SystemParameterConfigMapper configMapper;
|
||||||
|
private final MessageHubPushConfigService messageHubPushConfigService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
/**
|
/**
|
||||||
@@ -81,6 +83,9 @@ public class SystemParameterConfigServiceImpl implements SystemParameterConfigSe
|
|||||||
} else {
|
} else {
|
||||||
configMapper.updateById(config);
|
configMapper.updateById(config);
|
||||||
}
|
}
|
||||||
|
if ("SMS".equals(group) && "SMS_PROVIDER".equals(key)) {
|
||||||
|
messageHubPushConfigService.switchSmsProvider(currentUser, config.getConfigValue());
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,15 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="system-settings">
|
<div class="system-settings">
|
||||||
<a-page-header title="系统设置" sub-title="管理店长账号默认密码" />
|
<a-page-header title="系统设置" sub-title="管理店长账号默认密码" />
|
||||||
|
<a-card title="短信供应商" :loading="loading">
|
||||||
|
<a-alert message="全局统一切换短信发送渠道" description="保存后会同步所有短信验证码场景的 MessageHub 模板、通道和发送方式。" show-icon type="info" />
|
||||||
|
<a-form class="settings-form" layout="vertical">
|
||||||
|
<a-form-item label="当前供应商">
|
||||||
|
<a-select v-model:value="smsProviderForm.configValue" :options="smsProviderOptions" />
|
||||||
|
</a-form-item>
|
||||||
|
<a-button type="primary" :loading="savingSmsProvider" @click="saveSmsProvider">保存短信供应商</a-button>
|
||||||
|
</a-form>
|
||||||
|
</a-card>
|
||||||
<a-card title="店长默认密码" :loading="loading">
|
<a-card title="店长默认密码" :loading="loading">
|
||||||
<a-alert
|
<a-alert
|
||||||
message="用于新增或重置店长账号"
|
message="用于新增或重置店长账号"
|
||||||
@@ -28,6 +37,7 @@ import { adminSystemParameterConfigApi, type SystemParameterConfigVO } from '@/a
|
|||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const saving = ref(false)
|
const saving = ref(false)
|
||||||
|
const savingSmsProvider = ref(false)
|
||||||
const enabled = ref(true)
|
const enabled = ref(true)
|
||||||
const form = reactive<SystemParameterConfigVO>({
|
const form = reactive<SystemParameterConfigVO>({
|
||||||
configGroup: 'USER',
|
configGroup: 'USER',
|
||||||
@@ -37,16 +47,29 @@ const form = reactive<SystemParameterConfigVO>({
|
|||||||
enabled: 1,
|
enabled: 1,
|
||||||
remark: '新增或重置店长账号时使用的默认密码'
|
remark: '新增或重置店长账号时使用的默认密码'
|
||||||
})
|
})
|
||||||
|
const smsProviderOptions = [
|
||||||
|
{ label: 'Spug 短信', value: 'SPUG' },
|
||||||
|
{ label: '阿里云短信认证服务', value: 'ALIYUN_SMS_VERIFY' }
|
||||||
|
]
|
||||||
|
const smsProviderForm = reactive<SystemParameterConfigVO>({
|
||||||
|
configGroup: 'SMS', configKey: 'SMS_PROVIDER', configName: '短信供应商', configValue: 'SPUG', enabled: 1,
|
||||||
|
remark: '全局切换短信供应商时同步验证码模板和 MessageHub 通道'
|
||||||
|
})
|
||||||
|
|
||||||
const load = async () => {
|
const load = async () => {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
const configs = await adminSystemParameterConfigApi.listConfigs('USER')
|
const [configs, smsConfigs] = await Promise.all([
|
||||||
|
adminSystemParameterConfigApi.listConfigs('USER'),
|
||||||
|
adminSystemParameterConfigApi.listConfigs('SMS')
|
||||||
|
])
|
||||||
const config = configs.find(item => item.configKey === 'DEFAULT_PASSWORD')
|
const config = configs.find(item => item.configKey === 'DEFAULT_PASSWORD')
|
||||||
if (config) {
|
if (config) {
|
||||||
Object.assign(form, config)
|
Object.assign(form, config)
|
||||||
enabled.value = config.enabled === 1
|
enabled.value = config.enabled === 1
|
||||||
}
|
}
|
||||||
|
const smsProvider = smsConfigs.find(item => item.configKey === 'SMS_PROVIDER')
|
||||||
|
if (smsProvider) Object.assign(smsProviderForm, smsProvider)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
message.error(error instanceof Error ? error.message : '默认密码加载失败')
|
message.error(error instanceof Error ? error.message : '默认密码加载失败')
|
||||||
} finally {
|
} finally {
|
||||||
@@ -54,6 +77,19 @@ const load = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const saveSmsProvider = async () => {
|
||||||
|
const confirmed = window.confirm('保存后会同步全部短信验证码场景的模板、通道和发送方式,确认切换吗?')
|
||||||
|
if (!confirmed) return
|
||||||
|
savingSmsProvider.value = true
|
||||||
|
try {
|
||||||
|
await adminSystemParameterConfigApi.saveConfig({ ...smsProviderForm, configValue: smsProviderForm.configValue.toUpperCase(), enabled: 1 })
|
||||||
|
message.success('短信供应商已切换')
|
||||||
|
await load()
|
||||||
|
} finally {
|
||||||
|
savingSmsProvider.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const save = async () => {
|
const save = async () => {
|
||||||
const password = form.configValue.trim()
|
const password = form.configValue.trim()
|
||||||
if (password.length < 8 || password.length > 32) {
|
if (password.length < 8 || password.length > 32) {
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
-- Salon 短信供应商全局切换配置
|
||||||
|
-- 版本:0.0.1
|
||||||
|
-- 说明:初始化全局短信供应商为 Spug;管理员可在系统设置中切换并同步短信场景。
|
||||||
|
|
||||||
|
INSERT INTO t_system_parameter_config (
|
||||||
|
id, config_group, config_key, config_name, config_value, enabled, remark, create_time, update_time, is_delete
|
||||||
|
) VALUES (
|
||||||
|
313931273555139010, 'SMS', 'SMS_PROVIDER', '短信供应商', 'SPUG', 1,
|
||||||
|
'全局切换短信供应商时同步验证码模板和 MessageHub 通道', NOW(), NOW(), 0
|
||||||
|
)
|
||||||
|
ON DUPLICATE KEY UPDATE
|
||||||
|
config_name = VALUES(config_name),
|
||||||
|
remark = VALUES(remark),
|
||||||
|
update_time = NOW();
|
||||||
@@ -1,19 +1,20 @@
|
|||||||
-- Salon 短信验证码模板编码映射调整
|
-- Salon 短信验证码模板编码映射调整
|
||||||
-- 版本:0.0.1
|
-- 版本:0.0.1
|
||||||
-- 说明:MessageHub 已配置阿里云 100001-100005 与 Spug SPUG_SMS_VERIFY_1-4 模板。
|
-- 说明:当前 Salon 使用 Spug 短信,模板 SPUG_SMS_VERIFY_1 支持 name、code、number 参数。
|
||||||
|
|
||||||
START TRANSACTION;
|
START TRANSACTION;
|
||||||
|
|
||||||
UPDATE t_messagehub_push_config
|
UPDATE t_messagehub_push_config
|
||||||
SET template_code = CASE scene_code
|
SET template_code = CASE scene_code
|
||||||
WHEN 'USER_REGISTER_SMS_CODE' THEN '100001'
|
WHEN 'USER_REGISTER_SMS_CODE' THEN 'SPUG_SMS_VERIFY_1'
|
||||||
WHEN 'USER_LOGIN_SMS_CODE' THEN '100001'
|
WHEN 'USER_LOGIN_SMS_CODE' THEN 'SPUG_SMS_VERIFY_1'
|
||||||
WHEN 'USER_RESET_PASSWORD_SMS_CODE' THEN '100003'
|
WHEN 'USER_RESET_PASSWORD_SMS_CODE' THEN 'SPUG_SMS_VERIFY_1'
|
||||||
WHEN 'USER_BIND_PHONE_SMS_CODE' THEN '100004'
|
WHEN 'USER_BIND_PHONE_SMS_CODE' THEN 'SPUG_SMS_VERIFY_1'
|
||||||
WHEN 'USER_CHANGE_PHONE_SMS_CODE' THEN '100002'
|
WHEN 'USER_CHANGE_PHONE_SMS_CODE' THEN 'SPUG_SMS_VERIFY_1'
|
||||||
WHEN 'USER_CHANGE_PASSWORD_SMS_CODE' THEN '100003'
|
WHEN 'USER_CHANGE_PASSWORD_SMS_CODE' THEN 'SPUG_SMS_VERIFY_1'
|
||||||
END,
|
END,
|
||||||
send_method = 'ALIYUN_SMS_VERIFY',
|
channel_id = NULL,
|
||||||
|
send_method = 'SPUG',
|
||||||
update_time = NOW()
|
update_time = NOW()
|
||||||
WHERE platform = 'SMS'
|
WHERE platform = 'SMS'
|
||||||
AND source_system = 'jayucloud-salon'
|
AND source_system = 'jayucloud-salon'
|
||||||
@@ -29,7 +30,7 @@ WHERE platform = 'SMS'
|
|||||||
|
|
||||||
COMMIT;
|
COMMIT;
|
||||||
|
|
||||||
SELECT scene_code, template_code, send_method
|
SELECT scene_code, template_code, channel_id, send_method
|
||||||
FROM t_messagehub_push_config
|
FROM t_messagehub_push_config
|
||||||
WHERE platform = 'SMS'
|
WHERE platform = 'SMS'
|
||||||
AND source_system = 'jayucloud-salon'
|
AND source_system = 'jayucloud-salon'
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
# Salon 短信供应商全局切换设计
|
||||||
|
|
||||||
|
## 目标
|
||||||
|
|
||||||
|
平台管理员在 Salon 管理端“系统设置”中统一选择短信供应商。选择变更后,所有短信验证码场景的 MessageHub 模板、发送方式和通道选择必须同步到同一供应商,避免模板与通道不匹配。
|
||||||
|
|
||||||
|
本次不处理 MessageHub 异步发送失败回传。
|
||||||
|
|
||||||
|
## 配置模型
|
||||||
|
|
||||||
|
复用 `t_system_parameter_config`,增加参数:
|
||||||
|
|
||||||
|
- 配置组:`SMS`
|
||||||
|
- 配置键:`SMS_PROVIDER`
|
||||||
|
- 可选值:`SPUG`、`ALIYUN_SMS_VERIFY`
|
||||||
|
- 默认值:`SPUG`
|
||||||
|
|
||||||
|
该配置仅平台管理员可读写,并沿用现有 `messagehub:config:manage` 权限。
|
||||||
|
|
||||||
|
## 场景同步规则
|
||||||
|
|
||||||
|
保存供应商配置时,在同一个数据库事务中更新 Salon 的六个短信场景:
|
||||||
|
|
||||||
|
### Spug
|
||||||
|
|
||||||
|
- 模板编码:`SPUG_SMS_VERIFY_1`
|
||||||
|
- `send_method`:`SPUG`
|
||||||
|
- `channel_id`:`NULL`,使用 MessageHub 来源系统的默认 Spug 通道
|
||||||
|
|
||||||
|
### 阿里云短信认证服务
|
||||||
|
|
||||||
|
- 注册、登录:`100001`
|
||||||
|
- 修改手机号:`100002`
|
||||||
|
- 重置密码:`100003`
|
||||||
|
- 绑定手机号:`100004`
|
||||||
|
- 验证绑定手机号:`100005`
|
||||||
|
- `send_method`:`ALIYUN_SMS_VERIFY`
|
||||||
|
- `channel_id`:配置的阿里云短信认证通道 ID
|
||||||
|
|
||||||
|
当前代码没有独立的“验证绑定手机号”场景时,不新增业务场景,只同步已存在的场景;模板 `100005` 保留给后续对应场景使用。
|
||||||
|
|
||||||
|
## 管理端交互
|
||||||
|
|
||||||
|
- 系统设置新增短信供应商选择器,展示当前供应商和切换后的模板策略。
|
||||||
|
- 保存前二次确认,明确会同步全部短信验证码场景。
|
||||||
|
- MessageHub 场景列表保留查看和测试能力。
|
||||||
|
- 禁止在场景编辑表单中单独修改模板编码、通道 ID、发送方式;这些字段改为只读展示。
|
||||||
|
|
||||||
|
## 错误处理
|
||||||
|
|
||||||
|
- 只接受 `SPUG` 和 `ALIYUN_SMS_VERIFY`,其他值明确拒绝。
|
||||||
|
- 同步场景数量不足、目标配置缺失或数据库更新失败时整个事务回滚。
|
||||||
|
- 切换成功后重新读取并展示六个场景的实际模板和通道配置。
|
||||||
|
|
||||||
|
## 验证范围
|
||||||
|
|
||||||
|
- 后端服务参数保存测试:供应商值校验、场景批量同步、事务回滚。
|
||||||
|
- MessageHub 消息体测试:读取场景配置后发送对应模板和 `channelId`。
|
||||||
|
- 前端构建测试:系统设置选择、确认、保存和只读场景展示。
|
||||||
Reference in New Issue
Block a user