예제 #1
0
  @Override
  public SearchResult<UserVO> searchUser(StoreUserSearch userSearch) {
    Search search = new Search(User.class);
    search.setFirstResult(userSearch.getStart());
    search.setMaxResults(userSearch.getCount());

    if (userSearch.getAccountId() != null) {
      search.addFilterEqual("account.id", userSearch.getAccountId());
    }

    if (userSearch.getEmail() != null) {
      search.addFilterEqual("email", userSearch.getEmail());
    }

    if (userSearch.getUsername() != null) {
      search.addFilterEqual("username", userSearch.getUsername());
    }
    if (userSearch.getRoleId() != null) {
      search.addFilterEqual("userRole.id", userSearch.getRoleId());
    }
    if (userSearch.getSortBy() != null && userSearch.getSortDesc() != null) {
      if (userSearch.getSortDesc()) {
        search.addSortDesc(userSearch.getSortBy());
      } else {
        search.addSortAsc(userSearch.getSortBy());
      }
    }

    search
        .addField("id", "id")
        .addField("username", "username")
        .addField("account.id", "accountId")
        .addField("account.name", "accountName")
        .addField("userRole.id", "roleId")
        .addField("userRole.name", "roleName")
        .addField("email", "email")
        .addField("fullName", "fullName")
        .addField("realName", "realName")
        .addField("createDate", "createDate")
        .addField("modifyDate", "modifyDate")
        .addField("isEnabled", "isEnabled")
        .addField("isLocked", "isLocked")
        .addField("editable", "editable");

    SearchResult<Map<String, Object>> searchResult = userRepository.searchAndCount(search);
    List<UserVO> results = new ArrayList<UserVO>();
    for (Map<String, Object> map : searchResult.getResult()) {
      UserVO vo = new UserVO(map);
      results.add(vo);
    }

    SearchResult<UserVO> res = new SearchResult<UserVO>();
    res.setTotalCount(searchResult.getTotalCount());
    res.setResult(results);
    return res;
  }