♻️ Refactoring code. 菜单删除提示优化

This commit is contained in:
pig666 2020-06-01 12:10:18 +08:00
parent 49866add78
commit 78979b8c18
3 changed files with 11 additions and 6 deletions

View File

@ -122,7 +122,7 @@ public class MenuController {
@DeleteMapping("/{id}")
@PreAuthorize("@pms.hasPermission('sys_menu_del')")
public R removeById(@PathVariable Integer id) {
return R.ok(sysMenuService.removeMenuById(id));
return sysMenuService.removeMenuById(id);
}
/**

View File

@ -23,6 +23,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.pig4cloud.pig.admin.api.dto.MenuTree;
import com.pig4cloud.pig.admin.api.entity.SysMenu;
import com.pig4cloud.pig.admin.api.vo.MenuVO;
import com.pig4cloud.pig.common.core.util.R;
import java.util.List;
import java.util.Set;
@ -50,7 +51,7 @@ public interface SysMenuService extends IService<SysMenu> {
* @param id 菜单ID
* @return true成功,false失败
*/
Boolean removeMenuById(Integer id);
R removeMenuById(Integer id);
/**
* 更新菜单信息

View File

@ -18,6 +18,7 @@
package com.pig4cloud.pig.admin.service.impl;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pig4cloud.pig.admin.api.dto.MenuTree;
@ -31,12 +32,12 @@ import com.pig4cloud.pig.admin.service.SysMenuService;
import com.pig4cloud.pig.common.core.constant.CacheConstants;
import com.pig4cloud.pig.common.core.constant.CommonConstants;
import com.pig4cloud.pig.common.core.constant.enums.MenuTypeEnum;
import com.pig4cloud.pig.common.core.util.R;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import java.util.Comparator;
import java.util.List;
@ -71,16 +72,19 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
@Override
@Transactional(rollbackFor = Exception.class)
@CacheEvict(value = CacheConstants.MENU_DETAILS, allEntries = true)
public Boolean removeMenuById(Integer id) {
public R removeMenuById(Integer id) {
// 查询父节点为当前节点的节点
List<SysMenu> menuList = this.list(Wrappers.<SysMenu>query()
.lambda().eq(SysMenu::getParentId, id));
Assert.isNull(menuList,"菜单含有下级不能删除");
if (CollUtil.isNotEmpty(menuList)) {
return R.failed("菜单含有下级不能删除");
}
sysRoleMenuMapper.delete(Wrappers.<SysRoleMenu>query()
.lambda().eq(SysRoleMenu::getMenuId, id));
//删除当前菜单及其子菜单
return this.removeById(id);
return R.ok(this.removeById(id));
}
@Override