123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720 |
- /***************************************************
- * Copyright 2014-7-23, -sinosoft.com.cn All rights reserved.
- *【创建日期】 : 2014-7-23
- *【创建人】 : 徐杨
- *【类名】:SysCustomMenuService.java
- *【功能】:本类是菜单角色自定义服务实现类
- *【修改日志】
- * --------------------------------------------------
- * VERSION DATE 修改人 修改内容
- * --------------------------------------------------
- * 1.0 2014-7-23
- * --------------------------------------------------
- **************************************************/
- package com.sinosoft.lz.system.menu.service;
- import java.io.UnsupportedEncodingException;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.List;
- import java.util.Map;
- import java.util.Set;
- import javax.ws.rs.POST;
- import javax.ws.rs.Path;
- import javax.ws.rs.ProduceMime;
- import net.sf.json.JSONArray;
- import org.apache.log4j.Logger;
- import com.formaction.Utils;
- import com.formaction.dao.OperateAble;
- import com.formaction.dao.OperateImpl;
- import com.formaction.vo.Msg;
- import com.google.gson.Gson;
- import com.persistence.DbConnection;
- import com.persistence.service.assitant.DataObject;
- import com.persistence.service.assitant.Field;
- import com.persistence.service.assitant.generator.IdentityGenerator;
- import com.persistence.service.exception.PersistenceException;
- import com.persistence.service.exception.TransformTypeException;
- import com.sinosoft.common.excel.JsonPluginsUtil;
- import com.sinosoft.lz.system.menu.dao.ISysCustomMenuDao;
- import com.sinosoft.lz.system.menu.dao.SysCustomMenuDaoImpl;
- import com.sinosoft.lz.system.menu.vo.CustomTreeNodeVO;
- import com.sinosoft.lz.system.menu.vo.CustomTreeVO;
- import com.sinosoft.lz.system.menu.vo.IndexMenu;
- import com.sinosoft.lz.system.menu.vo.SysMenu;
- import com.sinosoft.lz.system.positiontab.service.PositionTabService;
- import com.sinosoft.lz.system.util.JsonUtil;
- import com.sinosoft.lz.system.util.tree.TreeNode;
- @Path("/SysCustomMenuService/")
- public class SysCustomMenuService {
-
- private final static Logger log = Logger.getLogger(SysCustomMenuService.class);
-
- private List showMenuList = new ArrayList();
- @ProduceMime("application/json")
- @POST
- @Path("/getShowMenuInfoByRoleIds/")
- public String getShowMenuInfoByRoleIds(String params){
- String roleids = Utils.getParameter("roleids", params) == null ?
- "" : Utils.getParameter("roleids", params);
- log.info("角色IDS-----------:"+roleids);
- String[] rids = null;
- if(roleids!=null&&!"".equals(roleids)){
- rids = roleids.split(",");
- String ins = "";
- for(int i=0;i<rids.length;i++){
- ins += "?,";
- }
- ins = ins.substring(0, ins.lastIndexOf(","));
-
- StringBuffer sql =new StringBuffer();
- sql.append(" select distinct m.fd_objectid,m.menu_id,m.menu_name,m.menu_url,m.parent_menu_id,m.menu_info,m.sortno,m.menu_statu,m.is_leaf,m.in_control,m.is_del,m.mod_date,m.menu_img");
- sql.append(" from sys_menu m , sys_role_right_rel r where m.menu_id = r.menu_id and r.role_id in ( ");
- sql.append(ins+" ) and m.is_del='0'");
- sql.append(" order by m.sortno");
- log.info(sql.toString());
- DbConnection dbConn = new DbConnection();
- Connection conn = null;
- PreparedStatement pstm = null;
- ResultSet rs = null;
- List<SysMenu> menuList = new ArrayList<SysMenu>();
- try{
- conn = dbConn.getConnection();
- pstm = conn.prepareStatement(sql.toString());
- for(int i=0;i<rids.length;i++){
- //ins += "?,";
- pstm.setString(i+1, rids[i]);
- }
- rs = pstm.executeQuery();
- while(rs.next()){
- SysMenu menu = new SysMenu();
- menu.setFd_objectid(rs.getString("fd_objectid"));
- menu.setMenu_id(rs.getString("menu_id"));
- menu.setMenu_name(rs.getString("menu_name"));
- menu.setMenu_url(rs.getString("menu_url"));
- menu.setParent_menu_id(rs.getString("parent_menu_id"));
- menu.setMenu_info(rs.getString("menu_info"));
- menu.setSortno(rs.getString("sortno"));
- menu.setMenu_statu(rs.getString("menu_statu"));
- menu.setIs_leaf(rs.getString("is_leaf"));
- menu.setIn_control(rs.getString("in_control"));
- menu.setIs_del(rs.getString("is_del"));
- menu.setMod_date(rs.getString("mod_date"));
- menu.setMenu_img(rs.getString("menu_img"));
- menuList.add(menu);
- }
- return menuList2Json(menuList);
- }catch(Exception e){
- log.error("查询菜单错误"+e.getMessage());
-
- }finally{
- try {
- rs.close();
- pstm.close();
- conn.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- log.error("关闭数据库连接错误:"+e.getMessage());
- }
- }
- }
- return "";
- //return "[{\"name\":\"sy\",\"submenu\":[{\"name\":\"应急组织机构管理\",\"submenu\":[{\"name\":\"应急组织结构维护\"},{\"name\":\"应急组织结构查询\"}]},{\"name\":\"应急制度规范文件管理\",\"submenu\":[{\"name\":\"应急制度规范文件维护\"},{\"name\":\"应急制度规范文件查询\"}]},{\"name\":\"应急预案管理\",\"submenu\":[{\"name\":\"预案模板管理\"},{\"name\":\"应急预案维护\"},{\"name\":\"应急预案查询\"}]},{\"name\":\"应急预案管理\",\"submenu\":[{\"name\":\"预案模板管理\"},{\"name\":\"应急预案维护\"},{\"name\":\"应急预案查询\"}]}]},{\"name\":\"xtgn\",\"submenu\":[{\"name\":\"应急组织机构管理\",\"submenu\":[{\"name\":\"应急组织结构维护\"},{\"name\":\"应急组织结构查询\"}]},{\"name\":\"应急制度规范文件管理\",\"submenu\":[{\"name\":\"应急制度规范文件维护\"},{\"name\":\"应急制度规范文件查询\"}]},{\"name\":\"应急预案管理\",\"submenu\":[{\"name\":\"预案模板管理\"},{\"name\":\"应急预案维护\"},{\"name\":\"应急预案查询\"}]},{\"name\":\"应急预案管理\",\"submenu\":[{\"name\":\"预案模板管理\"},{\"name\":\"应急预案维护\"},{\"name\":\"应急预案查询\"}]}]},{\"name\":\"xtgl\",\"submenu\":[{\"name\":\"应急组织机构管理\",\"submenu\":[{\"name\":\"应急组织结构维护\"},{\"name\":\"应急组织结构查询\"}]},{\"name\":\"应急制度规范文件管理\",\"submenu\":[{\"name\":\"应急制度规范文件维护\"},{\"name\":\"应急制度规范文件查询\"}]},{\"name\":\"应急预案管理\",\"submenu\":[{\"name\":\"预案模板管理\"},{\"name\":\"应急预案维护\"},{\"name\":\"应急预案查询\"}]},{\"name\":\"应急预案管理\",\"submenu\":[{\"name\":\"预案模板管理\"},{\"name\":\"应急预案维护\"},{\"name\":\"应急预案查询\"}]}]},{\"name\":\"yb\"},{\"name\":\"db\"}]";
- }
-
- @ProduceMime("application/json")
- @POST
- @Path("/getIndexMenuByRoleIds/")
- public String getIndexMenuByRoleIds(String params){
- String roleids = Utils.getParameter("roleids", params) == null ?
- "" : Utils.getParameter("roleids", params);
- log.info("角色IDS-----------:"+roleids);
- if(roleids!=null&&!"".equals(roleids)){
- SysCustomMenuDaoImpl mDao = new SysCustomMenuDaoImpl();
- List<Map<String,Object>> mList = new ArrayList<Map<String,Object>>();
-
- Map<String,Object> rcMap = new HashMap<String,Object>();
- rcMap.put("display","日常管理");
- List<SysMenu> rcList = mDao.getIndexMenu("3", roleids);
- rcMap.put("value",rcList);
- mList.add(rcMap);
-
- Map<String,Object> czMap = new HashMap<String,Object>();
- czMap.put("display","应急处置");
- List<SysMenu> czList = mDao.getIndexMenu("4", roleids);
- czMap.put("value",czList);
- mList.add(czMap);
-
- Map<String,Object> bgdMap = new HashMap<String,Object>();
- bgdMap.put("display","保供电");
- List<SysMenu> bgdList = mDao.getIndexMenu("5", roleids);
- bgdMap.put("value",bgdList);
- mList.add(bgdMap);
-
- Map<String,Object> sysMap = new HashMap<String,Object>();
- sysMap.put("display","系统管理");
- List<SysMenu> sysList = mDao.getIndexMenu("9", roleids);
- sysMap.put("value",sysList);
- mList.add(sysMap);
-
- String menuStr = JsonPluginsUtil.listToJson(mList);
- log.info(menuStr);
- return menuStr;
- }
- return JsonUtil.string2json("");
- }
-
- @ProduceMime("application/json")
- @POST
- @Path("/queryIndexMenu/")
- public String queryIndexMenu(String params){
- String roleids = Utils.getParameter("roleids", params) == null ?
- "" : Utils.getParameter("roleids", params);
- String menuName = Utils.getParameter("menuName", params) == null ?
- "" : Utils.getParameter("menuName", params);
- log.info("角色IDS-----------:"+roleids);
- if(roleids!=null&&!"".equals(roleids)){
- SysCustomMenuDaoImpl mDao = new SysCustomMenuDaoImpl();
- List<Map<String,Object>> mList = new ArrayList<Map<String,Object>>();
- List<SysMenu> spList = mDao.queryIndexMenu(menuName, roleids);
- List<SysMenu> sbList = mDao.queryIndexSubMenu(menuName, roleids);
- for(int i=0;i<spList.size();i++){
- SysMenu spMenu = spList.get(i);
- Map<String,Object> rcMap = new HashMap<String,Object>();
- rcMap.put("display",spMenu.getMenu_name());
- List<SysMenu> rcList = new ArrayList<SysMenu>();
- for(int j=0;j<sbList.size();j++){
- SysMenu sbMenu = sbList.get(j);
- if(sbMenu.getParent_menu_id().equals(spMenu.getMenu_id())){
- rcList.add(sbMenu);
- }
-
- }
- rcMap.put("value",rcList);
- mList.add(rcMap);
- }
-
- String menuStr = JsonPluginsUtil.listToJson(mList);
- log.info(menuStr);
- return menuStr;
- }
- return "";
- }
-
-
- /**
- * 根据url查询菜单信息;若有菜单信息,继续根据menu_id查询页签信息
- * @param params
- * @return
- */
- @SuppressWarnings("resource")
- @ProduceMime("html/text")
- @POST
- @Path("/getMenuInfoByUrl/")
- public String getMenuInfoByUrl(String params){
- String frmsrc = Utils.getParameter("frmsrc", params) == null ?
- "" : Utils.getParameter("frmsrc", params);
- String userId = Utils.getParameter("userId", params) == null ? "" : Utils
- .getParameter("userId", params);
- frmsrc = frmsrc.trim();
- String sql = "select MENU_IMG MENU_IMG,MENU_ID,MENU_NAME from SYS_MENU where TRIM(BOTH ' ' FROM menu_url)=? and is_del='0' ";
- DbConnection dbConn = new DbConnection();
- Connection conn = null;
- PreparedStatement pstm = null;
- ResultSet rs = null;
- StringBuffer sb = new StringBuffer();
- sb.append("[{");
- try{
- conn = dbConn.getConnection();
- pstm = conn.prepareStatement(sql);
- pstm.setString(1, frmsrc);
- rs = pstm.executeQuery();
- String imgClass = "";
- String menu_id = "";
- String menu_name = "";
- while(rs.next()){
- imgClass = rs.getString("MENU_IMG");
- menu_id = rs.getString("MENU_ID");
- menu_name = rs.getString("MENU_NAME");
- }
- if("".equals(menu_id)){//如果在sys_menu(菜单主表)中没有数据,判断是否是带有页签的页面,故再去页签表EMC_AM_YQSJCLB去查数据
- String sql1 = "select MENU_IMG MENU_IMG,MENU_ID,MENU_NAME from SYS_MENU where menu_id=(select YO_CDID from EMC_AM_YQSJCLB where TRIM(BOTH ' ' FROM YQ_SRC)=?)";
- pstm = conn.prepareStatement(sql1);
- pstm.setString(1, frmsrc);
- rs = pstm.executeQuery();
- while(rs.next()){
- imgClass = rs.getString("MENU_IMG");
- menu_id = rs.getString("MENU_ID");
- menu_name = rs.getString("MENU_NAME");
- }
- }
-
- sb.append("\"menuData\":{\"imgClass\":\""+imgClass+"\",\"menu_id\":\""+menu_id+"\",\"menu_name\":\""+menu_name+"\"}}");
- if(!"".equals(menu_id)){
- PositionTabService pt = new PositionTabService();
- params = "menuId="+menu_id+"&userId="+userId+"&frmsrc="+frmsrc;
- String tabData = pt.getTabById(params);
- sb.append(",{\"tabData\":"+tabData+"}");
- }
- sb.append("]");
- return sb.toString();
- }catch(Exception e){
- log.error("查询图标错误"+e.getMessage());
-
- }finally{
- try {
- rs.close();
- pstm.close();
- conn.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- log.error("关闭数据库连接错误:"+e.getMessage());
- }
- }
- return "";
- }
-
- public String menuList2Json(List menuList){
- TreeNode root = new TreeNode("0", "0", "root", "root","","");
- TreeNode treeNode = getTreeNode(root,menuList);
- JSONArray obj = JSONArray.fromObject(root.getSubmenu());;
- log.info(obj.toString());
- return obj.toString();
- }
-
- public TreeNode getTreeNode(TreeNode node,List menuList){
- for(int i=0;i<menuList.size();i++){
- SysMenu menu = (SysMenu)menuList.get(i);
- if(menu.getParent_menu_id().equals(node.getId())){
- TreeNode tNode = new TreeNode(menu.getMenu_id(),menu.getParent_menu_id(),menu.getMenu_name(),menu.getMenu_url(),menu.getSortno(),menu.getMenu_img());
- TreeNode cNode = getTreeNode(tNode,menuList); //递归添加节点
- node.add(cNode);
- }
- }
- return node;
- }
-
-
- /**
- * 新增工作台菜单
- * 若该用户该菜单工作台菜单表中已存在,只是被移除,则将移除状态改成使用
- * 即state=0为使用 state=1为移除
- * @param params
- * @return
- */
- @POST
- @ProduceMime("application/json")
- @Path("/addIndexMenu/")
- public String addIndexMenu(String params){
- String result = JsonUtil.string2json("");
- SysCustomMenuDaoImpl mDao = new SysCustomMenuDaoImpl();
- String menu_id = Utils.getParameter("menu_id", params) == null ? "" : Utils.getParameter("menu_id", params);
- String user_id = Utils.getParameter("user_id", params) == null ? "" : Utils.getParameter("user_id", params);
- if(checkAddMenu(user_id,menu_id)){
- List<IndexMenu> list = mDao.queryIndexMenu(user_id);
- result = JsonPluginsUtil.listToJson(list);
- }else{
- String menu_name = Utils.getParameter("menu_name", params) == null ? "" : Utils.getParameter("menu_name", params);
- String menu_url = Utils.getParameter("menu_url", params) == null ? "" : Utils.getParameter("menu_url", params);
- String menu_img_url = Utils.getParameter("menu_img_url", params) == null ? "" : Utils.getParameter("menu_img_url", params);
- //String state = Utils.getParameter("state", params) == null ? "" : Utils.getParameter("state", params);
- String sort = Utils.getParameter("sort", params) == null ? "" : Utils.getParameter("sort", params);
- //封装一条数据
- IndexMenu indexMenu = new IndexMenu();
- indexMenu.setFD_OBJECTID(IdentityGenerator.getIdentityGenerator().gerenalIdentity(394));
- indexMenu.setBUSINESS_URL(menu_url);
- indexMenu.setIMAGE_URL(menu_img_url);
- indexMenu.setIS_DEL("0");
- indexMenu.setSTATE("0");
- indexMenu.setCLICK_NUM(0);
- indexMenu.setTITLE_NAME(menu_name);
- indexMenu.setSORT(sort);
- indexMenu.setUSER_ID(user_id);
- Date date = new Date();
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- indexMenu.setUPDATEDAE(sdf.format(date));
- indexMenu.setMENU_ID(menu_id);
- result = mDao.addIndexMenu(indexMenu);
- if("ok".equals(result)){
- List<IndexMenu> list = mDao.queryIndexMenu(user_id);
- result = JsonPluginsUtil.listToJson(list);
- }
- }
- return result;
-
- }
-
- /**
- * 用户工作台菜单使用频率计数
- * @param params
- * @return
- */
- @POST
- @ProduceMime("html/text")
- @Path("/setUserClickNum/")
- public String setUserClickNum(String params){
- String result = "error";
- SysCustomMenuDaoImpl mDao = new SysCustomMenuDaoImpl();
- String menu_id = Utils.getParameter("menu_id", params) == null ? "" : Utils.getParameter("menu_id", params);
- String user_id = Utils.getParameter("user_id", params) == null ? "" : Utils.getParameter("user_id", params);
- result = mDao.setUserClickNum(menu_id,user_id);
- log.info(user_id+"===改变=====菜单:"+menu_id+"==========="+result);
- return result;
-
- }
-
-
- /**
- * 删除工作台菜单
- * state=0为使用 state=1为移除
- * @param params
- * @return
- */
- @POST
- @ProduceMime("html/text")
- @Path("/deleteIndexMenu/")
- public String deleteIndexMenu(String params){
- String result = "error";
- String fd_id = Utils.getParameter("fd_id", params) == null ? "" : Utils.getParameter("fd_id", params);
- SysCustomMenuDaoImpl mDao = new SysCustomMenuDaoImpl();
- result = mDao.deleteAddMenu(fd_id);
- return result;
-
- }
-
- /**
- * 检查工作台菜单表中是否已存在该菜单,若存在则将其状态state改成1
- * 即使用状态
- * @param menu_id
- * @param user_id
- * @return
- */
- private boolean checkAddMenu(String user_id, String menu_id) {
- boolean flag = false;
- int result = 0;
- SysCustomMenuDaoImpl mDao = new SysCustomMenuDaoImpl();
- result = mDao.checkAddMenu(user_id,menu_id);
- if(result==1){
- flag = true;
- }
- return flag;
- }
- /**
- * 查询个人偏好菜单
- * @param params
- * @return
- */
- @POST
- @ProduceMime("application/json")
- @Path("/queryIndexMenuByroleId/")
- public String queryIndexMenuByroleId(String params){
- String user_id = Utils.getParameter("user_id", params) == null ?
- "" : Utils.getParameter("user_id", params);
- String moduleStr = "{\"state\":\"ok\",\"length\":0,\"resultData\":\"[]\"}";
- if(user_id!=null&&!"".equals(user_id)){
- SysCustomMenuDaoImpl mDao = new SysCustomMenuDaoImpl();
- List<IndexMenu> result = mDao.queryIndexMenu(user_id);
- int len = result.size();
- String resultStr = JsonPluginsUtil.listToJson(result);
- moduleStr = "{\"state\":\"ok\",\"length\":"+len+",\"resultData\":"+resultStr+"}";
- }
- log.info(user_id+"==工作台菜单查询==:"+moduleStr);
- return moduleStr;
-
- }
-
-
-
- /**
- * 功能:根据角色查询出功能菜单树的信息
- * @param roleid 角色编号
- */
- @SuppressWarnings("unchecked")
- @POST
- @ProduceMime("application/json")
- @Path("/getMenuTreeByRoleId/")
- public String getMenuTreeByRoleId(String params){
- //获取角色id
- String roleid = Utils.getParameter("roleid", params) == null ? "" : Utils.getParameter("roleid", params);
- String isAdmin = Utils.getParameter("isAdmin", params) == null ? "" : Utils.getParameter("isAdmin", params);
-
- ISysCustomMenuDao dao = new SysCustomMenuDaoImpl();
-
- //如果角色值为ADMIN_ROLEID常量的值,则表明是管理员角色,查出所有权限
- List<Map<String, String>> list = null;
-
- //查询左边树数据
- if("1".equals(isAdmin)){
-
- list = dao.loadMenuInfo();
-
- log.info("-- "+JSONArray.fromObject(list).toString());
-
- return JSONArray.fromObject(list).toString().toLowerCase();
-
- }else{
-
- list = dao.loadMenuInfoByRoleId(roleid);
-
- //处理数据
- Set set = processData(list);
-
- log.info("--- "+JSONArray.fromObject(set).toString());
-
- return JSONArray.fromObject(set).toString().toLowerCase();
-
- }
-
- }
-
- /**
- * 功能:根据角色查询出自定义菜单显示树的信息
- * @param roleid 角色编号
- */
- @SuppressWarnings("unchecked")
- @POST
- @ProduceMime("application/json")
- @Path("/getCustomTreeByRoleId/")
- public String getCustomTreeByRoleId(String params){
- //获取角色id
- String roleid = Utils.getParameter("roleid", params) == null ?
- "" : Utils.getParameter("roleid", params);
- log.info("----- "+roleid);
- ISysCustomMenuDao dao = new SysCustomMenuDaoImpl();
-
- List<Map<String, String>> list = null;
-
- //查询右边树数据
- list = dao.loadCustomMenuInfoByRoleId(roleid);
-
- log.info(JSONArray.fromObject(list).toString());
-
- return JSONArray.fromObject(list).toString().toLowerCase();
- }
-
- /**
- * 功能:根据角色复制菜单权限
- * @param params
- */
- @POST
- @ProduceMime("application/json")
- @Path("/grantMenu")
- public Msg grantMenu(String params){
- Gson gson = new Gson();
- ISysCustomMenuDao dao = new SysCustomMenuDaoImpl();
- OperateAble persistence = new OperateImpl();
- DataObject dataObject = null;
-
- Msg msg = null;
- log.info("params--- "+params);
- try {
- params = java.net.URLDecoder.decode(params, "utf-8");
- CustomTreeVO customTree = gson.fromJson(params, CustomTreeVO.class);
-
- //保存数据之前,先删除数据
- dao.clearCustomMenuByRoleId(customTree.getRoleid());
-
- //模型方式保存数据
- for(CustomTreeNodeVO ct : customTree.getNodes()){
- dataObject = new DataObject();
-
- /* dataObject.setClassid(892);
-
- //为保证SYS_CUSTOM_MENU表中的id和pid的值不与实际功能菜单中的id和pid的值冲突,故要做规则处理
- dataObject.addAttribute(new Field("id", ct.getId()));
- dataObject.addAttribute(new Field("pid", "null".equals(ct.getPid()) ? "10" : ct.getPid()));
-
- dataObject.addAttribute(new Field("roleid", customTree.getRoleid()));
- dataObject.addAttribute(new Field("name", "null".equals(ct.getName()) ? "" : ct.getName()));
- dataObject.addAttribute(new Field("sort", "null".equals(ct.getSort()) ? "" : ct.getSort()));
- dataObject.addAttribute(new Field("type", "null".equals(ct.getType()) ? "" : ct.getType()));
- dataObject.addAttribute(new Field("handler", "null".equals(ct.getHandler()) ? "" : ct.getHandler()));
-
- //如果handler和type值都为”1“, 则表明该菜单项是可显示的功能菜单,所有要关联实际功能菜单的id值
- if("1".equals(ct.getHandler()) && "1".equals(ct.getType())){
- dataObject.addAttribute(new Field("menuid", ct.getId()));
- }*/
- dataObject.setClassid(886);
-
- //为保证SYS_CUSTOM_MENU表中的id和pid的值不与实际功能菜单中的id和pid的值冲突,故要做规则处理
- // dataObject.addAttribute(new Field("FD_OBJECTID", customTree.getRoleid()+ct.getId()));
- dataObject.addAttribute(new Field("ROLE_ID", customTree.getRoleid()));
- dataObject.addAttribute(new Field("MENU_ID", ct.getId()));
- dataObject.addAttribute(new Field("IS_DEL", "0"));
- log.info("-------------");
- msg = persistence.createDataObject(dataObject);
- }
- } catch (UnsupportedEncodingException e) {
- log.error(e);
- } catch (TransformTypeException e) {
- log.error(e);
- } catch (PersistenceException e) {
- log.error(e);
- }
-
- return msg;
- }
-
- /**
- * 功能:根据角色获取显示菜单数据
- * @return
- */
- @POST
- @ProduceMime("application/json")
- @Path("/getShowMenuInfoByRoleId")
- public String getShowMenuInfoByRoleId(String params){
- String roleid = Utils.getParameter("roleid", params) == null ?
- "" : Utils.getParameter("roleid", params);
- String nodeId = Utils.getParameter("nodeid", params) == null ?
- "10" : Utils.getParameter("nodeid", params);
-
- ISysCustomMenuDao dao = new SysCustomMenuDaoImpl();
-
- List retList = new ArrayList();
-
- //把菜单数据全部读到内存中
- showMenuList = dao.loadShowMenuInfoByRoleId(roleid);
-
- retList = findChildren(nodeId);
-
- log.info(JSONArray.fromObject(retList).toString().toLowerCase());
-
- return JSONArray.fromObject(retList).toString();
- };
-
-
- /**
- * 功能:根据权限过滤功能菜单
- * @param list 源数据集
- * @return Set 结果数据集
- */
- private Set processData(List<Map<String, String>> list) {
- Set<Map<String, String>> set = new HashSet<Map<String, String>>();
- if(list != null){
-
- for(int i = 0, len = list.size(); i < len; i++){
-
- Map<String, String> entry = list.get(i);
- String value = entry.get("menuid");
-
- if(value == null) continue;
-
- if("".equals(value)) continue;
-
- if("null".equals(value)) continue;
-
- set.add(entry);
-
- this.findParent(set, list, entry);
- }
- }
- return set;
- }
-
- /**
- * 功能:递归查询父节点
- * @param list
- * @param srcList
- * @param value
- */
- private void findParent(Set<Map<String, String>> list,
- List<Map<String, String>> srcList,
- Map<String, String> value){
-
- for(int i = 0, len = srcList.size(); i < len; i++){
-
- Map<String, String> entry = srcList.get(i);
-
- if(value.get("pid").equals(entry.get("id"))){
-
- list.add(entry);
-
- this.findParent(list, srcList, entry);
-
- }
- }
-
- }
-
- /***
- * 递归查询显示菜单的树形结构数据
- * 算法思路:先把所有的数据查询出来并放到内存中,再进行递归查询
- * @param nodeId 当前节点的id
- * @return
- */
- private List findChildren(String nodeId){
-
- List list = new ArrayList();
-
- if(showMenuList.size() > 0){
-
- for(int i = 0, len = showMenuList.size(); i < len; i++){
-
- Map entry = (Map)showMenuList.get(i);
- //获取pid
- String pid = (String)entry.get("PID");
- //获取id
- String id = (String)entry.get("ID");
- //如果该条数据等于pid,则加入集合当中
- if(nodeId.equals(pid)){
-
- entry.put("leaf", (this.isLeaf(id)));
-
- entry.put("children", findChildren(id));
-
- list.add(entry);
-
- }
-
-
- }
- }
-
- return list;
-
- }
-
- private boolean isLeaf(String nodeId){
- boolean flag = true;
- int n = 0;
- for(int i = 0, len = showMenuList.size(); i < len; i++){
-
- Map entry = (Map)showMenuList.get(i);
- //获取pid
- String pid = (String)entry.get("PID");
- //如果该条数据等于pid,则加入集合当中
- if(pid.equals(nodeId)){
- n++;
- }
-
- }
- if (n > 0) {
- flag = false;
- }
- return flag;
- }
-
-
- }
|