@RequestMapping("/operations/{resourceId}")
  public void getOperations(
      HttpServletResponse response, @PathVariable("resourceId") Long resourceId) {
    List<String> list =
        PermissionHelper.getInstance()
            .getOperationsByResource(
                resourceId, RecordPermission.class.getName(), RecordResource.class);

    print("Operation", EasyUtils.list2Str(list));
  }
  @RequestMapping(value = "/detail/{type}")
  public void getRecord(
      HttpServletRequest request, HttpServletResponse response, @PathVariable("type") int type) {
    String uri = null;
    if (Record.TYPE0 == type) {
      uri = "template/group_xform.xml";
    } else {
      uri = "template/record_xform.xml";
    }

    XFormEncoder xformEncoder;
    String recordIdValue = request.getParameter("recordId");

    if (recordIdValue == null) {
      Map<String, Object> map = new HashMap<String, Object>();

      String parentIdValue = request.getParameter("parentId");
      if ("_root".equals(parentIdValue)) {
        parentIdValue = null;
      }

      Long parentId =
          parentIdValue == null ? Record.DEFAULT_PARENT_ID : EasyUtils.obj2Long(parentIdValue);
      map.put("parentId", parentId);
      map.put("type", type);
      xformEncoder = new XFormEncoder(uri, map);
    } else {
      Long recordId = EasyUtils.obj2Long(recordIdValue);
      Record record = recordService.getRecord(recordId);
      xformEncoder = new XFormEncoder(uri, record);
    }

    if (Record.TYPE1 == type) {
      try {
        List<Param> datasources = ParamManager.getComboParam(DMConstants.DATASOURCE_LIST);
        xformEncoder.fixCombo("datasource", datasources);
      } catch (Exception e) {
      }
    }

    print("SourceInfo", xformEncoder);
  }
  /*
   * jobConfig的格式为 :
   * 		sql @ datasource
   */
  protected void excuteJob(String jobConfig) {
    log.info("开始用户对角色信息同步......");

    String info[] = EasyUtils.split(jobConfig, "@");
    if (info.length < 2) {
      log.info("用户对角色信息同步的配置信息有误。" + jobConfig);
      return;
    }

    String sql = info[0];
    String dataSource = info[1];
    Date fromDay = DateUtil.subDays(DateUtil.today(), 3);

    List<Map<String, Object>> list = SQLExcutor.query(dataSource, sql, fromDay, fromDay);
    List<Object[]> addList = new ArrayList<Object[]>();
    List<Object[]> delList = new ArrayList<Object[]>();

    for (Map<String, Object> item : list) {
      Long user = EasyUtils.obj2Long(item.get("user"));
      String[] role1 = EasyUtils.obj2String(item.get("role1")).split(","); // 需要新增的用户角色关系
      String[] role2 = EasyUtils.obj2String(item.get("role2")).split(","); // 需要删除的用户角色关系

      for (String role : role1) {
        if (!EasyUtils.isNullOrEmpty(role)) {
          Long _role = EasyUtils.obj2Long(role);
          if (getCount(user, _role) == 0) {
            addList.add(new Object[] {user, _role});
          }
        }
      }

      for (String role : role2) {
        if (!EasyUtils.isNullOrEmpty(role)) {
          Long _role = EasyUtils.obj2Long(role);
          delList.add(new Object[] {user, _role});
        }
      }
    }

    SQLExcutor.excuteBatchII(insertSQL, addList, DMConstants.LOCAL_CONN_POOL);
    SQLExcutor.excuteBatchII(deleteSQL, delList, DMConstants.LOCAL_CONN_POOL);

    log.info("完成用户对角色信息同步。");
  }
  public TreeNode parse(Object data) {
    List<Group> mainAndAssistantGroups = (List<Group>) data;

    TreeNode root = new TreeNode();
    Map<Long, TreeNode> treeNodeMap = new HashMap<Long, TreeNode>();

    // 解析主用户组和辅助用户组
    if (!EasyUtils.isNullOrEmpty(mainAndAssistantGroups)) {
      for (Group group : mainAndAssistantGroups) {
        TreeNode item = new TreeNode(group);
        treeNodeMap.put(group.getId(), item);
      }

      parserGroup(root, (List<Group>) mainAndAssistantGroups, treeNodeMap);
    }

    return root;
  }
 int getCount(Long user, Long role) {
   String sql = "select count(*) num from um_roleuser where roleId = ? and userId = ?";
   Object result =
       SQLExcutor.query(DMConstants.LOCAL_CONN_POOL, sql, role, user).get(0).get("num");
   return EasyUtils.obj2Int(result);
 }