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

📄 postupdate.java

📁 天乙虚拟社区8.05版本。只支持Mysql
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.laoer.bbscs.update;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;

import com.laoer.bbscs.bean.Board;
import com.laoer.bbscs.bean.Forum;
import com.laoer.bbscs.bean.ForumMain;
import com.laoer.bbscs.bean.UserInfo;
import com.laoer.bbscs.comm.BBSCSUtil;
import com.laoer.bbscs.comm.Constant;
import com.laoer.bbscs.exception.BbscsException;
import com.laoer.bbscs.service.BoardService;
import com.laoer.bbscs.service.ForumService;
import com.laoer.bbscs.service.UserService;
import com.laoer.bbscs.service.config.ForumConfig;

public class PostUpdate {

	private ForumService forumService;

	private ForumService forumHistoryService;

	private BoardService boardService;

	private UserService userService;

	private ForumConfig forumConfig;

	public ForumService getForumService() {
		return forumService;
	}

	public void setForumService(ForumService forumService) {
		this.forumService = forumService;
	}

	public BoardService getBoardService() {
		return boardService;
	}

	public void setBoardService(BoardService boardService) {
		this.boardService = boardService;
	}

	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public ForumConfig getForumConfig() {
		return forumConfig;
	}

	public void setForumConfig(ForumConfig forumConfig) {
		this.forumConfig = forumConfig;
	}

	public ForumService getForumHistoryService() {
		return forumHistoryService;
	}

	public void setForumHistoryService(ForumService forumHistoryService) {
		this.forumHistoryService = forumHistoryService;
	}

	public void update() {
		String safepath = this.getForumConfig().getSafePath();
		if (!safepath.endsWith("/")) {
			safepath = safepath + "/";
		}
		File updateFile = new File(safepath + "update.txt");
		int flag = 0;
		try {
			String updeted = FileUtils.readFileToString(updateFile, Constant.CHARSET);
			if (StringUtils.isNotBlank(updeted)) {
				updeted = updeted.trim();
				flag = Integer.parseInt(updeted);
			}
		} catch (IOException e) {
			flag = 0;
		}
		if (flag == 0) {
			List l = this.getForumService().findForums(-1, -1, -1, -1, null);
			this.changeFile(l);
			// this.changeFilePath(l);

			l = this.getForumHistoryService().findForums(-1, -1, -1, -1, null);
			this.changeFile(l);
			// this.changeFilePath(l);
			try {
				FileUtils.writeStringToFile(updateFile, "1", Constant.CHARSET);
			} catch (IOException e) {
				// TODO 自动生成 catch 块
				e.printStackTrace();
			}
		}
	}

	private void changeFile(List l) {
		for (int i = 0; i < l.size(); i++) {
			Forum f = (Forum) l.get(i);
			if (f.getIsVote() == 0) {
				System.out.println(i + ":Post id:" + f.getId());
				String detail = f.getDetail();

				String postFileName = "P_" + f.getBoardID() + "_" + f.getId() + ".txt";
				File postFile = new File(this.getForumConfig().getForumPath(f.getBoardID(), f.getPostTime())
						+ postFileName);
				try {
					FileUtils.writeStringToFile(postFile, detail, Constant.CHARSET);
				} catch (IOException e) {
					// TODO 自动生成 catch 块
					e.printStackTrace();
				}
				f.setDetail(postFileName);

				try {
					this.getForumService().saveOrUpdateForum(f);
				} catch (BbscsException e) {
					// TODO 自动生成 catch 块
					e.printStackTrace();
				}
			}
		}
	}

	/*
	private void changeFilePath(List l) {
		for (int i = 0; i < l.size(); i++) {
			Forum f = (Forum) l.get(i);

			String detail = "";
			File oldFile = new File(this.getForumConfig().getForumPathOld(f.getBoardID(), f.getPostTime())
					+ f.getDetail());
			if (oldFile.exists()) {
				System.out.println(i + ":Post id:" + f.getId());
				try {
					// detail = FileUtils.readFileToString(oldFile);
					detail = FileUtils.readFileToString(oldFile, Constant.CHARSET);
				} catch (IOException e1) {
					// TODO 自动生成 catch 块
					e1.printStackTrace();
				}

				String postFileName = f.getDetail();
				File postFile = new File(this.getForumConfig().getForumPath(f.getBoardID(), f.getPostTime())
						+ postFileName);
				try {
					FileUtils.writeStringToFile(postFile, detail, Constant.CHARSET);
				} catch (IOException e) {
					// TODO 自动生成 catch 块
					e.printStackTrace();
				}

⌨️ 快捷键说明

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