Commit 775cb8896b9a0009bae1f84f53511f380cafa660
1 parent
f6edee50
feat: 新增短信模板批量删除接口
Showing
3 changed files
with
56 additions
and
15 deletions
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/sms/SmsTemplateController.java
| 1 | 1 | package cn.iocoder.yudao.module.system.controller.admin.sms; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 4 | 5 | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| 6 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 5 | 7 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 6 | -import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.*; | |
| 8 | +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | |
| 9 | +import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplatePageReqVO; | |
| 10 | +import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplateRespVO; | |
| 11 | +import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplateSaveReqVO; | |
| 12 | +import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplateSendReqVO; | |
| 7 | 13 | import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; |
| 8 | -import cn.iocoder.yudao.module.system.service.sms.SmsTemplateService; | |
| 9 | 14 | import cn.iocoder.yudao.module.system.service.sms.SmsSendService; |
| 10 | -import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 11 | -import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 12 | -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; | |
| 13 | -import io.swagger.v3.oas.annotations.tags.Tag; | |
| 14 | -import io.swagger.v3.oas.annotations.Parameter; | |
| 15 | +import cn.iocoder.yudao.module.system.service.sms.SmsTemplateService; | |
| 15 | 16 | import io.swagger.v3.oas.annotations.Operation; |
| 16 | -import org.springframework.security.access.prepost.PreAuthorize; | |
| 17 | -import org.springframework.web.bind.annotation.*; | |
| 18 | - | |
| 17 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 18 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 19 | 19 | import jakarta.annotation.Resource; |
| 20 | 20 | import jakarta.servlet.http.HttpServletResponse; |
| 21 | 21 | import jakarta.validation.Valid; |
| 22 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 23 | +import org.springframework.web.bind.annotation.*; | |
| 24 | + | |
| 22 | 25 | import java.io.IOException; |
| 23 | 26 | import java.util.List; |
| 24 | 27 | |
| ... | ... | @@ -59,6 +62,15 @@ public class SmsTemplateController { |
| 59 | 62 | return success(true); |
| 60 | 63 | } |
| 61 | 64 | |
| 65 | + @DeleteMapping("/delete-list") | |
| 66 | + @Parameter(name = "ids", description = "编号列表", required = true) | |
| 67 | + @Operation(summary = "批量删除短信模板") | |
| 68 | + @PreAuthorize("@ss.hasPermission('system:sms-template:delete')") | |
| 69 | + public CommonResult<Boolean> deleteSmsTemplateList(@RequestParam("ids") List<Long> ids) { | |
| 70 | + smsTemplateService.deleteSmsTemplateList(ids); | |
| 71 | + return success(true); | |
| 72 | + } | |
| 73 | + | |
| 62 | 74 | @GetMapping("/get") |
| 63 | 75 | @Operation(summary = "获得短信模板") |
| 64 | 76 | @Parameter(name = "id", description = "编号", required = true, example = "1024") | ... | ... |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateService.java
| ... | ... | @@ -4,8 +4,9 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplatePageReqVO; |
| 5 | 5 | import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplateSaveReqVO; |
| 6 | 6 | import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; |
| 7 | - | |
| 8 | 7 | import jakarta.validation.Valid; |
| 8 | + | |
| 9 | +import java.util.List; | |
| 9 | 10 | import java.util.Map; |
| 10 | 11 | |
| 11 | 12 | /** |
| ... | ... | @@ -39,6 +40,13 @@ public interface SmsTemplateService { |
| 39 | 40 | void deleteSmsTemplate(Long id); |
| 40 | 41 | |
| 41 | 42 | /** |
| 43 | + * 批量删除短信模板 | |
| 44 | + * | |
| 45 | + * @param ids 编号数组 | |
| 46 | + */ | |
| 47 | + void deleteSmsTemplateList(List<Long> ids); | |
| 48 | + | |
| 49 | + /** | |
| 42 | 50 | * 获得短信模板 |
| 43 | 51 | * |
| 44 | 52 | * @param id 编号 | ... | ... |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceImpl.java
| 1 | 1 | package cn.iocoder.yudao.module.system.service.sms; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 3 | 4 | import cn.hutool.core.exceptions.ExceptionUtil; |
| 4 | 5 | import cn.hutool.core.lang.Assert; |
| 5 | 6 | import cn.hutool.core.util.ReUtil; |
| ... | ... | @@ -7,22 +8,22 @@ import cn.hutool.core.util.StrUtil; |
| 7 | 8 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 8 | 9 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 9 | 10 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 10 | -import cn.iocoder.yudao.module.system.framework.sms.core.client.SmsClient; | |
| 11 | -import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsTemplateRespDTO; | |
| 12 | -import cn.iocoder.yudao.module.system.framework.sms.core.enums.SmsTemplateAuditStatusEnum; | |
| 13 | 11 | import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplatePageReqVO; |
| 14 | 12 | import cn.iocoder.yudao.module.system.controller.admin.sms.vo.template.SmsTemplateSaveReqVO; |
| 15 | 13 | import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsChannelDO; |
| 16 | 14 | import cn.iocoder.yudao.module.system.dal.dataobject.sms.SmsTemplateDO; |
| 17 | 15 | import cn.iocoder.yudao.module.system.dal.mysql.sms.SmsTemplateMapper; |
| 18 | 16 | import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants; |
| 17 | +import cn.iocoder.yudao.module.system.framework.sms.core.client.SmsClient; | |
| 18 | +import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsTemplateRespDTO; | |
| 19 | +import cn.iocoder.yudao.module.system.framework.sms.core.enums.SmsTemplateAuditStatusEnum; | |
| 19 | 20 | import com.google.common.annotations.VisibleForTesting; |
| 21 | +import jakarta.annotation.Resource; | |
| 20 | 22 | import lombok.extern.slf4j.Slf4j; |
| 21 | 23 | import org.springframework.cache.annotation.CacheEvict; |
| 22 | 24 | import org.springframework.cache.annotation.Cacheable; |
| 23 | 25 | import org.springframework.stereotype.Service; |
| 24 | 26 | |
| 25 | -import jakarta.annotation.Resource; | |
| 26 | 27 | import java.util.List; |
| 27 | 28 | import java.util.Map; |
| 28 | 29 | import java.util.Objects; |
| ... | ... | @@ -100,12 +101,32 @@ public class SmsTemplateServiceImpl implements SmsTemplateService { |
| 100 | 101 | smsTemplateMapper.deleteById(id); |
| 101 | 102 | } |
| 102 | 103 | |
| 104 | + @Override | |
| 105 | + @CacheEvict(cacheNames = RedisKeyConstants.SMS_TEMPLATE, | |
| 106 | + allEntries = true) // allEntries 清空所有缓存,因为 id 不是直接的缓存 code,不好清理 | |
| 107 | + public void deleteSmsTemplateList(List<Long> ids) { | |
| 108 | + if (CollUtil.isEmpty(ids)) { | |
| 109 | + return; | |
| 110 | + } | |
| 111 | + // 校验存在 | |
| 112 | + validateSmsTemplateListExists(ids); | |
| 113 | + // 批量删除 | |
| 114 | + smsTemplateMapper.deleteByIds(ids); | |
| 115 | + } | |
| 116 | + | |
| 103 | 117 | private void validateSmsTemplateExists(Long id) { |
| 104 | 118 | if (smsTemplateMapper.selectById(id) == null) { |
| 105 | 119 | throw exception(SMS_TEMPLATE_NOT_EXISTS); |
| 106 | 120 | } |
| 107 | 121 | } |
| 108 | 122 | |
| 123 | + private void validateSmsTemplateListExists(List<Long> ids) { | |
| 124 | + List<SmsTemplateDO> templates = smsTemplateMapper.selectByIds(ids); | |
| 125 | + if (templates.size() != ids.size()) { | |
| 126 | + throw exception(SMS_TEMPLATE_NOT_EXISTS); | |
| 127 | + } | |
| 128 | + } | |
| 129 | + | |
| 109 | 130 | @Override |
| 110 | 131 | public SmsTemplateDO getSmsTemplate(Long id) { |
| 111 | 132 | return smsTemplateMapper.selectById(id); | ... | ... |