⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 forumserviceimp.java

📁 天乙虚拟社区8.05版本。只支持Mysql
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                * attachFileSmall = new File(filePath + fn +
                * Constant.IMG_SMALL_FILEPREFIX); if (attachFileSmall.exists()) {
                * FileUtils.forceDelete(attachFileSmall); } fl.remove(fn); }
                */
            List fl = this.getForumUploadFile().delUploadFile(forum, fileNames);
            forum.setAttachFileName(fl);
            this.getForumDAO().saveOrUpdateForum(forum);
        } catch (Exception ex) {
            logger.error(ex);
            throw new BbscsException(ex);
        }
    }

    public void removeForum(String id, long bid) throws BbscsException {
        try {
            this.getForumDAO().removeForum(id, bid);
        } catch (Exception ex) {
            logger.error(ex);
            throw new BbscsException(ex);
        }
    }

    public void removeForum(String id) throws BbscsException {
        try {
            this.getForumDAO().removeForum(id);
        } catch (Exception ex) {
            logger.error(ex);
            throw new BbscsException(ex);
        }

    }

    public void removeForum(Forum forum) throws BbscsException {
        try {
            this.getForumDAO().removeForum(forum);
        } catch (Exception ex) {
            logger.error(ex);
            throw new BbscsException(ex);
        }
    }

    public void removeToHistory(long atime) throws BbscsException {
        // String month = Util.formatDate(new Date(atime), "yyyy-MM");
        // if (!BBSCSUtil.ArchivesMonthInFile(month)) {
        // BBSCSUtil.writeMonthToFile(month);
        // }
        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, -1, null);
            for (int j = 0; j < fl.size(); j++) {
                Forum mf = (Forum) fl.get(j);
                Forum fh = new ForumHistory();
                try {
                    BeanUtils.copyProperties(fh, mf);
                    this.getForumHistoryDAO().saveForum(fh);
                    this.getForumDAO().removeForum(mf);
                } catch (Exception ex) {
                    logger.error(ex);
                    throw new BbscsException(ex);
                }
            }
        }
    }

    public Forum saveEditForum(Forum forum) throws BbscsException {
        this.getSysListObjCache().remove(Constant.FORUM_NEW_CACHE_NAME);
        try {
            if (Constant.POST_STORAGE_MODE == 0) {
                return this.getForumDAO().saveOrUpdateForum(forum);
            } else {
                String detail = forum.getDetail();
                String postFileName = "P_" + forum.getBoardID() + "_" + forum.getId() + ".txt";
                File postFile = new File(this.getForumConfig().getForumPath(forum.getBoardID(), forum.getPostTime())
                        + postFileName);
                FileUtils.writeStringToFile(postFile, detail, Constant.CHARSET);
                forum.setDetail(postFileName);
                forum = this.getForumDAO().saveOrUpdateForum(forum);
                this.getPostCache().remove(forum.getId());
                return forum;
            }
        } catch (Exception ex) {
            logger.error(ex);
            throw new BbscsException(ex);
        }
    }

    public Forum saveForum(Forum forum) throws BbscsException {
        try {
            return this.getForumDAO().saveForum(forum);
        } catch (Exception e) {
            logger.error(e);
            throw new BbscsException(e);
        }
    }

    public void saveForumBuy(long bid, String postId, Forum f, UserInfo buyFromUi) throws BbscsException {
        ForumBuy forumBuy = new ForumBuy();
        forumBuy.setPostID(postId);
        forumBuy.setBuyFromID(buyFromUi.getId());
        forumBuy.setBuyFromName(buyFromUi.getUserName());
        forumBuy.setBuyPrice(f.getIsHiddenValue());
        forumBuy.setBuyTime(System.currentTimeMillis());
        forumBuy.setBuyToID(f.getUserID());
        forumBuy.setBuyToName(f.getUserName());

        int income = (int) (f.getIsHiddenValue() * this.getSysConfig().getPostPriceTax());
        forumBuy.setBuyToUserIncome(income);
        buyFromUi.setCoin(buyFromUi.getCoin() - f.getIsHiddenValue());
        UserInfo ui = this.getUserInfoDAO().findUserInfoById(f.getUserID());
        ui.setCoin(ui.getCoin() + income);

        try {
            this.getForumBuyDAO().saveForumBuy(forumBuy);
            ui = this.getUserInfoDAO().saveUserInfo(ui);
            buyFromUi = this.getUserInfoDAO().saveUserInfo(buyFromUi);
            this.getUserInfoFileIO().writeUserFile(ui);
            this.getUserInfoFileIO().writeUserFile(buyFromUi);
        } catch (Exception ex) {
            logger.error(ex);
            throw new BbscsException(ex);
        }
    }

    public void saveForumChangeUser(Forum forum, int[] titleType, int[] values) throws BbscsException {
        try {
            forum = this.getForumDAO().saveOrUpdateForum(forum);
            if (titleType != null && values != null && titleType.length == values.length) {
                UserInfo ui = this.getUserInfoDAO().findUserInfoById(forum.getUserID());
                if (ui != null) {
                    for (int i = 0; i < titleType.length; i++) {
                        switch (titleType[i]) {
                            case 0:
                                ui.setExperience(ui.getExperience() + values[i]);
                            case 1:
                                ui.setLiterary(ui.getLiterary() + values[i]);
                            case 2:
                                ui.setUserKnow(ui.getUserKnow() + values[i]);
                            case 3:
                                ui.setCoin(ui.getCoin() + values[i]);
                            default:
                                ui.setExperience(ui.getExperience() + values[i]);
                        }
                    }
                    ui = this.getUserInfoDAO().saveUserInfo(ui);
                    this.getUserInfoFileIO().writeUserFile(ui);
                }
            }
        } catch (Exception ex) {
            logger.error(ex);
            throw new BbscsException(ex);
        }
    }

    public void saveForumChangeUser(Forum forum, int titleType, int values) throws BbscsException {
        try {
            forum = this.getForumDAO().saveOrUpdateForum(forum);
            UserInfo ui = this.getUserInfoDAO().findUserInfoById(forum.getUserID());
            if (ui != null) {
                switch (titleType) {
                    case 0:
                        ui.setExperience(ui.getExperience() + values);
                    case 1:
                        ui.setLiterary(ui.getLiterary() + values);
                    case 2:
                        ui.setUserKnow(ui.getUserKnow() + values);
                    case 3:
                        ui.setCoin(ui.getCoin() + values);
                    default:
                        ui.setExperience(ui.getExperience() + values);
                }
                ui = this.getUserInfoDAO().saveUserInfo(ui);
                this.getUserInfoFileIO().writeUserFile(ui);
            }
        } catch (Exception ex) {
            logger.error(ex);
            throw new BbscsException(ex);
        }
    }

    public void saveForumCommend(int createOrDel, Board board, Forum f) throws BbscsException {
        long topbid = board.getTopBid();
        if (createOrDel == 0) {
            if (f.getCommend() == 0) {
                try {
                    f.setCommend(topbid);
                    f = this.getForumDAO().saveOrUpdateForum(f);
                    UserInfo ui = this.getUserInfoDAO().findUserInfoById(f.getUserID());
                    ui.setLiterary(ui.getLiterary() + 1);
                    ui = this.getUserInfoDAO().saveUserInfo(ui);
                    this.getUserInfoFileIO().writeUserFile(ui);
                    Commend commend = this.getCommendDAO().findCommendByPostID(f.getId());
                    if (commend == null) {
                        commend = new Commend();
                        commend.setBoardCategory("");
                        commend.setBoardID(board.getId().longValue());
                        commend.setBoardName(board.getBoardName());
                        commend.setCommendBoardID(topbid);
                        commend.setCommendTop(0);
                        commend.setCreateTime(System.currentTimeMillis());
                        commend.setPostID(f.getId());
                        commend.setPostMainID(f.getMainID());
                        commend.setTitle(f.getTitle());
                        commend.setTopCategory("");
                        commend.setUserID(f.getUserID());
                        commend.setUserName(f.getUserName());
                        this.getCommendDAO().saveCommend(commend);
                    }
                    List commendList = this.getCommendDAO().findCommendsByCommendBoardID(topbid, 0, 10);
                    this.getCommendFileIO().saveCommendInReadPageFile(topbid, commendList);
                } catch (Exception ex1) {
                    logger.error(ex1);
                    throw new BbscsException(ex1);
                }
            }
        } else {
            if (f.getCommend() != 0) {
                try {
                    f.setCommend(0);
                    f = this.getForumDAO().saveOrUpdateForum(f);
                    UserInfo ui = this.getUserInfoDAO().findUserInfoById(f.getUserID());
                    ui.setLiterary(ui.getLiterary() - 1);
                    ui = this.getUserInfoDAO().saveUserInfo(ui);
                    this.getUserInfoFileIO().writeUserFile(ui);
                    this.getCommendDAO().removeCommend(f.getId());
                    List commendList = this.getCommendDAO().findCommendsByCommendBoardID(topbid, 0, 10);
                    this.getCommendFileIO().saveCommendInReadPageFile(topbid, commendList);
                } catch (Exception ex2) {
                    logger.error(ex2);
                    throw new BbscsException(ex2);
                }
            }
        }
        // -------------
        this.getSysListObjCache().remove(Constant.COMMEND_CACHE_NAME);
        // -------------
    }

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

    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().saveOrUpdateForum(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());
                        mainForum.setLastPostTitle(forum.getTitle());
                        mainForum.setLastTime(forum.getPostTime());

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

                        this.getForumDAO().saveOrUpdateForum(mainForum);
                    }
                    Forum pforum = this.getForumDAO().findForumByID(forum.getParentID(), forum.getBoardID());
                    if (pforum != null) {
                        if (pforum.getCanNotRe() == 0) {
                            pforum.setCanNotRe(1); // 置父帖帖为不可自己删除和修改
                        }
                        this.getForumDAO().saveOrUpdateForum(pforum);
                    }
                }
                if (board.getAddUserPostNum() == 1) {
                    UserInfo ui = this.getUserInfoDAO().findUserInfoById(forum.getUserID());
                    if (ui != null) {
                        ui.setArticleNum(ui.getArticleNum() + 1);
                        if (forum.getIsNew() == 1) {
                            ui.setExperience(ui.getExperience() + 2); // 发帖增加经验值2点。add
                            // at
                            // 2007.2.23
                        } else {
                            ui.setExperience(ui.getExperience() + 1); //

⌨️ 快捷键说明

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