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

📄 forum.java

📁 BBS论坛设计JSP+MYSQL
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
package com.bcxy.bbs.forum;

/**
 * <p>Title:</p>
 * <p>Description:</p>
 * <p>Copyright:</p>
 * <p>Company: www.liyunet.com</p>
 * 
 * @author lishujiang
 * @version 1.0
 */

import java.util.Vector;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.bcxy.bbs.database.DBConnect;
import com.bcxy.bbs.util.Format;
import com.bcxy.bbs.util.GCookie;
import com.bcxy.bbs.util.ParamUtil;
import com.bcxy.bbs.util.StringUtils;
import com.bcxy.cache.CacheManager;
import com.bcxy.conf.ENV;
import com.bcxy.db.SqlQuery;
import com.bcxy.mail.SendMail;
import com.bcxy.util.StringUtil;
import com.bcxy.util.SysUtil;

public class Forum {

	private static Logger log = Logger.getLogger(Forum.class);

	int forumID, forumClass, lockForum, forumSkin, lastBbsNum;

	int lastTopicNum, strAllowForumCode, strAllowHTML, strIMGInPosts;

	int strIcons, strFlash, lastRootID, todayNum;

	int voteID;

	String forumType, readMe, forumMaster;

	String tableBack, tableTitle, tableBody, aTableBody, tableFont,
			tableContent;

	String alertFont, lastPostUser, lastPostTime, forumLogo, indexIMG,
			lastTopic, forumUser;

	Vector forumOLUsers;

	int forumTopicNum;

	int forumOLGuestUsersNum = 0, forumOLMemberUsersNum = 0,
			forumsOLUsersNum = 0;

	int forumMSGsNum = 0;

	ForumTopic forumMSGTopic;

	public Forum() {
	}

	public Forum(HttpServletRequest request, HttpServletResponse response,
			int forumID) throws ForumNotFoundException {
		init(forumID);
		SkinUtil.checkUserStats(request, response, this.forumType);
		this.getOnline();
	}

	public Forum(int forumID) throws ForumNotFoundException {
		init(forumID);

		this.getOnline();
	}

	public void init(int forumID) throws ForumNotFoundException {
		Forum theForum = (Forum) CacheManager.getCache(ENV.FORUM).get(
				String.valueOf(forumID));
		if (theForum != null) {
			this.forumID = theForum.getForumID();
			forumType = theForum.getForumType();
			forumClass = theForum.getForumClass();
			readMe = theForum.getReadMe();
			forumMaster = theForum.getForumMaster();
			lockForum = theForum.getLockForum();
			forumSkin = theForum.getForumSkin();
			tableBack = theForum.getTableBack();
			tableTitle = theForum.getTableTitle();
			tableBody = theForum.getTableBody();
			aTableBody = theForum.getATableBody();
			tableFont = theForum.getTableFont();
			tableContent = theForum.getTableContent();
			alertFont = theForum.getAlertFont();
			lastPostUser = theForum.getLastPostUser();
			lastPostTime = theForum.getLastPostTime();
			lastBbsNum = theForum.getLastBbsNum();
			lastTopicNum = theForum.getLastTopicNum();
			strAllowForumCode = theForum.getStrAllowForumCode() ? 1 : 0;
			strAllowHTML = theForum.getStrAllowHTML() ? 1 : 0;
			strIMGInPosts = theForum.getStrIMGInPosts() ? 1 : 0;
			strIcons = theForum.getStrIcons() ? 1 : 0;
			strFlash = theForum.getStrFlash() ? 1 : 0;
			forumLogo = theForum.getForumLogo();
			indexIMG = theForum.getIndexIMG();
			lastRootID = theForum.getLastRootID();
			lastTopic = theForum.getLastTopic();
			todayNum = theForum.getTodayNum();
			forumUser = theForum.getForumUser();
		} else {
			//
			theForum = new Forum();
			SqlQuery rs = new SqlQuery();
			try {
				rs.doQuery("select * from board where boardid=" + forumID);
				rs.next();
				this.forumID = rs.getInt(1);

				forumType = rs.getString(2);
				forumClass = rs.getInt(3);
				readMe = rs.getString(4);
				forumMaster = rs.getString(5);
				lockForum = rs.getInt(6);
				forumSkin = rs.getInt(7);
				tableBack = rs.getString(8);
				tableTitle = rs.getString(9);
				tableBody = rs.getString(10);
				aTableBody = rs.getString(11);
				tableFont = rs.getString(12);
				tableContent = rs.getString(13);
				alertFont = rs.getString(14);
				lastPostUser = rs.getString(15);
				lastPostTime = rs.getString(16);
				lastBbsNum = rs.getInt(17);
				lastTopicNum = rs.getInt(18);
				strAllowForumCode = rs.getInt(19);
				strAllowHTML = rs.getInt(20);
				strIMGInPosts = rs.getInt(21);
				strIcons = rs.getInt(22);
				strFlash = rs.getInt(23);
				forumLogo = rs.getString(24);
				indexIMG = rs.getString(25);
				lastRootID = rs.getInt(26);
				lastTopic = rs.getString(27);
				todayNum = rs.getInt(28);
				forumUser = rs.getString(29);
				//
				CacheManager.getCache(ENV.FORUM).put(
						String.valueOf(this.forumID), this);
			} catch (Exception e) {
				log.error(e);
				throw new ForumNotFoundException(e.getMessage());
			} finally {
				rs.close();
			}
		}
	}

	public Vector getOnline() throws ForumNotFoundException {
		SqlQuery rs = new SqlQuery();
		forumOLUsers = new Vector();
		try {
			forumsOLUsersNum = rs
					.doIntSearch("select count(*) from online order by id");
			rs.doQuery("select * from online where stats like '%"
					+ SysUtil.encodeInDB(forumType) + "%' order by id");

			while (rs.next()) {// &&this.forumType.equals(rs.getString(4).trim())){
				OLUser tempOLUser = new OLUser();
				tempOLUser.setUserID(rs.getString(1));
				if ("guest".equals(rs.getString(2)))
					forumOLGuestUsersNum++;
				else
					forumOLMemberUsersNum++;
				tempOLUser.setUserName(rs.getString(2));
				tempOLUser.setUserClass(rs.getString(3));
				tempOLUser.setStats(rs.getString(4));
				tempOLUser.setUserIP(rs.getString(5));
				tempOLUser.setStartTime(rs.getString(6));
				tempOLUser.setLastTimeBK(rs.getString(7));
				tempOLUser.setLastTime(rs.getString(8));
				tempOLUser.setBrowser(rs.getString(9));
				tempOLUser.setActForIP(rs.getString(10));
				tempOLUser.setComeFrom(rs.getString(11));
				tempOLUser.setActCome(rs.getString(12));
				forumOLUsers.add(tempOLUser);
			}
		} catch (Exception e) {
			log.error(e);
			throw new ForumNotFoundException(e.getMessage());
		} finally {
			rs.close();
		}
		return forumOLUsers;

	}

	public Vector getForumTopics(int forumID, int Page, int perPage)
			throws ForumTopicNotFoundException {
		SqlQuery rs = new SqlQuery(); // 每次取出20条数据,和用JDBC性能相差不大
		Vector forumTopics = new Vector();
		try {
			forumTopicNum = rs
					.doIntSearch("select count(announceid) from bbs1 where boardID="
							+ forumID + " and parentID=0  and  locktopic!=2");
			int maxAnnouncePerPage = StringUtil.parseInt(ForumPropertiesManager
					.getString("MaxAnnouncePerPage"));
			// 数据量比较大,利用MYSQL特性实现分页提高性能
			String sql = "select announceid,rootid,child,hits from bbs1 where (boardID="
					+ forumID
					+ " or istop=2) and parentID=0  and  locktopic!=2 ORDER BY istop desc,times desc,announceid desc limit "
					+ ((Page - 1) * maxAnnouncePerPage) + ","
					+ maxAnnouncePerPage;
			rs.doQuery(sql);
			while (rs.next()) {
				int announceID = rs.getInt(1);
				int forumRootID = rs.getInt(2);
				ForumTopic theTopic = (ForumTopic) CacheManager.getCache(
						ENV.FORUM_TOPIC).get(String.valueOf(announceID));
				if (theTopic == null) {
					theTopic = new ForumTopic(forumRootID, announceID);
					CacheManager.getCache(ENV.FORUM_TOPIC).put(
							String.valueOf(announceID), theTopic);
				}else{
					theTopic.setChildNum(rs.getInt(3));
					theTopic.setHits(rs.getInt(4));
				}
				forumTopics.add(theTopic);
			}
		} catch (Exception e) {
			log.error(e);
			throw new ForumTopicNotFoundException(e.getMessage());
		} finally {
			rs.close();
		}
		return forumTopics;
	}

	/**
	 * 取得所有帖子主题信息
	 * @param Page
	 * @param perPage
	 * @param type 1:普通帖子;2:固顶帖子;3:精华帖子;
	 * @return
	 * @throws ForumTopicNotFoundException
	 */
	public static Vector getAllTopics(int Page, int perPage, int type)
			throws ForumTopicNotFoundException {
		SqlQuery rs = new SqlQuery(); // 每次取出20条数据,和用JDBC性能相差不大
		Vector forumTopics = new Vector();
		try {
			// 数据量比较大,利用MYSQL特性实现分页提高性能
			String sql = "select announceid,rootid from bbs1 where ";
			switch(type)
			{
				case 1:
					sql += " 1=1 ";
					break;
				case 2:
					sql += " istop=1 ";
					break;
				case 3:
					sql += " isbest=1 ";
					break;
				default:
					sql += " 1=1 ";	
			}
			sql += " and parentID=0  and  locktopic!=2 ORDER BY times desc,announceid desc limit "
				+ ((Page - 1) * perPage) + ","
				+ perPage;

			rs.doQuery(sql);
			while (rs.next()) {
				int announceID = rs.getInt(1);
				int forumRootID = rs.getInt(2);
				ForumTopic theTopic = (ForumTopic) CacheManager.getCache(
						ENV.FORUM_TOPIC).get(String.valueOf(announceID));
				if (theTopic == null) {
					theTopic = new ForumTopic(forumRootID, announceID);
					CacheManager.getCache(ENV.FORUM_TOPIC).put(
							String.valueOf(announceID), theTopic);
				}
				forumTopics.add(theTopic);
			}
		} catch (Exception e) {
			log.error(e);
			throw new ForumTopicNotFoundException(e.getMessage());
		} finally {
			rs.close();
		}
		return forumTopics;
	}

	public Vector getForumBestTopics(int forumID, int Page, int perPage)
			throws ForumTopicNotFoundException {
		SqlQuery rs = new SqlQuery();
		Vector forumTopics = new Vector();
		try {
			// 数据量比较少,利用方法实现分页提高可移植性
			String sql = "select announceid,rootid from bbs1 where boardID="
					+ forumID
					+ " and isBest=1 and locktopic!=2  ORDER BY bbs1.times desc,bbs1.announceid desc";
			rs.doQuery(sql, perPage, Page);
			forumTopicNum = rs.rowAllCount();
			while (rs.next()) {
				int announceID = rs.getInt(1);
				int forumRootID = rs.getInt(2);
				ForumTopic theTopic = (ForumTopic) CacheManager.getCache(
						ENV.FORUM_TOPIC).get(String.valueOf(announceID));
				if (theTopic == null) {
					theTopic = new ForumTopic(forumRootID, announceID);
					CacheManager.getCache(ENV.FORUM_TOPIC).put(
							String.valueOf(announceID), theTopic);
				}
				forumTopics.add(theTopic);
			}
		} catch (Exception e) {
			log.error(e);
			throw new ForumTopicNotFoundException(e.getMessage());
		} finally {
			rs.close();
		}
		return forumTopics;
	}

	public static Vector getFollowTopics(int forumID, int rootID) {
		SqlQuery rs = new SqlQuery();
		Vector followTopics = new Vector();
		try {
			String sql = "select announceID from bbs1,board where bbs1.boardid="
					+ forumID
					+ " and bbs1.rootid="
					+ rootID
					+ " and bbs1.announceid<>"
					+ rootID
					+ " and bbs1.boardid=board.boardid and  bbs1.locktopic!=2 order by bbs1.rootid desc,bbs1.orders";
			rs.doQuery(sql);

			while (rs.next()) {
				int announceID = rs.getInt(1);
				ForumTopic theMSG = (ForumTopic) CacheManager.getCache(
						ENV.FORUM_TOPIC).get(String.valueOf(announceID));
				if (theMSG == null) {
					theMSG = new ForumTopic(rootID, announceID);
					CacheManager.getCache(ENV.FORUM_TOPIC).put(
							String.valueOf(announceID), theMSG);
				}
				followTopics.add(theMSG);
			}
		} catch (Exception e) {
			log.error(e);
		} finally {
			rs.close();
		}
		return followTopics;
	}

	public ForumMSG getForumMSGTopic() {
		return this.forumMSGTopic;
	}

	public Vector getForumMSGs(int forumID, int rootID, int announceID,
			int start, int perPage) throws ForumMSGNotFoundException {
		SqlQuery rs = new SqlQuery();
		Vector forumMSGs = new Vector();
		String sql = null;
		try {
			// 回复帖子数量
			sql = " select count(*) from bbs1 B where B.rootid=" + rootID
					+ " and B.lockTopic!=2 order by announceid ";
			forumMSGsNum = rs.doIntSearch(sql);

			sql = " Select B.AnnounceID,B.UserName " + " from bbs1 B "
					//+ " where (B.boardid=" + forumID + " or B.istop=2) and B.rootid=" + rootID
					+ " where B.rootid=" + rootID
					+ " and B.lockTopic!=2 order by announceid limit "
					+ (start - 1) + "," + (perPage);
			//
			rs.doQuery(sql);
			while (rs.next()) {
				//
				int aid = rs.getInt(1);
				ForumMSG theMSG = (ForumMSG) CacheManager.getCache(
						ENV.FORUM_NEWS).get(String.valueOf(aid));
				if (theMSG == null) {
					theMSG = new ForumMSG(aid);
					CacheManager.getCache(ENV.FORUM_NEWS).put(

⌨️ 快捷键说明

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