예제 #1
0
  /** 获取用户权限 */
  public Map<String, String> getUQX(Session session) {
    PageData pd = new PageData();
    Map<String, String> map = new HashMap<String, String>();
    try {
      String USERNAME = session.getAttribute(Const.SESSION_USERNAME).toString();
      pd.put(Const.SESSION_USERNAME, USERNAME);
      String ROLE_ID = userService.findByUId(pd).get("ROLE_ID").toString();

      pd.put("ROLE_ID", ROLE_ID);

      PageData pd2 = new PageData();
      pd2.put(Const.SESSION_USERNAME, USERNAME);
      pd2.put("ROLE_ID", ROLE_ID);

      pd = roleService.findObjectById(pd);

      pd2 = roleService.findGLbyrid(pd2);
      if (null != pd2) {
        map.put("FX_QX", pd2.get("FX_QX").toString());
        map.put("FW_QX", pd2.get("FW_QX").toString());
        map.put("QX1", pd2.get("QX1").toString());
        map.put("QX2", pd2.get("QX2").toString());
        map.put("QX3", pd2.get("QX3").toString());
        map.put("QX4", pd2.get("QX4").toString());

        pd2.put("ROLE_ID", ROLE_ID);
        pd2 = roleService.findYHbyrid(pd2);
        map.put("C1", pd2.get("C1").toString());
        map.put("C2", pd2.get("C2").toString());
        map.put("C3", pd2.get("C3").toString());
        map.put("C4", pd2.get("C4").toString());
        map.put("Q1", pd2.get("Q1").toString());
        map.put("Q2", pd2.get("Q2").toString());
        map.put("Q3", pd2.get("Q3").toString());
        map.put("Q4", pd2.get("Q4").toString());
      }

      map.put("adds", pd.getString("ADD_QX"));
      map.put("dels", pd.getString("DEL_QX"));
      map.put("edits", pd.getString("EDIT_QX"));
      map.put("chas", pd.getString("CHA_QX"));

      // System.out.println(map);

      this.getRemortIP(USERNAME);
    } catch (Exception e) {
      logger.error(e.toString(), e);
    }
    return map;
  }
예제 #2
0
  /** 访问系统首页 */
  @RequestMapping(value = "/main/{changeMenu}")
  public ModelAndView login_index(@PathVariable("changeMenu") String changeMenu) {
    ModelAndView mv = this.getModelAndView();
    PageData pd = new PageData();
    pd = this.getPageData();
    try {

      // shiro管理的session
      Subject currentUser = SecurityUtils.getSubject();
      Session session = currentUser.getSession();

      User user = (User) session.getAttribute(Const.SESSION_USER);
      if (user != null) {

        User userr = (User) session.getAttribute(Const.SESSION_USERROL);
        if (null == userr) {
          user = userService.getUserAndRoleById(user.getUSER_ID());
          session.setAttribute(Const.SESSION_USERROL, user);
        } else {
          user = userr;
        }
        Role role = user.getRole();
        String roleRights = role != null ? role.getRIGHTS() : "";
        // 避免每次拦截用户操作时查询数据库,以下将用户所属角色权限、用户权限限都存入session
        session.setAttribute(Const.SESSION_ROLE_RIGHTS, roleRights); // 将角色权限存入session
        session.setAttribute(Const.SESSION_USERNAME, user.getUSERNAME()); // 放入用户名

        List<Menu> allmenuList = new ArrayList<Menu>();

        if (null == session.getAttribute(Const.SESSION_allmenuList)) {
          allmenuList = menuService.listAllMenu();
          if (Tools.notEmpty(roleRights)) {
            for (Menu menu : allmenuList) {
              menu.setHasMenu(RightsHelper.testRights(roleRights, menu.getMENU_ID()));
              if (menu.isHasMenu()) {
                List<Menu> subMenuList = menu.getSubMenu();
                for (Menu sub : subMenuList) {
                  sub.setHasMenu(RightsHelper.testRights(roleRights, sub.getMENU_ID()));
                }
              }
            }
          }
          session.setAttribute(Const.SESSION_allmenuList, allmenuList); // 菜单权限放入session中
        } else {
          allmenuList = (List<Menu>) session.getAttribute(Const.SESSION_allmenuList);
        }

        // 切换菜单=====
        List<Menu> menuList = new ArrayList<Menu>();
        // if(null == session.getAttribute(Const.SESSION_menuList) ||
        // ("yes".equals(pd.getString("changeMenu")))){
        if (null == session.getAttribute(Const.SESSION_menuList) || ("yes".equals(changeMenu))) {
          List<Menu> menuList1 = new ArrayList<Menu>();
          List<Menu> menuList2 = new ArrayList<Menu>();

          // 拆分菜单
          for (int i = 0; i < allmenuList.size(); i++) {
            Menu menu = allmenuList.get(i);
            if ("1".equals(menu.getMENU_TYPE())) {
              menuList1.add(menu);
            } else {
              menuList2.add(menu);
            }
          }

          session.removeAttribute(Const.SESSION_menuList);
          if ("2".equals(session.getAttribute("changeMenu"))) {
            session.setAttribute(Const.SESSION_menuList, menuList1);
            session.removeAttribute("changeMenu");
            session.setAttribute("changeMenu", "1");
            menuList = menuList1;
          } else {
            session.setAttribute(Const.SESSION_menuList, menuList2);
            session.removeAttribute("changeMenu");
            session.setAttribute("changeMenu", "2");
            menuList = menuList2;
          }
        } else {
          menuList = (List<Menu>) session.getAttribute(Const.SESSION_menuList);
        }
        // 切换菜单=====

        if (null == session.getAttribute(Const.SESSION_QX)) {
          session.setAttribute(Const.SESSION_QX, this.getUQX(session)); // 按钮权限放到session中
        }

        // FusionCharts 报表
        //			 	String strXML = "<graph caption='前12个月订单销量柱状图' xAxisName='月份' yAxisName='值'
        // decimalPrecision='0' formatNumberScale='0'><set name='2013-05' value='4'
        // color='AFD8F8'/><set name='2013-04' value='0' color='AFD8F8'/><set name='2013-03'
        // value='0' color='AFD8F8'/><set name='2013-02' value='0' color='AFD8F8'/><set
        // name='2013-01' value='0' color='AFD8F8'/><set name='2012-01' value='0'
        // color='AFD8F8'/><set name='2012-11' value='0' color='AFD8F8'/><set name='2012-10'
        // value='0' color='AFD8F8'/><set name='2012-09' value='0' color='AFD8F8'/><set
        // name='2012-08' value='0' color='AFD8F8'/><set name='2012-07' value='0'
        // color='AFD8F8'/><set name='2012-06' value='0' color='AFD8F8'/></graph>" ;
        //			 	mv.addObject("strXML", strXML);
        // FusionCharts 报表

        // 读取websocket配置
        String strWEBSOCKET = Tools.readTxtFile(Const.WEBSOCKET); // 读取WEBSOCKET配置
        if (null != strWEBSOCKET && !"".equals(strWEBSOCKET)) {
          String strIW[] = strWEBSOCKET.split(",fh,");
          if (strIW.length == 4) {
            pd.put("WIMIP", strIW[0]);
            pd.put("WIMPORT", strIW[1]);
            pd.put("OLIP", strIW[2]);
            pd.put("OLPORT", strIW[3]);
          }
        }
        // 读取websocket配置

        mv.setViewName("system/admin/index");
        mv.addObject("user", user);
        mv.addObject("menuList", menuList);
      } else {
        mv.setViewName("system/admin/login"); // session失效后跳转登录页面
      }

    } catch (Exception e) {
      mv.setViewName("system/admin/login");
      logger.error(e.getMessage(), e);
    }
    pd.put("SYSNAME", Tools.readTxtFile(Const.SYSNAME)); // 读取系统名称
    mv.addObject("pd", pd);
    return mv;
  }