diff --git a/yudao-module-infra/src/main/resources/codegen/java/service/serviceImpl.vm b/yudao-module-infra/src/main/resources/codegen/java/service/serviceImpl.vm index d91421a05..ee9fc49f9 100644 --- a/yudao-module-infra/src/main/resources/codegen/java/service/serviceImpl.vm +++ b/yudao-module-infra/src/main/resources/codegen/java/service/serviceImpl.vm @@ -175,8 +175,6 @@ public class ${table.className}ServiceImpl implements ${table.className}Service @Transactional(rollbackFor = Exception.class) #end public void delete${simpleClassName}ListByIds(List<${primaryColumn.javaType}> ids) { - // 校验存在 - validate${simpleClassName}Exists(ids); // 删除 ${classNameVar}Mapper.deleteByIds(ids); ## 特殊:主子表专属逻辑 @@ -193,12 +191,6 @@ public class ${table.className}ServiceImpl implements ${table.className}Service #end } - private void validate${simpleClassName}Exists(List<${primaryColumn.javaType}> ids) { - List<${table.className}DO> list = ${classNameVar}Mapper.selectByIds(ids); - if (CollUtil.isEmpty(list) || list.size() != ids.size()) { - throw exception(${simpleClassName_underlineCase.toUpperCase()}_NOT_EXISTS); - } - } #end private void validate${simpleClassName}Exists(${primaryColumn.javaType} id) { diff --git a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountServiceImpl.java b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountServiceImpl.java index 99aba35b2..ac0b6d26c 100644 --- a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountServiceImpl.java +++ b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailAccountServiceImpl.java @@ -1,6 +1,5 @@ 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.util.object.BeanUtils; import cn.iocoder.yudao.module.system.controller.admin.mail.vo.account.MailAccountPageReqVO; @@ -71,20 +70,17 @@ public class MailAccountServiceImpl implements MailAccountService { } @Override - @CacheEvict(value = RedisKeyConstants.MAIL_ACCOUNT, allEntries = true) + @CacheEvict(value = RedisKeyConstants.MAIL_ACCOUNT, + allEntries = true) // allEntries 清空所有缓存,因为 Spring Cache 不支持按照 ids 批量删除 public void deleteMailAccountList(List ids) { - if (CollUtil.isEmpty(ids)) { - return; - } - // 校验是否存在 - validateMailAccountsExists(ids); - // 校验是否存在关联模版 + // 1. 校验是否存在关联模版 for (Long id : ids) { if (mailTemplateService.getMailTemplateCountByAccountId(id) > 0) { throw exception(MAIL_ACCOUNT_RELATE_TEMPLATE_EXISTS); } } - // 批量删除 + + // 2. 批量删除 mailAccountMapper.deleteByIds(ids); } @@ -94,17 +90,6 @@ public class MailAccountServiceImpl implements MailAccountService { } } - private void validateMailAccountsExists(List ids) { - if (CollUtil.isEmpty(ids)) { - return; - } - // 校验存在 - List accounts = mailAccountMapper.selectByIds(ids); - if (CollUtil.isEmpty(accounts) || accounts.size() != ids.size()) { - throw exception(MAIL_ACCOUNT_NOT_EXISTS); - } - } - @Override public MailAccountDO getMailAccount(Long id) { return mailAccountMapper.selectById(id); diff --git a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateServiceImpl.java b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateServiceImpl.java index 100eb542c..3088ee79a 100644 --- a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateServiceImpl.java +++ b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/mail/MailTemplateServiceImpl.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.system.service.mail; -import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjUtil; import cn.hutool.core.util.ReUtil; import cn.hutool.core.util.StrUtil; @@ -102,12 +101,6 @@ public class MailTemplateServiceImpl implements MailTemplateService { @CacheEvict(cacheNames = RedisKeyConstants.MAIL_TEMPLATE, allEntries = true) // allEntries 清空所有缓存,因为 id 不是直接的缓存 code,不好清理 public void deleteMailTemplateList(List ids) { - if (CollUtil.isEmpty(ids)) { - return; - } - // 校验存在 - validateMailTemplatesExists(ids); - // 批量删除 mailTemplateMapper.deleteByIds(ids); } @@ -117,17 +110,6 @@ public class MailTemplateServiceImpl implements MailTemplateService { } } - private void validateMailTemplatesExists(List ids) { - if (CollUtil.isEmpty(ids)) { - return; - } - // 校验存在 - List templates = mailTemplateMapper.selectByIds(ids); - if (CollUtil.isEmpty(templates) || templates.size() != ids.size()) { - throw exception(MAIL_TEMPLATE_NOT_EXISTS); - } - } - @Override public MailTemplateDO getMailTemplate(Long id) {return mailTemplateMapper.selectById(id);} diff --git a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/notice/NoticeServiceImpl.java b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/notice/NoticeServiceImpl.java index 90fdd573b..718d21989 100644 --- a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/notice/NoticeServiceImpl.java +++ b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/notice/NoticeServiceImpl.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.system.service.notice; -import cn.hutool.core.collection.CollUtil; 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.notice.vo.NoticePageReqVO; @@ -53,9 +52,6 @@ public class NoticeServiceImpl implements NoticeService { @Override public void deleteNoticeList(List ids) { - // 校验是否存在 - validateNoticesExists(ids); - // 批量删除通知公告 noticeMapper.deleteByIds(ids); } @@ -80,15 +76,4 @@ public class NoticeServiceImpl implements NoticeService { } } - private void validateNoticesExists(List ids) { - if (CollUtil.isEmpty(ids)) { - return; - } - // 校验存在 - List notices = noticeMapper.selectByIds(ids); - if (CollUtil.isEmpty(notices) || notices.size() != ids.size()) { - throw exception(NOTICE_NOT_FOUND); - } - } - } 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 998a55153..45a832ddc 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,6 +1,5 @@ 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; @@ -90,23 +89,9 @@ public class NotifyTemplateServiceImpl implements NotifyTemplateService { @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); diff --git a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2ClientServiceImpl.java b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2ClientServiceImpl.java index f592de8c6..140db0f14 100644 --- a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2ClientServiceImpl.java +++ b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2ClientServiceImpl.java @@ -77,12 +77,6 @@ public class OAuth2ClientServiceImpl implements OAuth2ClientService { @CacheEvict(cacheNames = RedisKeyConstants.OAUTH_CLIENT, allEntries = true) // allEntries 清空所有缓存,因为 id 不是直接的缓存 key,不好清理 public void deleteOAuth2ClientList(List ids) { - if (CollUtil.isEmpty(ids)) { - return; - } - // 校验存在 - validateOAuth2ClientBatchExists(ids); - // 批量删除 oauth2ClientMapper.deleteByIds(ids); } @@ -92,13 +86,6 @@ public class OAuth2ClientServiceImpl implements OAuth2ClientService { } } - private void validateOAuth2ClientBatchExists(List ids) { - List clients = oauth2ClientMapper.selectByIds(ids); - if (clients.size() != ids.size()) { - throw exception(OAUTH2_CLIENT_NOT_EXISTS); - } - } - @VisibleForTesting void validateClientIdExists(Long id, String clientId) { OAuth2ClientDO client = oauth2ClientMapper.selectByClientId(clientId); diff --git a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelServiceImpl.java b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelServiceImpl.java index c16dffb59..66ad5e022 100644 --- a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelServiceImpl.java +++ b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsChannelServiceImpl.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.system.service.sms; -import cn.hutool.core.collection.CollUtil; 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.sms.vo.channel.SmsChannelPageReqVO; @@ -68,18 +67,14 @@ public class SmsChannelServiceImpl implements SmsChannelService { @Override public void deleteSmsChannelList(List ids) { - if (CollUtil.isEmpty(ids)) { - return; - } - // 校验存在 - validateSmsChannelBatchExists(ids); - // 校验是否有在使用该账号的模版 - for (Long id : ids) { + // 1. 校验是否有在使用该账号的模版 + ids.forEach(id -> { if (smsTemplateService.getSmsTemplateCountByChannelId(id) > 0) { throw exception(SMS_CHANNEL_HAS_CHILDREN); } - } - // 批量删除 + }); + + // 2. 批量删除 smsChannelMapper.deleteByIds(ids); } @@ -91,13 +86,6 @@ public class SmsChannelServiceImpl implements SmsChannelService { return channel; } - private void validateSmsChannelBatchExists(List ids) { - List channels = smsChannelMapper.selectByIds(ids); - if (channels.size() != ids.size()) { - throw exception(SMS_CHANNEL_NOT_EXISTS); - } - } - @Override public SmsChannelDO getSmsChannel(Long id) { return smsChannelMapper.selectById(id); diff --git a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceImpl.java b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceImpl.java index 557073018..65d201797 100644 --- a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceImpl.java +++ b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/sms/SmsTemplateServiceImpl.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.system.service.sms; -import cn.hutool.core.collection.CollUtil; import cn.hutool.core.exceptions.ExceptionUtil; import cn.hutool.core.lang.Assert; import cn.hutool.core.util.ReUtil; @@ -105,12 +104,6 @@ public class SmsTemplateServiceImpl implements SmsTemplateService { @CacheEvict(cacheNames = RedisKeyConstants.SMS_TEMPLATE, allEntries = true) // allEntries 清空所有缓存,因为 id 不是直接的缓存 code,不好清理 public void deleteSmsTemplateList(List ids) { - if (CollUtil.isEmpty(ids)) { - return; - } - // 校验存在 - validateSmsTemplateListExists(ids); - // 批量删除 smsTemplateMapper.deleteByIds(ids); } @@ -120,13 +113,6 @@ public class SmsTemplateServiceImpl implements SmsTemplateService { } } - private void validateSmsTemplateListExists(List ids) { - List templates = smsTemplateMapper.selectByIds(ids); - if (templates.size() != ids.size()) { - throw exception(SMS_TEMPLATE_NOT_EXISTS); - } - } - @Override public SmsTemplateDO getSmsTemplate(Long id) { return smsTemplateMapper.selectById(id); diff --git a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImpl.java b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImpl.java index 6b75cc15c..5cc0c77f0 100644 --- a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImpl.java +++ b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/social/SocialClientServiceImpl.java @@ -468,12 +468,6 @@ public class SocialClientServiceImpl implements SocialClientService { @Override public void deleteSocialClientList(List ids) { - if (CollUtil.isEmpty(ids)) { - return; - } - // 校验存在 - validateSocialClientBatchExists(ids); - // 批量删除 socialClientMapper.deleteByIds(ids); } @@ -483,13 +477,6 @@ public class SocialClientServiceImpl implements SocialClientService { } } - private void validateSocialClientBatchExists(List ids) { - List clients = socialClientMapper.selectByIds(ids); - if (clients.size() != ids.size()) { - throw exception(SOCIAL_CLIENT_NOT_EXISTS); - } - } - /** * 校验社交应用是否重复,需要保证 userType + socialType 唯一 * 原因是,不同端(userType)选择某个社交登录(socialType)时,需要通过 {@link #buildAuthRequest(Integer, Integer)} 构建对应的请求 diff --git a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantPackageServiceImpl.java b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantPackageServiceImpl.java index 16798f4b6..14e33bcc3 100755 --- a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantPackageServiceImpl.java +++ b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantPackageServiceImpl.java @@ -78,14 +78,14 @@ public class TenantPackageServiceImpl implements TenantPackageService { @Override public void deleteTenantPackageList(List ids) { - if (CollUtil.isEmpty(ids)) { - return; + // 1. 校验是否有租户正在使用该套餐 + for (Long id : ids) { + if (tenantService.getTenantCountByPackageId(id) > 0) { + throw exception(TENANT_PACKAGE_USED); + } } - // 校验存在 - ids.forEach(this::validateTenantPackageExists); - // 校验正在使用 - validateTenantUsedBatch(ids); - // 批量删除 + + // 2. 批量删除 tenantPackageMapper.deleteByIds(ids); } @@ -103,20 +103,6 @@ public class TenantPackageServiceImpl implements TenantPackageService { } } - /** - * 校验租户套餐是否被使用 - 批量 - * - * @param ids 租户套餐编号数组 - */ - private void validateTenantUsedBatch(List ids) { - // 查询是否有租户正在使用该套餐 - for (Long id : ids) { - if (tenantService.getTenantCountByPackageId(id) > 0) { - throw exception(TENANT_PACKAGE_USED); - } - } - } - @Override public TenantPackageDO getTenantPackage(Long id) { return tenantPackageMapper.selectById(id); diff --git a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImpl.java b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImpl.java index 07a4203f1..30c634007 100755 --- a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImpl.java +++ b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/tenant/TenantServiceImpl.java @@ -227,12 +227,10 @@ public class TenantServiceImpl implements TenantService { @Override public void deleteTenantList(List ids) { - if (CollUtil.isEmpty(ids)) { - return; - } - // 校验存在 - validateUpdateTenantBatch(ids); - // 批量删除 + // 1. 校验存在 + ids.forEach(this::validateUpdateTenant); + + // 2. 批量删除 tenantMapper.deleteByIds(ids); } @@ -248,26 +246,6 @@ public class TenantServiceImpl implements TenantService { return tenant; } - /** - * 校验租户是否可以更新 - 批量 - * - * @param ids 租户编号数组 - */ - private void validateUpdateTenantBatch(List ids) { - // 查询租户 - List tenants = tenantMapper.selectByIds(ids); - if (tenants.size() != ids.size()) { - throw exception(TENANT_NOT_EXISTS); - } - - // 校验是否有系统内置租户 - tenants.forEach(tenant -> { - if (isSystemTenant(tenant)) { - throw exception(TENANT_CAN_NOT_UPDATE_SYSTEM); - } - }); - } - @Override public TenantDO getTenant(Long id) { return tenantMapper.selectById(id); diff --git a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java index 40664ecaf..41b9dbeef 100644 --- a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java +++ b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java @@ -251,19 +251,10 @@ public class AdminUserServiceImpl implements AdminUserService { @Override @Transactional(rollbackFor = Exception.class) public void deleteUserList(List ids) { - if (CollUtil.isEmpty(ids)) { - return; - } - // 1. 校验用户存在 - List users = userMapper.selectByIds(ids); - if (CollUtil.isEmpty(users)) { - return; - } - - // 2. 批量删除用户 + // 1. 批量删除用户 userMapper.deleteByIds(ids); - // 3. 批量删除用户关联数据 + // 2. 批量删除用户关联数据 ids.forEach(id -> { permissionService.processUserDeleted(id); userPostMapper.deleteByUserId(id);