From 29d76d56b5538d79eb1092104034e916af7b082e Mon Sep 17 00:00:00 2001 From: FLYPHT <1035748121@qq.com> Date: Fri, 9 Sep 2022 15:11:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=98=E7=9A=84=E6=9D=83=E9=99=90=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/design/preview/PreviewMenuTreeService.java | 26 +++++++++++++++++----- .../bpm/web/sys/user/menuPlan/MenuPlanContent.java | 17 +++++++++++++- .../bpm/web/sys/user/menuPlan/MenuPlanItem.java | 12 ++++++++++ .../system/bpm/web/sys/user/role/RoleHelper.java | 10 +++++++++ 4 files changed, 58 insertions(+), 7 deletions(-) diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/preview/PreviewMenuTreeService.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/preview/PreviewMenuTreeService.java index 84162c7..1f9b501 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/preview/PreviewMenuTreeService.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/design/preview/PreviewMenuTreeService.java @@ -34,9 +34,14 @@ public class PreviewMenuTreeService { public R treeAll(@SwParam("module") String module, UserSession us) { String prj_id = ModelProjectCache.getInstance().getIdByModule(module); if (!SwConsts.SysParam.SYS_DEBUG) { - List menuVOList = buildMenu(prj_id, module, us); + MenuVO home = new MenuVO(); + List menuVOList = buildMenu(prj_id, module, us,home); if (!CommUtil.isEmpty(menuVOList)) { - return R.success(menuVOList); + R r = R.success(menuVOList); + if(home.getId()>0){ + r.put("home",home); + } + return r; }else { return R.success(new ArrayList<>()); } @@ -76,11 +81,10 @@ public class PreviewMenuTreeService { root.setPath(module); root.setId(-1L); List data = TreeDataUtil.buildTree(root, list, MenuVO.createTreeHandler()); - - return R.success(data); + return R.success(data); } - public List buildMenu(String prj_id, String module, UserSession us) { + public List buildMenu(String prj_id, String module, UserSession us,MenuVO home) { Set set = RoleHelper.getMenuPlans(us.getUserId(),us.getPartyId()); if (CommUtil.isEmpty(set)) { return new ArrayList<>(); @@ -89,8 +93,18 @@ public class PreviewMenuTreeService { MenuPlanContent mpc = new MenuPlanContent(menuPlan.getContent()); List list = new ArrayList<>(); Set rightMenuIds = RoleHelper.getRoleMenuIds(us.getUserId() , us.getPartyId(),menuPlan.getId(), true); + for(MenuPlanItem item : mpc.getHomeList()){ + long id = item.getId(); + if(rightMenuIds.contains(id)){ + home.setId(item.getId()); + home.setName(item.getLabel()); + home.setIcon(item.getIcon()); + home.setPath(MenuCache.getInstance().getPath(item.getMenu())); + break; + } + } for (MenuPlanItem mp : mpc.getChildren(0)) { - List menuVOList = buildMenuWithRight(-1, mp,rightMenuIds); + List menuVOList = RoleHelper.isAdmin(us.getUserId())? buildMenu(-1,mp):buildMenuWithRight(-1, mp,rightMenuIds); if (menuVOList == null) continue; list.addAll(menuVOList); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanContent.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanContent.java index d3dd293..c762580 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanContent.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanContent.java @@ -75,6 +75,7 @@ public class MenuPlanContent { oldItem.setMenu(item.getMenu()); oldItem.setIcon(item.getIcon()); oldItem.setSeq(item.getSeq()); + oldItem.setHome(item.getHome()); } } @@ -122,7 +123,21 @@ public class MenuPlanContent { MenuPlanItem parent = findById(parentId); return parent == null ? new ArrayList<>(): parent.getChildren(); } - + // 获取主页 + public List getHomeList(){ + List homeList = new ArrayList<>(); + findHome(list,homeList); + return homeList; + } + private void findHome(List source,List homeList){ + if(CommUtil.isEmpty(source))return; + for(MenuPlanItem item: source){ + if(item.getHome() == 1){ + homeList.add(item); + } + findHome(item.getChildren(),homeList); + } + } private MenuPlanItem findById(long id, List itemList) { if (CommUtil.isEmpty(itemList)) { return null; diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanItem.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanItem.java index e9d275f..fda1d80 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanItem.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/menuPlan/MenuPlanItem.java @@ -80,7 +80,19 @@ public class MenuPlanItem extends BaseBean { public void setSeq(int seq) { put("seq", seq); } + /** + * 排序码 + */ + public int getHome() { + return getInt("home"); + } + /** + * 排序码 + */ + public void setHome(int home) { + put("home", home); + } public void setChildren(List children) { put("children", children); } diff --git a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleHelper.java b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleHelper.java index 71d41ec..a468715 100644 --- a/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleHelper.java +++ b/smtweb-framework/bpm/src/main/java/cc/smtweb/system/bpm/web/sys/user/role/RoleHelper.java @@ -4,6 +4,8 @@ import cc.smtweb.system.bpm.web.sys.user.menuPlan.MenuPlan; import cc.smtweb.system.bpm.web.sys.user.menuPlan.MenuPlanCache; import cc.smtweb.system.bpm.web.sys.user.menuPlan.MenuPlanContent; import cc.smtweb.system.bpm.web.sys.user.menuPlan.MenuPlanItem; +import cc.smtweb.system.bpm.web.sys.user.user.User; +import cc.smtweb.system.bpm.web.sys.user.user.UserCache; import cc.smtweb.system.bpm.web.sys.user.user.UserRoleCache; import java.util.HashSet; @@ -16,6 +18,14 @@ import java.util.Set; * @Desc: 角色辅助类 */ public final class RoleHelper { + public static boolean isAdmin(long userId){ + if(userId ==1L) return true; + User user = UserCache.getInstance().get(userId); + if(user!=null){ + return "admin".equalsIgnoreCase(user.getNicky()); + } + return false; + } /** * 获取角色权限 * @param userId 用户ID