Ejemplo n.º 1
0
  @Override
  public String update() throws Exception {
    String userName = p("userName");
    boolean isExits = userService.checkUserName(userName, this.id);
    if (isExits) {
      User user = (User) getDefService().get(this.id);
      setEntity(user);
      String StrRoleArr = p("role");
      String roleArr[] = StrRoleArr.split(",");
      List<Role> list = new ArrayList<Role>();
      if (StrRoleArr != null && StrRoleArr != "") {
        String as[];
        int j = (as = roleArr).length;
        for (int i = 0; i < j; i++) {
          String id = as[i];
          Role role = AdminHelper.toRole(id);
          list.add(role);
        }

        user.setRoles(list);
      } else {
        user.setRoles(list);
      }
      userService.update(user);
      jo.put("entity", toJsonObject(user));
      setJsonMessage(
          true,
          user.toString().equals("")
              ? "更新了一条记录!"
              : (new StringBuilder("更新了(")).append(user).append(")的记录").toString());
      return render(jo);
    } else {
      setJsonMessage(
          false, (new StringBuilder("修改失败,用户")).append(userName).append("已经存在").toString());
      return render(jo);
    }
  }
Ejemplo n.º 2
0
  @Override
  public String create() throws Exception {
    String userName = p("userName");
    boolean isExist = userService.checkUserName(userName, null);
    if (isExist) {
      User user = (User) getEntityClass().newInstance();
      setEntity(user);
      String StrRoleArr = p("role");
      String roleArr[] = StrRoleArr.split(",");
      List<Role> roleList = new ArrayList<Role>();
      String as[];
      int j = (as = roleArr).length;
      for (int i = 0; i < j; i++) {
        String id = as[i];
        Role role = AdminHelper.toRole(id);
        roleList.add(role);
      }

      user.setRoles(roleList);
      Employee e = employeeService.get(p("employee"));
      List<Organization> organizations = new ArrayList<Organization>();
      organizations.add(e.getOrganization());
      user.setOrganizations(organizations);
      userService.add(user);
      jo.put("entity", toJsonObject(user));
      setJsonMessage(
          true,
          user.toString().equals("")
              ? "新增了一条记录!"
              : (new StringBuilder("新增了(")).append(user).append(")的记录").toString());
      return render(jo);
    } else {
      setJsonMessage(
          false, (new StringBuilder(String.valueOf(userName))).append("已经存在").toString());
      return render(jo);
    }
  }