Example #1
0
 /**
  * @author upshi
  * @date 20160219
  * @url /rest/appRole/search/appId/{appId}
  */
 @ResponseBody
 @RequestMapping(value = "/search/appId/{appId}", method = RequestMethod.GET)
 public Map<String, Object> search(@PathVariable Integer appId) {
   Map<String, Object> map = new HashMap<String, Object>();
   List<AppRole> appRoles = null;
   appRoles = appRoleService.getRoleListForApp(appId);
   if (appRoles != null && appRoles.size() != 0) {
     map.put("code", "8000");
     map.put("result", "success");
     map.put("appRoles", appRoles);
   } else {
     map.put("code", "5002");
     map.put("result", "failure");
     map.put("reason", "您查询的应用下没有角色");
   }
   return map;
 }
Example #2
0
  /**
   * @author ishadow
   * @date 20160820 旧版添加
   * @url /rest/appRole 请求参数json格式:{"name":"","appId":"","personUserNames":[],"departmentNames" :[]}
   */
  @ResponseBody
  @RequestMapping(method = RequestMethod.POST)
  public Map<String, Object> oldAddRole(
      @RequestBody AppRoleVO appRoleVO, HttpServletRequest request) {
    Map<String, Object> map = new HashMap<String, Object>();
    // AppInfo appInfo = appInfoService.getAppById(appRoleVO.getAppId());
    // 判断有没有权限进行操作
    Map<String, Object> preHandleMap = preHandle(request, appRoleVO.getAppId());
    if (preHandleMap != null) {
      return preHandleMap;
    }

    // 判断角色名是否存在
    List<AppRole> roleListForApp = appRoleService.getRoleListForApp(appRoleVO.getAppId());
    for (AppRole appRole : roleListForApp) {
      if (appRole.getName().equals(appRoleVO.getName())) {
        map.put("code", "5013");
        map.put("result", "failure");
        map.put("reason", "角色名已经存在");
        return map;
      }
    }

    // 判断添加的人员有没有不存在的
    List<String> personUserNames = appRoleVO.getPersonUserNames();
    List<Person> personsResult = null;
    if (personUserNames != null) {
      personsResult = personService.getPersonsByUserNames(personUserNames);
      // 根据参数中的用户名查询出的结果集数量与参数的集合数量是否一致判断是否有不存在的用户名
      if (personsResult != null && personsResult.size() != personUserNames.size()) {
        String inexistenceUserNames = "";
        String resultUserNames = "";
        // 组成查到的用户名字符串
        for (Person p : personsResult) {
          resultUserNames = resultUserNames + p.getUsername() + ",";
        }
        // 判断参数中的用户名,找出不在数据库中的用户名
        for (String s : personUserNames) {
          if (resultUserNames.indexOf("," + s + ",") < 0) {
            inexistenceUserNames = inexistenceUserNames + s + " ";
          }
        }
        map.put("code", "5014");
        map.put("result", "failure");
        map.put("reason", inexistenceUserNames + "用户不存在,创建角色失败");
        return map;
      }
    }

    // 判断部门有没有不存在的
    // 判断添加的人员有没有不存在的
    List<String> departmentsNames = appRoleVO.getDepartmentNames();
    List<Department> departmentsResult = null;
    if (departmentsNames != null) {
      departmentsResult = departmentService.getDepartmentsByNames(departmentsNames);
      // 根据参数中的用户名查询出的结果集数量与参数的集合数量是否一致判断是否有不存在的用户名
      if (departmentsResult != null && departmentsResult.size() != departmentsNames.size()) {
        String inexistenceDepartmentNames = "";
        String resultDepartmentNames = "";
        // 组成查到的用户名字符串
        for (Department d : departmentsResult) {
          resultDepartmentNames = resultDepartmentNames + d.getName() + ",";
        }
        // 判断参数中的用户名,找出不在数据库中的用户名
        for (String s : departmentsNames) {
          if (resultDepartmentNames.indexOf("," + s + ",") < 0) {
            inexistenceDepartmentNames = inexistenceDepartmentNames + s + " ";
          }
        }
        map.put("code", "5015");
        map.put("result", "failure");
        map.put("reason", inexistenceDepartmentNames + "部门不存在,创建角色失败");
        return map;
      }
    }

    // 都存在后即可进行添加该角色
    // 构造AppRole对象
    AppRole appRole = new AppRole();
    appRole.setAppId(appRoleVO.getAppId());
    appRole.setName(appRoleVO.getName());
    appRole.setPersons(personsResult);
    appRole.setDepartments(departmentsResult);
    // 调用service方法插入角色信息
    appRoleService.addRoleForApp(appRole);

    map.put("code", "8000");
    map.put("result", "success");
    return map;
  }