Beispiel #1
0
  /**
   * 如果第二个字符串为空则返回第一个字符串,否则取两个字符串的交集
   *
   * @return "34,777"
   */
  public static String justInFirstString(String str1, String str2) {
    if (CommonUtil.isEmptyString(str2)) {
      return str1;
    }
    String[] str1Arr = str1.split(",");
    String[] str2Arr = str2.split(",");
    Set<String> set1 = new HashSet<String>();
    Set<String> set2 = new HashSet<String>();
    for (String str : str1Arr) {
      set1.add(str);
    }
    for (String str : str2Arr) {
      set2.add(str);
    }
    Set<String> retainSet = new HashSet<String>();
    retainSet.addAll(set1);
    retainSet.retainAll(set2);

    StringBuffer strB = new StringBuffer();
    for (String str : retainSet) {
      strB.append(str).append(",");
    }
    String resultStr = strB.toString();
    if (resultStr.endsWith(",")) {
      return resultStr.substring(0, resultStr.length() - 1);
    }
    return resultStr;
  }
Beispiel #2
0
 /**
  * 设置部门领导和用户登录后数据权限
  *
  * @param request
  * @param conditions
  */
 public static void setLeadersOrgans(HttpServletRequest request, Map<String, Object> conditions) {
   Map<String, Object> userMap = CommonUtil.getSessionUser(request);
   Object oLoginType = userMap.get(Constant.SESSION_UER_LOGIN_TYPE);
   int loginType =
       CommonUtil.notEmptyString(oLoginType) ? Integer.valueOf(oLoginType.toString()) : -2;
   if (loginType == 2) {
     String leadersOrganId = userMap.get(Constant.SESSION_UER_LOGIN_ORGANS).toString();
     String searchOrgId =
         conditions.get("organ_id") == null ? "" : conditions.get("organ_id").toString();
     String organ_id = CommonUtil.justInFirstString(leadersOrganId, searchOrgId);
     organ_id = CommonUtil.isEmptyString(organ_id) ? "-1" : organ_id;
     conditions.put("organ_id", organ_id);
   } else if (loginType == 3) {
     CommonUtil.setUserId2ParamsMap(conditions, request);
   }
 }
Beispiel #3
0
 /**
  * 获取session中的用户来源
  *
  * @param request
  * @return
  */
 public static String getSessionUserSource(HttpServletRequest request) {
   Object userFromSource = request.getSession().getAttribute(Constant.SESSION_USER_SOURCE);
   return CommonUtil.isEmptyString(userFromSource) ? null : userFromSource.toString();
 }