Commit 7853ac9f2355b663e9185e534e2aba4601bec2d7
1 parent
f0efbd76
feat: 新增批量删除邮箱账号接口
Showing
3 changed files
with
50 additions
and
4 deletions
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/mail/MailAccountController.java
| ... | ... | @@ -13,11 +13,11 @@ import cn.iocoder.yudao.module.system.service.mail.MailAccountService; |
| 13 | 13 | import io.swagger.v3.oas.annotations.Operation; |
| 14 | 14 | import io.swagger.v3.oas.annotations.Parameter; |
| 15 | 15 | import io.swagger.v3.oas.annotations.tags.Tag; |
| 16 | +import jakarta.annotation.Resource; | |
| 17 | +import jakarta.validation.Valid; | |
| 16 | 18 | import org.springframework.security.access.prepost.PreAuthorize; |
| 17 | 19 | import org.springframework.web.bind.annotation.*; |
| 18 | 20 | |
| 19 | -import jakarta.annotation.Resource; | |
| 20 | -import jakarta.validation.Valid; | |
| 21 | 21 | import java.util.List; |
| 22 | 22 | |
| 23 | 23 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| ... | ... | @@ -54,6 +54,15 @@ public class MailAccountController { |
| 54 | 54 | return success(true); |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | + @DeleteMapping("/delete-list") | |
| 58 | + @Operation(summary = "批量删除邮箱账号") | |
| 59 | + @Parameter(name = "ids", description = "编号列表", required = true) | |
| 60 | + @PreAuthorize("@ss.hasPermission('system:mail-account:delete')") | |
| 61 | + public CommonResult<Boolean> deleteMailAccountList(@RequestParam("ids") List<Long> ids) { | |
| 62 | + mailAccountService.deleteMailAccountList(ids); | |
| 63 | + return success(true); | |
| 64 | + } | |
| 65 | + | |
| 57 | 66 | @GetMapping("/get") |
| 58 | 67 | @Operation(summary = "获得邮箱账号") |
| 59 | 68 | @Parameter(name = "id", description = "编号", required = true, example = "1024") | ... | ... |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountService.java
| ... | ... | @@ -4,8 +4,8 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 4 | import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; |
| 5 | 5 | import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountSaveReqVO; |
| 6 | 6 | import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; |
| 7 | - | |
| 8 | 7 | import jakarta.validation.Valid; |
| 8 | + | |
| 9 | 9 | import java.util.List; |
| 10 | 10 | |
| 11 | 11 | /** |
| ... | ... | @@ -39,6 +39,13 @@ public interface MailAccountService { |
| 39 | 39 | void deleteMailAccount(Long id); |
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | + * 批量删除邮箱账号 | |
| 43 | + * | |
| 44 | + * @param ids 编号列表 | |
| 45 | + */ | |
| 46 | + void deleteMailAccountList(List<Long> ids); | |
| 47 | + | |
| 48 | + /** | |
| 42 | 49 | * 获取邮箱账号信息 |
| 43 | 50 | * |
| 44 | 51 | * @param id 编号 | ... | ... |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountServiceImpl.java
| 1 | 1 | package cn.iocoder.yudao.module.system.service.mail; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 3 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | 5 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 5 | 6 | import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; |
| ... | ... | @@ -7,13 +8,13 @@ import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccou |
| 7 | 8 | import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; |
| 8 | 9 | import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; |
| 9 | 10 | import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants; |
| 11 | +import jakarta.annotation.Resource; | |
| 10 | 12 | import lombok.extern.slf4j.Slf4j; |
| 11 | 13 | import org.springframework.cache.annotation.CacheEvict; |
| 12 | 14 | import org.springframework.cache.annotation.Cacheable; |
| 13 | 15 | import org.springframework.stereotype.Service; |
| 14 | 16 | import org.springframework.validation.annotation.Validated; |
| 15 | 17 | |
| 16 | -import jakarta.annotation.Resource; | |
| 17 | 18 | import java.util.List; |
| 18 | 19 | |
| 19 | 20 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| ... | ... | @@ -69,12 +70,41 @@ public class MailAccountServiceImpl implements MailAccountService { |
| 69 | 70 | mailAccountMapper.deleteById(id); |
| 70 | 71 | } |
| 71 | 72 | |
| 73 | + @Override | |
| 74 | + @CacheEvict(value = RedisKeyConstants.MAIL_ACCOUNT, allEntries = true) | |
| 75 | + public void deleteMailAccountList(List<Long> ids) { | |
| 76 | + if (CollUtil.isEmpty(ids)) { | |
| 77 | + return; | |
| 78 | + } | |
| 79 | + // 校验是否存在 | |
| 80 | + validateMailAccountsExists(ids); | |
| 81 | + // 校验是否存在关联模版 | |
| 82 | + for (Long id : ids) { | |
| 83 | + if (mailTemplateService.getMailTemplateCountByAccountId(id) > 0) { | |
| 84 | + throw exception(MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS); | |
| 85 | + } | |
| 86 | + } | |
| 87 | + // 批量删除 | |
| 88 | + mailAccountMapper.deleteByIds(ids); | |
| 89 | + } | |
| 90 | + | |
| 72 | 91 | private void validateMailAccountExists(Long id) { |
| 73 | 92 | if (mailAccountMapper.selectById(id) == null) { |
| 74 | 93 | throw exception(MAIL_ACCOUNT_NOT_EXISTS); |
| 75 | 94 | } |
| 76 | 95 | } |
| 77 | 96 | |
| 97 | + private void validateMailAccountsExists(List<Long> ids) { | |
| 98 | + if (CollUtil.isEmpty(ids)) { | |
| 99 | + return; | |
| 100 | + } | |
| 101 | + // 校验存在 | |
| 102 | + List<MailAccountDO> accounts = mailAccountMapper.selectByIds(ids); | |
| 103 | + if (CollUtil.isEmpty(accounts) || accounts.size() != ids.size()) { | |
| 104 | + throw exception(MAIL_ACCOUNT_NOT_EXISTS); | |
| 105 | + } | |
| 106 | + } | |
| 107 | + | |
| 78 | 108 | @Override |
| 79 | 109 | public MailAccountDO getMailAccount(Long id) { |
| 80 | 110 | return mailAccountMapper.selectById(id); | ... | ... |