|
@@ -1,14 +1,18 @@
|
|
|
package com.storlead.system.controller;
|
|
package com.storlead.system.controller;
|
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.storlead.framework.common.result.Result;
|
|
import com.storlead.framework.common.result.Result;
|
|
|
import com.storlead.framework.common.util.PingyinUtil;
|
|
import com.storlead.framework.common.util.PingyinUtil;
|
|
|
import com.storlead.framework.util.LoginUserUtil;
|
|
import com.storlead.framework.util.LoginUserUtil;
|
|
|
import com.storlead.system.pojo.entity.MenuEntity;
|
|
import com.storlead.system.pojo.entity.MenuEntity;
|
|
|
|
|
+import com.storlead.system.pojo.entity.SysAppEntity;
|
|
|
|
|
+import com.storlead.system.pojo.vo.AppRouterVO;
|
|
|
import com.storlead.system.pojo.vo.MetaVo;
|
|
import com.storlead.system.pojo.vo.MetaVo;
|
|
|
import com.storlead.system.pojo.vo.RouterVo;
|
|
import com.storlead.system.pojo.vo.RouterVo;
|
|
|
import com.storlead.system.pojo.vo.UserMenuVO;
|
|
import com.storlead.system.pojo.vo.UserMenuVO;
|
|
|
import com.storlead.system.service.IMenuService;
|
|
import com.storlead.system.service.IMenuService;
|
|
|
|
|
+import com.storlead.system.service.SysAppService;
|
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
import lombok.extern.log4j.Log4j2;
|
|
@@ -21,6 +25,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @program: sp-sales-platform
|
|
* @program: sp-sales-platform
|
|
@@ -37,6 +42,10 @@ public class PermissionResApiController {
|
|
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
|
private IMenuService menuService;
|
|
private IMenuService menuService;
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private SysAppService sysAppService;
|
|
|
|
|
+
|
|
|
private static final String PARENT_VIEW = "ParentView";
|
|
private static final String PARENT_VIEW = "ParentView";
|
|
|
private static final String LAYOUT = "Layout";
|
|
private static final String LAYOUT = "Layout";
|
|
|
|
|
|
|
@@ -47,25 +56,14 @@ public class PermissionResApiController {
|
|
|
Map<String,Object> map = new HashMap();
|
|
Map<String,Object> map = new HashMap();
|
|
|
Long currentUserId = LoginUserUtil.getCurrentUserId();
|
|
Long currentUserId = LoginUserUtil.getCurrentUserId();
|
|
|
List<MenuEntity> userMenuList = menuService.getUserMenuList(currentUserId,Arrays.asList(0),Arrays.asList(1,2));
|
|
List<MenuEntity> userMenuList = menuService.getUserMenuList(currentUserId,Arrays.asList(0),Arrays.asList(1,2));
|
|
|
- List<UserMenuVO> menuls = new ArrayList();
|
|
|
|
|
-
|
|
|
|
|
- userMenuList.forEach(menu -> {
|
|
|
|
|
- UserMenuVO menuVo = new UserMenuVO();
|
|
|
|
|
- BeanUtils.copyProperties(menu,menuVo);
|
|
|
|
|
- menuls.add(menuVo);
|
|
|
|
|
- });
|
|
|
|
|
- if (!CollectionUtils.isEmpty(menuls)) {
|
|
|
|
|
- menuls.forEach(e -> {
|
|
|
|
|
- if (StrUtil.isNotBlank(e.getMenuName())) {
|
|
|
|
|
- String pyIcon = PingyinUtil.getLowFullSpell(e.getMenuName());
|
|
|
|
|
- e.setIcon(pyIcon);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
- List<UserMenuVO> menuRes = createTreeMenus(Long.valueOf(0),menuls);
|
|
|
|
|
- List<RouterVo> treeRouter = new ArrayList<>();
|
|
|
|
|
- menuToRouter(menuRes, null, treeRouter);
|
|
|
|
|
- map.put("routerVo",treeRouter);
|
|
|
|
|
|
|
+ List<UserMenuVO> menuls = toUserMenuVoList(userMenuList);
|
|
|
|
|
+ List<AppRouterVO> appRouterList = buildAppRouterList(menuls);
|
|
|
|
|
+ List<RouterVo> treeRouter = appRouterList.stream()
|
|
|
|
|
+ .filter(app -> !CollectionUtils.isEmpty(app.getChildren()))
|
|
|
|
|
+ .flatMap(app -> app.getChildren().stream())
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ map.put("appRouterVo", appRouterList);
|
|
|
|
|
+// map.put("routerVo", treeRouter);
|
|
|
return Result.result(map);
|
|
return Result.result(map);
|
|
|
}catch (Exception e) {
|
|
}catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
@@ -106,6 +104,88 @@ public class PermissionResApiController {
|
|
|
return Result.error("获取菜单信息错误:"+e.getMessage());
|
|
return Result.error("获取菜单信息错误:"+e.getMessage());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 按应用分组构建菜单路由:应用 -> 菜单树。
|
|
|
|
|
+ */
|
|
|
|
|
+ private List<AppRouterVO> buildAppRouterList(List<UserMenuVO> menuls) {
|
|
|
|
|
+ if (CollectionUtils.isEmpty(menuls)) {
|
|
|
|
|
+ return Collections.emptyList();
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<Long, List<UserMenuVO>> menusByApp = menuls.stream()
|
|
|
|
|
+ .collect(Collectors.groupingBy(menu -> menu.getAppId() == null ? 0L : menu.getAppId()));
|
|
|
|
|
+
|
|
|
|
|
+ Set<Long> appIds = menusByApp.keySet();
|
|
|
|
|
+ List<SysAppEntity> apps = sysAppService.list(new LambdaQueryWrapper<SysAppEntity>()
|
|
|
|
|
+ .in(SysAppEntity::getId, appIds)
|
|
|
|
|
+ .eq(SysAppEntity::getIsDelete, 0)
|
|
|
|
|
+ .eq(SysAppEntity::getEnabled, 1)
|
|
|
|
|
+ .orderByAsc(SysAppEntity::getSort)
|
|
|
|
|
+ .orderByAsc(SysAppEntity::getId));
|
|
|
|
|
+
|
|
|
|
|
+ List<AppRouterVO> appRouterList = new ArrayList<>();
|
|
|
|
|
+ Set<Long> handledAppIds = new HashSet<>();
|
|
|
|
|
+
|
|
|
|
|
+ for (SysAppEntity app : apps) {
|
|
|
|
|
+ List<UserMenuVO> appMenus = menusByApp.get(app.getId());
|
|
|
|
|
+ if (CollectionUtils.isEmpty(appMenus)) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ handledAppIds.add(app.getId());
|
|
|
|
|
+ appRouterList.add(buildOneAppRouter(app, appMenus));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for (Long appId : appIds) {
|
|
|
|
|
+ if (handledAppIds.contains(appId)) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<UserMenuVO> appMenus = menusByApp.get(appId);
|
|
|
|
|
+ if (CollectionUtils.isEmpty(appMenus)) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ AppRouterVO appRouter = new AppRouterVO();
|
|
|
|
|
+ appRouter.setAppId(appId);
|
|
|
|
|
+ appRouter.setAppName("应用" + appId);
|
|
|
|
|
+ appRouter.setChildren(buildMenuRouters(appMenus));
|
|
|
|
|
+ appRouterList.add(appRouter);
|
|
|
|
|
+ }
|
|
|
|
|
+ return appRouterList;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private AppRouterVO buildOneAppRouter(SysAppEntity app, List<UserMenuVO> appMenus) {
|
|
|
|
|
+ AppRouterVO appRouter = new AppRouterVO();
|
|
|
|
|
+ appRouter.setAppId(app.getId());
|
|
|
|
|
+ appRouter.setAppCode(app.getAppCode());
|
|
|
|
|
+ appRouter.setAppName(app.getAppName());
|
|
|
|
|
+ appRouter.setAppTitle(app.getAppTitle());
|
|
|
|
|
+ appRouter.setIcon(app.getIcon());
|
|
|
|
|
+ appRouter.setHomePath(app.getHomePath());
|
|
|
|
|
+ appRouter.setChildren(buildMenuRouters(appMenus));
|
|
|
|
|
+ return appRouter;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<RouterVo> buildMenuRouters(List<UserMenuVO> appMenus) {
|
|
|
|
|
+ List<UserMenuVO> menuTree = createTreeMenus(0L, appMenus);
|
|
|
|
|
+ List<RouterVo> routers = new ArrayList<>();
|
|
|
|
|
+ menuToRouter(menuTree, null, routers);
|
|
|
|
|
+ return routers;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private List<UserMenuVO> toUserMenuVoList(List<MenuEntity> userMenuList) {
|
|
|
|
|
+ if (CollectionUtils.isEmpty(userMenuList)) {
|
|
|
|
|
+ return Collections.emptyList();
|
|
|
|
|
+ }
|
|
|
|
|
+ List<UserMenuVO> menuls = new ArrayList<>();
|
|
|
|
|
+ userMenuList.forEach(menu -> {
|
|
|
|
|
+ UserMenuVO menuVo = new UserMenuVO();
|
|
|
|
|
+ BeanUtils.copyProperties(menu, menuVo);
|
|
|
|
|
+ if (StrUtil.isNotBlank(menuVo.getMenuName())) {
|
|
|
|
|
+ menuVo.setIcon(PingyinUtil.getLowFullSpell(menuVo.getMenuName()));
|
|
|
|
|
+ }
|
|
|
|
|
+ menuls.add(menuVo);
|
|
|
|
|
+ });
|
|
|
|
|
+ return menuls;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 是否为parent_view组件
|
|
* 是否为parent_view组件
|
|
|
*/
|
|
*/
|