Пример #1
0
  public List<Topic> getRecentReplyTopics(int userId, Pager pager) {

    Map<Integer, UserProfile> authors = new HashMap<Integer, UserProfile>();
    Cnd cnd = Cnd.where("userId", "=", userId);
    cnd.desc("createTime");

    Sql sql =
        Sqls.queryString("select DISTINCT topicId from t_topic_reply $cnd")
            .setEntity(dao.getEntity(TopicReply.class))
            .setVar("cnd", cnd);
    pager.setRecordCount(
        dao.execute(
                Sqls.fetchInt("select count(DISTINCT topicId) from t_topic_reply $cnd")
                    .setEntity(dao.getEntity(TopicReply.class))
                    .setVar("cnd", cnd))
            .getInt());
    sql.setPager(pager);
    String[] replies_topic_ids = dao.execute(sql).getObject(String[].class);
    List<Topic> recent_replies = new ArrayList<Topic>();
    for (String topic_id : replies_topic_ids) {
      Topic _topic = dao.fetch(Topic.class, topic_id);
      if (_topic == null) continue;
      recent_replies.add(_topic);
    }
    if (!recent_replies.isEmpty()) {
      for (Topic topic : recent_replies) {
        fillTopic(topic, authors);
      }
    }
    return recent_replies;
  }
Пример #2
0
  /**
   * 分页查找 resource
   *
   * @param categoryId 分类id好好
   * @param order
   * @param pager
   * @return
   */
  public List<Resource> search(Integer categoryId, String order, Pager pager, Integer userId) {
    List<Resource> query = null;

    Cnd cnd = Cnd.NEW();
    if (userId != null) {
      cnd = cnd.and("author", "=", userId);
    }

    if (categoryId != null && categoryId != 0) {
      cnd = cnd.and("categoryId", "=", categoryId);
    }

    if (pager != null) {
      pager.setRecordCount(dao.count(Resource.class, cnd));
    }
    query = dao.query(Resource.class, cnd.desc("id"), pager);

    for (Resource resource : query) {
      resourceRelationFull(resource);
    }
    return query;
  }