From d60aeb76a3d7a11a5ed6ebd2c95ed422e6b35810 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Tue, 10 Jun 2025 15:48:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=AB=99=E5=86=85=E4=BF=A1=E6=A8=A1=E7=89=88?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notify/NotifyTemplateController.java | 19 ++++++++++++--- .../service/notify/NotifyTemplateService.java | 10 +++++++- .../notify/NotifyTemplateServiceImpl.java | 24 ++++++++++++++++++- 3 files changed, 48 insertions(+), 5 deletions(-) diff --git a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyTemplateController.java b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyTemplateController.java index 57c35db38f..a4a00034c4 100644 --- a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/notify/NotifyTemplateController.java +++ b/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; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; -import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.*; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplatePageReqVO; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateRespVO; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateSaveReqVO; +import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateSendReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; import cn.iocoder.yudao.module.system.service.notify.NotifySendService; import cn.iocoder.yudao.module.system.service.notify.NotifyTemplateService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.annotation.Resource; +import jakarta.validation.Valid; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import jakarta.annotation.Resource; -import jakarta.validation.Valid; +import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -56,6 +60,15 @@ public class NotifyTemplateController { return success(true); } + @DeleteMapping("/delete-list") + @Operation(summary = "批量删除站内信模版") + @Parameter(name = "ids", description = "编号列表", required = true) + @PreAuthorize("@ss.hasPermission('system:notify-template:delete')") + public CommonResult deleteNotifyTemplateList(@RequestParam("ids") List ids) { + notifyTemplateService.deleteNotifyTemplateList(ids); + return success(true); + } + @GetMapping("/get") @Operation(summary = "获得站内信模版") @Parameter(name = "id", description = "编号", required = true, example = "1024") diff --git a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateService.java b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateService.java index bac122d887..2253ba9780 100644 --- a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateService.java +++ b/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; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplatePageReqVO; import cn.iocoder.yudao.module.system.controller.admin.notify.vo.template.NotifyTemplateSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; - import jakarta.validation.Valid; + +import java.util.List; import java.util.Map; /** @@ -37,6 +38,13 @@ public interface NotifyTemplateService { */ void deleteNotifyTemplate(Long id); + /** + * 批量删除站内信模版 + * + * @param ids 编号列表 + */ + void deleteNotifyTemplateList(List ids); + /** * 获得站内信模版 * diff --git a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImpl.java b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImpl.java index d52b2b7eec..998a551533 100644 --- a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImpl.java +++ b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/notify/NotifyTemplateServiceImpl.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.system.service.notify; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ReUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -10,13 +11,13 @@ import cn.iocoder.yudao.module.system.dal.dataobject.notify.NotifyTemplateDO; import cn.iocoder.yudao.module.system.dal.mysql.notify.NotifyTemplateMapper; import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants; import com.google.common.annotations.VisibleForTesting; +import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; -import jakarta.annotation.Resource; import java.util.List; import java.util.Map; import java.util.regex.Pattern; @@ -85,6 +86,27 @@ public class NotifyTemplateServiceImpl implements NotifyTemplateService { notifyTemplateMapper.deleteById(id); } + @Override + @CacheEvict(cacheNames = RedisKeyConstants.NOTIFY_TEMPLATE, + allEntries = true) // allEntries 清空所有缓存,因为 id 不是直接的缓存 code,不好清理 + public void deleteNotifyTemplateList(List ids) { + // 校验存在 + validateNotifyTemplatesExists(ids); + // 批量删除 + notifyTemplateMapper.deleteByIds(ids); + } + + private void validateNotifyTemplatesExists(List ids) { + if (CollUtil.isEmpty(ids)) { + return; + } + // 校验存在 + List templates = notifyTemplateMapper.selectByIds(ids); + if (CollUtil.isEmpty(templates) || templates.size() != ids.size()) { + throw exception(NOTIFY_TEMPLATE_NOT_EXISTS); + } + } + private void validateNotifyTemplateExists(Long id) { if (notifyTemplateMapper.selectById(id) == null) { throw exception(NOTIFY_TEMPLATE_NOT_EXISTS);