linwe
2023-12-23 55d677758efadb6d42e6d4e595cecc2c50c20d5a
src/main/java/org/springblade/modules/system/service/impl/MenuServiceImpl.java
@@ -16,6 +16,7 @@
 */
package org.springblade.modules.system.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -79,7 +80,14 @@
      if (Func.isEmpty(Func.toStr(param.get(PARENT_ID)))) {
         parentId = null;
      }
      return baseMapper.lazyList(parentId, param);
      List<MenuVO> menuVOS = baseMapper.lazyList(parentId, param);
      for (MenuVO menuVO : menuVOS) {
         if(StringUtils.isNotBlank(menuVO.getLabelStr())){
            List<List<String>> lists = (List<List<String>>)JSON.parse(menuVO.getLabelStr() );
            menuVO.setLabelList(lists);
         }
      }
      return menuVOS;
   }
   @Override
@@ -87,29 +95,26 @@
      if (Func.isEmpty(Func.toStr(param.get(PARENT_ID)))) {
         parentId = null;
      }
      return baseMapper.lazyMenuList(parentId, param);
      List<MenuVO> menuVOS = baseMapper.lazyList(parentId, param);
      for (MenuVO menuVO : menuVOS) {
         if(StringUtils.isNotBlank(menuVO.getLabelStr())){
            List<List<String>> lists = (List<List<String>>)JSON.parse(menuVO.getLabelStr() );
            menuVO.setLabelList(lists);
         }
      }
      return menuVOS;
   }
   public static final List<Integer> list1 = Arrays.asList(1, 2, 3, 4, 5, 6, 11, null);
   public static final List<Integer> list2 = Arrays.asList(1, 11, null);
   /**
    * apache测试方法
    */
   public static void main(String[] args) {
      System.out.println("交集:" + CollectionUtils.intersection(list1, list2)); // 交集
      System.out.println("补集:" + CollectionUtils.disjunction(list1, list2)); // 补集
      System.out.println("并集:" + CollectionUtils.union(list1, list2)); // 并集
      System.out.println("list1的差集:" + CollectionUtils.subtract(list1, list2)); // list1的差集
      System.out.println("list2的差集:" + CollectionUtils.subtract(list2, list1)); // list2的差集
   }
   @Override
   public List<MenuVO> routes(String roleId, Long topMenuId, Integer labelType) {
   public List<MenuVO> routes(String roleId, Long topMenuId, Integer labelType,Integer menuType) {
      if (StringUtil.isBlank(roleId)) {
         return null;
      }
      List<Menu> allMenus = baseMapper.allMenu();
      List<Menu> allMenus = baseMapper.selectList(Wrappers.<Menu>lambdaQuery().eq(Menu::getCategory,1).eq(Menu::getMenuType,menuType));
      List<Menu> roleMenus;
      // 超级管理员并且不是顶部菜单请求则返回全部菜单
      if (AuthUtil.isAdministrator() && Func.isEmpty(topMenuId)) {
@@ -117,7 +122,7 @@
      }
      // 非超级管理员并且不是顶部菜单请求则返回对应角色权限菜单
      else if (!AuthUtil.isAdministrator() && Func.isEmpty(topMenuId)) {
         roleMenus = tenantPackageMenu(baseMapper.roleMenuByRoleId(Func.toLongList(roleId)));
         roleMenus = tenantPackageMenu(baseMapper.roleMenuByRoleId(Func.toLongList(roleId), menuType));
         UserHouseLabelDTO userHouseLabelDTO = new UserHouseLabelDTO();
         userHouseLabelDTO.setUserId(AuthUtil.getUserId());
         userHouseLabelDTO.setLableType(labelType);
@@ -133,6 +138,25 @@
                  if (union.size() == 0) {
                     iterator.remove();
                  }
               } else {
                  if (next.getName().trim().equals("标签报事")) {
                     iterator.remove();
                  }
                  if (next.getName().trim().equals("打金店")) {
                     iterator.remove();
                  }
                  if (next.getName().trim().equals("旅馆安全")) {
                     iterator.remove();
                  }
                  if (next.getName().trim().equals("二手车交易")) {
                     iterator.remove();
                  }
                  if (next.getName().trim().equals("二手手机维修")) {
                     iterator.remove();
                  }
                  if (next.getName().trim().equals("校园安全")) {
                     iterator.remove();
                  }
               }
            }
         }
@@ -140,7 +164,7 @@
      // 顶部菜单请求返回对应角色权限菜单
      else {
         // 角色配置对应菜单
         List<Menu> roleIdMenus = baseMapper.roleMenuByRoleId(Func.toLongList(roleId));
         List<Menu> roleIdMenus = baseMapper.roleMenuByRoleId(Func.toLongList(roleId),menuType);
         // 反向递归角色菜单所有父级
         List<Menu> routes = new LinkedList<>(roleIdMenus);
         roleIdMenus.forEach(roleMenu -> recursion(allMenus, routes, roleMenu));
@@ -315,7 +339,7 @@
   }
   @Override
   public boolean submit(Menu menu) {
   public boolean submit(MenuDTO menu) {
      LambdaQueryWrapper<Menu> menuQueryWrapper = Wrappers.lambdaQuery();
      if (menu.getId() == null) {
         menuQueryWrapper.eq(Menu::getCode, menu.getCode()).or(
@@ -341,6 +365,13 @@
            throw new ServiceException("父节点只可选择菜单类型!");
         }
      }
      menu.setLabelStr(JSON.toJSONString(menu.getLabelList()));
      List<List<String>> labelList = menu.getLabelList();
      StringBuffer stringBuffer = new StringBuffer();
      for (List<String> strings : labelList) {
         stringBuffer.append(strings.get(strings.size()-1)).append(",");
      }
      menu.setLabelId(stringBuffer.toString());
      menu.setIsDeleted(BladeConstant.DB_NOT_DELETED);
      return saveOrUpdate(menu);
   }