Example #1
0
  /**
   * 隐藏类别(该类别的子类别也需隐藏)
   *
   * @param supvisorId 管理员id
   * @param typeId 隐藏类别的id
   * @param error
   * @return
   */
  public static int hideType(long supvisorId, long typeId, ErrorInfo error) {
    EntityManager em = JPA.em();

    String mySql = "update t_content_news_types set status = ? where id = ?";

    int rows = 0;

    try {
      rows = em.createQuery(mySql).setParameter(1, false).setParameter(2, typeId).executeUpdate();
    } catch (Exception e) {
      JPA.setRollbackOnly();
      e.printStackTrace();
      Logger.info("隐藏类别,更新类别状态时:" + e.getMessage());
      error.code = -1;
      error.msg = "更新类别状态失败";

      return error.code;
    }

    if (rows == 0) {
      JPA.setRollbackOnly();
      error.code = -1;
      error.msg = "数据未更新";

      return error.code;
    }

    /*
     * 递归修改子类别的属性
     */
    String sql2 = "select id from t_content_news_types where parent_id = ?";
    List<Long> ids = null;

    try {
      ids = t_content_news_types.find(sql2, typeId).fetch();
    } catch (Exception e) {
      e.printStackTrace();
      Logger.info("隐藏类别,更新类别状态时:" + e.getMessage());
      error.code = -2;
      error.msg = "查询子类别失败";

      return error.code;
    }

    if (ids != null && ids.size() != 0) {

      for (long id : ids) {
        hideType(supvisorId, id, error);
      }
    }

    DealDetail.supervisorEvent(supvisorId, SupervisorEvent.HIDE_NEWSTYPE, "隐藏类别", error);

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

      return error.code;
    }

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

    return 0;
  }