mirror of
				https://github.com/YunaiV/ruoyi-vue-pro.git
				synced 2025-10-31 18:49:06 +08:00 
			
		
		
		
	feat: 新增批量删除邮箱账号接口
This commit is contained in:
		| @ -13,11 +13,11 @@ import cn.iocoder.yudao.module.system.service.mail.MailAccountService; | |||||||
| import io.swagger.v3.oas.annotations.Operation; | import io.swagger.v3.oas.annotations.Operation; | ||||||
| import io.swagger.v3.oas.annotations.Parameter; | import io.swagger.v3.oas.annotations.Parameter; | ||||||
| import io.swagger.v3.oas.annotations.tags.Tag; | 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.security.access.prepost.PreAuthorize; | ||||||
| import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||||
|  |  | ||||||
| import jakarta.annotation.Resource; |  | ||||||
| import jakarta.validation.Valid; |  | ||||||
| import java.util.List; | import java.util.List; | ||||||
|  |  | ||||||
| import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||||||
| @ -54,6 +54,15 @@ public class MailAccountController { | |||||||
|         return success(true); |         return success(true); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @DeleteMapping("/delete-list") | ||||||
|  |     @Operation(summary = "批量删除邮箱账号") | ||||||
|  |     @Parameter(name = "ids", description = "编号列表", required = true) | ||||||
|  |     @PreAuthorize("@ss.hasPermission('system:mail-account:delete')") | ||||||
|  |     public CommonResult<Boolean> deleteMailAccountList(@RequestParam("ids") List<Long> ids) { | ||||||
|  |         mailAccountService.deleteMailAccountList(ids); | ||||||
|  |         return success(true); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     @GetMapping("/get") |     @GetMapping("/get") | ||||||
|     @Operation(summary = "获得邮箱账号") |     @Operation(summary = "获得邮箱账号") | ||||||
|     @Parameter(name = "id", description = "编号", required = true, example = "1024") |     @Parameter(name = "id", description = "编号", required = true, example = "1024") | ||||||
|  | |||||||
| @ -4,8 +4,8 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; | |||||||
| import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; | import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; | ||||||
| import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountSaveReqVO; | import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountSaveReqVO; | ||||||
| import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; | import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; | ||||||
|  |  | ||||||
| import jakarta.validation.Valid; | import jakarta.validation.Valid; | ||||||
|  |  | ||||||
| import java.util.List; | import java.util.List; | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @ -38,6 +38,13 @@ public interface MailAccountService { | |||||||
|      */ |      */ | ||||||
|     void deleteMailAccount(Long id); |     void deleteMailAccount(Long id); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * 批量删除邮箱账号 | ||||||
|  |      * | ||||||
|  |      * @param ids 编号列表 | ||||||
|  |      */ | ||||||
|  |     void deleteMailAccountList(List<Long> ids); | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 获取邮箱账号信息 |      * 获取邮箱账号信息 | ||||||
|      * |      * | ||||||
|  | |||||||
| @ -1,5 +1,6 @@ | |||||||
| package cn.iocoder.yudao.module.system.service.mail; | package cn.iocoder.yudao.module.system.service.mail; | ||||||
|  |  | ||||||
|  | import cn.hutool.core.collection.CollUtil; | ||||||
| import cn.iocoder.yudao.framework.common.pojo.PageResult; | import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||||||
| import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||||||
| import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; | 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 | |||||||
| import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; | import cn.iocoder.yudao.module.system.dal.dataobject.mail.MailAccountDO; | ||||||
| import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; | import cn.iocoder.yudao.module.system.dal.mysql.mail.MailAccountMapper; | ||||||
| import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants; | import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants; | ||||||
|  | import jakarta.annotation.Resource; | ||||||
| import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||||
| import org.springframework.cache.annotation.CacheEvict; | import org.springframework.cache.annotation.CacheEvict; | ||||||
| import org.springframework.cache.annotation.Cacheable; | import org.springframework.cache.annotation.Cacheable; | ||||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||||
| import org.springframework.validation.annotation.Validated; | import org.springframework.validation.annotation.Validated; | ||||||
|  |  | ||||||
| import jakarta.annotation.Resource; |  | ||||||
| import java.util.List; | import java.util.List; | ||||||
|  |  | ||||||
| import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||||||
| @ -69,12 +70,41 @@ public class MailAccountServiceImpl implements MailAccountService { | |||||||
|         mailAccountMapper.deleteById(id); |         mailAccountMapper.deleteById(id); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     @CacheEvict(value = RedisKeyConstants.MAIL_ACCOUNT, allEntries = true) | ||||||
|  |     public void deleteMailAccountList(List<Long> ids) { | ||||||
|  |         if (CollUtil.isEmpty(ids)) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |         // 校验是否存在 | ||||||
|  |         validateMailAccountsExists(ids); | ||||||
|  |         // 校验是否存在关联模版 | ||||||
|  |         for (Long id : ids) { | ||||||
|  |             if (mailTemplateService.getMailTemplateCountByAccountId(id) > 0) { | ||||||
|  |                 throw exception(MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         // 批量删除 | ||||||
|  |         mailAccountMapper.deleteByIds(ids); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     private void validateMailAccountExists(Long id) { |     private void validateMailAccountExists(Long id) { | ||||||
|         if (mailAccountMapper.selectById(id) == null) { |         if (mailAccountMapper.selectById(id) == null) { | ||||||
|             throw exception(MAIL_ACCOUNT_NOT_EXISTS); |             throw exception(MAIL_ACCOUNT_NOT_EXISTS); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     private void validateMailAccountsExists(List<Long> ids) { | ||||||
|  |         if (CollUtil.isEmpty(ids)) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |         // 校验存在 | ||||||
|  |         List<MailAccountDO> accounts = mailAccountMapper.selectByIds(ids); | ||||||
|  |         if (CollUtil.isEmpty(accounts) || accounts.size() != ids.size()) { | ||||||
|  |             throw exception(MAIL_ACCOUNT_NOT_EXISTS); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public MailAccountDO getMailAccount(Long id) { |     public MailAccountDO getMailAccount(Long id) { | ||||||
|         return mailAccountMapper.selectById(id); |         return mailAccountMapper.selectById(id); | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 puhui999
					puhui999