/** * 终端命令菜单 * * @return */ private String terminalCommandMenuJson() { JSONArray jsonArray = new JSONArray(); for (FuncModel root : authorizedFuncs) { // FuncModel root = (FuncModel) iterator.next(); if (root.getParentId() != 900700 || root.getDeleted()) continue; JSONObject rootJsonObject = new JSONObject(); rootJsonObject.put("id", "" + root.getEntityId()); rootJsonObject.put("text", root.getDescr()); rootJsonObject.put("icon", root.getIcon()); /** * if (this.selectUserFuncsMap.containsKey(root.getId())) rootJsonObject.put("checked", * Boolean.valueOf(true)); else { rootJsonObject.put("checked", Boolean.valueOf(false)); } */ JSONObject attributes = new JSONObject(); attributes.put("funcName", root.getFuncName()); // attributes.put("style", root.getStyle()); rootJsonObject.put("attributes", attributes); List subGroupInfos = findSubSyssFuncByParnetId(root.getEntityId()); genSubGroupsTreeJson(rootJsonObject, subGroupInfos); jsonArray.add(rootJsonObject); } return jsonArray.toString(); }
private void genSubGroupsTreeJson(JSONObject jsonObject, List<FuncModel> subSysFunc) { if (subSysFunc.size() > 0) { JSONArray jsonArray = new JSONArray(); for (int i = 0; i < subSysFunc.size(); i++) { FuncModel v = (FuncModel) subSysFunc.get(i); if (v.getDeleted()) continue; JSONObject jsonObjectChild = new JSONObject(); jsonObjectChild.put("id", "" + v.getEntityId()); jsonObjectChild.put("icon", v.getIcon()); jsonObjectChild.put("text", v.getDescr()); // getText("menu." + // v.getId())); /** * if ((this.selectUserFuncsMap.containsKey(v.getId())) && (v.getLevel() != * SysFunc.LEVEL_GROUT)) { jsonObjectChild.put("checked", Boolean.valueOf(true)); } else * jsonObjectChild.put("checked", Boolean.valueOf(false)); */ JSONObject attributes = new JSONObject(); attributes.put("funcName", v.getFuncName()); jsonObjectChild.put("attributes", attributes); List subGroupInfosChild = findSubSyssFuncByParnetId(v.getEntityId()); genSubGroupsTreeJson(jsonObjectChild, subGroupInfosChild); jsonArray.add(jsonObjectChild); } jsonObject.put("menu", jsonArray); } }
private boolean isAuthorized(FuncModel f) { for (FuncModel fn : authorizedFuncs) { if (f.getEntityId() == fn.getEntityId() && fn.getDeleted() == false) { return true; } } return false; }
/** * 将用户分配的权限转换成主菜单的JSON数据,输出到前台 * * @param authorizedFuncs 用户分配的功能权限 * @param funcType 主菜单 * @return */ private String convertFuncsToMenu(List<FuncModel> authorizedFuncs, Integer funcType) { System.setProperty("java.util.Arrays.useLegacyMergeSort", "true"); Collections.sort( authorizedFuncs, new Comparator<FuncModel>() { public int compare(FuncModel obj1, FuncModel obj2) { return obj2.getMenuSort() - obj1.getMenuSort(); } }); String webPath = getRequest().getContextPath(); /** 查找数据库的主菜单的顶级菜单项记录,然后将功能权限作为子菜单加入到顶级菜单中,如果顶级菜单下没有权限,将忽略不显示 */ String hsql = "from FuncModel where parentId = ? and funcType = ? and deleted = ? order by menuSort"; List<FuncModel> subSysFuncs = this.getBaseService().query(hsql, new Object[] {Integer.valueOf(-1), 1, false}); JSONArray jsonArray = new JSONArray(); for (FuncModel func : subSysFuncs) { List<FuncModel> childSysFuns = findChidFuncByParentId(func.getEntityId(), authorizedFuncs); JSONObject menuItem = new JSONObject(); menuItem.put("id", "" + func.getEntityId()); menuItem.put("text", func.getDescr()); menuItem.put("icon", func.getIcon()); JSONObject attributes = new JSONObject(); attributes.put("url", func.getUrl()); menuItem.put("attributes", attributes); JSONArray childMenuItems = new JSONArray(); for (FuncModel childSysFunc : childSysFuns) { JSONObject childItem = new JSONObject(); childItem.put("id", "" + childSysFunc.getEntityId()); childItem.put("text", childSysFunc.getDescr()); childItem.put("icon", childSysFunc.getIcon()); String url = ""; if (!StringUtil.isEmpty(childSysFunc.getUrl())) { url = webPath + "/" + func.getUrl() + "/" + childSysFunc.getUrl(); } attributes = new JSONObject(); attributes.put("url", url); childItem.put("attributes", attributes); childMenuItems.add(childItem); } if (childMenuItems.size() > 0) { menuItem.put("menu", childMenuItems); jsonArray.add(menuItem); // 如果父菜单下没有子菜单,就不显示在前台 } else if (isAuthorized(func)) { jsonArray.add(menuItem); } } return jsonArray.toString(); }
public String getMapToolMenu() { JSONArray jsonArray = new JSONArray(); for (FuncModel root : authorizedFuncs) { // FuncModel root = (FuncModel) iterator.next(); if (root.getParentId() != 900200 || root.getDeleted()) continue; JSONObject rootJsonObject = new JSONObject(); rootJsonObject.put("id", "" + root.getEntityId()); rootJsonObject.put("text", root.getDescr()); rootJsonObject.put("icon", root.getIcon()); rootJsonObject.put("code", root.getFuncName()); /** * if (this.selectUserFuncsMap.containsKey(root.getId())) rootJsonObject.put("checked", * Boolean.valueOf(true)); else { rootJsonObject.put("checked", Boolean.valueOf(false)); } */ JSONObject attributes = new JSONObject(); attributes.put("funcName", root.getFuncName()); // attributes.put("style", root.getStyle()); rootJsonObject.put("attributes", attributes); jsonArray.add(rootJsonObject); } return jsonArray.toString(); }