Commit d60aeb76a3d7a11a5ed6ebd2c95ed422e6b35810
1 parent
14a80f9c
feat: 新增批量删除站内信模版接口
Showing
3 changed files
with
48 additions
and
5 deletions
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyTemplateController.java
| @@ -4,19 +4,23 @@ import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | @@ -4,19 +4,23 @@ import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||
| 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 6 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 7 | -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.*; | 7 | +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplatePageReqVO; |
| 8 | +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateRespVO; | ||
| 9 | +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateSaveReqVO; | ||
| 10 | +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateSendReqVO; | ||
| 8 | import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; | 11 | import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; |
| 9 | import cn.iocoder.yudao.module.system.service.notify.NotifySendService; | 12 | import cn.iocoder.yudao.module.system.service.notify.NotifySendService; |
| 10 | import cn.iocoder.yudao.module.system.service.notify.NotifyTemplateService; | 13 | import cn.iocoder.yudao.module.system.service.notify.NotifyTemplateService; |
| 11 | import io.swagger.v3.oas.annotations.Operation; | 14 | import io.swagger.v3.oas.annotations.Operation; |
| 12 | import io.swagger.v3.oas.annotations.Parameter; | 15 | import io.swagger.v3.oas.annotations.Parameter; |
| 13 | import io.swagger.v3.oas.annotations.tags.Tag; | 16 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 17 | +import jakarta.annotation.Resource; | ||
| 18 | +import jakarta.validation.Valid; | ||
| 14 | import org.springframework.security.access.prepost.PreAuthorize; | 19 | import org.springframework.security.access.prepost.PreAuthorize; |
| 15 | import org.springframework.validation.annotation.Validated; | 20 | import org.springframework.validation.annotation.Validated; |
| 16 | import org.springframework.web.bind.annotation.*; | 21 | import org.springframework.web.bind.annotation.*; |
| 17 | 22 | ||
| 18 | -import jakarta.annotation.Resource; | ||
| 19 | -import jakarta.validation.Valid; | 23 | +import java.util.List; |
| 20 | 24 | ||
| 21 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | 25 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 22 | 26 | ||
| @@ -56,6 +60,15 @@ public class NotifyTemplateController { | @@ -56,6 +60,15 @@ public class NotifyTemplateController { | ||
| 56 | return success(true); | 60 | return success(true); |
| 57 | } | 61 | } |
| 58 | 62 | ||
| 63 | + @DeleteMapping("/delete-list") | ||
| 64 | + @Operation(summary = "批量删除站内信模版") | ||
| 65 | + @Parameter(name = "ids", description = "编号列表", required = true) | ||
| 66 | + @PreAuthorize("@ss.hasPermission('system:notify-template:delete')") | ||
| 67 | + public CommonResult<Boolean> deleteNotifyTemplateList(@RequestParam("ids") List<Long> ids) { | ||
| 68 | + notifyTemplateService.deleteNotifyTemplateList(ids); | ||
| 69 | + return success(true); | ||
| 70 | + } | ||
| 71 | + | ||
| 59 | @GetMapping("/get") | 72 | @GetMapping("/get") |
| 60 | @Operation(summary = "获得站内信模版") | 73 | @Operation(summary = "获得站内信模版") |
| 61 | @Parameter(name = "id", description = "编号", required = true, example = "1024") | 74 | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateService.java
| @@ -4,8 +4,9 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; | @@ -4,8 +4,9 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||
| 4 | import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplatePageReqVO; | 4 | import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplatePageReqVO; |
| 5 | import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateSaveReqVO; | 5 | import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateSaveReqVO; |
| 6 | import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; | 6 | import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; |
| 7 | - | ||
| 8 | import jakarta.validation.Valid; | 7 | import jakarta.validation.Valid; |
| 8 | + | ||
| 9 | +import java.util.List; | ||
| 9 | import java.util.Map; | 10 | import java.util.Map; |
| 10 | 11 | ||
| 11 | /** | 12 | /** |
| @@ -38,6 +39,13 @@ public interface NotifyTemplateService { | @@ -38,6 +39,13 @@ public interface NotifyTemplateService { | ||
| 38 | void deleteNotifyTemplate(Long id); | 39 | void deleteNotifyTemplate(Long id); |
| 39 | 40 | ||
| 40 | /** | 41 | /** |
| 42 | + * 批量删除站内信模版 | ||
| 43 | + * | ||
| 44 | + * @param ids 编号列表 | ||
| 45 | + */ | ||
| 46 | + void deleteNotifyTemplateList(List<Long> ids); | ||
| 47 | + | ||
| 48 | + /** | ||
| 41 | * 获得站内信模版 | 49 | * 获得站内信模版 |
| 42 | * | 50 | * |
| 43 | * @param id 编号 | 51 | * @param id 编号 |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImpl.java
| 1 | package cn.iocoder.yudao.module.system.service.notify; | 1 | package cn.iocoder.yudao.module.system.service.notify; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.collection.CollUtil; | ||
| 3 | import cn.hutool.core.util.ReUtil; | 4 | import cn.hutool.core.util.ReUtil; |
| 4 | import cn.hutool.core.util.StrUtil; | 5 | import cn.hutool.core.util.StrUtil; |
| 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| @@ -10,13 +11,13 @@ import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; | @@ -10,13 +11,13 @@ import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; | ||
| 10 | import cn.iocoder.yudao.module.system.dal.mysql.notify.NotifyTemplateMapper; | 11 | import cn.iocoder.yudao.module.system.dal.mysql.notify.NotifyTemplateMapper; |
| 11 | import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants; | 12 | import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants; |
| 12 | import com.google.common.annotations.VisibleForTesting; | 13 | import com.google.common.annotations.VisibleForTesting; |
| 14 | +import jakarta.annotation.Resource; | ||
| 13 | import lombok.extern.slf4j.Slf4j; | 15 | import lombok.extern.slf4j.Slf4j; |
| 14 | import org.springframework.cache.annotation.CacheEvict; | 16 | import org.springframework.cache.annotation.CacheEvict; |
| 15 | import org.springframework.cache.annotation.Cacheable; | 17 | import org.springframework.cache.annotation.Cacheable; |
| 16 | import org.springframework.stereotype.Service; | 18 | import org.springframework.stereotype.Service; |
| 17 | import org.springframework.validation.annotation.Validated; | 19 | import org.springframework.validation.annotation.Validated; |
| 18 | 20 | ||
| 19 | -import jakarta.annotation.Resource; | ||
| 20 | import java.util.List; | 21 | import java.util.List; |
| 21 | import java.util.Map; | 22 | import java.util.Map; |
| 22 | import java.util.regex.Pattern; | 23 | import java.util.regex.Pattern; |
| @@ -85,6 +86,27 @@ public class NotifyTemplateServiceImpl implements NotifyTemplateService { | @@ -85,6 +86,27 @@ public class NotifyTemplateServiceImpl implements NotifyTemplateService { | ||
| 85 | notifyTemplateMapper.deleteById(id); | 86 | notifyTemplateMapper.deleteById(id); |
| 86 | } | 87 | } |
| 87 | 88 | ||
| 89 | + @Override | ||
| 90 | + @CacheEvict(cacheNames = RedisKeyConstants.NOTIFY_TEMPLATE, | ||
| 91 | + allEntries = true) // allEntries 清空所有缓存,因为 id 不是直接的缓存 code,不好清理 | ||
| 92 | + public void deleteNotifyTemplateList(List<Long> ids) { | ||
| 93 | + // 校验存在 | ||
| 94 | + validateNotifyTemplatesExists(ids); | ||
| 95 | + // 批量删除 | ||
| 96 | + notifyTemplateMapper.deleteByIds(ids); | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + private void validateNotifyTemplatesExists(List<Long> ids) { | ||
| 100 | + if (CollUtil.isEmpty(ids)) { | ||
| 101 | + return; | ||
| 102 | + } | ||
| 103 | + // 校验存在 | ||
| 104 | + List<NotifyTemplateDO> templates = notifyTemplateMapper.selectByIds(ids); | ||
| 105 | + if (CollUtil.isEmpty(templates) || templates.size() != ids.size()) { | ||
| 106 | + throw exception(NOTIFY_TEMPLATE_NOT_EXISTS); | ||
| 107 | + } | ||
| 108 | + } | ||
| 109 | + | ||
| 88 | private void validateNotifyTemplateExists(Long id) { | 110 | private void validateNotifyTemplateExists(Long id) { |
| 89 | if (notifyTemplateMapper.selectById(id) == null) { | 111 | if (notifyTemplateMapper.selectById(id) == null) { |
| 90 | throw exception(NOTIFY_TEMPLATE_NOT_EXISTS); | 112 | throw exception(NOTIFY_TEMPLATE_NOT_EXISTS); |