예제 #1
0
 /**
  * 获取用户某个分类下的全部分类节点
  *
  * @param parentId 父节点编号
  * @param userId 用户登录账号
  * @return
  */
 public List<TreeModel> getTreeModels(long parentId, String actorId) {
   List<TreeModel> treeModels = new java.util.ArrayList<TreeModel>();
   SysUser user = sysUserService.findByAccount(actorId);
   if (user != null) {
     user = sysUserService.getUserPrivileges(user);
     TreeModel root = sysTreeService.findById(parentId);
     if (user.isSystemAdministrator()) {
       this.loadChildrenTreeModels(treeModels, parentId, user);
       // SysTreeQuery query = new SysTreeQuery();
       // query.treeIdLike(root.getTreeId() + "%");
       // List<SysTree> trees = sysTreeMapper.getSysTrees(query);
       // if (trees != null && !trees.isEmpty()) {
       // for (SysTree tree : trees) {
       // treeModels.add(tree);
       // }
       // }
     } else {
       this.loadChildrenTreeModels(treeModels, parentId, user);
       // SysTreeQuery query = new SysTreeQuery();
       // query.treeIdLike(root.getTreeId() + "%");
       // query.setActorId(actorId);
       // List<SysTree> trees =
       // sysTreeMapper.getTreeListByUsers(query);
       // if (trees != null && !trees.isEmpty()) {
       // for (SysTree tree : trees) {
       // treeModels.add(tree);
       // }
       // }
     }
     treeModels.remove(root);
   }
   return treeModels;
 }
예제 #2
0
 public static JSONArray listToArray(java.util.List<SysUser> list) {
   JSONArray array = new JSONArray();
   if (list != null && !list.isEmpty()) {
     for (SysUser model : list) {
       JSONObject jsonObject = model.toJsonObject();
       array.add(jsonObject);
     }
   }
   return array;
 }
예제 #3
0
  public List<SysApplication> getAccessAppList(long parentId, SysUser user) {
    long parentAppId = parentId;
    SysApplication parentApp = findById(parentId);
    if (parentApp != null) {
      parentAppId = parentApp.getNode().getId();
    }

    logger.debug("parent node:" + parentAppId);

    SysApplicationQuery query = new SysApplicationQuery();
    query.parentId(parentAppId);
    query.setLocked(0);
    List<Long> nodeIds = new java.util.ArrayList<Long>();
    nodeIds.add(-1L);

    List<SysApplication> apps = sysApplicationMapper.getSysApplicationByUserId(user.getId());
    if (apps != null && !apps.isEmpty()) {
      for (SysApplication app : apps) {
        nodeIds.add(app.getNodeId());
      }
    }
    query.nodeIds(nodeIds);

    return this.list(query);
  }
예제 #4
0
  public JSONArray getUserMenu2(long parent, String userId) {
    JSONArray array = new JSONArray();
    SysUser user = authorizeService.login(userId);
    if (user != null) {
      List<SysApplication> list = null;
      if (user.isSystemAdmin()) {
        logger.debug("#admin user="******"#user="******"#app list=" + list);
      }
      if (list != null && list.size() > 0) {
        Iterator<SysApplication> iter = list.iterator();
        while (iter.hasNext()) {
          SysApplication bean = (SysApplication) iter.next();
          if (bean.getLocked() == 1) {
            continue;
          }
          JSONObject item = new JSONObject();
          item.put("id", String.valueOf(bean.getId()));
          item.put("nodeId", bean.getNodeId());
          item.put("showMenu", bean.getShowMenu());
          item.put("sort", bean.getSort());
          item.put("description", bean.getDesc());
          item.put("name", bean.getName());
          item.put("icon", "icon-sys");
          item.put("url", bean.getUrl());

          List<SysApplication> childrenNodes = null;
          if (user.isSystemAdmin()) {
            childrenNodes = getApplicationList((int) bean.getId());
          } else {
            childrenNodes = getAccessAppList(bean.getId(), user);
          }
          if (childrenNodes != null && childrenNodes.size() > 0) { // 有子菜单
            JSONArray children = this.getUserMenu(bean.getId(), user);
            item.put("children", children);
          }

          array.put(item);
        }
      }
    }
    return array;
  }
예제 #5
0
  public String getMenu(long parent, SysUser user) {
    StringBuffer menu = new StringBuffer("");
    List<SysApplication> list = getAccessAppList(parent, user);
    if (list == null || list.isEmpty()) {
      if (user.isSystemAdmin()) {
        list = getApplicationList((int) parent);
      }
    }
    if (list != null && list.size() > 0) {
      Iterator<SysApplication> iter = list.iterator();
      while (iter.hasNext()) {
        SysApplication bean = (SysApplication) iter.next();
        menu.append("<li>");
        menu.append("<a href=\"javascript:jump('");
        // System.out.println("ContextUtil.getContextPath():"+ContextUtil.getContextPath());
        if (bean.getUrl() != null && bean.getUrl().startsWith("/")) {
          if (ApplicationContext.getContextPath() != null) {
            menu.append(ApplicationContext.getContextPath());
          }
        }
        menu.append(bean.getUrl());
        menu.append("',");
        menu.append(bean.getShowMenu());
        menu.append(");\">");
        menu.append(bean.getName()).append("</a>\n");

        List<SysApplication> sonNode = getAccessAppList(bean.getId(), user);
        if (sonNode == null || sonNode.isEmpty()) {
          if (user.isSystemAdmin()) {
            sonNode = getApplicationList((int) bean.getId());
          }
        }
        if (sonNode != null && sonNode.size() > 0) { // 有子菜单
          menu.append("<ul>");
          menu.append(getMenu(bean.getId(), user));
          menu.append("</ul>");
        }
        menu.append("</li>").append("<li></li>\n");
      }
    }
    return menu.toString();
  }
예제 #6
0
  protected void loadChildrenTreeModels(List<TreeModel> treeModels, long parentId, SysUser user) {
    List<SysApplication> list = null;
    if (user.isSystemAdmin()) {
      logger.debug("#admin user="******"#user="******"#app list=" + list);
    }
    if (list != null && list.size() > 0) {
      Iterator<SysApplication> iter = list.iterator();
      while (iter.hasNext()) {
        SysApplication bean = (SysApplication) iter.next();
        if (bean.getLocked() == 1) {
          continue;
        }
        TreeModel treeModel = new BaseTree();
        treeModel.setCode(bean.getCode());
        treeModel.setId(bean.getId());
        treeModel.setParentId(parentId);
        treeModel.setName(bean.getName());
        treeModel.setLocked(bean.getLocked());
        treeModel.setDescription(bean.getDesc());
        treeModel.setUrl(bean.getUrl());
        treeModel.setSortNo(bean.getSort());

        List<SysApplication> childrenNodes = null;
        if (user.isSystemAdmin()) {
          childrenNodes = getApplicationList((int) bean.getId());
        } else {
          childrenNodes = getAccessAppList(bean.getId(), user);
        }
        if (childrenNodes != null && childrenNodes.size() > 0) { // 有子菜单
          this.loadChildrenTreeModels(treeModels, bean.getId(), user);
        }
        treeModels.add(treeModel);
      }
    }
  }
예제 #7
0
  public static SysUser jsonToObject(JSONObject jsonObject) {
    SysUser model = new SysUser();

    if (jsonObject.containsKey("actorId")) {
      model.setActorId(jsonObject.getString("actorId"));
    }
    if (jsonObject.containsKey("account")) {
      model.setActorId(jsonObject.getString("account"));
    }
    if (jsonObject.containsKey("name")) {
      model.setName(jsonObject.getString("name"));
    }

    if (jsonObject.containsKey("evection")) {
      model.setEvection(jsonObject.getIntValue("evection"));
    }

    if (jsonObject.containsKey("gender")) {
      model.setGender(jsonObject.getIntValue("gender"));
    }

    if (jsonObject.containsKey("userType")) {
      model.setUserType(jsonObject.getIntValue("userType"));
    }

    if (jsonObject.containsKey("accountType")) {
      model.setAccountType(jsonObject.getIntValue("accountType"));
    }

    if (jsonObject.containsKey("dumpFlag")) {
      model.setDumpFlag(jsonObject.getIntValue("dumpFlag"));
    }

    if (jsonObject.containsKey("createDate")) {
      model.setCreateDate(jsonObject.getDate("createDate"));
    }

    if (jsonObject.containsKey("createBy")) {
      model.setCreateBy(jsonObject.getString("createBy"));
    }
    if (jsonObject.containsKey("updateBy")) {
      model.setUpdateBy(jsonObject.getString("updateBy"));
    }
    if (jsonObject.containsKey("updateDate")) {
      model.setUpdateDate(jsonObject.getDate("updateDate"));
    }

    if (jsonObject.containsKey("lastLoginTime")) {
      model.setLastLoginTime(jsonObject.getDate("lastLoginTime"));
    }

    if (jsonObject.containsKey("lastLoginIP")) {
      model.setLastLoginIP(jsonObject.getString("lastLoginIP"));
    }

    if (jsonObject.containsKey("remark")) {
      model.setRemark(jsonObject.getString("remark"));
    }

    if (jsonObject.containsKey("deptId")) {
      model.setDeptId(jsonObject.getInteger("deptId"));
    }

    if (jsonObject.containsKey("mail")) {
      model.setMail(jsonObject.getString("mail"));
    }

    if (jsonObject.containsKey("mobile")) {
      model.setMobile(jsonObject.getString("mobile"));
    }

    if (jsonObject.containsKey("telephone")) {
      model.setTelephone(jsonObject.getString("telephone"));
    }

    if (jsonObject.containsKey("headship")) {
      model.setHeadship(jsonObject.getString("headship"));
    }

    if (jsonObject.containsKey("superiorIds")) {
      model.setSuperiorIds(jsonObject.getString("superiorIds"));
    }

    if (jsonObject.containsKey("status")) {
      model.setStatus(jsonObject.getString("status"));
    }

    if (jsonObject.containsKey("adminFlag")) {
      model.setAdminFlag(jsonObject.getString("adminFlag"));
    }

    if (jsonObject.containsKey("userRoles")) {
      JSONArray array = jsonObject.getJSONArray("userRoles");
      if (array != null && !array.isEmpty()) {
        for (int i = 0; i < array.size(); i++) {
          JSONObject json = array.getJSONObject(i);
          SysUserRole r = SysUserRoleJsonFactory.jsonToObject(json);
          model.getUserRoles().add(r);
        }
      }
    }

    if (jsonObject.containsKey("roles")) {
      JSONArray array = jsonObject.getJSONArray("roles");
      if (array != null && !array.isEmpty()) {
        for (int i = 0; i < array.size(); i++) {
          JSONObject json = array.getJSONObject(i);
          SysRole r = SysRoleJsonFactory.jsonToObject(json);
          model.getRoles().add(r);
        }
      }
    }

    if (jsonObject.containsKey("functions")) {
      JSONArray array = jsonObject.getJSONArray("functions");
      if (array != null && !array.isEmpty()) {
        for (int i = 0; i < array.size(); i++) {
          JSONObject json = array.getJSONObject(i);
          SysFunction r = SysFunctionJsonFactory.jsonToObject(json);
          model.getFunctions().add(r);
        }
      }
    }

    if (jsonObject.containsKey("apps")) {
      JSONArray array = jsonObject.getJSONArray("apps");
      if (array != null && !array.isEmpty()) {
        for (int i = 0; i < array.size(); i++) {
          JSONObject json = array.getJSONObject(i);
          SysApplication r = SysApplicationJsonFactory.jsonToObject(json);
          model.getApps().add(r);
        }
      }
    }

    return model;
  }
예제 #8
0
  public static ObjectNode toObjectNode(SysUser user) {
    ObjectNode jsonObject = new ObjectMapper().createObjectNode();

    jsonObject.put("actorId", user.getAccount());
    jsonObject.put("actorId_enc", RequestUtils.encodeString(user.getAccount()));
    jsonObject.put("userId", user.getAccount());
    jsonObject.put("userId_enc", RequestUtils.encodeString(user.getAccount()));

    jsonObject.put("name", user.getName());
    jsonObject.put("locked", user.getStatus());
    jsonObject.put("status", user.getStatus());

    if (user.getDepartment() != null) {
      jsonObject.put("deptId", user.getDepartment().getId());
      jsonObject.put("deptName", user.getDepartment().getName());
    } else {
      jsonObject.put("deptId", user.getDeptId());
    }

    jsonObject.put("accountType", user.getAccountType());
    jsonObject.put("userType", user.getUserType());
    jsonObject.put("dumpFlag", user.getDumpFlag());
    jsonObject.put("gender", user.getGender());
    jsonObject.put("evection", user.getEvection());
    jsonObject.put("superiorIds", user.getSuperiorIds());

    jsonObject.put("fax", user.getFax());
    jsonObject.put("telephone", user.getTelephone());
    jsonObject.put("headship", user.getHeadship());
    jsonObject.put("adminFlag", user.getAdminFlag());

    if (user.getEmail() != null) {
      jsonObject.put("mail", user.getEmail());
      jsonObject.put("email", user.getEmail());
    }
    if (user.getMobile() != null) {
      jsonObject.put("mobile", user.getMobile());
    }
    if (user.getLastLoginTime() != null) {
      jsonObject.put("lastLoginDate", DateUtils.getDateTime(user.getLastLoginDate()));
      jsonObject.put("lastLoginTime", DateUtils.getDateTime(user.getLastLoginDate()));
    }
    if (user.getLastLoginIP() != null) {
      jsonObject.put("loginIP", user.getLastLoginIP());
    }

    if (user.getCreateBy() != null) {
      jsonObject.put("createBy", user.getCreateBy());
    }
    if (user.getUpdateBy() != null) {
      jsonObject.put("updateBy", user.getUpdateBy());
    }
    if (user.getUpdateDate() != null) {
      jsonObject.put("updateDate", DateUtils.getDate(user.getUpdateDate()));
      jsonObject.put("updateDate_date", DateUtils.getDate(user.getUpdateDate()));
      jsonObject.put("updateDate_datetime", DateUtils.getDateTime(user.getUpdateDate()));
    }

    if (user.getUserRoles() != null && !user.getUserRoles().isEmpty()) {
      ArrayNode array = new ObjectMapper().createArrayNode();
      for (SysUserRole sysUserRole : user.getUserRoles()) {
        array.add(sysUserRole.toObjectNode());
      }
      jsonObject.set("userRoles", array);
    }

    if (user.getRoles() != null && !user.getRoles().isEmpty()) {
      ArrayNode array = new ObjectMapper().createArrayNode();
      for (SysRole sysRole : user.getRoles()) {
        array.add(sysRole.toObjectNode());
      }
      jsonObject.set("roles", array);
    }

    if (user.getFunctions() != null && !user.getFunctions().isEmpty()) {
      ArrayNode array = new ObjectMapper().createArrayNode();
      for (SysFunction sysFunction : user.getFunctions()) {
        array.add(sysFunction.toObjectNode());
      }
      // jsonObject.set("functions", array);
    }

    if (user.getApps() != null && !user.getApps().isEmpty()) {
      ArrayNode array = new ObjectMapper().createArrayNode();
      for (SysApplication app : user.getApps()) {
        array.add(app.toObjectNode());
      }
      // jsonObject.set("apps", array);
    }

    return jsonObject;
  }
예제 #9
0
  public JSONArray getUserMenu(long parent, String actorId) {
    JSONArray array = new JSONArray();
    SysUser user = authorizeService.login(actorId);
    if (user != null) {
      List<SysTree> treeList = null;
      SysApplication app = this.findById(parent);
      SysTreeQuery query = new SysTreeQuery();
      query.treeId(app.getNode().getTreeId());
      query.treeIdLike(app.getNode().getTreeId() + "%");
      if (!user.isSystemAdmin()) {
        List<String> actorIds = new java.util.ArrayList<String>();
        List<Object> rows = entityService.getList("getAgents", actorId);
        if (rows != null && !rows.isEmpty()) {
          for (Object object : rows) {
            if (object instanceof Agent) {
              Agent agent = (Agent) object;
              if (!agent.isValid()) {
                continue;
              }
              switch (agent.getAgentType()) {
                case 0: // 全局代理
                  actorIds.add(agent.getAssignFrom());
                  break;
                default:
                  break;
              }
            }
          }
        }
        if (!actorIds.isEmpty()) {
          actorIds.add(actorId);
          query.setActorIds(actorIds);
        } else {
          query.setActorId(actorId);
        }
        treeList = sysTreeMapper.getTreeListByUsers(query);
      } else {
        treeList = sysTreeMapper.getTreeList(query);
      }

      List<TreeModel> treeModels = new java.util.ArrayList<TreeModel>();
      for (SysTree tree : treeList) {
        if (StringUtils.isNotEmpty(tree.getUrl())) {
          if (StringUtils.startsWith(tree.getUrl(), "/")) {
            if (StringUtils.isNotEmpty(SystemConfig.getServiceUrl())) {
              String link = SystemConfig.getServiceUrl() + tree.getUrl();
              tree.setUrl(link);
            } else {
              String link = ApplicationContext.getContextPath() + tree.getUrl();
              tree.setUrl(link);
            }
          }
        }
        treeModels.add(tree);
      }
      TreeHelper treeHelper = new TreeHelper();
      array = treeHelper.getTreeJSONArray(treeModels);
      // logger.debug(array.toString('\n'));
    }
    return array;
  }
예제 #10
0
  @RequestMapping("/jump")
  public void jump(HttpServletRequest request, HttpServletResponse response) {
    logger.debug("---------------------------jump----------------------");
    LoginContext loginContext = RequestUtils.getLoginContext(request);
    if (loginContext == null) {
      try {
        response.sendRedirect(request.getContextPath() + ViewProperties.getString("loginUrl"));
        return;
      } catch (Exception ex) {
      }
    }
    String menuId = request.getParameter("menuId");
    if (menuId != null) {
      menuId = RequestUtils.decodeString(menuId);
    }
    logger.debug("menuId:" + menuId);
    if (menuId != null && StringUtils.isNumeric(menuId)) {
      SysApplication app = sysApplicationService.findById(Long.parseLong(menuId));
      if (app != null) {
        boolean accessable = false;
        if (loginContext.isSystemAdministrator()) {
          accessable = true;
        } else {
          AuthorizeBean bean = new AuthorizeBean();
          SysUser sysUser = bean.getUser(loginContext.getActorId());
          if (sysUser != null) {
            accessable = sysUser.hasApplicationAccess(app.getId());
          }
        }
        logger.debug("accessable:" + accessable);
        if (accessable) {
          try {
            String url = app.getUrl();
            if (url != null) {
              if (!(url.toLowerCase().startsWith("http://")
                  || url.toLowerCase().startsWith("https://"))) {
                if (url.startsWith("/")) {
                  url = request.getContextPath() + url;
                } else {
                  url = request.getContextPath() + "/" + url;
                }
              }
              if (url.indexOf("?") != -1) {
                url = url + "&time=" + System.currentTimeMillis();
              } else {
                url = url + "?time=" + System.currentTimeMillis();
              }

              String key = SystemProperties.getDefaultSecurityKey();

              String actorId = SecurityUtils.encode(key, loginContext.getActorId());

              if (StringUtils.endsWithIgnoreCase(app.getLinkFileName(), ".cpt")) {
                url = SystemConfig.getString("report_service_url");
                String cpt_path = "fileId=" + app.getLinkFileId();
                String dsJson = DBConfiguration.encodeJsonCurrentSystem();
                if (url.indexOf("?") == -1) {
                  url = url + "?q=1";
                }
                url = url + "&" + cpt_path + "&datasourceJson=" + dsJson;
                if (app.getRefId1() != null) {
                  url = url + "&refId1=" + app.getRefId1() + "&treedot_index_id=" + app.getRefId1();
                }
                if (app.getRefId2() != null) {
                  url =
                      url + "&refId2=" + app.getRefId2() + "&treepinfo_index_id=" + app.getRefId2();
                }

                if (StringUtils.isNotEmpty(app.getLinkParam())) {
                  url = url + "&" + app.getLinkParam();
                }
              }

              if (StringUtils.endsWithIgnoreCase(app.getPrintFileName(), ".cpt")) {
                url = url + "&printFileId=" + app.getPrintFileId();
                if (StringUtils.isNotEmpty(app.getPrintParam())) {
                  url = url + "&" + app.getPrintParam();
                }
              }

              url = url + "&security_actorId=" + actorId;
              logger.debug(url);
              response.sendRedirect(url);
            } else {
              return;
            }
          } catch (Exception ex) {
            ex.printStackTrace();
          }
        }
      }
    }
    try {
      request.getRequestDispatcher("/WEB-INF/views/404.jsp").forward(request, response);
    } catch (Exception e) {
    }
  }