예제 #1
0
  /**
   * 编辑类别
   *
   * @param supvisorId
   * @param typeId
   * @param error
   * @return
   */
  public int editType(long supervisorId, long id, ErrorInfo error) {
    error.clear();

    t_content_news_types type = null;

    try {
      type = t_content_news_types.findById(id);
    } catch (Exception e) {
      e.printStackTrace();
      Logger.info("编辑类别,查询类别时:" + e.getMessage());
      error.code = -1;
      error.msg = "编辑类别失败";

      return error.code;
    }

    type.name = this.name;
    type.description = this.description;
    type._order = this.order;

    try {
      type.save();
    } catch (Exception e) {
      e.printStackTrace();
      Logger.info("编辑类别,更新类别时:" + e.getMessage());
      error.code = -2;
      error.msg = "编辑类别失败";

      return error.code;
    }

    DealDetail.supervisorEvent(supervisorId, SupervisorEvent.EDIT_NEWSTYPE, "编辑类别", error);

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

      return error.code;
    }

    error.code = 0;
    error.msg = "更新类别成功";

    return 0;
  }
예제 #2
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;
  }