|
@@ -24,12 +24,11 @@ import com.boman.system.service.ISysMenuService;
|
|
|
|
|
|
/**
|
|
|
* 菜单 业务层处理
|
|
|
- *
|
|
|
+ *
|
|
|
* @author ruoyi
|
|
|
*/
|
|
|
@Service
|
|
|
-public class SysMenuServiceImpl implements ISysMenuService
|
|
|
-{
|
|
|
+public class SysMenuServiceImpl implements ISysMenuService {
|
|
|
public static final String PREMISSION_STRING = "perms[\"{0}\"]";
|
|
|
|
|
|
@Autowired
|
|
@@ -43,54 +42,51 @@ public class SysMenuServiceImpl implements ISysMenuService
|
|
|
|
|
|
/**
|
|
|
* 根据用户查询系统菜单列表
|
|
|
- *
|
|
|
+ *
|
|
|
* @param userId 用户ID
|
|
|
* @return 菜单列表
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<SysMenu> selectMenuList(Long userId)
|
|
|
- {
|
|
|
+ public List<SysMenu> selectMenuList(Long userId) {
|
|
|
return selectMenuList(new SysMenu(), userId);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询系统菜单列表
|
|
|
- *
|
|
|
+ *
|
|
|
* @param menu 菜单信息
|
|
|
* @return 菜单列表
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<SysMenu> selectMenuList(SysMenu menu, Long userId)
|
|
|
- {
|
|
|
+ public List<SysMenu> selectMenuList(SysMenu menu, Long userId) {
|
|
|
List<SysMenu> menuList = null;
|
|
|
// 管理员显示所有菜单信息
|
|
|
- if (SysUser.isAdmin(userId))
|
|
|
- {
|
|
|
+ if (SysUser.isAdmin(userId)) {
|
|
|
menuList = menuMapper.selectMenuList(menu);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
menu.getParams().put("userId", userId);
|
|
|
menuList = menuMapper.selectMenuListByUserId(menu);
|
|
|
}
|
|
|
return menuList;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<SysMenu> selectMenuListAll(SysMenu menu) {
|
|
|
+ return menuMapper.selectMenuList(menu);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 根据用户ID查询权限
|
|
|
- *
|
|
|
+ *
|
|
|
* @param id 用户ID
|
|
|
* @return 权限列表
|
|
|
*/
|
|
|
@Override
|
|
|
- public Set<String> selectMenuPermsById(Long id)
|
|
|
- {
|
|
|
+ public Set<String> selectMenuPermsById(Long id) {
|
|
|
List<String> perms = menuMapper.selectMenuPermsById(id);
|
|
|
Set<String> permsSet = new HashSet<>();
|
|
|
- for (String perm : perms)
|
|
|
- {
|
|
|
- if (StringUtils.isNotEmpty(perm))
|
|
|
- {
|
|
|
+ for (String perm : perms) {
|
|
|
+ if (StringUtils.isNotEmpty(perm)) {
|
|
|
permsSet.addAll(Arrays.asList(perm.trim().split(",")));
|
|
|
}
|
|
|
}
|
|
@@ -99,20 +95,16 @@ public class SysMenuServiceImpl implements ISysMenuService
|
|
|
|
|
|
/**
|
|
|
* 根据用户ID查询菜单
|
|
|
- *
|
|
|
+ *
|
|
|
* @param id 用户名称
|
|
|
* @return 菜单列表
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<SysMenu> selectMenuTreeById(Long id)
|
|
|
- {
|
|
|
+ public List<SysMenu> selectMenuTreeById(Long id) {
|
|
|
List<SysMenu> menus = null;
|
|
|
- if (SecurityUtils.isAdmin(id))
|
|
|
- {
|
|
|
+ if (SecurityUtils.isAdmin(id)) {
|
|
|
menus = menuMapper.selectMenuTreeAll();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
menus = menuMapper.selectMenuTreeById(id);
|
|
|
}
|
|
|
return getChildPerms(menus, 0);
|
|
@@ -154,54 +146,48 @@ public class SysMenuServiceImpl implements ISysMenuService
|
|
|
|
|
|
/**
|
|
|
* 根据角色ID查询菜单树信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @param roleId 角色ID
|
|
|
* @return 选中菜单列表
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<Integer> selectMenuListByRoleId(Long roleId)
|
|
|
- {
|
|
|
+ public List<Integer> selectMenuListByRoleId(Long roleId) {
|
|
|
SysRole role = roleMapper.selectRoleById(roleId);
|
|
|
return menuMapper.selectMenuListByRoleId(roleId, role.isMenuCheckStrictly());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 构建前端路由所需要的菜单
|
|
|
- *
|
|
|
+ *
|
|
|
* @param menus 菜单列表
|
|
|
* @return 路由列表
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<RouterVo> buildMenus(List<SysMenu> menus)
|
|
|
- {
|
|
|
+ public List<RouterVo> buildMenus(List<SysMenu> menus) {
|
|
|
List<RouterVo> routers = new LinkedList<RouterVo>();
|
|
|
- for (SysMenu menu : menus)
|
|
|
- {
|
|
|
+ for (SysMenu menu : menus) {
|
|
|
RouterVo router = new RouterVo();
|
|
|
router.setHidden("1".equals(menu.getVisible()));
|
|
|
router.setName(getRouteName(menu));
|
|
|
router.setPath(getRouterPath(menu));
|
|
|
router.setComponent(getComponent(menu));
|
|
|
router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache())));
|
|
|
- if (menu.getSysTableName() != null){
|
|
|
+ if (menu.getSysTableName() != null) {
|
|
|
router.setSysTableName(menu.getSysTableName());
|
|
|
}
|
|
|
List<SysMenu> cMenus = menu.getChildren();
|
|
|
- if (!cMenus.isEmpty() && cMenus.size() > 0 && UserConstants.TYPE_DIR.equals(menu.getMenuType()))
|
|
|
- {
|
|
|
+ if (!cMenus.isEmpty() && cMenus.size() > 0 && UserConstants.TYPE_DIR.equals(menu.getMenuType())) {
|
|
|
router.setAlwaysShow(true);
|
|
|
router.setRedirect("noRedirect");
|
|
|
router.setChildren(buildMenus(cMenus));
|
|
|
- }
|
|
|
- else if (isMeunFrame(menu))
|
|
|
- {
|
|
|
+ } else if (isMeunFrame(menu)) {
|
|
|
List<RouterVo> childrenList = new ArrayList<RouterVo>();
|
|
|
RouterVo children = new RouterVo();
|
|
|
children.setPath(menu.getPath());
|
|
|
children.setComponent(menu.getComponent());
|
|
|
children.setName(StringUtils.capitalize(menu.getPath()));
|
|
|
children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache())));
|
|
|
- if (menu.getSysTableName() != null){
|
|
|
+ if (menu.getSysTableName() != null) {
|
|
|
children.setSysTableName(menu.getSysTableName());
|
|
|
}
|
|
|
childrenList.add(children);
|
|
@@ -214,7 +200,7 @@ public class SysMenuServiceImpl implements ISysMenuService
|
|
|
|
|
|
/**
|
|
|
* 构建前端所需要树结构
|
|
|
- *
|
|
|
+ *
|
|
|
* @param menus 菜单列表
|
|
|
* @return 树结构列表
|
|
|
*/
|
|
@@ -281,13 +267,12 @@ public class SysMenuServiceImpl implements ISysMenuService
|
|
|
|
|
|
/**
|
|
|
* 构建前端所需要下拉树结构
|
|
|
- *
|
|
|
+ *
|
|
|
* @param menus 菜单列表
|
|
|
* @return 下拉树结构列表
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<TreeSelect> buildMenuTreeSelect(List<SysMenu> menus)
|
|
|
- {
|
|
|
+ public List<TreeSelect> buildMenuTreeSelect(List<SysMenu> menus) {
|
|
|
List<SysMenu> menuTrees = buildMenuTree(menus);
|
|
|
return menuTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
|
|
|
}
|
|
@@ -299,103 +284,104 @@ public class SysMenuServiceImpl implements ISysMenuService
|
|
|
* @return 下拉树结构列表
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<TreeSelect> buildMenuTreeSelectNotAddLeafNode(List<SysMenu> menus)
|
|
|
- {
|
|
|
+ public List<TreeSelect> buildMenuTreeSelectNotAddLeafNode(List<SysMenu> menus) {
|
|
|
List<SysMenu> menuTrees = buildMenuTreeNotAddLeafNode(menus);
|
|
|
return menuTrees.stream().map(TreeSelect::new).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据菜单ID查询信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @param id 菜单ID
|
|
|
* @return 菜单信息
|
|
|
*/
|
|
|
@Override
|
|
|
- public SysMenu selectMenuById(Long id)
|
|
|
- {
|
|
|
+ public SysMenu selectMenuById(Long id) {
|
|
|
return menuMapper.selectMenuById(id);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 是否存在菜单子节点
|
|
|
- *
|
|
|
+ *
|
|
|
* @param id 菜单ID
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public boolean hasChildById(Long id)
|
|
|
- {
|
|
|
+ public boolean hasChildById(Long id) {
|
|
|
int result = menuMapper.hasChildById(id);
|
|
|
return result > 0 ? true : false;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询菜单使用数量
|
|
|
- *
|
|
|
+ *
|
|
|
* @param id 菜单ID
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public boolean checkMenuExistRole(Long id)
|
|
|
- {
|
|
|
+ public boolean checkMenuExistRole(Long id) {
|
|
|
int result = roleMenuMapper.checkMenuExistRole(id);
|
|
|
return result > 0 ? true : false;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 新增保存菜单信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @param menu 菜单信息
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public AjaxResult insertMenu(SysMenu menu)
|
|
|
- {
|
|
|
+ public AjaxResult insertMenu(SysMenu menu) {
|
|
|
int i = menuMapper.insertMenu(menu);
|
|
|
- if (menu.getId() != null){
|
|
|
- return AjaxResult.success(Integer.parseInt(menu.getId().toString()));
|
|
|
- }
|
|
|
- return i > 0?AjaxResult.success():AjaxResult.error();
|
|
|
+ if (menu.getId() != null) {
|
|
|
+ return AjaxResult.success(Integer.parseInt(menu.getId().toString()));
|
|
|
+ }
|
|
|
+ return i > 0 ? AjaxResult.success() : AjaxResult.error();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 修改保存菜单信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @param menu 菜单信息
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int updateMenu(SysMenu menu)
|
|
|
- {
|
|
|
+ public int updateMenu(SysMenu menu) {
|
|
|
return menuMapper.updateMenu(menu);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除菜单管理信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @param id 菜单ID
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int deleteMenuById(Long id)
|
|
|
- {
|
|
|
+ public int deleteMenuById(Long id) {
|
|
|
return menuMapper.deleteMenuById(id);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 逻辑删除
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int removeMenuById(Long id) {
|
|
|
+ return menuMapper.updateMenuById(id);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 校验菜单名称是否唯一
|
|
|
- *
|
|
|
+ *
|
|
|
* @param menu 菜单信息
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public String checkMenuNameUnique(SysMenu menu)
|
|
|
- {
|
|
|
+ public String checkMenuNameUnique(SysMenu menu) {
|
|
|
Long id = StringUtils.isNull(menu.getId()) ? -1L : menu.getId();
|
|
|
SysMenu info = menuMapper.checkMenuNameUnique(menu.getMenuName(), menu.getParentId());
|
|
|
- if (StringUtils.isNotNull(info) && info.getId().longValue() != id.longValue())
|
|
|
- {
|
|
|
+ if (StringUtils.isNotNull(info) && info.getId().longValue() != id.longValue()) {
|
|
|
return UserConstants.NOT_UNIQUE;
|
|
|
}
|
|
|
return UserConstants.UNIQUE;
|
|
@@ -403,16 +389,14 @@ public class SysMenuServiceImpl implements ISysMenuService
|
|
|
|
|
|
/**
|
|
|
* 获取路由名称
|
|
|
- *
|
|
|
+ *
|
|
|
* @param menu 菜单信息
|
|
|
* @return 路由名称
|
|
|
*/
|
|
|
- public String getRouteName(SysMenu menu)
|
|
|
- {
|
|
|
+ public String getRouteName(SysMenu menu) {
|
|
|
String routerName = StringUtils.capitalize(menu.getPath());
|
|
|
// 非外链并且是一级目录(类型为目录)
|
|
|
- if (isMeunFrame(menu))
|
|
|
- {
|
|
|
+ if (isMeunFrame(menu)) {
|
|
|
routerName = StringUtils.EMPTY;
|
|
|
}
|
|
|
return routerName;
|
|
@@ -420,22 +404,19 @@ public class SysMenuServiceImpl implements ISysMenuService
|
|
|
|
|
|
/**
|
|
|
* 获取路由地址
|
|
|
- *
|
|
|
+ *
|
|
|
* @param menu 菜单信息
|
|
|
* @return 路由地址
|
|
|
*/
|
|
|
- public String getRouterPath(SysMenu menu)
|
|
|
- {
|
|
|
+ public String getRouterPath(SysMenu menu) {
|
|
|
String routerPath = menu.getPath();
|
|
|
// 非外链并且是一级目录(类型为目录)
|
|
|
if (0 == menu.getParentId().intValue() && UserConstants.TYPE_DIR.equals(menu.getMenuType())
|
|
|
- && UserConstants.NO_FRAME.equals(menu.getIsFrame()))
|
|
|
- {
|
|
|
+ && UserConstants.NO_FRAME.equals(menu.getIsFrame())) {
|
|
|
routerPath = "/" + menu.getPath();
|
|
|
}
|
|
|
// 非外链并且是一级目录(类型为菜单)
|
|
|
- else if (isMeunFrame(menu))
|
|
|
- {
|
|
|
+ else if (isMeunFrame(menu)) {
|
|
|
routerPath = "/";
|
|
|
}
|
|
|
return routerPath;
|
|
@@ -443,19 +424,15 @@ public class SysMenuServiceImpl implements ISysMenuService
|
|
|
|
|
|
/**
|
|
|
* 获取组件信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @param menu 菜单信息
|
|
|
* @return 组件信息
|
|
|
*/
|
|
|
- public String getComponent(SysMenu menu)
|
|
|
- {
|
|
|
+ public String getComponent(SysMenu menu) {
|
|
|
String component = UserConstants.LAYOUT;
|
|
|
- if (StringUtils.isNotEmpty(menu.getComponent()) && !isMeunFrame(menu))
|
|
|
- {
|
|
|
+ if (StringUtils.isNotEmpty(menu.getComponent()) && !isMeunFrame(menu)) {
|
|
|
component = menu.getComponent();
|
|
|
- }
|
|
|
- else if (StringUtils.isEmpty(menu.getComponent()) && isParentView(menu))
|
|
|
- {
|
|
|
+ } else if (StringUtils.isEmpty(menu.getComponent()) && isParentView(menu)) {
|
|
|
component = UserConstants.PARENT_VIEW;
|
|
|
}
|
|
|
return component;
|
|
@@ -463,43 +440,38 @@ public class SysMenuServiceImpl implements ISysMenuService
|
|
|
|
|
|
/**
|
|
|
* 是否为菜单内部跳转
|
|
|
- *
|
|
|
+ *
|
|
|
* @param menu 菜单信息
|
|
|
* @return 结果
|
|
|
*/
|
|
|
- public boolean isMeunFrame(SysMenu menu)
|
|
|
- {
|
|
|
+ public boolean isMeunFrame(SysMenu menu) {
|
|
|
return menu.getParentId().intValue() == 0 && UserConstants.TYPE_MENU.equals(menu.getMenuType())
|
|
|
&& menu.getIsFrame().equals(UserConstants.NO_FRAME);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 是否为parent_view组件
|
|
|
- *
|
|
|
+ *
|
|
|
* @param menu 菜单信息
|
|
|
* @return 结果
|
|
|
*/
|
|
|
- public boolean isParentView(SysMenu menu)
|
|
|
- {
|
|
|
+ public boolean isParentView(SysMenu menu) {
|
|
|
return menu.getParentId().intValue() != 0 && UserConstants.TYPE_DIR.equals(menu.getMenuType());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据父节点的ID获取所有子节点
|
|
|
- *
|
|
|
- * @param list 分类表
|
|
|
+ *
|
|
|
+ * @param list 分类表
|
|
|
* @param parentId 传入的父节点ID
|
|
|
* @return String
|
|
|
*/
|
|
|
- public List<SysMenu> getChildPerms(List<SysMenu> list, int parentId)
|
|
|
- {
|
|
|
+ public List<SysMenu> getChildPerms(List<SysMenu> list, int parentId) {
|
|
|
List<SysMenu> returnList = new ArrayList<SysMenu>();
|
|
|
- for (Iterator<SysMenu> iterator = list.iterator(); iterator.hasNext();)
|
|
|
- {
|
|
|
+ for (Iterator<SysMenu> iterator = list.iterator(); iterator.hasNext(); ) {
|
|
|
SysMenu t = (SysMenu) iterator.next();
|
|
|
// 一、根据传入的某个父节点ID,遍历该父节点的所有子节点
|
|
|
- if (t.getParentId() == parentId)
|
|
|
- {
|
|
|
+ if (t.getParentId() == parentId) {
|
|
|
recursionFn(list, t);
|
|
|
returnList.add(t);
|
|
|
}
|
|
@@ -509,19 +481,16 @@ public class SysMenuServiceImpl implements ISysMenuService
|
|
|
|
|
|
/**
|
|
|
* 递归列表
|
|
|
- *
|
|
|
+ *
|
|
|
* @param list
|
|
|
* @param t
|
|
|
*/
|
|
|
- private void recursionFn(List<SysMenu> list, SysMenu t)
|
|
|
- {
|
|
|
+ private void recursionFn(List<SysMenu> list, SysMenu t) {
|
|
|
// 得到子节点列表
|
|
|
List<SysMenu> childList = getChildList(list, t);
|
|
|
t.setChildren(childList);
|
|
|
- for (SysMenu tChild : childList)
|
|
|
- {
|
|
|
- if (hasChild(list, tChild))
|
|
|
- {
|
|
|
+ for (SysMenu tChild : childList) {
|
|
|
+ if (hasChild(list, tChild)) {
|
|
|
recursionFn(list, tChild);
|
|
|
}
|
|
|
}
|
|
@@ -530,15 +499,12 @@ public class SysMenuServiceImpl implements ISysMenuService
|
|
|
/**
|
|
|
* 得到子节点列表
|
|
|
*/
|
|
|
- private List<SysMenu> getChildList(List<SysMenu> list, SysMenu t)
|
|
|
- {
|
|
|
+ private List<SysMenu> getChildList(List<SysMenu> list, SysMenu t) {
|
|
|
List<SysMenu> tlist = new ArrayList<SysMenu>();
|
|
|
Iterator<SysMenu> it = list.iterator();
|
|
|
- while (it.hasNext())
|
|
|
- {
|
|
|
+ while (it.hasNext()) {
|
|
|
SysMenu n = (SysMenu) it.next();
|
|
|
- if (n.getParentId().longValue() == t.getId().longValue())
|
|
|
- {
|
|
|
+ if (n.getParentId().longValue() == t.getId().longValue()) {
|
|
|
tlist.add(n);
|
|
|
}
|
|
|
}
|
|
@@ -548,8 +514,7 @@ public class SysMenuServiceImpl implements ISysMenuService
|
|
|
/**
|
|
|
* 判断是否有子节点
|
|
|
*/
|
|
|
- private boolean hasChild(List<SysMenu> list, SysMenu t)
|
|
|
- {
|
|
|
+ private boolean hasChild(List<SysMenu> list, SysMenu t) {
|
|
|
return getChildList(list, t).size() > 0;
|
|
|
}
|
|
|
}
|