@@ -34,9 +34,14 @@ public class PreviewMenuTreeService { | |||||
public R treeAll(@SwParam("module") String module, UserSession us) { | public R treeAll(@SwParam("module") String module, UserSession us) { | ||||
String prj_id = ModelProjectCache.getInstance().getIdByModule(module); | String prj_id = ModelProjectCache.getInstance().getIdByModule(module); | ||||
if (!SwConsts.SysParam.SYS_DEBUG) { | if (!SwConsts.SysParam.SYS_DEBUG) { | ||||
List<MenuVO> menuVOList = buildMenu(prj_id, module, us); | |||||
MenuVO home = new MenuVO(); | |||||
List<MenuVO> menuVOList = buildMenu(prj_id, module, us,home); | |||||
if (!CommUtil.isEmpty(menuVOList)) { | if (!CommUtil.isEmpty(menuVOList)) { | ||||
return R.success(menuVOList); | |||||
R r = R.success(menuVOList); | |||||
if(home.getId()>0){ | |||||
r.put("home",home); | |||||
} | |||||
return r; | |||||
}else { | }else { | ||||
return R.success(new ArrayList<>()); | return R.success(new ArrayList<>()); | ||||
} | } | ||||
@@ -76,11 +81,10 @@ public class PreviewMenuTreeService { | |||||
root.setPath(module); | root.setPath(module); | ||||
root.setId(-1L); | root.setId(-1L); | ||||
List<MenuVO> data = TreeDataUtil.buildTree(root, list, MenuVO.createTreeHandler()); | List<MenuVO> data = TreeDataUtil.buildTree(root, list, MenuVO.createTreeHandler()); | ||||
return R.success(data); | |||||
return R.success(data); | |||||
} | } | ||||
public List<MenuVO> buildMenu(String prj_id, String module, UserSession us) { | |||||
public List<MenuVO> buildMenu(String prj_id, String module, UserSession us,MenuVO home) { | |||||
Set<MenuPlan> set = RoleHelper.getMenuPlans(us.getUserId(),us.getPartyId()); | Set<MenuPlan> set = RoleHelper.getMenuPlans(us.getUserId(),us.getPartyId()); | ||||
if (CommUtil.isEmpty(set)) { | if (CommUtil.isEmpty(set)) { | ||||
return new ArrayList<>(); | return new ArrayList<>(); | ||||
@@ -89,8 +93,18 @@ public class PreviewMenuTreeService { | |||||
MenuPlanContent mpc = new MenuPlanContent(menuPlan.getContent()); | MenuPlanContent mpc = new MenuPlanContent(menuPlan.getContent()); | ||||
List<MenuVO> list = new ArrayList<>(); | List<MenuVO> list = new ArrayList<>(); | ||||
Set<Long> rightMenuIds = RoleHelper.getRoleMenuIds(us.getUserId() , us.getPartyId(),menuPlan.getId(), true); | Set<Long> 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)) { | for (MenuPlanItem mp : mpc.getChildren(0)) { | ||||
List<MenuVO> menuVOList = buildMenuWithRight(-1, mp,rightMenuIds); | |||||
List<MenuVO> menuVOList = RoleHelper.isAdmin(us.getUserId())? buildMenu(-1,mp):buildMenuWithRight(-1, mp,rightMenuIds); | |||||
if (menuVOList == null) continue; | if (menuVOList == null) continue; | ||||
list.addAll(menuVOList); | list.addAll(menuVOList); | ||||
} | } | ||||
@@ -75,6 +75,7 @@ public class MenuPlanContent { | |||||
oldItem.setMenu(item.getMenu()); | oldItem.setMenu(item.getMenu()); | ||||
oldItem.setIcon(item.getIcon()); | oldItem.setIcon(item.getIcon()); | ||||
oldItem.setSeq(item.getSeq()); | oldItem.setSeq(item.getSeq()); | ||||
oldItem.setHome(item.getHome()); | |||||
} | } | ||||
} | } | ||||
@@ -122,7 +123,21 @@ public class MenuPlanContent { | |||||
MenuPlanItem parent = findById(parentId); | MenuPlanItem parent = findById(parentId); | ||||
return parent == null ? new ArrayList<>(): parent.getChildren(); | return parent == null ? new ArrayList<>(): parent.getChildren(); | ||||
} | } | ||||
// 获取主页 | |||||
public List<MenuPlanItem> getHomeList(){ | |||||
List<MenuPlanItem> homeList = new ArrayList<>(); | |||||
findHome(list,homeList); | |||||
return homeList; | |||||
} | |||||
private void findHome(List<MenuPlanItem> source,List<MenuPlanItem> 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<MenuPlanItem> itemList) { | private MenuPlanItem findById(long id, List<MenuPlanItem> itemList) { | ||||
if (CommUtil.isEmpty(itemList)) { | if (CommUtil.isEmpty(itemList)) { | ||||
return null; | return null; | ||||
@@ -80,7 +80,19 @@ public class MenuPlanItem extends BaseBean { | |||||
public void setSeq(int seq) { | public void setSeq(int seq) { | ||||
put("seq", seq); | put("seq", seq); | ||||
} | } | ||||
/** | |||||
* 排序码 | |||||
*/ | |||||
public int getHome() { | |||||
return getInt("home"); | |||||
} | |||||
/** | |||||
* 排序码 | |||||
*/ | |||||
public void setHome(int home) { | |||||
put("home", home); | |||||
} | |||||
public void setChildren(List<MenuPlanItem> children) { | public void setChildren(List<MenuPlanItem> children) { | ||||
put("children", children); | put("children", children); | ||||
} | } | ||||
@@ -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.MenuPlanCache; | ||||
import cc.smtweb.system.bpm.web.sys.user.menuPlan.MenuPlanContent; | 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.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 cc.smtweb.system.bpm.web.sys.user.user.UserRoleCache; | ||||
import java.util.HashSet; | import java.util.HashSet; | ||||
@@ -16,6 +18,14 @@ import java.util.Set; | |||||
* @Desc: 角色辅助类 | * @Desc: 角色辅助类 | ||||
*/ | */ | ||||
public final class RoleHelper { | 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 | * @param userId 用户ID | ||||