Esempio n. 1
0
  /** @param id */
  public void setParentId(long id) {
    this.parentId = id;
    parentType = new NewsType();

    if (this.lazy) {
      parentType._id = id;
    }

    if (!this.lazy && id > 0) {
      parentType.id = id;
    }
  }
Esempio n. 2
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;
  }
Esempio n. 3
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;
  }
Esempio n. 4
0
  /**
   * 用于前台
   *
   * @param supervisorId
   * @param parentId
   * @param error
   * @return
   */
  public static List<NewsType> queryChildTypes(long parentId, ErrorInfo error) {
    error.clear();

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

    String sql =
        "select new t_content_news_types(id, name) from t_content_news_types type where "
            + "type.parent_id = ? and type.status = true order by _order";

    try {
      types = t_content_news_types.find(sql, 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;

      childTypes.add(childType);
    }

    NewsType latestNewsType = new NewsType();
    latestNewsType.setParentId(3L);
    latestNewsType.name = "最新动态";
    childTypes.add(latestNewsType);
    error.code = 0;

    return childTypes;
  }
Esempio n. 5
0
  /**
   * 添加类别
   *
   * @param supvisorId 管理员id
   * @param error
   * @return
   */
  public int addChildType(long supervisorId, ErrorInfo error) {
    error.clear();

    if (this._parentId <= 0) {
      error.code = -1;
      error.msg = "请选择父类别";

      return error.code;
    }

    if (StringUtils.isBlank(name)) {
      error.code = -1;
      error.msg = "请输入类别名称";

      return error.code;
    }

    if (this.order <= 0) {
      error.code = -1;
      error.msg = "请输入排序";

      return error.code;
    }

    if (NewsType.orderExist(this._parentId, order, error)) {
      return error.code;
    }

    t_content_news_types childType = new t_content_news_types();

    childType.parent_id = this._parentId;
    childType.name = this.name;
    childType.description = this.description;
    childType.status = Constants.TRUE;
    childType._order = this.order;

    try {
      childType.save();
    } catch (Exception e) {
      e.printStackTrace();
      Logger.info("添加添加类别时,保存添加的类别时:" + e.getMessage());
      error.code = -1;
      error.msg = "添加类别失败";

      return -1;
    }

    DealDetail.supervisorEvent(supervisorId, SupervisorEvent.ADD_NEWSTYPE, "添加类别", error);

    if (error.code < 0) {
      JPA.setRollbackOnly();

      return error.code;
    }

    error.code = 0;
    error.msg = "添加类别成功";
    this._id = childType.id;

    return 0;
  }