Ejemplo n.º 1
0
  /**
   * 查询最顶级的类别
   *
   * @param supervisorId
   * @param error
   * @return
   */
  public static List<NewsType> queryTopTypes(ErrorInfo error) {
    error.clear();

    List<t_content_news_types> types = new ArrayList<t_content_news_types>();
    List<NewsType> childTypes = new ArrayList<NewsType>();

    try {
      types = t_content_news_types.find("parent_id = -1 order by _order").fetch();
    } catch (Exception e) {
      e.printStackTrace();
      error.code = -1;
      error.msg = "查询类别失败";
      return null;
    }

    NewsType childType = null;

    for (t_content_news_types type : types) {

      childType = new NewsType();

      childType._id = type.id;
      childType.name = type.name;
      childType.parentId = type.parent_id;
      childType.description = type.description;
      childType.status = type.status;
      childType.order = type._order;

      childTypes.add(childType);
    }

    error.code = 0;

    return childTypes;
  }
Ejemplo n.º 2
0
  /**
   * 根据父类别id查询子类别信息(列表显示)
   *
   * @param parentId 父类别id
   * @param error
   * @return
   */
  public static List<NewsType> queryChildTypes(
      long supervisorId, String parentIdStr, ErrorInfo error) {
    error.clear();

    if (!NumberUtil.isNumericInt(parentIdStr)) {
      error.code = -1;
      error.msg = "传入类型参数有误!";
    }

    long parentId = Long.parseLong(parentIdStr);

    List<t_content_news_types> types = new ArrayList<t_content_news_types>();
    List<NewsType> childTypes = new ArrayList<NewsType>();

    try {
      types = t_content_news_types.find("parent_id = ? order by _order", parentId).fetch();
    } catch (Exception e) {
      e.printStackTrace();
      error.code = -1;
      error.msg = "查询类别失败";
      return null;
    }

    NewsType childType = null;

    for (t_content_news_types type : types) {

      childType = new NewsType();

      childType._id = type.id;
      childType.name = type.name;
      childType.parentId = type.parent_id;
      childType.description = type.description;
      childType.status = type.status;
      childType.order = type._order;

      childTypes.add(childType);
    }

    error.code = 0;

    return childTypes;
  }