private List<Map<String, String>> findActorMasters(Long[] followerIds) {
    if (followerIds == null || followerIds.length == 0) return null;

    StringBuffer hql = new StringBuffer();
    hql.append("select distinct ar.follower_id as fid,ar.master_id as id,m.type_ as type");
    hql.append(
        ",m.code as code,m.name as name,m.pcode as pcode,m.pname as pname,m.order_ as orderNo");
    hql.append(" from BC_IDENTITY_ACTOR_RELATION as ar");
    hql.append(" inner join BC_IDENTITY_ACTOR as m on m.id = ar.master_id");
    hql.append(" where ar.type_=0");
    hql.append(" and ar.follower_id");
    if (logger.isDebugEnabled()) {
      logger.debug("findActorMasters.hql=" + hql);
      logger.debug("findActorMasters.args=" + StringUtils.arrayToCommaDelimitedString(followerIds));
    }
    if (followerIds.length == 1) {
      hql.append(" = ?");
    } else {
      hql.append(" in (?");
      for (int i = 1; i < followerIds.length; i++) {
        hql.append(",?");
      }
      hql.append(")");
    }
    hql.append(" order by m.order_");
    return HibernateJpaNativeQuery.executeNativeSql(
        jpaTemplate, hql.toString(), followerIds, new Follower2MasterMapper());
  }
 public List<Map<String, String>> findShortcuts(Long[] actorIds, Long[] resourceIds) {
   StringBuffer hql = new StringBuffer();
   hql.append("select s.aid,s.sid,s.id,s.standalone,s.name,s.url,s.iconclass,s.order_");
   hql.append(" from bc_desktop_shortcut s");
   hql.append(" where s.aid in (?");
   List<Object> args = new ArrayList<Object>();
   args.add(new Long(0));
   if (actorIds != null) {
     for (Long id : actorIds) {
       hql.append(",?");
       args.add(id);
     }
   }
   hql.append(") and s.sid in (?");
   args.add(new Long(0));
   if (resourceIds != null) {
     for (Long id : resourceIds) {
       hql.append(",?");
       args.add(id);
     }
   }
   hql.append(") order by s.order_");
   if (logger.isDebugEnabled()) {
     logger.debug("actorIds=" + StringUtils.arrayToCommaDelimitedString(actorIds));
     logger.debug("resourceIds=" + StringUtils.arrayToCommaDelimitedString(resourceIds));
     logger.debug("hql=" + hql);
   }
   return HibernateJpaNativeQuery.executeNativeSql(
       jpaTemplate,
       hql.toString(),
       args.toArray(),
       new RowMapper<Map<String, String>>() {
         public Map<String, String> mapRow(Object[] rs, int rowNum) {
           Map<String, String> s = new HashMap<String, String>();
           int i = 0;
           s.put("aid", rs[i] != null ? rs[i].toString() : null);
           i++;
           s.put("sid", rs[i] != null ? rs[i].toString() : null);
           i++;
           s.put("id", rs[i++].toString());
           s.put("standalone", rs[i++].toString());
           s.put("name", rs[i] != null ? rs[i].toString() : null);
           i++;
           s.put("url", rs[i] != null ? rs[i].toString() : null);
           i++;
           s.put("iconClass", rs[i] != null ? rs[i].toString() : null);
           i++;
           s.put("orderNo", rs[i] != null ? rs[i].toString() : null);
           return s;
         }
       });
 }
 public List<Map<String, String>> findActorAncestors(Long actorId) {
   if ("oracle".equals(JdbcUtils.dbtype)) {
     StringBuffer hql = new StringBuffer();
     hql.append("select distinct ar.follower_id as fid,ar.master_id as id,m.type_ as type");
     hql.append(",m.code as code,m.name as name,m.pcode as pcode,m.pname as pname");
     hql.append(" from BC_IDENTITY_ACTOR_RELATION as ar");
     hql.append(" inner join BC_IDENTITY_ACTOR as m on m.id = ar.master_id");
     hql.append(" where ar.type_=0");
     hql.append(" start with ar.follower_id = ?");
     hql.append(" connect by prior ar.master_id = ar.follower_id");
     if (logger.isDebugEnabled()) {
       logger.debug("actorId=" + actorId + ",hql=" + hql);
     }
     return HibernateJpaNativeQuery.executeNativeSql(
         jpaTemplate, hql.toString(), new Object[] {actorId}, new Follower2MasterMapper());
   } else {
     // 使用原始的递归方式获取祖先组织信息
     return this.findActorAncestorsDefault(actorId);
   }
 }
  public List<Map<String, String>> findActorRoles(Long[] actorIds) {
    if (actorIds == null || actorIds.length == 0) return new ArrayList<Map<String, String>>();

    StringBuffer hql = new StringBuffer();
    hql.append(
        "select distinct r.id as id,r.code as code,r.name as name,r.order_ as orderNo from BC_IDENTITY_ROLE as r");
    hql.append(" inner join BC_IDENTITY_ROLE_ACTOR as ra on ra.rid=r.id");
    hql.append(" where r.status_ = 0 and ra.aid");
    if (actorIds.length == 1) {
      hql.append(" = ?");
    } else {
      hql.append(" in (?");
      for (int i = 1; i < actorIds.length; i++) {
        hql.append(",?");
      }
      hql.append(")");
    }
    hql.append(" order by r.order_");
    if (logger.isDebugEnabled()) {
      logger.debug("actorIds=" + StringUtils.arrayToCommaDelimitedString(actorIds));
      logger.debug("hql=" + hql);
    }
    return HibernateJpaNativeQuery.executeNativeSql(
        jpaTemplate,
        hql.toString(),
        actorIds,
        new RowMapper<Map<String, String>>() {
          public Map<String, String> mapRow(Object[] rs, int rowNum) {
            Map<String, String> role = new HashMap<String, String>();
            int i = 0;
            role.put("id", rs[i++].toString());
            role.put("code", rs[i++].toString());
            return role;
          }
        });
  }
  public Set<Resource> findResources(Long[] roleIds) {
    if (roleIds == null || roleIds.length == 0) return new HashSet<Resource>();

    StringBuffer hql = new StringBuffer();
    hql.append(
        "select distinct s.belong,s.id,s.type_,s.name,s.url,s.iconclass,s.order_,s.pname,s.option_");
    hql.append(" from bc_identity_resource s");
    hql.append(" inner join bc_identity_role_resource rs on rs.sid=s.id");
    hql.append(" where rs.rid");
    if (roleIds.length == 1) {
      hql.append(" = ?");
    } else {
      hql.append(" in (?");
      for (int i = 1; i < roleIds.length; i++) {
        hql.append(",?");
      }
      hql.append(")");
    }
    hql.append(" order by s.order_");
    if (logger.isDebugEnabled()) {
      logger.debug("roleIds=" + StringUtils.arrayToCommaDelimitedString(roleIds));
      logger.debug("hql=" + hql);
    }
    List<Long> sIds =
        HibernateJpaNativeQuery.executeNativeSql(
            jpaTemplate,
            hql.toString(),
            roleIds,
            new RowMapper<Long>() {
              public Long mapRow(Object[] rs, int rowNum) {
                // Map<String, String> s = new HashMap<String,
                // String>();
                // int i = 0;
                // s.put("pid", rs[i] != null ? rs[i].toString() :
                // null);
                // i++;
                // s.put("id", rs[i++].toString());
                // s.put("type", rs[i++].toString());
                // s.put("name", rs[i] != null ? rs[i].toString() :
                // null);
                // i++;
                // s.put("url", rs[i] != null ? rs[i].toString() :
                // null);
                // i++;
                // s.put("iconClass", rs[i] != null ? rs[i].toString()
                // : null);
                // i++;
                // s.put("orderNo", rs[i] != null ? rs[i].toString()
                // : null);
                // i++;
                // s.put("pname", rs[i] != null ? rs[i].toString() :
                // null);
                // i++;
                // s.put("option", rs[i] != null ? rs[i].toString() :
                // null);
                return new Long(rs[1].toString());
              }
            });

    Set<Resource> ss = new HashSet<Resource>();
    Map<Long, Resource> allResources = this.resourceService.findAll();
    for (Long sid : sIds) {
      if (allResources.containsKey(sid)) ss.add(allResources.get(sid));
    }

    return ss;
  }