mirror of
				https://github.com/continew-org/continew-admin.git
				synced 2025-10-31 22:57:17 +08:00 
			
		
		
		
	feat(system/smsConfig): 短信配置新增设为默认功能
This commit is contained in:
		| @@ -84,18 +84,6 @@ public class CaptchaProperties { | ||||
|          */ | ||||
|         private long expirationInMinutes; | ||||
|  | ||||
|         /** | ||||
|          * 模板 ID | ||||
|          */ | ||||
|         private String templateId; | ||||
|  | ||||
|         /** | ||||
|          * 短信厂商 | ||||
|          * | ||||
|          * @see top.continew.admin.system.model.resp.SmsConfigResp#supplier | ||||
|          */ | ||||
|         private String supplier; | ||||
|  | ||||
|         /** | ||||
|          * 验证码字段模板键名 | ||||
|          */ | ||||
|   | ||||
| @@ -94,6 +94,11 @@ public class SmsConfigDO extends BaseDO { | ||||
|      */ | ||||
|     private String supplierConfig; | ||||
|  | ||||
|     /** | ||||
|      * 是否为默认存储 | ||||
|      */ | ||||
|     private Boolean isDefault; | ||||
|  | ||||
|     /** | ||||
|      * 状态 | ||||
|      */ | ||||
|   | ||||
| @@ -125,6 +125,13 @@ public class SmsConfigResp extends BaseDetailResp { | ||||
|     @ExcelProperty(value = "各个厂商独立配置") | ||||
|     private String supplierConfig; | ||||
|  | ||||
|     /** | ||||
|      * 是否为默认存储 | ||||
|      */ | ||||
|     @Schema(description = "是否为默认存储", example = "true") | ||||
|     @ExcelProperty(value = "是否为默认存储") | ||||
|     private Boolean isDefault; | ||||
|  | ||||
|     /** | ||||
|      * 状态 | ||||
|      */ | ||||
|   | ||||
| @@ -16,6 +16,7 @@ | ||||
|  | ||||
| package top.continew.admin.system.service; | ||||
|  | ||||
| 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.SmsConfigResp; | ||||
| @@ -27,4 +28,19 @@ import top.continew.starter.extension.crud.service.BaseService; | ||||
|  * @author luoqiz | ||||
|  * @since 2025/03/15 18:41 | ||||
|  */ | ||||
| public interface SmsConfigService extends BaseService<SmsConfigResp, SmsConfigResp, SmsConfigQuery, SmsConfigReq> {} | ||||
| public interface SmsConfigService extends BaseService<SmsConfigResp, SmsConfigResp, SmsConfigQuery, SmsConfigReq> { | ||||
|  | ||||
|     /** | ||||
|      * 设置默认配置 | ||||
|      * | ||||
|      * @param id ID | ||||
|      */ | ||||
|     void setDefaultConfig(Long id); | ||||
|  | ||||
|     /** | ||||
|      * 获取默认短信配置 | ||||
|      * | ||||
|      * @return 默认短信配置 | ||||
|      */ | ||||
|     SmsConfigDO getDefaultConfig(); | ||||
| } | ||||
| @@ -45,7 +45,7 @@ public interface StorageService extends BaseService<StorageResp, StorageResp, St | ||||
|      * | ||||
|      * @param id ID | ||||
|      */ | ||||
|     void setDefault(Long id); | ||||
|     void setDefaultStorage(Long id); | ||||
|  | ||||
|     /** | ||||
|      * 查询默认存储 | ||||
|   | ||||
| @@ -20,6 +20,8 @@ import lombok.RequiredArgsConstructor; | ||||
| import org.dromara.sms4j.core.factory.SmsFactory; | ||||
| import org.dromara.sms4j.provider.config.BaseConfig; | ||||
| import org.springframework.stereotype.Service; | ||||
| import org.springframework.transaction.annotation.Transactional; | ||||
| import top.continew.admin.common.enums.DisEnableStatusEnum; | ||||
| import top.continew.admin.system.config.sms.SmsConfigUtil; | ||||
| import top.continew.admin.system.mapper.SmsConfigMapper; | ||||
| import top.continew.admin.system.model.entity.SmsConfigDO; | ||||
| @@ -27,6 +29,7 @@ import top.continew.admin.system.model.query.SmsConfigQuery; | ||||
| import top.continew.admin.system.model.req.SmsConfigReq; | ||||
| import top.continew.admin.system.model.resp.SmsConfigResp; | ||||
| import top.continew.admin.system.service.SmsConfigService; | ||||
| import top.continew.starter.core.validation.CheckUtils; | ||||
| import top.continew.starter.extension.crud.service.BaseServiceImpl; | ||||
|  | ||||
| import java.util.List; | ||||
| @@ -62,6 +65,24 @@ public class SmsConfigServiceImpl extends BaseServiceImpl<SmsConfigMapper, SmsCo | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     @Transactional(rollbackFor = Exception.class) | ||||
|     public void setDefaultConfig(Long id) { | ||||
|         SmsConfigDO smsConfig = super.getById(id); | ||||
|         if (Boolean.TRUE.equals(smsConfig.getIsDefault())) { | ||||
|             return; | ||||
|         } | ||||
|         // 启用状态才能设为默认配置 | ||||
|         CheckUtils.throwIfNotEqual(DisEnableStatusEnum.ENABLE, smsConfig.getStatus(), "请先启用所选配置"); | ||||
|         baseMapper.lambdaUpdate().eq(SmsConfigDO::getIsDefault, true).set(SmsConfigDO::getIsDefault, false).update(); | ||||
|         baseMapper.lambdaUpdate().eq(SmsConfigDO::getId, id).set(SmsConfigDO::getIsDefault, true).update(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public SmsConfigDO getDefaultConfig() { | ||||
|         return baseMapper.lambdaQuery().eq(SmsConfigDO::getIsDefault, true).eq(SmsConfigDO::getStatus, DisEnableStatusEnum.ENABLE).one(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 加载配置 | ||||
|      * | ||||
|   | ||||
| @@ -139,7 +139,7 @@ public class StorageServiceImpl extends BaseServiceImpl<StorageMapper, StorageDO | ||||
|  | ||||
|     @Override | ||||
|     @Transactional(rollbackFor = Exception.class) | ||||
|     public void setDefault(Long id) { | ||||
|     public void setDefaultStorage(Long id) { | ||||
|         StorageDO storage = super.getById(id); | ||||
|         if (Boolean.TRUE.equals(storage.getIsDefault())) { | ||||
|             return; | ||||
| @@ -152,7 +152,7 @@ public class StorageServiceImpl extends BaseServiceImpl<StorageMapper, StorageDO | ||||
|  | ||||
|     @Override | ||||
|     public StorageDO getDefaultStorage() { | ||||
|         return baseMapper.lambdaQuery().eq(StorageDO::getIsDefault, true).one(); | ||||
|         return baseMapper.lambdaQuery().eq(StorageDO::getIsDefault, true).eq(StorageDO::getStatus, DisEnableStatusEnum.ENABLE).one(); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|   | ||||
| @@ -47,7 +47,9 @@ import top.continew.admin.common.config.properties.CaptchaProperties; | ||||
| import top.continew.admin.common.constant.CacheConstants; | ||||
| import top.continew.admin.common.constant.SysConstants; | ||||
| import top.continew.admin.system.enums.OptionCategoryEnum; | ||||
| import top.continew.admin.system.model.entity.SmsConfigDO; | ||||
| import top.continew.admin.system.service.OptionService; | ||||
| import top.continew.admin.system.service.SmsConfigService; | ||||
| import top.continew.starter.cache.redisson.util.RedisUtils; | ||||
| import top.continew.starter.captcha.graphic.core.GraphicCaptchaService; | ||||
| import top.continew.starter.core.autoconfigure.project.ProjectProperties; | ||||
| @@ -87,6 +89,7 @@ public class CaptchaController { | ||||
|     private final CaptchaService behaviorCaptchaService; | ||||
|     private final GraphicCaptchaService graphicCaptchaService; | ||||
|     private final OptionService optionService; | ||||
|     private final SmsConfigService smsConfigService; | ||||
|  | ||||
|     @Log(ignore = true) | ||||
|     @Operation(summary = "获取行为验证码", description = "获取行为验证码(Base64编码)") | ||||
| @@ -201,14 +204,17 @@ public class CaptchaController { | ||||
|         CaptchaProperties.CaptchaSms captchaSms = captchaProperties.getSms(); | ||||
|         // 生成验证码 | ||||
|         String captcha = RandomUtil.randomNumbers(captchaSms.getLength()); | ||||
|         // 发送验证码 | ||||
|         Long expirationInMinutes = captchaSms.getExpirationInMinutes(); | ||||
|         SmsBlend smsBlend = SmsFactory.getBySupplier(captchaSms.getSupplier()); | ||||
|         // 获取短信配置 | ||||
|         SmsConfigDO smsConfig = smsConfigService.getDefaultConfig(); | ||||
|         SmsBlend smsBlend = smsConfig != null | ||||
|             ? SmsFactory.getBySupplier(smsConfig.getSupplier()) | ||||
|             : SmsFactory.getSmsBlend(); | ||||
|         Map<String, String> messageMap = MapUtil.newHashMap(2, true); | ||||
|         messageMap.put(captchaSms.getCodeKey(), captcha); | ||||
|         messageMap.put(captchaSms.getTimeKey(), String.valueOf(expirationInMinutes)); | ||||
|         SmsResponse smsResponse = smsBlend.sendMessage(phone, captchaSms | ||||
|             .getTemplateId(), (LinkedHashMap<String, String>)messageMap); | ||||
|         // 发送验证码 | ||||
|         SmsResponse smsResponse = smsBlend.sendMessage(phone, (LinkedHashMap<String, String>)messageMap); | ||||
|         CheckUtils.throwIf(!smsResponse.isSuccess(), "验证码发送失败"); | ||||
|         // 保存验证码 | ||||
|         String captchaKey = CacheConstants.CAPTCHA_KEY_PREFIX + phone; | ||||
|   | ||||
| @@ -16,8 +16,14 @@ | ||||
|  | ||||
| package top.continew.admin.controller.system; | ||||
|  | ||||
| import cn.dev33.satoken.annotation.SaCheckPermission; | ||||
| import io.swagger.v3.oas.annotations.Operation; | ||||
| import io.swagger.v3.oas.annotations.Parameter; | ||||
| import io.swagger.v3.oas.annotations.enums.ParameterIn; | ||||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||||
| import org.springframework.validation.annotation.Validated; | ||||
| import org.springframework.web.bind.annotation.PathVariable; | ||||
| import org.springframework.web.bind.annotation.PutMapping; | ||||
| import org.springframework.web.bind.annotation.RestController; | ||||
| import top.continew.admin.common.controller.BaseController; | ||||
| import top.continew.admin.system.model.query.SmsConfigQuery; | ||||
| @@ -38,4 +44,13 @@ import top.continew.starter.extension.crud.enums.Api; | ||||
| @Validated | ||||
| @RestController | ||||
| @CrudRequestMapping(value = "/system/smsConfig", api = {Api.PAGE, Api.GET, Api.CREATE, Api.UPDATE, Api.DELETE}) | ||||
| public class SmsConfigController extends BaseController<SmsConfigService, SmsConfigResp, SmsConfigResp, SmsConfigQuery, SmsConfigReq> {} | ||||
| public class SmsConfigController extends BaseController<SmsConfigService, SmsConfigResp, SmsConfigResp, SmsConfigQuery, SmsConfigReq> { | ||||
|  | ||||
|     @Operation(summary = "设为默认配置", description = "设为默认配置") | ||||
|     @Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH) | ||||
|     @SaCheckPermission("system:smsConfig:setDefault") | ||||
|     @PutMapping({"/{id}/default"}) | ||||
|     public void setDefault(@PathVariable("id") Long id) { | ||||
|         baseService.setDefaultConfig(id); | ||||
|     } | ||||
| } | ||||
| @@ -60,6 +60,6 @@ public class StorageController extends BaseController<StorageService, StorageRes | ||||
|     @SaCheckPermission("system:storage:setDefault") | ||||
|     @PutMapping({"/{id}/default"}) | ||||
|     public void setDefault(@PathVariable("id") Long id) { | ||||
|         baseService.setDefault(id); | ||||
|         baseService.setDefaultStorage(id); | ||||
|     } | ||||
| } | ||||
| @@ -130,8 +130,6 @@ captcha: | ||||
|     length: 6 | ||||
|     # 过期时间 | ||||
|     expirationInMinutes: 5 | ||||
|     # 模板 ID | ||||
|     templateId: 1 | ||||
|  | ||||
| --- ### 日志配置 | ||||
| ## API 请求/响应日志配置 | ||||
|   | ||||
| @@ -132,8 +132,6 @@ captcha: | ||||
|     length: 6 | ||||
|     # 过期时间 | ||||
|     expirationInMinutes: 5 | ||||
|     # 模板 ID | ||||
|     templateId: 1 | ||||
|  | ||||
| --- ### 日志配置 | ||||
| ## API 请求/响应日志配置 | ||||
|   | ||||
| @@ -93,6 +93,7 @@ VALUES | ||||
| (1214, '修改', 1210, 3, NULL, NULL, NULL, NULL, NULL, b'0', b'0', b'0', 'system:smsConfig:update', 4, 1, 1, NOW()), | ||||
| (1215, '删除', 1210, 3, NULL, NULL, NULL, NULL, NULL, b'0', b'0', b'0', 'system:smsConfig:delete', 5, 1, 1, NOW()), | ||||
| (1216, '导出', 1210, 3, NULL, NULL, NULL, NULL, NULL, b'0', b'0', b'0', 'system:smsConfig:export', 6, 1, 1, NOW()), | ||||
| (1217, '设为默认配置', 1210, 3, NULL, NULL, NULL, NULL, NULL, b'0', b'0', b'0', 'system:smsConfig:setDefault', 7, 1, 1, NOW()), | ||||
| (1230, '存储配置', 1150, 2, '/system/config?tab=storage', 'SystemStorage', 'system/config/storage/index', NULL, 'storage', b'0', b'0', b'1', NULL, 6, 1, 1, NOW()), | ||||
| (1231, '列表', 1230, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'system:storage:list', 1, 1, 1, NOW()), | ||||
| (1232, '详情', 1230, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'system:storage:get', 2, 1, 1, NOW()), | ||||
|   | ||||
| @@ -335,6 +335,7 @@ CREATE TABLE IF NOT EXISTS `sys_sms_config`  ( | ||||
|     `max_retries`     int          DEFAULT NULL                COMMENT '重试次数', | ||||
|     `maximum`         int          DEFAULT NULL                COMMENT '发送上限', | ||||
|     `supplier_config` text         DEFAULT NULL                COMMENT '各个厂商独立配置', | ||||
|     `is_default`      bit(1)       NOT NULL DEFAULT b'0'       COMMENT '是否为默认配置', | ||||
|     `status`          tinyint(1)   UNSIGNED NOT NULL DEFAULT 1 COMMENT '状态(1:启用;2:禁用)', | ||||
|     `create_user`     bigint(20)   NOT NULL                    COMMENT '创建人', | ||||
|     `create_time`     datetime     NOT NULL                    COMMENT '创建时间', | ||||
|   | ||||
| @@ -93,6 +93,7 @@ VALUES | ||||
| (1214, '修改', 1210, 3, NULL, NULL, NULL, NULL, NULL, false, false, false, 'system:smsConfig:update', 4, 1, 1, NOW()), | ||||
| (1215, '删除', 1210, 3, NULL, NULL, NULL, NULL, NULL, false, false, false, 'system:smsConfig:delete', 5, 1, 1, NOW()), | ||||
| (1216, '导出', 1210, 3, NULL, NULL, NULL, NULL, NULL, false, false, false, 'system:smsConfig:export', 6, 1, 1, NOW()), | ||||
| (1217, '设为默认配置', 1210, 3, NULL, NULL, NULL, NULL, NULL, false, false, false, 'system:smsConfig:setDefault', 7, 1, 1, NOW()), | ||||
| (1230, '存储配置', 1150, 2, '/system/config?tab=storage', 'SystemStorage', 'system/config/storage/index', NULL, 'storage', false, false, true, NULL, 6, 1, 1, NOW()), | ||||
| (1231, '列表', 1230, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'system:storage:list', 1, 1, 1, NOW()), | ||||
| (1232, '详情', 1230, 3, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'system:storage:get', 2, 1, 1, NOW()), | ||||
|   | ||||
| @@ -553,6 +553,7 @@ CREATE TABLE IF NOT EXISTS "sys_sms_config" ( | ||||
|     "max_retries"     int4         DEFAULT NULL, | ||||
|     "maximum"         int4         DEFAULT NULL, | ||||
|     "supplier_config" text         DEFAULT NULL , | ||||
|     "is_default"      bool         NOT NULL DEFAULT false, | ||||
|     "status"          int2         NOT NULL DEFAULT 1, | ||||
|     "create_user"     int8         NOT NULL, | ||||
|     "create_time"     timestamp    NOT NULL, | ||||
| @@ -574,6 +575,7 @@ COMMENT ON COLUMN "sys_sms_config"."retry_interval"  IS '重试间隔(单位 | ||||
| COMMENT ON COLUMN "sys_sms_config"."max_retries"     IS '重试次数'; | ||||
| COMMENT ON COLUMN "sys_sms_config"."maximum"         IS '发送上限'; | ||||
| COMMENT ON COLUMN "sys_sms_config"."supplier_config" IS '各个厂商独立配置'; | ||||
| COMMENT ON COLUMN "sys_sms_config"."is_default"      IS '是否为默认配置'; | ||||
| COMMENT ON COLUMN "sys_sms_config"."status"          IS '状态(1:启用;2:禁用)'; | ||||
| COMMENT ON COLUMN "sys_sms_config"."create_user"     IS '创建人'; | ||||
| COMMENT ON COLUMN "sys_sms_config"."create_time"     IS '创建时间'; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user