Commit 03d3ebdf05f2f95c68b7e25c1e4d5b46d373ee52
1 parent
bcd6ed4c
review:【INFRA 基础设施】批量删除接口
Showing
12 changed files
with
30 additions
and
112 deletions
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/dal/mysql/codegen/CodegenColumnMapper.java
| @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | ||
| 5 | import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenColumnDO; | 5 | import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenColumnDO; |
| 6 | import org.apache.ibatis.annotations.Mapper; | 6 | import org.apache.ibatis.annotations.Mapper; |
| 7 | 7 | ||
| 8 | +import java.util.Collection; | ||
| 8 | import java.util.List; | 9 | import java.util.List; |
| 9 | 10 | ||
| 10 | @Mapper | 11 | @Mapper |
| @@ -17,8 +18,12 @@ public interface CodegenColumnMapper extends BaseMapperX<CodegenColumnDO> { | @@ -17,8 +18,12 @@ public interface CodegenColumnMapper extends BaseMapperX<CodegenColumnDO> { | ||
| 17 | } | 18 | } |
| 18 | 19 | ||
| 19 | default void deleteListByTableId(Long tableId) { | 20 | default void deleteListByTableId(Long tableId) { |
| 21 | + delete(CodegenColumnDO::getTableId, tableId); | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + default void deleteListByTableId(Collection<Long> tableIds) { | ||
| 20 | delete(new LambdaQueryWrapperX<CodegenColumnDO>() | 25 | delete(new LambdaQueryWrapperX<CodegenColumnDO>() |
| 21 | - .eq(CodegenColumnDO::getTableId, tableId)); | 26 | + .in(CodegenColumnDO::getTableId, tableIds)); |
| 22 | } | 27 | } |
| 23 | 28 | ||
| 24 | } | 29 | } |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java
| @@ -225,20 +225,10 @@ public class CodegenServiceImpl implements CodegenService { | @@ -225,20 +225,10 @@ public class CodegenServiceImpl implements CodegenService { | ||
| 225 | @Override | 225 | @Override |
| 226 | @Transactional(rollbackFor = Exception.class) | 226 | @Transactional(rollbackFor = Exception.class) |
| 227 | public void deleteCodegenList(List<Long> tableIds) { | 227 | public void deleteCodegenList(List<Long> tableIds) { |
| 228 | - if (CollUtil.isEmpty(tableIds)) { | ||
| 229 | - return; | ||
| 230 | - } | ||
| 231 | - | ||
| 232 | - // 校验是否都存在 | ||
| 233 | - List<CodegenTableDO> tables = codegenTableMapper.selectByIds(tableIds); | ||
| 234 | - if (tables.size() != tableIds.size()) { | ||
| 235 | - throw exception(CODEGEN_TABLE_NOT_EXISTS); | ||
| 236 | - } | ||
| 237 | - | ||
| 238 | // 批量删除 table 表定义 | 228 | // 批量删除 table 表定义 |
| 239 | codegenTableMapper.deleteByIds(tableIds); | 229 | codegenTableMapper.deleteByIds(tableIds); |
| 240 | // 批量删除 column 字段定义 | 230 | // 批量删除 column 字段定义 |
| 241 | - tableIds.forEach(tableId -> codegenColumnMapper.deleteListByTableId(tableId)); | 231 | + codegenColumnMapper.deleteListByTableId(tableIds); |
| 242 | } | 232 | } |
| 243 | 233 | ||
| 244 | @Override | 234 | @Override |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/config/ConfigServiceImpl.java
| 1 | package cn.iocoder.yudao.module.infra.service.config; | 1 | package cn.iocoder.yudao.module.infra.service.config; |
| 2 | 2 | ||
| 3 | -import cn.hutool.core.collection.CollUtil; | ||
| 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigPageReqVO; | 4 | import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigPageReqVO; |
| 6 | import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigSaveReqVO; | 5 | import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigSaveReqVO; |
| @@ -68,21 +67,13 @@ public class ConfigServiceImpl implements ConfigService { | @@ -68,21 +67,13 @@ public class ConfigServiceImpl implements ConfigService { | ||
| 68 | 67 | ||
| 69 | @Override | 68 | @Override |
| 70 | public void deleteConfigList(List<Long> ids) { | 69 | public void deleteConfigList(List<Long> ids) { |
| 71 | - if (CollUtil.isEmpty(ids)) { | ||
| 72 | - return; | ||
| 73 | - } | ||
| 74 | - // 校验配置存在 | ||
| 75 | - List<ConfigDO> configs = configMapper.selectByIds(ids); | ||
| 76 | - if (configs.size() != ids.size()) { | ||
| 77 | - throw exception(CONFIG_NOT_EXISTS); | ||
| 78 | - } | ||
| 79 | - | ||
| 80 | // 校验是否有内置配置 | 70 | // 校验是否有内置配置 |
| 81 | - for (ConfigDO config : configs) { | 71 | + List<ConfigDO> configs = configMapper.selectByIds(ids); |
| 72 | + configs.forEach(config -> { | ||
| 82 | if (ConfigTypeEnum.SYSTEM.getType().equals(config.getType())) { | 73 | if (ConfigTypeEnum.SYSTEM.getType().equals(config.getType())) { |
| 83 | throw exception(CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE); | 74 | throw exception(CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE); |
| 84 | } | 75 | } |
| 85 | - } | 76 | + }); |
| 86 | 77 | ||
| 87 | // 批量删除 | 78 | // 批量删除 |
| 88 | configMapper.deleteByIds(ids); | 79 | configMapper.deleteByIds(ids); |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/db/DataSourceConfigServiceImpl.java
| 1 | package cn.iocoder.yudao.module.infra.service.db; | 1 | package cn.iocoder.yudao.module.infra.service.db; |
| 2 | 2 | ||
| 3 | -import cn.hutool.core.collection.CollUtil; | ||
| 4 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | 3 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 5 | import cn.iocoder.yudao.framework.mybatis.core.util.JdbcUtils; | 4 | import cn.iocoder.yudao.framework.mybatis.core.util.JdbcUtils; |
| 6 | import cn.iocoder.yudao.module.infra.controller.admin.db.vo.DataSourceConfigSaveReqVO; | 5 | import cn.iocoder.yudao.module.infra.controller.admin.db.vo.DataSourceConfigSaveReqVO; |
| @@ -66,12 +65,6 @@ public class DataSourceConfigServiceImpl implements DataSourceConfigService { | @@ -66,12 +65,6 @@ public class DataSourceConfigServiceImpl implements DataSourceConfigService { | ||
| 66 | 65 | ||
| 67 | @Override | 66 | @Override |
| 68 | public void deleteDataSourceConfigList(List<Long> ids) { | 67 | public void deleteDataSourceConfigList(List<Long> ids) { |
| 69 | - if (CollUtil.isEmpty(ids)) { | ||
| 70 | - return; | ||
| 71 | - } | ||
| 72 | - // 校验存在 | ||
| 73 | - ids.forEach(this::validateDataSourceConfigExists); | ||
| 74 | - // 批量删除 | ||
| 75 | dataSourceConfigMapper.deleteByIds(ids); | 68 | dataSourceConfigMapper.deleteByIds(ids); |
| 76 | } | 69 | } |
| 77 | 70 |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileConfigServiceImpl.java
| 1 | package cn.iocoder.yudao.module.infra.service.file; | 1 | package cn.iocoder.yudao.module.infra.service.file; |
| 2 | 2 | ||
| 3 | -import cn.hutool.core.collection.CollUtil; | ||
| 4 | import cn.hutool.core.io.resource.ResourceUtil; | 3 | import cn.hutool.core.io.resource.ResourceUtil; |
| 5 | import cn.hutool.core.util.IdUtil; | 4 | import cn.hutool.core.util.IdUtil; |
| 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 5 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| @@ -138,17 +137,8 @@ public class FileConfigServiceImpl implements FileConfigService { | @@ -138,17 +137,8 @@ public class FileConfigServiceImpl implements FileConfigService { | ||
| 138 | 137 | ||
| 139 | @Override | 138 | @Override |
| 140 | public void deleteFileConfigList(List<Long> ids) { | 139 | public void deleteFileConfigList(List<Long> ids) { |
| 141 | - if (CollUtil.isEmpty(ids)) { | ||
| 142 | - return; | ||
| 143 | - } | ||
| 144 | - | ||
| 145 | - // 校验存在 | ||
| 146 | - List<FileConfigDO> configs = fileConfigMapper.selectByIds(ids); | ||
| 147 | - if (configs.size() != ids.size()) { | ||
| 148 | - throw exception(FILE_CONFIG_NOT_EXISTS); | ||
| 149 | - } | ||
| 150 | - | ||
| 151 | // 校验是否有主配置 | 140 | // 校验是否有主配置 |
| 141 | + List<FileConfigDO> configs = fileConfigMapper.selectByIds(ids); | ||
| 152 | for (FileConfigDO config : configs) { | 142 | for (FileConfigDO config : configs) { |
| 153 | if (Boolean.TRUE.equals(config.getMaster())) { | 143 | if (Boolean.TRUE.equals(config.getMaster())) { |
| 154 | throw exception(FILE_CONFIG_DELETE_FAIL_MASTER); | 144 | throw exception(FILE_CONFIG_DELETE_FAIL_MASTER); |
| @@ -159,9 +149,7 @@ public class FileConfigServiceImpl implements FileConfigService { | @@ -159,9 +149,7 @@ public class FileConfigServiceImpl implements FileConfigService { | ||
| 159 | fileConfigMapper.deleteByIds(ids); | 149 | fileConfigMapper.deleteByIds(ids); |
| 160 | 150 | ||
| 161 | // 清空缓存 | 151 | // 清空缓存 |
| 162 | - for (Long id : ids) { | ||
| 163 | - clearCache(id, null); | ||
| 164 | - } | 152 | + ids.forEach(id -> clearCache(id, null)); |
| 165 | } | 153 | } |
| 166 | 154 | ||
| 167 | /** | 155 | /** |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/file/FileServiceImpl.java
| 1 | package cn.iocoder.yudao.module.infra.service.file; | 1 | package cn.iocoder.yudao.module.infra.service.file; |
| 2 | 2 | ||
| 3 | -import cn.hutool.core.collection.CollUtil; | ||
| 4 | import cn.hutool.core.date.LocalDateTimeUtil; | 3 | import cn.hutool.core.date.LocalDateTimeUtil; |
| 5 | import cn.hutool.core.io.FileUtil; | 4 | import cn.hutool.core.io.FileUtil; |
| 6 | import cn.hutool.core.lang.Assert; | 5 | import cn.hutool.core.lang.Assert; |
| @@ -22,8 +21,6 @@ import lombok.SneakyThrows; | @@ -22,8 +21,6 @@ import lombok.SneakyThrows; | ||
| 22 | import org.springframework.stereotype.Service; | 21 | import org.springframework.stereotype.Service; |
| 23 | 22 | ||
| 24 | import java.util.List; | 23 | import java.util.List; |
| 25 | -import java.util.Map; | ||
| 26 | -import java.util.stream.Collectors; | ||
| 27 | 24 | ||
| 28 | import static cn.hutool.core.date.DatePattern.PURE_DATE_PATTERN; | 25 | import static cn.hutool.core.date.DatePattern.PURE_DATE_PATTERN; |
| 29 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 26 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| @@ -162,29 +159,16 @@ public class FileServiceImpl implements FileService { | @@ -162,29 +159,16 @@ public class FileServiceImpl implements FileService { | ||
| 162 | } | 159 | } |
| 163 | 160 | ||
| 164 | @Override | 161 | @Override |
| 165 | - public void deleteFileList(List<Long> ids) throws Exception { | ||
| 166 | - if (CollUtil.isEmpty(ids)) { | ||
| 167 | - return; | ||
| 168 | - } | ||
| 169 | - | ||
| 170 | - // 校验存在 | 162 | + @SneakyThrows |
| 163 | + public void deleteFileList(List<Long> ids) { | ||
| 164 | + // 删除文件 | ||
| 171 | List<FileDO> files = fileMapper.selectByIds(ids); | 165 | List<FileDO> files = fileMapper.selectByIds(ids); |
| 172 | - if (files.size() != ids.size()) { | ||
| 173 | - throw exception(FILE_NOT_EXISTS); | ||
| 174 | - } | ||
| 175 | - | ||
| 176 | - // 按照配置分组,批量删除 | ||
| 177 | - Map<Long, List<FileDO>> configFiles = files.stream() | ||
| 178 | - .collect(Collectors.groupingBy(FileDO::getConfigId)); | ||
| 179 | - for (Map.Entry<Long, List<FileDO>> entry : configFiles.entrySet()) { | 166 | + for (FileDO file : files) { |
| 180 | // 获取客户端 | 167 | // 获取客户端 |
| 181 | - FileClient client = fileConfigService.getFileClient(entry.getKey()); | ||
| 182 | - Assert.notNull(client, "客户端({}) 不能为空", entry.getKey()); | ||
| 183 | - | ||
| 184 | - // 批量删除文件 | ||
| 185 | - for (FileDO file : entry.getValue()) { | ||
| 186 | - client.delete(file.getPath()); | ||
| 187 | - } | 168 | + FileClient client = fileConfigService.getFileClient(file.getConfigId()); |
| 169 | + Assert.notNull(client, "客户端({}) 不能为空", file.getPath()); | ||
| 170 | + // 删除文件 | ||
| 171 | + client.delete(file.getPath()); | ||
| 188 | } | 172 | } |
| 189 | 173 | ||
| 190 | // 删除记录 | 174 | // 删除记录 |
yudao-module-infra/src/main/java/cn/iocoder/yudao/module/infra/service/job/JobServiceImpl.java
| @@ -172,17 +172,8 @@ public class JobServiceImpl implements JobService { | @@ -172,17 +172,8 @@ public class JobServiceImpl implements JobService { | ||
| 172 | @Override | 172 | @Override |
| 173 | @Transactional(rollbackFor = Exception.class) | 173 | @Transactional(rollbackFor = Exception.class) |
| 174 | public void deleteJobList(List<Long> ids) throws SchedulerException { | 174 | public void deleteJobList(List<Long> ids) throws SchedulerException { |
| 175 | - if (ids == null || ids.isEmpty()) { | ||
| 176 | - return; | ||
| 177 | - } | ||
| 178 | - | ||
| 179 | - // 校验存在 | ||
| 180 | - List<JobDO> jobs = jobMapper.selectByIds(ids); | ||
| 181 | - if (jobs.size() != ids.size()) { | ||
| 182 | - throw exception(JOB_NOT_EXISTS); | ||
| 183 | - } | ||
| 184 | - | ||
| 185 | // 批量删除 | 175 | // 批量删除 |
| 176 | + List<JobDO> jobs = jobMapper.selectByIds(ids); | ||
| 186 | jobMapper.deleteByIds(ids); | 177 | jobMapper.deleteByIds(ids); |
| 187 | 178 | ||
| 188 | // 删除 Job 到 Quartz 中 | 179 | // 删除 Job 到 Quartz 中 |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImpl.java
| @@ -64,7 +64,6 @@ public class PostServiceImpl implements PostService { | @@ -64,7 +64,6 @@ public class PostServiceImpl implements PostService { | ||
| 64 | 64 | ||
| 65 | @Override | 65 | @Override |
| 66 | public void deletePostList(List<Long> ids) { | 66 | public void deletePostList(List<Long> ids) { |
| 67 | - // 删除岗位 | ||
| 68 | postMapper.deleteByIds(ids); | 67 | postMapper.deleteByIds(ids); |
| 69 | } | 68 | } |
| 70 | 69 |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictDataServiceImpl.java
| @@ -100,13 +100,6 @@ public class DictDataServiceImpl implements DictDataService { | @@ -100,13 +100,6 @@ public class DictDataServiceImpl implements DictDataService { | ||
| 100 | 100 | ||
| 101 | @Override | 101 | @Override |
| 102 | public void deleteDictDataList(List<Long> ids) { | 102 | public void deleteDictDataList(List<Long> ids) { |
| 103 | - if (CollUtil.isEmpty(ids)) { | ||
| 104 | - return; | ||
| 105 | - } | ||
| 106 | - // 校验是否存在 | ||
| 107 | - ids.forEach(this::validateDictDataExists); | ||
| 108 | - | ||
| 109 | - // 批量删除字典数据 | ||
| 110 | dictDataMapper.deleteByIds(ids); | 103 | dictDataMapper.deleteByIds(ids); |
| 111 | } | 104 | } |
| 112 | 105 |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/dict/DictTypeServiceImpl.java
| @@ -89,21 +89,15 @@ public class DictTypeServiceImpl implements DictTypeService { | @@ -89,21 +89,15 @@ public class DictTypeServiceImpl implements DictTypeService { | ||
| 89 | 89 | ||
| 90 | @Override | 90 | @Override |
| 91 | public void deleteDictTypeList(List<Long> ids) { | 91 | public void deleteDictTypeList(List<Long> ids) { |
| 92 | - if (ids == null || ids.isEmpty()) { | ||
| 93 | - return; | ||
| 94 | - } | ||
| 95 | - // 校验是否存在 | ||
| 96 | - ids.forEach(this::validateDictTypeExists); | ||
| 97 | - | ||
| 98 | - // 校验是否有字典数据 | 92 | + // 1. 校验是否有字典数据 |
| 99 | List<DictTypeDO> dictTypes = dictTypeMapper.selectByIds(ids); | 93 | List<DictTypeDO> dictTypes = dictTypeMapper.selectByIds(ids); |
| 100 | - for (DictTypeDO dictType : dictTypes) { | 94 | + dictTypes.forEach(dictType -> { |
| 101 | if (dictDataService.getDictDataCountByDictType(dictType.getType()) > 0) { | 95 | if (dictDataService.getDictDataCountByDictType(dictType.getType()) > 0) { |
| 102 | throw exception(DICT_TYPE_HAS_CHILDREN); | 96 | throw exception(DICT_TYPE_HAS_CHILDREN); |
| 103 | } | 97 | } |
| 104 | - } | 98 | + }); |
| 105 | 99 | ||
| 106 | - // 批量删除字典类型 | 100 | + // 2. 批量删除字典类型 |
| 107 | LocalDateTime now = LocalDateTime.now(); | 101 | LocalDateTime now = LocalDateTime.now(); |
| 108 | ids.forEach(id -> dictTypeMapper.updateToDelete(id, now)); | 102 | ids.forEach(id -> dictTypeMapper.updateToDelete(id, now)); |
| 109 | } | 103 | } |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/permission/MenuServiceImpl.java
| @@ -106,22 +106,15 @@ public class MenuServiceImpl implements MenuService { | @@ -106,22 +106,15 @@ public class MenuServiceImpl implements MenuService { | ||
| 106 | 106 | ||
| 107 | @Override | 107 | @Override |
| 108 | @Transactional(rollbackFor = Exception.class) | 108 | @Transactional(rollbackFor = Exception.class) |
| 109 | - @CacheEvict(value = RedisKeyConstants.PERMISSION_MENU_ID_LIST, allEntries = true) | 109 | + @CacheEvict(value = RedisKeyConstants.PERMISSION_MENU_ID_LIST, |
| 110 | + allEntries = true) // allEntries 清空所有缓存,因为 Spring Cache 不支持按照 ids 批量删除 | ||
| 110 | public void deleteMenuList(List<Long> ids) { | 111 | public void deleteMenuList(List<Long> ids) { |
| 111 | - if (CollUtil.isEmpty(ids)) { | ||
| 112 | - return; | ||
| 113 | - } | ||
| 114 | // 校验是否还有子菜单 | 112 | // 校验是否还有子菜单 |
| 115 | - for (Long id : ids) { | 113 | + ids.forEach(id -> { |
| 116 | if (menuMapper.selectCountByParentId(id) > 0) { | 114 | if (menuMapper.selectCountByParentId(id) > 0) { |
| 117 | throw exception(MENU_EXISTS_CHILDREN); | 115 | throw exception(MENU_EXISTS_CHILDREN); |
| 118 | } | 116 | } |
| 119 | - } | ||
| 120 | - // 校验删除的菜单是否存在 | ||
| 121 | - List<MenuDO> menus = menuMapper.selectByIds(ids); | ||
| 122 | - if (menus.size() != ids.size()) { | ||
| 123 | - throw exception(MENU_NOT_EXISTS); | ||
| 124 | - } | 117 | + }); |
| 125 | 118 | ||
| 126 | // 标记删除 | 119 | // 标记删除 |
| 127 | menuMapper.deleteByIds(ids); | 120 | menuMapper.deleteByIds(ids); |
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/permission/RoleServiceImpl.java
| @@ -125,10 +125,7 @@ public class RoleServiceImpl implements RoleService { | @@ -125,10 +125,7 @@ public class RoleServiceImpl implements RoleService { | ||
| 125 | @Override | 125 | @Override |
| 126 | @Transactional(rollbackFor = Exception.class) | 126 | @Transactional(rollbackFor = Exception.class) |
| 127 | public void deleteRoleList(List<Long> ids) { | 127 | public void deleteRoleList(List<Long> ids) { |
| 128 | - if (CollUtil.isEmpty(ids)) { | ||
| 129 | - return; | ||
| 130 | - } | ||
| 131 | - // 1. 校验是否可以更新 | 128 | + // 1. 校验是否可以删除 |
| 132 | ids.forEach(this::validateRoleForUpdate); | 129 | ids.forEach(this::validateRoleForUpdate); |
| 133 | 130 | ||
| 134 | // 2.1 标记删除 | 131 | // 2.1 标记删除 |