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 cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenColumnDO;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
@ -17,8 +18,12 @@ public interface CodegenColumnMapper extends BaseMapperX<CodegenColumnDO> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
default void deleteListByTableId(Long tableId) {
|
default void deleteListByTableId(Long tableId) {
|
||||||
|
delete(CodegenColumnDO::getTableId, tableId);
|
||||||
|
}
|
||||||
|
|
||||||
|
default void deleteListByTableId(Collection<Long> tableIds) {
|
||||||
delete(new LambdaQueryWrapperX<CodegenColumnDO>()
|
delete(new LambdaQueryWrapperX<CodegenColumnDO>()
|
||||||
.eq(CodegenColumnDO::getTableId, tableId));
|
.in(CodegenColumnDO::getTableId, tableIds));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -225,20 +225,10 @@ public class CodegenServiceImpl implements CodegenService {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void deleteCodegenList(List<Long> tableIds) {
|
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 表定义
|
// 批量删除 table 表定义
|
||||||
codegenTableMapper.deleteByIds(tableIds);
|
codegenTableMapper.deleteByIds(tableIds);
|
||||||
// 批量删除 column 字段定义
|
// 批量删除 column 字段定义
|
||||||
tableIds.forEach(tableId -> codegenColumnMapper.deleteListByTableId(tableId));
|
codegenColumnMapper.deleteListByTableId(tableIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package cn.iocoder.yudao.module.infra.service.config;
|
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.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.ConfigPageReqVO;
|
||||||
import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigSaveReqVO;
|
import cn.iocoder.yudao.module.infra.controller.admin.config.vo.ConfigSaveReqVO;
|
||||||
@ -68,21 +67,13 @@ public class ConfigServiceImpl implements ConfigService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteConfigList(List<Long> ids) {
|
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())) {
|
if (ConfigTypeEnum.SYSTEM.getType().equals(config.getType())) {
|
||||||
throw exception(CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE);
|
throw exception(CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
// 批量删除
|
// 批量删除
|
||||||
configMapper.deleteByIds(ids);
|
configMapper.deleteByIds(ids);
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package cn.iocoder.yudao.module.infra.service.db;
|
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.common.util.object.BeanUtils;
|
||||||
import cn.iocoder.yudao.framework.mybatis.core.util.JdbcUtils;
|
import cn.iocoder.yudao.framework.mybatis.core.util.JdbcUtils;
|
||||||
import cn.iocoder.yudao.module.infra.controller.admin.db.vo.DataSourceConfigSaveReqVO;
|
import cn.iocoder.yudao.module.infra.controller.admin.db.vo.DataSourceConfigSaveReqVO;
|
||||||
@ -66,12 +65,6 @@ public class DataSourceConfigServiceImpl implements DataSourceConfigService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteDataSourceConfigList(List<Long> ids) {
|
public void deleteDataSourceConfigList(List<Long> ids) {
|
||||||
if (CollUtil.isEmpty(ids)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 校验存在
|
|
||||||
ids.forEach(this::validateDataSourceConfigExists);
|
|
||||||
// 批量删除
|
|
||||||
dataSourceConfigMapper.deleteByIds(ids);
|
dataSourceConfigMapper.deleteByIds(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package cn.iocoder.yudao.module.infra.service.file;
|
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.io.resource.ResourceUtil;
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
@ -138,17 +137,8 @@ public class FileConfigServiceImpl implements FileConfigService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteFileConfigList(List<Long> ids) {
|
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) {
|
for (FileConfigDO config : configs) {
|
||||||
if (Boolean.TRUE.equals(config.getMaster())) {
|
if (Boolean.TRUE.equals(config.getMaster())) {
|
||||||
throw exception(FILE_CONFIG_DELETE_FAIL_MASTER);
|
throw exception(FILE_CONFIG_DELETE_FAIL_MASTER);
|
||||||
@ -159,9 +149,7 @@ public class FileConfigServiceImpl implements FileConfigService {
|
|||||||
fileConfigMapper.deleteByIds(ids);
|
fileConfigMapper.deleteByIds(ids);
|
||||||
|
|
||||||
// 清空缓存
|
// 清空缓存
|
||||||
for (Long id : ids) {
|
ids.forEach(id -> clearCache(id, null));
|
||||||
clearCache(id, null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package cn.iocoder.yudao.module.infra.service.file;
|
package cn.iocoder.yudao.module.infra.service.file;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
|
||||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
@ -22,8 +21,6 @@ import lombok.SneakyThrows;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
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.hutool.core.date.DatePattern.PURE_DATE_PATTERN;
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
@ -162,29 +159,16 @@ public class FileServiceImpl implements FileService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteFileList(List<Long> ids) throws Exception {
|
@SneakyThrows
|
||||||
if (CollUtil.isEmpty(ids)) {
|
public void deleteFileList(List<Long> ids) {
|
||||||
return;
|
// 删除文件
|
||||||
}
|
|
||||||
|
|
||||||
// 校验存在
|
|
||||||
List<FileDO> files = fileMapper.selectByIds(ids);
|
List<FileDO> files = fileMapper.selectByIds(ids);
|
||||||
if (files.size() != ids.size()) {
|
for (FileDO file : files) {
|
||||||
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()) {
|
|
||||||
// 获取客户端
|
// 获取客户端
|
||||||
FileClient client = fileConfigService.getFileClient(entry.getKey());
|
FileClient client = fileConfigService.getFileClient(file.getConfigId());
|
||||||
Assert.notNull(client, "客户端({}) 不能为空", entry.getKey());
|
Assert.notNull(client, "客户端({}) 不能为空", file.getPath());
|
||||||
|
// 删除文件
|
||||||
// 批量删除文件
|
client.delete(file.getPath());
|
||||||
for (FileDO file : entry.getValue()) {
|
|
||||||
client.delete(file.getPath());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除记录
|
// 删除记录
|
||||||
|
@ -172,17 +172,8 @@ public class JobServiceImpl implements JobService {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void deleteJobList(List<Long> ids) throws SchedulerException {
|
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);
|
jobMapper.deleteByIds(ids);
|
||||||
|
|
||||||
// 删除 Job 到 Quartz 中
|
// 删除 Job 到 Quartz 中
|
||||||
|
@ -64,7 +64,6 @@ public class PostServiceImpl implements PostService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deletePostList(List<Long> ids) {
|
public void deletePostList(List<Long> ids) {
|
||||||
// 删除岗位
|
|
||||||
postMapper.deleteByIds(ids);
|
postMapper.deleteByIds(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,13 +100,6 @@ public class DictDataServiceImpl implements DictDataService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteDictDataList(List<Long> ids) {
|
public void deleteDictDataList(List<Long> ids) {
|
||||||
if (CollUtil.isEmpty(ids)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 校验是否存在
|
|
||||||
ids.forEach(this::validateDictDataExists);
|
|
||||||
|
|
||||||
// 批量删除字典数据
|
|
||||||
dictDataMapper.deleteByIds(ids);
|
dictDataMapper.deleteByIds(ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,21 +89,15 @@ public class DictTypeServiceImpl implements DictTypeService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteDictTypeList(List<Long> ids) {
|
public void deleteDictTypeList(List<Long> ids) {
|
||||||
if (ids == null || ids.isEmpty()) {
|
// 1. 校验是否有字典数据
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 校验是否存在
|
|
||||||
ids.forEach(this::validateDictTypeExists);
|
|
||||||
|
|
||||||
// 校验是否有字典数据
|
|
||||||
List<DictTypeDO> dictTypes = dictTypeMapper.selectByIds(ids);
|
List<DictTypeDO> dictTypes = dictTypeMapper.selectByIds(ids);
|
||||||
for (DictTypeDO dictType : dictTypes) {
|
dictTypes.forEach(dictType -> {
|
||||||
if (dictDataService.getDictDataCountByDictType(dictType.getType()) > 0) {
|
if (dictDataService.getDictDataCountByDictType(dictType.getType()) > 0) {
|
||||||
throw exception(DICT_TYPE_HAS_CHILDREN);
|
throw exception(DICT_TYPE_HAS_CHILDREN);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
// 批量删除字典类型
|
// 2. 批量删除字典类型
|
||||||
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime now = LocalDateTime.now();
|
||||||
ids.forEach(id -> dictTypeMapper.updateToDelete(id, now));
|
ids.forEach(id -> dictTypeMapper.updateToDelete(id, now));
|
||||||
}
|
}
|
||||||
|
@ -106,22 +106,15 @@ public class MenuServiceImpl implements MenuService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@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) {
|
public void deleteMenuList(List<Long> ids) {
|
||||||
if (CollUtil.isEmpty(ids)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 校验是否还有子菜单
|
// 校验是否还有子菜单
|
||||||
for (Long id : ids) {
|
ids.forEach(id -> {
|
||||||
if (menuMapper.selectCountByParentId(id) > 0) {
|
if (menuMapper.selectCountByParentId(id) > 0) {
|
||||||
throw exception(MENU_EXISTS_CHILDREN);
|
throw exception(MENU_EXISTS_CHILDREN);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
// 校验删除的菜单是否存在
|
|
||||||
List<MenuDO> menus = menuMapper.selectByIds(ids);
|
|
||||||
if (menus.size() != ids.size()) {
|
|
||||||
throw exception(MENU_NOT_EXISTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 标记删除
|
// 标记删除
|
||||||
menuMapper.deleteByIds(ids);
|
menuMapper.deleteByIds(ids);
|
||||||
|
@ -125,10 +125,7 @@ public class RoleServiceImpl implements RoleService {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void deleteRoleList(List<Long> ids) {
|
public void deleteRoleList(List<Long> ids) {
|
||||||
if (CollUtil.isEmpty(ids)) {
|
// 1. 校验是否可以删除
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 1. 校验是否可以更新
|
|
||||||
ids.forEach(this::validateRoleForUpdate);
|
ids.forEach(this::validateRoleForUpdate);
|
||||||
|
|
||||||
// 2.1 标记删除
|
// 2.1 标记删除
|
||||||
|
Loading…
x
Reference in New Issue
Block a user