review:【INFRA 基础设施】批量删除接口
This commit is contained in:
@@ -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 标记删除
|
||||
|
Reference in New Issue
Block a user