forumserviceimp.java

来自「一个jsp写的bbs」· Java 代码 · 共 1,964 行 · 第 1/5 页

JAVA
1,964
字号

    //System.out.println(pages.getTotalNum());

    List l = this.getForumDAO().findForumsInMainIDByUserID(bid, mainID, userID, -1, 0, 0, "postTime",
        Constant.ORDER_ASC, pages.getSpage(), pages.getPerPageNum());
    pl.setObjectList(l);
    pl.setPages(pages);
    return pl;
  }

  public void removeAttachFile(Forum forum, String[] fileNames) throws BbscsException {
    List fl = forum.getAttachFileName();
    String filePath = BBSCSUtil.getUpFilePath(forum.getBoardID(), forum.getPostTime());
    try {
      for (int i = 0; i < fileNames.length; i++) {
        File attachFile = new File(filePath + fileNames[i]);
        if (attachFile.exists()) {
          FileUtils.forceDelete(attachFile);
        }
        File attachFileSmall = new File(filePath + fileNames[i] + Constant.IMG_SMALL_FILEPREFIX);
        if (attachFileSmall.exists()) {
          FileUtils.forceDelete(attachFileSmall);
        }
        fl.remove(fileNames[i]);
      }
      forum.setAttachFileName(fl);
      this.getForumDAO().saveForum(forum);
    }
    catch (Exception ex) {
      logger.error(ex);
      throw new BbscsException(ex);
    }
  }

  /**
   * 删除某个帖子所有附件
   * @param forum Forum
   * @throws BbscsException
   */
  public void removeAllAttachFile(Forum forum) throws BbscsException {
    if (forum.getHaveAttachFile() == 1) {
      List fl = forum.getAttachFileName();
      String filePath = BBSCSUtil.getUpFilePath(forum.getBoardID(), forum.getPostTime());
      try {
        for (int i = 0; i < fl.size(); i++) {
          File attachFile = new File(filePath + (String) fl.get(i));
          if (attachFile.exists()) {
            FileUtils.forceDelete(attachFile);
          }
          File attachFileSmall = new File(filePath + (String) fl.get(i) + Constant.IMG_SMALL_FILEPREFIX);
          if (attachFileSmall.exists()) {
            FileUtils.forceDelete(attachFileSmall);
          }
        }
        fl.clear();
        forum.setAttachFileName(fl);
        forum.setAuditingAttachFile(0);
        forum.setHaveAttachFile(0);
        this.getForumDAO().saveForum(forum);
      }
      catch (Exception ex) {
        logger.error(ex);
        throw new BbscsException(ex);
      }
    }
  }

  /**
   * 删除未通过审核的帖子附件
   * @param ids List
   * @throws BbscsException
   */
  public void delForumsNotAuditingAttachFile(List ids) throws BbscsException {
    List forums = this.getForumDAO().findForumsInIds(ids);
    for (int i = 0; i < forums.size(); i++) {
      Forum forum = (Forum) forums.get(i);
      if (forum.getHaveAttachFile() == 1) {
        List fl = forum.getAttachFileName();
        String filePath = BBSCSUtil.getUpFilePath(forum.getBoardID(), forum.getPostTime());
        try {
          for (int j = 0; j < fl.size(); j++) {
            File attachFile = new File(filePath + (String) fl.get(j));
            if (attachFile.exists()) {
              FileUtils.forceDelete(attachFile);
            }
            File attachFileSmall = new File(filePath + (String) fl.get(j) + Constant.IMG_SMALL_FILEPREFIX);
            if (attachFileSmall.exists()) {
              FileUtils.forceDelete(attachFileSmall);
            }
          }
          fl.clear();
          forum.setAttachFileName(fl);
          forum.setAuditingAttachFile(0);
          forum.setHaveAttachFile(0);
          this.getForumDAO().saveForum(forum);
        }
        catch (Exception ex) {
          logger.error(ex);
          throw new BbscsException(ex);
        }
      }
    }
  }

  public int getForumNumHotTopic(long bid, int reNum, int click) {
    return this.getForumDAO().getForumNumHotTopic(bid, reNum, click);
  }

  public PageList findForumsHotTopic(long bid, int reNum, int click, Pages pages) {
    PageList pl = new PageList();
    if (pages.getTotalNum() == -1) {
      pages.setTotalNum(this.getForumNumHotTopic(bid, reNum, click));
    }
    pages.executeCount();

    List l = this.getForumDAO().findForumsHotTopic(bid, reNum, click, pages.getSpage(), pages.getPerPageNum());
    pl.setObjectList(l);
    pl.setPages(pages);
    return pl;
  }

  public int getForumNumHotTopic(List bids, int reNum, int click) {
    return this.getForumDAO().getForumNumHotTopic(bids, reNum, click);
  }

  public PageList findForumsHotTopic(List bids, int reNum, int click, Pages pages) {
    PageList pl = new PageList();
    if (pages.getTotalNum() == -1) {
      pages.setTotalNum(this.getForumNumHotTopic(bids, reNum, click));
    }
    pages.executeCount();

    List l = this.getForumDAO().findForumsHotTopic(bids, reNum, click, pages.getSpage(), pages.getPerPageNum());
    pl.setObjectList(l);
    pl.setPages(pages);
    return pl;
  }

  public void removeToHistory(long atime) throws BbscsException {
    List ml = this.getForumDAO().findForumsToHistory(atime);
    for (int i = 0; i < ml.size(); i++) {
      Forum f = (Forum) ml.get(i);
      List fl = this.getForumDAO().findForumsTopic(f.getBoardID(), f.getId(), 0, 0, null, 0);
      for (int j = 0; j < fl.size(); j++) {
        Forum mf = (Forum) fl.get(j);
        ForumHistory fh = new ForumHistory();
        try {
          BeanUtils.copyProperties(fh, mf);
          this.getForumHistoryDAO().saveForumHistory(fh);
          this.getForumDAO().removeForum(mf);
        }
        catch (Exception ex) {
          logger.error(ex);
          throw new BbscsException(ex);
        }
      }
    }
  }

  public List findForumsInIds(long bid, List ids) {
    return this.getForumDAO().findForumsInIds(bid, ids);
  }

  public List findForumsInIds(List ids) {
    return this.getForumDAO().findForumsInIds(ids);
  }

  public void delPostReal(Forum forum) throws BbscsException {
    try {
      if (forum.getHaveAttachFile() == 1 && forum.getAttachFileName() != null &&
          forum.getAttachFileName().size() > 0) {
        List fl = forum.getAttachFileName();
        String filePath = BBSCSUtil.getUpFilePath(forum.getBoardID(), forum.getPostTime());
        for (int i = 0; i < fl.size(); i++) {
          File attachFile = new File(filePath + (String) fl.get(i));
          if (attachFile.exists()) {
            FileUtils.forceDelete(attachFile);
          }
          File attachFileSmall = new File(filePath + (String) fl.get(i) + Constant.IMG_SMALL_FILEPREFIX);
          if (attachFileSmall.exists()) {
            FileUtils.forceDelete(attachFileSmall);
          }
        }
      }
      this.getForumDAO().removeForum(forum);
    }
    catch (Exception ex) {
      logger.error(ex);
      throw new BbscsException(ex);
    }
  }

  public void delPostsReal(List ids) throws BbscsException {
    List forums = this.getForumDAO().findForumsInIds(ids);
    for (int i = 0; i < forums.size(); i++) {
      Forum forum = (Forum) forums.get(i);
      if ( (System.currentTimeMillis() - forum.getDelTime()) > 7 * 24 * 3600 * 1000) {
        try {
          if (forum.getHaveAttachFile() == 1 && forum.getAttachFileName() != null &&
              forum.getAttachFileName().size() > 0) {
            List fl = forum.getAttachFileName();
            String filePath = BBSCSUtil.getUpFilePath(forum.getBoardID(), forum.getPostTime());
            for (int j = 0; j < fl.size(); j++) {
              File attachFile = new File(filePath + (String) fl.get(j));
              if (attachFile.exists()) {
                FileUtils.forceDelete(attachFile);
              }
              File attachFileSmall = new File(filePath + (String) fl.get(j) + Constant.IMG_SMALL_FILEPREFIX);
              if (attachFileSmall.exists()) {
                FileUtils.forceDelete(attachFileSmall);
              }

            }
          }
          this.getForumDAO().removeForum(forum);
        }
        catch (Exception ex) {
          logger.error(ex);
          throw new BbscsException(ex);
        }
      }
    }
  }

  public void delWastePost(long bid) throws BbscsException {
    long atime = System.currentTimeMillis() - 7 * 24 * 3600 * 1000;
    List forums = this.getForumDAO().findForumsRealDelAll(bid, atime);
    for (int i = 0; i < forums.size(); i++) {
      Forum forum = (Forum) forums.get(i);
      try {
        if (forum.getHaveAttachFile() == 1 && forum.getAttachFileName() != null &&
            forum.getAttachFileName().size() > 0) {
          List fl = forum.getAttachFileName();
          String filePath = BBSCSUtil.getUpFilePath(forum.getBoardID(), forum.getPostTime());
          for (int j = 0; j < fl.size(); j++) {
            File attachFile = new File(filePath + (String) fl.get(j));
            if (attachFile.exists()) {
              FileUtils.forceDelete(attachFile);
            }
            File attachFileSmall = new File(filePath + (String) fl.get(j) + Constant.IMG_SMALL_FILEPREFIX);
            if (attachFileSmall.exists()) {
              FileUtils.forceDelete(attachFileSmall);
            }

          }
        }
        this.getForumDAO().removeForum(forum);
      }
      catch (Exception ex) {
        logger.error(ex);
        throw new BbscsException(ex);
      }
    }
  }

  public PageList findForumsAllManage(long bid, Pages pages) {
    OrderObj oo0 = new OrderObj("postTime", Constant.ORDER_DESC);
    OrderObj[] oo = {oo0};
    return this.findForums(bid, -1, 0, 0, oo, pages);
  }

  public PageList findForumsAllManage(List bids, Pages pages) {
    OrderObj oo0 = new OrderObj("postTime", Constant.ORDER_DESC);
    OrderObj[] oo = {oo0};
    return this.findForumsInBids(bids, -1, 0, 0, oo, pages);
  }

  public void saveForumsResume(List ids, Board board) throws BbscsException {
    List forums = this.getForumDAO().findForumsInIds(ids);
    for (int i = 0; i < forums.size(); i++) {
      Forum forum = (Forum) forums.get(i);
      if (forum.getAuditing() == 0) { //已通过审核的帖子恢复
        forum.setDelSign(0);
        if (forum.getIndexStatus() == Constant.INDEX_STATUS_NO_INDEX_TO_DEL) {
          forum.setIndexStatus(Constant.INDEX_STATUS_NO_INDEX);
        }
        else if (forum.getIndexStatus() == Constant.INDEX_STATUS_DELED) {
          forum.setIndexStatus(Constant.INDEX_STATUS_NO_INDEX);
        }
        try {
          this.getForumDAO().saveForum(forum);
          if (!forum.getId().equals(forum.getMainID())) {
            Forum mainForum = this.getForumDAO().findForumByID(forum.getMainID(), forum.getBoardID());
            if (mainForum != null) {
              mainForum.setReNum(mainForum.getReNum() + 1);
              this.getForumDAO().saveForum(mainForum);
            }
          }
          if (board.getAddUserPostNum() == 1) {
            UserInfo ui = this.getUserInfoDAO().findUserInfoById(forum.getUserID());
            if (ui != null) {
              ui.setArticleNum(ui.getArticleNum() + 1);
              ui = this.getUserInfoDAO().saveUserInfo(ui);
              this.getUserInfoFileIO().writeUserFile(ui);
            }
          }
        }
        catch (Exception ex) {
          logger.error(ex);
          throw new BbscsException(ex);
        }
      }
      else { //未通过审核的被删除的帖子恢复
        forum.setDelSign(0);
        try {
          this.getForumDAO().saveForum(forum);
        }
        catch (Exception ex1) {
          logger.error(ex1);
          throw new BbscsException(ex1);
        }
      }
    }
  }

  public void saveForumsAuditing(List ids, Board board) throws BbscsException {
    List forums = this.getForumDAO().findForumsInIds(ids);
    for (int i = 0; i < forums.size(); i++) {
      Forum forum = (Forum) forums.get(i);
      forum.setAuditing(0);
      if (forum.getIndexStatus() == Constant.INDEX_STATUS_AUDIT) {
        forum.setIndexStatus(Constant.INDEX_STATUS_NO_INDEX);
      }

      try {
        forum = this.getForumDAO().saveForum(forum);
        if (!forum.getId().equals(forum.getMainID())) { //不是主帖
          Forum mainForum = this.getForumDAO().findForumByID(forum.getMainID(), forum.getBoardID()); //取得主帖
          if (mainForum != null) {
            mainForum.setReNum(mainForum.getReNum() + 1); //增加主帖回复数
            mainForum.setLastPostNickName(forum.getNickName());
            mainForum.setLastPostUserName(forum.getUserName());

            if (forum.getParentID().equals(forum.getMainID())) { //回复的是主帖
              if (mainForum.getCanNotRe() == 0) {
                mainForum.setCanNotRe(1); //置主帖为不可自己删除和修改
              }
            }

            this.getForumDAO().saveForum(mainForum);
          }
        }
        if (board.getAddUserPostNum() == 1) {
          UserInfo ui = this.getUserInfoDAO().findUserInfoById(forum.getUserID());
          if (ui != null) {
            ui.setArticleNum(ui.getArticleNum() + 1);
            ui = this.getUserInfoDAO().saveUserInfo(ui);
            this.getUserInfoFileIO().writeUserFile(ui);
          }
        }
      }
      catch (Exception ex) {
        logger.error(ex);
        throw new BbscsException(ex);
      }
    }
  }

  public void saveForumsAuditingAttachFile(List ids) throws BbscsException {
    List forums = this.getForumDAO().findForumsInIds(ids);
    for (int i = 0; i < forums.size(); i++) {
      Forum forum = (Forum) forums.get(i);
      forum.setAuditingAttachFile(0);
      try {
        this.getForumDAO().saveForum(forum);
      }
      catch (Exception ex) {
        logger.error(ex);
        throw new BbscsException(ex);
      }
    }
  }

  public int getForumsAuditingAttachFileNum(long bid) {
    return this.getForumDAO().getForumNum(bid, -1, 0, -1, 1);
  }

  public PageList findForumsAuditingAttachFile(long bid, Pages pages) {
    OrderObj oo0 = new OrderObj("postTime", Constant.ORDER_DESC);
    OrderObj[] oo = {oo0};
    return this.findForums(bid, -1, 0, -1, 1, oo, pages);
  }

  public List findForumsTopicAuditingAttachFile(long bid, String mainID) {
    OrderObj oo0 = new OrderObj("postTime", Constant.ORDER_ASC);
    OrderObj[] oo = {oo0};
    return this.getForumDAO().findForumsTopic(bid, mainID, 0, -1, 1, oo);
  }

  public void saveForumChangeUser(Forum forum, int[] titleType, int[] values) throws BbscsException {
    try {
      forum = this.getForumDAO().saveForum

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?