Esempio n. 1
0
 /**
  * 获取登录类型
  *
  * @param request
  * @return
  */
 public static int getLoginType(HttpServletRequest request) {
   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()) : -1;
   return loginType;
 }
Esempio n. 2
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;
  }
Esempio n. 3
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);
   }
 }
Esempio n. 4
0
 /**
  * 获取session中的用户企业ID
  *
  * @param request
  * @return
  */
 public static String getSessionUserTenantId(HttpServletRequest request) {
   Map<String, Object> userMap = getSessionUser(request);
   String tenantId = null;
   if (CommonUtil.notEmptyCollections(userMap)) {
     String sessionUserType = userMap.get(Constant.SESSION_USER_TYPE).toString();
     if (sessionUserType.equals(Constant.SESSION_USER_TYPE_USER)) {
       tenantId = userMap.get("tenant_id").toString();
     } else if (sessionUserType.equals(Constant.SESSION_USER_TYPE_TENANT)) {
       tenantId = userMap.get("id").toString();
     }
   }
   return tenantId;
 }
Esempio n. 5
0
 /**
  * 将jsonArray字符串转换成Map对象
  *
  * @param params
  * @return
  * @throws Exception
  */
 public static List<Map<String, Object>> convertJsonArrayStringA2Map(String params)
     throws Exception {
   List<Map<String, Object>> paramsList = new ArrayList<Map<String, Object>>();
   if (CommonUtil.notEmptyString(params)) {
     JSONArray jsonArray = new JSONArray(params);
     int len = jsonArray.length();
     for (int i = 0; i < len; i++) {
       Map<String, Object> map = convertJsonString2Map(jsonArray.getJSONObject(i).toString());
       paramsList.add(map);
     }
   }
   return paramsList;
 }
Esempio n. 6
0
 /**
  * 将企业ID加入到参数中
  *
  * @param paramsMap
  * @param request
  */
 public static void setUserId2ParamsMap(
     Map<String, Object> paramsMap, HttpServletRequest request) {
   Map<String, Object> userMap = getSessionUser(request);
   String userId = null;
   if (CommonUtil.notEmptyCollections(userMap)) {
     String sessionUserType = userMap.get(Constant.SESSION_USER_TYPE).toString();
     if (sessionUserType.equals(Constant.SESSION_USER_TYPE_USER)) {
       userId = userMap.get("id").toString();
     } else if (sessionUserType.equals(Constant.SESSION_USER_TYPE_TENANT)) {
       userId = userMap.get("id").toString(); // 企业ID
     }
   }
   paramsMap.put("user_id", userId);
 }
Esempio n. 7
0
 /**
  * 将json字符串转换成Map对象
  *
  * @param params
  * @return
  * @throws Exception
  */
 public static HashMap<String, Object> convertJsonString2Map(String params) throws Exception {
   HashMap<String, Object> paramsMap = new HashMap<String, Object>();
   if (CommonUtil.notEmptyString(params)) {
     JSONObject jsonObject = new JSONObject(params);
     Iterator it = jsonObject.keys();
     while (it.hasNext()) {
       String key = (String) it.next();
       String value = jsonObject.getString(key);
       if (notEmptyString(value)) {
         paramsMap.put(key, value);
       }
     }
   }
   return paramsMap;
 }
Esempio n. 8
0
 /**
  * 获取登录类型
  *
  * @param request
  * @return -1、异常状态; 0、客户端登录; 1、企业管理员登录; 2、部门领导登录; 3、企业用户个人登录
  */
 public static int loginTypeCode(HttpServletRequest request) {
   String userFromSource = getSessionUserSource(request);
   if (Constant.SESSION_USER_SOURCE_MOBILE.equals(userFromSource)) {
     return Constant.SESSION_UER_LOGIN_TYPE_CLIENT;
   }
   if (userFromSource.equals(Constant.SESSION_USER_SOURCE_WEB)) {
     Map<String, Object> userMap = getSessionUser(request);
     String sessionUserType = userMap.get(Constant.SESSION_USER_TYPE).toString();
     if (sessionUserType.equals(Constant.SESSION_USER_TYPE_TENANT)) {
       return Constant.SESSION_UER_LOGIN_TYPE_ADMIN;
     } else if (sessionUserType.equals(Constant.SESSION_USER_TYPE_USER)) {
       Object oIsLeader = userMap.get("isLeader");
       if (CommonUtil.notEmptyString(oIsLeader) && Boolean.valueOf(oIsLeader.toString())) {
         return Constant.SESSION_UER_LOGIN_TYPE_ORGAN;
       } else {
         return Constant.SESSION_UER_LOGIN_TYPE_USER;
       }
     }
   }
   return Constant.SESSION_UER_LOGIN_TYPE_ERROR;
 }
Esempio n. 9
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();
 }
Esempio n. 10
0
 /**
  * 参数为空
  *
  * @param params
  * @return
  */
 public static ModelAndView getNullParamsResult(String params) {
   ModelMap model = new ModelMap();
   CommonUtil.setFailureMessage(model, "01", "参数为空");
   return new ModelAndView("/page", model);
 }