mirror of
https://gitee.com/myxzgzs/boyue-vue-pro.git
synced 2025-08-08 08:22:45 +08:00
review:【INFRA 基础设施】批量删除接口
This commit is contained in:
parent
bcd6ed4c4c
commit
03d3ebdf05
@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenColumnDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
@ -17,8 +18,12 @@ public interface CodegenColumnMapper extends BaseMapperX<CodegenColumnDO> {
|
||||
}
|
||||
|
||||
default void deleteListByTableId(Long tableId) {
|
||||
delete(CodegenColumnDO::getTableId, tableId);
|
||||
}
|
||||
|
||||
default void deleteListByTableId(Collection<Long> tableIds) {
|
||||
delete(new LambdaQueryWrapperX<CodegenColumnDO>()
|
||||
.eq(CodegenColumnDO::getTableId, tableId));
|
||||
.in(CodegenColumnDO::getTableId, tableIds));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -225,20 +225,10 @@ public class CodegenServiceImpl implements CodegenService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteCodegenList(List<Long> tableIds) {
|
||||
if (CollUtil.isEmpty(tableIds)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 校验是否都存在
|
||||
List<CodegenTableDO> tables = codegenTableMapper.selectByIds(tableIds);
|
||||
if (tables.size() != tableIds.size()) {
|
||||
throw exception(CODEGEN_TABLE_NOT_EXISTS);
|
||||
}
|
||||
|
||||
// 批量删除 table 表定义
|
||||
codegenTableMapper.deleteByIds(tableIds);
|
||||
// 批量删除 column 字段定义
|
||||
tableIds.forEach(tableId -> codegenColumnMapper.deleteListByTableId(tableId));
|
||||
codegenColumnMapper.deleteListByTableId(tableIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,5 @@
|
||||
package cn.iocoder.yudao.module.infra.service.config;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigPageReqVO;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigSaveReqVO;
|
||||
@ -68,21 +67,13 @@ public class ConfigServiceImpl implements ConfigService {
|
||||
|
||||
@Override
|
||||
public void deleteConfigList(List<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return;
|
||||
}
|
||||
// 校验配置存在
|
||||
List<ConfigDO> configs = configMapper.selectByIds(ids);
|
||||
if (configs.size() != ids.size()) {
|
||||
throw exception(CONFIG_NOT_EXISTS);
|
||||
}
|
||||
|
||||
// 校验是否有内置配置
|
||||
for (ConfigDO config : configs) {
|
||||
List<ConfigDO> configs = configMapper.selectByIds(ids);
|
||||
configs.forEach(config -> {
|
||||
if (ConfigTypeEnum.SYSTEM.getType().equals(config.getType())) {
|
||||
throw exception(CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 批量删除
|
||||
configMapper.deleteByIds(ids);
|
||||
|
@ -1,6 +1,5 @@
|
||||
package cn.iocoder.yudao.module.infra.service.db;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.util.JdbcUtils;
|
||||
import cn.iocoder.yudao.module.infra.controller.admin.db.vo.DataSourceConfigSaveReqVO;
|
||||
@ -66,12 +65,6 @@ public class DataSourceConfigServiceImpl implements DataSourceConfigService {
|
||||
|
||||
@Override
|
||||
public void deleteDataSourceConfigList(List<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return;
|
||||
}
|
||||
// 校验存在
|
||||
ids.forEach(this::validateDataSourceConfigExists);
|
||||
// 批量删除
|
||||
dataSourceConfigMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package cn.iocoder.yudao.module.infra.service.file;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
@ -138,17 +137,8 @@ public class FileConfigServiceImpl implements FileConfigService {
|
||||
|
||||
@Override
|
||||
public void deleteFileConfigList(List<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 校验存在
|
||||
List<FileConfigDO> configs = fileConfigMapper.selectByIds(ids);
|
||||
if (configs.size() != ids.size()) {
|
||||
throw exception(FILE_CONFIG_NOT_EXISTS);
|
||||
}
|
||||
|
||||
// 校验是否有主配置
|
||||
List<FileConfigDO> configs = fileConfigMapper.selectByIds(ids);
|
||||
for (FileConfigDO config : configs) {
|
||||
if (Boolean.TRUE.equals(config.getMaster())) {
|
||||
throw exception(FILE_CONFIG_DELETE_FAIL_MASTER);
|
||||
@ -159,9 +149,7 @@ public class FileConfigServiceImpl implements FileConfigService {
|
||||
fileConfigMapper.deleteByIds(ids);
|
||||
|
||||
// 清空缓存
|
||||
for (Long id : ids) {
|
||||
clearCache(id, null);
|
||||
}
|
||||
ids.forEach(id -> clearCache(id, null));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,5 @@
|
||||
package cn.iocoder.yudao.module.infra.service.file;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
@ -22,8 +21,6 @@ import lombok.SneakyThrows;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.hutool.core.date.DatePattern.PURE_DATE_PATTERN;
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
@ -162,30 +159,17 @@ public class FileServiceImpl implements FileService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteFileList(List<Long> ids) throws Exception {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 校验存在
|
||||
@SneakyThrows
|
||||
public void deleteFileList(List<Long> ids) {
|
||||
// 删除文件
|
||||
List<FileDO> files = fileMapper.selectByIds(ids);
|
||||
if (files.size() != ids.size()) {
|
||||
throw exception(FILE_NOT_EXISTS);
|
||||
}
|
||||
|
||||
// 按照配置分组,批量删除
|
||||
Map<Long, List<FileDO>> configFiles = files.stream()
|
||||
.collect(Collectors.groupingBy(FileDO::getConfigId));
|
||||
for (Map.Entry<Long, List<FileDO>> entry : configFiles.entrySet()) {
|
||||
for (FileDO file : files) {
|
||||
// 获取客户端
|
||||
FileClient client = fileConfigService.getFileClient(entry.getKey());
|
||||
Assert.notNull(client, "客户端({}) 不能为空", entry.getKey());
|
||||
|
||||
// 批量删除文件
|
||||
for (FileDO file : entry.getValue()) {
|
||||
FileClient client = fileConfigService.getFileClient(file.getConfigId());
|
||||
Assert.notNull(client, "客户端({}) 不能为空", file.getPath());
|
||||
// 删除文件
|
||||
client.delete(file.getPath());
|
||||
}
|
||||
}
|
||||
|
||||
// 删除记录
|
||||
fileMapper.deleteByIds(ids);
|
||||
|
@ -172,17 +172,8 @@ public class JobServiceImpl implements JobService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteJobList(List<Long> ids) throws SchedulerException {
|
||||
if (ids == null || ids.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 校验存在
|
||||
List<JobDO> jobs = jobMapper.selectByIds(ids);
|
||||
if (jobs.size() != ids.size()) {
|
||||
throw exception(JOB_NOT_EXISTS);
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
List<JobDO> jobs = jobMapper.selectByIds(ids);
|
||||
jobMapper.deleteByIds(ids);
|
||||
|
||||
// 删除 Job 到 Quartz 中
|
||||
|
@ -64,7 +64,6 @@ public class PostServiceImpl implements PostService {
|
||||
|
||||
@Override
|
||||
public void deletePostList(List<Long> ids) {
|
||||
// 删除岗位
|
||||
postMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
|
@ -100,13 +100,6 @@ public class DictDataServiceImpl implements DictDataService {
|
||||
|
||||
@Override
|
||||
public void deleteDictDataList(List<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return;
|
||||
}
|
||||
// 校验是否存在
|
||||
ids.forEach(this::validateDictDataExists);
|
||||
|
||||
// 批量删除字典数据
|
||||
dictDataMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
|
@ -89,21 +89,15 @@ public class DictTypeServiceImpl implements DictTypeService {
|
||||
|
||||
@Override
|
||||
public void deleteDictTypeList(List<Long> ids) {
|
||||
if (ids == null || ids.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
// 校验是否存在
|
||||
ids.forEach(this::validateDictTypeExists);
|
||||
|
||||
// 校验是否有字典数据
|
||||
// 1. 校验是否有字典数据
|
||||
List<DictTypeDO> dictTypes = dictTypeMapper.selectByIds(ids);
|
||||
for (DictTypeDO dictType : dictTypes) {
|
||||
dictTypes.forEach(dictType -> {
|
||||
if (dictDataService.getDictDataCountByDictType(dictType.getType()) > 0) {
|
||||
throw exception(DICT_TYPE_HAS_CHILDREN);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 批量删除字典类型
|
||||
// 2. 批量删除字典类型
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
ids.forEach(id -> dictTypeMapper.updateToDelete(id, now));
|
||||
}
|
||||
|
@ -106,22 +106,15 @@ public class MenuServiceImpl implements MenuService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@CacheEvict(value = RedisKeyConstants.PERMISSION_MENU_ID_LIST, allEntries = true)
|
||||
@CacheEvict(value = RedisKeyConstants.PERMISSION_MENU_ID_LIST,
|
||||
allEntries = true) // allEntries 清空所有缓存,因为 Spring Cache 不支持按照 ids 批量删除
|
||||
public void deleteMenuList(List<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return;
|
||||
}
|
||||
// 校验是否还有子菜单
|
||||
for (Long id : ids) {
|
||||
ids.forEach(id -> {
|
||||
if (menuMapper.selectCountByParentId(id) > 0) {
|
||||
throw exception(MENU_EXISTS_CHILDREN);
|
||||
}
|
||||
}
|
||||
// 校验删除的菜单是否存在
|
||||
List<MenuDO> menus = menuMapper.selectByIds(ids);
|
||||
if (menus.size() != ids.size()) {
|
||||
throw exception(MENU_NOT_EXISTS);
|
||||
}
|
||||
});
|
||||
|
||||
// 标记删除
|
||||
menuMapper.deleteByIds(ids);
|
||||
|
@ -125,10 +125,7 @@ public class RoleServiceImpl implements RoleService {
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteRoleList(List<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return;
|
||||
}
|
||||
// 1. 校验是否可以更新
|
||||
// 1. 校验是否可以删除
|
||||
ids.forEach(this::validateRoleForUpdate);
|
||||
|
||||
// 2.1 标记删除
|
||||
|
Loading…
x
Reference in New Issue
Block a user