review:【INFRA 基础设施】批量删除接口

This commit is contained in:
YunaiV
2025-06-15 18:43:50 +08:00
parent bcd6ed4c4c
commit 03d3ebdf05
12 changed files with 30 additions and 112 deletions

View File

@@ -64,7 +64,6 @@ public class PostServiceImpl implements PostService {
@Override
public void deletePostList(List<Long> ids) {
// 删除岗位
postMapper.deleteByIds(ids);
}

View File

@@ -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);
}

View File

@@ -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));
}

View File

@@ -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);

View File

@@ -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 标记删除