Пример #1
0
  public List<Feed> getFeedList(long cur) {
    List<Integer> managerTeamIds =
        TeamMemberEntity.find(
                "select pk.teamId from TeamMemberEntity where pk.userId = ? and status = ?",
                id,
                MemberStatus.MANAGER.value())
            .fetch();
    List<Integer> memberTeamIds =
        TeamMemberEntity.find(
                "select pk.teamId from TeamMemberEntity where pk.userId = ? and status = ?",
                id,
                MemberStatus.MEMBER.value())
            .fetch();

    StringBuilder sb = new StringBuilder("select f from FeedEntity f where (userId = ?");
    if (managerTeamIds.size() > 0) {
      sb.append("or (target = ? and teamId in (");
      boolean first = true;
      for (int teamId : managerTeamIds) {
        if (first) sb.append(teamId);
        else sb.append(",").append(teamId);
        first = false;
      }
      sb.append("))");
    }
    if (memberTeamIds.size() > 0) {
      sb.append("or (target = ? and teamId in (");
      boolean first = true;
      for (int teamId : memberTeamIds) {
        if (first) sb.append(teamId);
        else sb.append(",").append(teamId);
        first = false;
      }
      sb.append("))");
    }
    if (cur > 0) sb.append(") and id < ?");
    else sb.append(")");
    sb.append(" order by id desc");

    Query query = JPA.em().createQuery(sb.toString());
    int idx = 1;
    query.setParameter(idx++, id);
    if (managerTeamIds.size() > 0) query.setParameter(idx++, MemberStatus.MANAGER.value());
    if (memberTeamIds.size() > 0) query.setParameter(idx++, MemberStatus.MEMBER.value());
    if (cur > 0) query.setParameter(idx++, cur);
    query.setMaxResults(Constants.MAX_FEED_FETCH_COUNT);

    List<FeedEntity> feedEntityList = query.getResultList();

    List<Feed> feedList = new ArrayList<Feed>();
    for (FeedEntity entity : feedEntityList) {
      feedList.add(entity.toFeed());
    }
    return feedList;
  }
Пример #2
0
  public List<TeamHint> getTeamHintList() {
    Query query =
        JPA.em()
            .createQuery(
                "select pk.teamId, status from TeamMemberEntity where pk.userId = ? and leavedAt is null and (status = ? or status = ?)");
    query.setParameter(1, id);
    query.setParameter(2, MemberStatus.MEMBER.value());
    query.setParameter(3, MemberStatus.MANAGER.value());
    List<Object[]> resultList = query.getResultList();

    List<TeamHint> teamHintList = new ArrayList<TeamHint>();
    for (Object[] objects : resultList) {
      TeamEntity teamEntity = TeamEntity.findById(objects[0]);
      TeamHint teamHint = teamEntity.toTeamHint((Integer) objects[1]);
      teamHintList.add(teamHint);
    }
    return teamHintList;
  }