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

📄 forummsgadmin.java

📁 一个用jsp写的完整的论坛源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		}
	}

	public void topMSG() throws Exception {
		JdbcWrapper jw = new JdbcWrapper();
		try {
			jw.setAutoClose(false);
			sql = "update " + BBSConst.TABLE_BBS1
					+ " set istop=1 where boardID=" + forumID + " and rootID="
					+ rootID;
			jw.executeUpdate(sql);
			url = "dispbbs.jsp?forumID=" + forumID + "&rootID=" + rootID
					+ "&announceID=" + rootID;
			sql = "insert into " + BBSConst.TABLE_LOG
					+ " (l_username,l_content,l_url,l_addtime) values (?,?,'"
					+ url + "','" + DateUtil.getLocalDate() + "')";
			jw.prepareStatement(sql);
			jw.setString(1, userName);
			jw.setString(2, "固顶帖子");
			jw.executeUpdate();
			// 清除缓存
			CacheManager.getCache(ENV.FORUM_TOPIC).remove(
					String.valueOf(rootID));
			CacheManager.getCache(ENV.FORUM_NEWS)
					.remove(String.valueOf(rootID));
		} catch (Exception e) {
			log.error("固顶帖子出错", e);
			throw e;
		} finally {
			jw.close();
		}
	}

	public void untopMSG() throws Exception {
		JdbcWrapper jw = new JdbcWrapper();
		try {
			jw.setAutoClose(false);
			sql = "update " + BBSConst.TABLE_BBS1
					+ " set istop=0 where boardID=" + forumID + " and rootID="
					+ rootID;
			jw.executeUpdate(sql);
			url = "dispbbs.jsp?forumID=" + forumID + "&rootID=" + rootID
					+ "&announceID=" + rootID;
			sql = "insert into " + BBSConst.TABLE_LOG
					+ " (l_username,l_content,l_url,l_addtime) values (?,?,'"
					+ url + "','" + DateUtil.getLocalDate() + "')";
			jw.prepareStatement(sql);
			jw.setString(1, userName);
			jw.setString(2, "解除固顶");
			jw.executeUpdate();
			// 清除缓存
			CacheManager.getCache(ENV.FORUM_TOPIC).remove(
					String.valueOf(rootID));
			CacheManager.getCache(ENV.FORUM_NEWS)
					.remove(String.valueOf(rootID));
		} catch (Exception e) {
			log.error("解除固顶帖子出错", e);
			throw e;
		} finally {
			jw.close();
		}
	}

	public void allTopMSG() throws Exception {
		JdbcWrapper jw = new JdbcWrapper();
		try {
			jw.setAutoClose(false);
			sql = "update " + BBSConst.TABLE_BBS1
					+ " set istop=2 where boardID=" + forumID + " and rootID="
					+ rootID;
			jw.executeUpdate(sql);
			url = "dispbbs.jsp?forumID=" + forumID + "&rootID=" + rootID
					+ "&announceID=" + rootID;
			sql = "insert into " + BBSConst.TABLE_LOG
					+ " (l_username,l_content,l_url,l_addtime) values (?,?,'"
					+ url + "','" + DateUtil.getLocalDate() + "')";
			jw.prepareStatement(sql);
			jw.setString(1, userName);
			jw.setString(2, "总固顶帖子");
			jw.executeUpdate();
			// 清除缓存
			CacheManager.getCache(ENV.FORUM_TOPIC).remove(
					String.valueOf(rootID));
			CacheManager.getCache(ENV.FORUM_NEWS)
					.remove(String.valueOf(rootID));
		} catch (Exception e) {
			log.error("总固顶帖子出错", e);
			throw e;
		} finally {
			jw.close();
		}
	}

	public void unAlltopMSG() throws Exception {
		JdbcWrapper jw = new JdbcWrapper();
		try {
			jw.setAutoClose(false);
			sql = "update " + BBSConst.TABLE_BBS1
					+ " set istop=0 where (boardID=" + forumID
					+ " or istop=2) and rootID=" + rootID;
			jw.executeUpdate(sql);
			url = "dispbbs.jsp?forumID=" + forumID + "&rootID=" + rootID
					+ "&announceID=" + rootID;
			sql = "insert into " + BBSConst.TABLE_LOG
					+ " (l_username,l_content,l_url,l_addtime) values (?,?,'"
					+ url + "','" + DateUtil.getLocalDate() + "')";
			jw.prepareStatement(sql);
			jw.setString(1, userName);
			jw.setString(2, "解除总固顶");
			jw.executeUpdate();
			// 清除缓存
			CacheManager.getCache(ENV.FORUM_TOPIC).remove(
					String.valueOf(rootID));
			CacheManager.getCache(ENV.FORUM_NEWS)
					.remove(String.valueOf(rootID));
		} catch (Exception e) {
			log.error("解除总固顶帖子出错", e);
			throw e;
		} finally {
			jw.close();
		}
	}

	public void bestMSG() throws Exception {
		JdbcWrapper jw = new JdbcWrapper();
		try {
			jw.setAutoClose(false);
			sql = "update " + BBSConst.TABLE_BBS1
					+ " set isbest=1 where boardID=" + forumID
					+ " and announceid=" + announceID;
			jw.executeUpdate(sql);
			url = "showannounce.jsp?forumID=" + forumID + "&rootID=" + rootID
					+ "&announceID=" + announceID;
			sql = "insert into " + BBSConst.TABLE_LOG
					+ " (l_username,l_content,l_url,l_addtime) values (?,?,'"
					+ url + "','" + DateUtil.getLocalDate() + "')";
			jw.prepareStatement(sql);
			jw.setString(1, userName);
			jw.setString(2, "加入精华");
			jw.executeUpdate();
			// 清除缓存
			CacheManager.getCache(ENV.FORUM_TOPIC).remove(
					String.valueOf(rootID));
			CacheManager.getCache(ENV.FORUM_NEWS)
					.remove(String.valueOf(rootID));
		} catch (Exception e) {
			log.error("将帖子加入精华出错", e);
			throw e;
		} finally {
			jw.close();
		}
	}

	public void unbestMSG() throws Exception {
		JdbcWrapper jw = new JdbcWrapper();
		try {
			jw.setAutoClose(false);
			sql = "update " + BBSConst.TABLE_BBS1
					+ " set isbest=0 where boardID=" + forumID
					+ " and announceid=" + announceID;
			jw.executeUpdate(sql);
			url = "showannounce.jsp?forumID=" + forumID + "&rootID=" + rootID
					+ "&announceID=" + announceID;
			sql = "insert into " + BBSConst.TABLE_LOG
					+ " (l_username,l_content,l_url,l_addtime) values (?,?,'"
					+ url + "','" + DateUtil.getLocalDate() + "')";
			jw.prepareStatement(sql);
			jw.setString(1, userName);
			jw.setString(2, "解除精华");
			jw.executeUpdate();
			// 清除缓存
			CacheManager.getCache(ENV.FORUM_TOPIC).remove(
					String.valueOf(rootID));
			CacheManager.getCache(ENV.FORUM_NEWS)
					.remove(String.valueOf(rootID));
		} catch (Exception e) {
			log.error("将帖子解除精华出错", e);
			throw e;
		} finally {
			jw.close();
		}
	}

	public void delMSG() throws Exception {
		JdbcWrapper jw = new JdbcWrapper();
		try {
			jw.setAutoClose(false);
			sql = "update " + BBSConst.TABLE_BBS1
					+ " set locktopic=2 where ParentID!=0 and announceid="
					+ announceID;
			jw.executeUpdate(sql);
			sql = "select Max(announceid) from " + BBSConst.TABLE_BBS1
					+ " where  locktopic!=2 and rootID=" + rootID
					+ " and boardID=" + forumID;
			int lastPostime = jw.doIntSearch(sql);
			//
			sql = "select count(*) from " + BBSConst.TABLE_BBS1
					+ " where announceid=" + announceID
					+ " and TO_DAYS(dateandtime)=TO_DAYS(now())";
			int todayNum = jw.doIntSearch(sql);
			//
			lastCount(forumID);
			forumNumSub(forumID, 0, 1, todayNum, jw);
			allForumNumSub(todayNum, 1, 0, jw);

			int wealthDel = Integer.parseInt(ForumPropertiesManager
					.getString("wealthDel"));

			int epDel = Integer.parseInt(ForumPropertiesManager
					.getString("epDel"));

			int cpDel = Integer.parseInt(ForumPropertiesManager
					.getString("cpDel"));

			sql = "update " + BBSConst.TABLE_BBS1 + " set times=" + lastPostime
					+ " where rootID=" + rootID + " and boardID=" + forumID;
			jw.executeUpdate(sql);
			// 修改论坛固顶存在的问题
			sql = "update " + BBSConst.TABLE_BBS1
					+ " set child=child-1 where announceid=" + rootID;
			jw.executeUpdate(sql);
			//
			sql = "update " + BBSConst.TABLE_USER
					+ " set article=article-1,userWealth=userWealth-"
					+ wealthDel + ",userEP=userEP-" + epDel + ",userCP=userCP-"
					+ cpDel + "  where username=?";
			jw.prepareStatement(sql);
			jw.setString(1, userName);
			jw.executeUpdate();
			jw.clearParameters();
			//
			url = "showannounce.jsp?forumID=" + forumID + "&rootID=" + rootID
					+ "&announceID=" + announceID;
			sql = "insert into " + BBSConst.TABLE_LOG
					+ " (l_username,l_content,l_url,l_addtime) values (?,?,'"
					+ url + "','" + DateUtil.getLocalDate() + "')";
			jw.prepareStatement(sql);
			jw.setString(1, userName);
			jw.setString(2, "删除帖子");
			jw.executeUpdate();
			// 清除缓存
			CacheManager.getCache(ENV.FORUM_TOPIC).remove(
					String.valueOf(announceID));
			CacheManager.getCache(ENV.FORUM_USER).remove(userName);
			ForumPropertiesManager.resetManager();
		} catch (Exception e) {
			log.error("删除帖子出错", e);
			throw e;
		} finally {
			jw.close();
		}
	}

	public void delTopic() throws Exception {
		JdbcWrapper jw = new JdbcWrapper();
		try {
			jw.setAutoClose(false);
			//
			sql = "select count(*) from " + BBSConst.TABLE_BBS1
					+ " where rootID=" + rootID;
			int postNum = jw.doIntSearch(sql);
			//
			sql = "select count(*) from " + BBSConst.TABLE_BBS1
					+ " where rootID=" + rootID
					+ " and TO_DAYS(dateandtime)=TO_DAYS(now())";
			int todayNum = jw.doIntSearch(sql);
			//
			int wealthDel = StringUtil.parseInt(ForumPropertiesManager
					.getString("wealthDel"));
			int epDel = StringUtil.parseInt(ForumPropertiesManager
					.getString("epDel"));
			int cpDel = StringUtil.parseInt(ForumPropertiesManager
					.getString("cpDel"));
			sql = "select username from " + BBSConst.TABLE_BBS1
					+ " where rootID=" + rootID;
			jw.executeQuery(sql);
			while (jw.next()) {
				String tempName = jw.getString(1);
				if (tempName != null && !"".equals(tempName)) {
					sql = "update " + BBSConst.TABLE_USER
							+ " set article=article-1,userWealth=userWealth-"
							+ wealthDel + ",userEP=userEP-" + epDel
							+ ",userCP=userCP-" + cpDel + " where username=?";
					jw.prepareStatement(sql);
					jw.setString(1, tempName);
					jw.executeUpdate();
					jw.clearParameters();
				}
			}
			//
			sql = "update " + BBSConst.TABLE_BBS1
					+ " set locktopic=2 where rootID=" + rootID;
			jw.executeUpdate(sql);
			//
			lastCount(forumID);
			forumNumSub(forumID, 1, postNum, todayNum, jw);
			allForumNumSub(todayNum, postNum, 1, jw);
			//
			url = "dispbbs.jsp?forumID=" + forumID + "&rootID=" + rootID
					+ "&announceID=" + rootID;
			sql = "insert into " + BBSConst.TABLE_LOG
					+ " (l_username,l_content,l_url,l_addtime) values (?,?,'"
					+ url + "','" + DateUtil.getLocalDate() + "')";
			jw.prepareStatement(sql);
			jw.setString(1, userName);
			jw.setString(2, "删除主题");
			jw.executeUpdate();
			// 清除缓存
			CacheManager.getCache(ENV.FORUM_TOPIC).remove(
					String.valueOf(rootID));
			CacheManager.getCache(ENV.FORUM).remove(String.valueOf(forumID));
			CacheManager.getCache(ENV.FORUM_USER).remove(userName);
			ForumPropertiesManager.resetManager();
		} catch (Exception e) {
			log.error("删除主题出错", e);
			throw e;
		} finally {
			jw.close();
		}
	}

	public void lastCount(int forumID) throws Exception {
		//
		JdbcWrapper _jw = new JdbcWrapper();
		_jw.executeQuery("select topic,body,rootID,dateandtime,username from "
				+ BBSConst.TABLE_BBS1 + " where locktopic!=2 and boardID="
				+ forumID + " order by announceid desc limit 0,1");
		String lastTopic, body, lastPost, lastPostUser;
		int lastRootID;
		if (_jw.next()) {
			lastTopic = _jw.getString(1);
			body = _jw.getString(2);
			if (lastTopic == null || "".equals(lastTopic)) {
				if (body.length() > 14) {
					lastTopic = body.substring(0, 14);
				} else {
					lastTopic = body;
				}
			}
			lastRootID = _jw.getInt(3);
			lastPost = _jw.getString(4);
			lastPostUser = _jw.getString(5);
		} else {
			lastTopic = "无";
			lastRootID = 0;
			lastPost = DateUtil.getLocalDate();
			lastPostUser = "无";
		}
		//
		sql = "update " + BBSConst.TABLE_BOARD + " set lastTopic='" + lastTopic
				+ "',lastRootID='" + lastRootID + "',lastPosttime='" + lastPost
				+ "',lastPostuser='" + lastPostUser + "' where boardID="
				+ forumID;
		_jw.executeUpdate(sql);
	}

	// 版面发帖数增加
	public void forumNumAdd(int forumID, int topicNum, int postNum,
			int todayNum, JdbcWrapper jw) throws Exception {
		sql = "update " + BBSConst.TABLE_BOARD + " set lastbbsnum=lastbbsnum+"
				+ postNum + ",lastTopicNum=lastTopicNum+" + topicNum
				+ ",todayNum=todayNum+" + todayNum + " where boardID="
				+ forumID;
		jw.executeUpdate(sql);
	}

	// 版面发帖数减少
	public void forumNumSub(int forumID, int topicNum, int postNum,
			int todayNum, JdbcWrapper jw) throws Exception {
		// 删除帖子,今日帖子数不减少
		todayNum = 0;
		sql = "update " + BBSConst.TABLE_BOARD + " set lastbbsnum=lastbbsnum-"
				+ postNum + ",lastTopicNum=lastTopicNum-" + topicNum
				+ ",todayNum=todayNum-" + todayNum + " where boardID="
				+ forumID;
		// 
		jw.executeUpdate(sql);
	}

	// 所有论坛发帖数增加
	public void allForumNumAdd(int todayNum, int postNum, int topicNum,
			JdbcWrapper jw) throws Exception {
		sql = "update config set TodayNum=todayNum+" + todayNum
				+ ",BbsNum=bbsNum+" + postNum + ",TopicNum=topicNum+"
				+ topicNum;
		jw.executeUpdate(sql);
	}

	// 所有论坛发帖数减少
	public void allForumNumSub(int todayNum, int postNum, int topicNum,
			JdbcWrapper jw) throws Exception {
		// 删除帖子,今日帖子数不减少
		todayNum = 0;
		sql = "update config set TodayNum=todayNum-" + todayNum
				+ ",BbsNum=bbsNum-" + postNum + ",TopicNum=topicNum-"
				+ topicNum;
		jw.executeUpdate(sql);
	}

}

⌨️ 快捷键说明

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