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

📄 forummsgpacker.java

📁 BBS论坛设计JSP+MYSQL
💻 JAVA
字号:
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.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.http.HttpServletRequest;

import com.bcxy.bbs.util.GCookie;
import com.bcxy.bbs.util.ParamUtil;
import com.bcxy.cache.CacheManager;
import com.bcxy.conf.ENV;
import com.bcxy.db.DBUtil;
import com.bcxy.db.SqlQuery;
import com.bcxy.util.SysUtil;

public class ForumMSGPacker {

	private int priID = 0;

	private int nextID = 0;

	private int rootID = 0;

	private int announceID = 0;

	private String priTopic = null;

	private String nextTopic = null;

	private String topic = null;

	private ForumMSG topicMSG = null;

	int hits = 0;

	public int getHits() {
		return hits;
	}

	public String getTopic() {
		return topic;
	}

	/**
	 * 
	 * @param viewMode
	 * @param viewNum
	 * @return
	 */
	public String checkViewMode(HttpServletRequest request, int rootId,
			int viewMode, int viewNum) {
		String ret = "";
		if (viewMode == 0) {
			return ret;
		}
		boolean foundUser = false, forumMaster = false, master = false;
		int userEP = 0, userCP = 0, userWealth = 0;
		SqlQuery rs = new SqlQuery();
		String userName = GCookie.getCookieValue(request, "UJBBUName", "");
		try {
			String sql = "select userclass, userep, usercp, userwealth from user where username='"
					+ userName + "'";
			rs.doQuery(sql);
			if (rs.next()) {
				int userClass = rs.getInt(1);
				userEP = rs.getInt(2);
				userCP = rs.getInt(3);
				userWealth = rs.getInt(4);
				//
				switch (userClass) {
				case 19:
					forumMaster = true;
					break;
				case 20:
					master = true;
					break;
				default:
					foundUser = true;
				}
				foundUser = true;
			}
		} catch (Exception e) {
			e.printStackTrace();
			foundUser = false;
			forumMaster = false;
			master = false;
		}
		//
		switch (viewMode) {
		case 0:
			ret = "";
			break;
		case 1:
			// 注册
			if (!foundUser) {
				ret = "<font color=red>该帖子内容只有<a href=login.jsp>登录</a>用户才可以查看!</font>";
			}
			break;
		case 2:
			// 回复
			if (foundUser) {
				String sql = "select announceid from bbs1 where username='"
						+ userName + "' and rootid=" + rootId;
				try {
					rs.doQuery(sql);
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				if (!rs.next()) {
					ret = "<font color=red>该帖子内容只有回复后才可以查看!</font>";
				}
			} else {
				ret = "<font color=red>该帖子内容只有回复后才可以查看!您还没有<a href=login.jsp>登录</a>!</font>";
			}
			break;
		case 3:
			// 管理员
			if (foundUser) {
				if (!(forumMaster || master)) {
					ret = "<font color=red>该帖子内容只有论坛版主或者管理员才可以查看!</font>";
				}
			} else {
				ret = "<font color=red>该帖子内容只有论坛版主或者管理员才可以查看!您还没有<a href=login.jsp>登录</a>!</font>";
			}
			break;
		case 4:
			// 经验
			if (foundUser) {
				if (userEP < viewNum) {
					ret = "<font color=red>您的经验值不够" + viewNum
							+ ",不能查看该帖子内容!</font>";
				}
			} else {
				ret = "<font color=red>您的经验值不够" + viewNum
						+ ",不能查看该帖子内容!您还没有<a href=login.jsp>登录</a>!</font>";
			}
			break;
		case 5:
			// 魅力
			if (foundUser) {
				if (userCP < viewNum) {
					ret = "<font color=red>您的魅力值不够" + viewNum
							+ ",不能查看该帖子内容!</font>";
				}
			} else {
				ret = "<font color=red>您的魅力值不够" + viewNum
						+ ",不能查看该帖子内容!您还没有<a href=login.jsp>登录</a>!</font>";
			}
			break;
		case 6:
			// 金钱
			if (foundUser) {
				if (userWealth < viewNum) {
					ret = "<font color=red>您的金钱值不够" + viewNum
							+ ",不能查看该帖子内容!</font>";
				}
			} else {
				ret = "<font color=red>您的金钱值不够" + viewNum
						+ ",不能查看该帖子内容!您还没有<a href=login.jsp>登录</a>!</font>";
			}
			break;
		}
		// System.out.println(ret);
		return ret;
	}

	public ForumMSGPacker(HttpServletRequest request, int forumID) {
		//
		int rRootID = ParamUtil.getInt(request, "rootID", 0);
		int rAnnounceID = ParamUtil.getInt(request, "announceID", 0);
		String action = ParamUtil.getString(request, "action", "");
		//
		SqlQuery db = new SqlQuery();
		Connection con = null;
		Statement stmt = null;
		ResultSet rs = null;
		String sql = null;
		int cnt = 0; // 主题的记录数
		try {
			// 是否上下主题
			if ("".equals(action)) {
				this.rootID = rRootID;
				this.announceID = rAnnounceID;
			} else {
				// 直接使用JDBC提高检索的效率
				sql = "select rootid from bbs1 where boardID="
						+ forumID
						+ " and parentID=0 and locktopic!=2 ORDER BY istop desc,times desc,announceid desc";
				con = DBUtil.getConnection();
				stmt = con.createStatement(ResultSet.CONCUR_READ_ONLY,
						ResultSet.TYPE_SCROLL_INSENSITIVE);
				rs = stmt.executeQuery(sql);
				while (rs.next()) {
					cnt++;
					if (rRootID == rs.getInt(1)) {
						break;
					}
				}
				if (cnt < 2) {
					cnt = 2;
				}
				rs.close();
				stmt.close();
				/**/
				if (!"next".equals(action)) {
					// 前一主题帖子的ID和标题
					sql = "select rootid,announceid from bbs1 where boardID="
							+ forumID
							+ " and parentID=0 and locktopic!=2 ORDER BY istop desc,times desc,announceid desc limit "
							+ (cnt - 2) + ",1";
					stmt = con.createStatement();
					rs = stmt.executeQuery(sql);
					while (rs.next()) {
						this.rootID = rs.getInt(1);
						this.announceID = rs.getInt(2);
					}
					rs.close();
					stmt.close();
				} else {
					// 下一主题帖子的ID和标题
					sql = "select rootid,announceid from bbs1 where boardID="
							+ forumID
							+ " and parentID=0 and locktopic!=2 ORDER BY istop desc,times desc,announceid desc limit "
							+ (cnt) + ",1";
					stmt = con.createStatement();
					rs = stmt.executeQuery(sql);
					while (rs.next()) {
						this.rootID = rs.getInt(1);
						this.announceID = rs.getInt(2);
					}
					rs.close();
					stmt.close();
				}
			}
			// 取得主题信息
			ForumMSG theMSG = (ForumMSG) CacheManager.getCache(ENV.FORUM_NEWS)
					.get(String.valueOf(this.rootID));
			if (theMSG == null) {
				theMSG = new ForumMSG(this.rootID);
				CacheManager.getCache(ENV.FORUM_NEWS).put(
						String.valueOf(this.rootID), theMSG);
			}
			this.topicMSG = theMSG;
			// 实时取得点击次数
			sql = "select topic, hits from bbs1 where rootid=" + this.rootID
					+ " and announceid=" + this.rootID;
			db.doQuery(sql);
			if (db.next()) {
				this.topic = db.get(1);
				this.hits = db.getInt(2);
			} else {
				this.topic = "";
				this.hits = 0;
			}

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			DBUtil.close(con);
		}
	}

	public ForumMSGPacker(int forumID, int rootID) {
		SqlQuery db = new SqlQuery();
		Connection con = null;
		Statement stmt = null;
		ResultSet rs = null;
		String sql = null;
		int cnt = 0; // 主题的记录数
		try {
			// 直接使用JDBC提高检索的效率
			sql = "select rootid,topic,hits from bbs1 where boardID="
					+ forumID
					+ " and parentID=0 and locktopic!=2 ORDER BY istop desc,times desc,announceid desc";
			con = DBUtil.getConnection();
			stmt = con.createStatement(ResultSet.CONCUR_READ_ONLY,
					ResultSet.TYPE_SCROLL_INSENSITIVE);
			rs = stmt.executeQuery(sql);
			while (rs.next()) {
				cnt++;
				if (rootID == rs.getInt(1)) {
					topic = SysUtil.encodeOutDB(rs.getString(2));
					hits = rs.getInt(3);
					break;
				}
			}
			if (cnt < 2) {
				cnt = 2;
			}
			rs.close();
			stmt.close();

			// 前一主题帖子的ID和标题
			sql = "select rootid,topic from bbs1 where boardID="
					+ forumID
					+ " and parentID=0 and locktopic!=2 ORDER BY			  istop desc,times desc,announceid desc limit "
					+ (cnt - 2) + ",1";
			db.doQuery(con, sql);
			while (db.next()) {
				priID = db.getInt(1);
				priTopic = db.get(2);
			}
			db.close(); // 下一主题帖子的ID和标题
			sql = "select  rootid,topic from bbs1 where boardID="
					+ forumID
					+ " and parentID=0  and locktopic!=2 ORDER BY istop desc,times desc,announceid desc limit "
					+ (cnt) + ",1";
			db.doQuery(con, sql);
			while (db.next()) {
				nextID = db.getInt(1);
				nextTopic = db.get(2);
			}
			db.close();

		} catch (Exception e) {
			System.out.println(e);
		} finally {
			DBUtil.close(con);
		}
	}

	public int getNextID() {
		return nextID;
	}

	public String getNextTopic() {
		return nextTopic;
	}

	public int getPriID() {
		return priID;
	}

	public String getPriTopic() {
		return priTopic;
	}

	public int getAnnounceID() {
		return announceID;
	}

	public void setAnnounceID(int announceID) {
		this.announceID = announceID;
	}

	public int getRootID() {
		return rootID;
	}

	public void setRootID(int rootID) {
		this.rootID = rootID;
	}

	public void setHits(int hits) {
		this.hits = hits;
	}

	public void setNextID(int nextID) {
		this.nextID = nextID;
	}

	public void setNextTopic(String nextTopic) {
		this.nextTopic = nextTopic;
	}

	public void setPriID(int priID) {
		this.priID = priID;
	}

	public void setPriTopic(String priTopic) {
		this.priTopic = priTopic;
	}

	public void setTopic(String topic) {
		this.topic = topic;
	}

	public ForumMSG getTopicMSG() {
		return topicMSG;
	}

	public void setTopicMSG(ForumMSG topicMSG) {
		this.topicMSG = topicMSG;
	}

}

⌨️ 快捷键说明

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