📄 forummsgadmin.java
字号:
package com.bcxy.bbs.forum.admin;
/**
* Title:
* Description:
* Copyright:
* Company: www.liyunet.com
*
* @author lishujiang
* @version 1.0
*/
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import com.bcxy.bbs.forum.Forum;
import com.bcxy.bbs.forum.ForumPropertiesManager;
import com.bcxy.bbs.forum.SkinUtil;
import com.bcxy.bbs.forum.User;
import com.bcxy.bbs.util.BBSConst;
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.JdbcWrapper;
import com.bcxy.util.DateUtil;
import com.bcxy.util.StringUtil;
public class ForumMSGAdmin {
int forumID, rootID, announceID;
String userName, sql, url, action;
User theUser;
private Logger log = Logger.getLogger(ForumMSGAdmin.class);
public ForumMSGAdmin() {
}
public ForumMSGAdmin(HttpServletRequest request,
HttpServletResponse response) throws Exception {
userName = GCookie.getCookieValue(request, "UJBBUName", "");
theUser = SkinUtil.checkUser(request, response, 4);
checkAdmin(request, response);
adminMSG(request, response);
}
public void checkAdmin(HttpServletRequest request,
HttpServletResponse response) throws Exception {
action = ParamUtil.getString(request, "action");
if (action == null || "".equals(action))
throw new Exception("错误请求!");
forumID = ParamUtil.getInt(request, "forumID");
if (!action.equals("delall")) {
rootID = ParamUtil.getInt(request, "rootID");
announceID = ParamUtil.getInt(request, "announceID");
}
if (forumID == 0)
throw new Exception("请指定论坛版面");
Forum theForum = new Forum(forumID);
if (theForum == null
|| (theForum.getForumMaster().indexOf(userName) < 0 && theUser
.getUserClass() < 20))
throw new Exception("您不是该版面斑竹或者系统管理员。");
}
public void adminMSG(HttpServletRequest request,
HttpServletResponse response) throws Exception {
if (action.equals("lock")) {
lockMSG();
} else if (action.equals("unlock")) {
unlockMSG();
} else if (action.equals("deltopic")) {
delTopic();
} else if (action.equals("move")) {
String tempString = ParamUtil.getString(request, "checked");
if (tempString != null && "yes".equals(tempString)) {
moveTopic(request);
} else {
return;
}
} else if (action.equals("delall")) {
String tempString = ParamUtil.getString(request, "checked");
if (tempString != null && "yes".equals(tempString)) {
delAll(request);
} else {
return;
}
} else if (action.equals("copy")) {
String tempString = ParamUtil.getString(request, "checked");
if (tempString != null && "yes".equals(tempString)) {
copyTopic(request);
}
} else if (action.equals("top")) {
topMSG();
} else if (action.equals("untop")) {
untopMSG();
} else if (action.equals("alltop")) {
allTopMSG();
} else if (action.equals("unalltop")) {
unAlltopMSG();
} else if (action.equals("delmsg")) {
delMSG();
} else if (action.equals("isbest")) {
bestMSG();
} else if (action.equals("nobest")) {
unbestMSG();
} else {
throw new Exception("请选择相应操作。");
}
}
public void delAll(HttpServletRequest request) throws Exception {
String username = ParamUtil.getString(request, "username");
if (username == null || "".equals(username))
throw new Exception("请输入被帖子删除用户名。");
JdbcWrapper jw = new JdbcWrapper();
try {
jw.setAutoClose(false);
sql = "Select Count(announceID) from " + BBSConst.TABLE_BBS1
+ " where boardID=" + forumID + " and username='"
+ username + "'";
int titlenum = jw.doIntSearch(sql);
//
if (titlenum != 0) {
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 locktopic=2 where boardID=" + forumID
+ " and username=?";
jw.prepareStatement(sql);
jw.setString(1, username);
jw.executeUpdate();
jw.clearParameters();
//
sql = "update " + BBSConst.TABLE_USER + " set article=article-"
+ titlenum + ",userWealth=userWealth-"
+ (titlenum * wealthDel) + ",userEP=userEP-"
+ (titlenum * epDel) + ",userCP=userCP-"
+ (titlenum * cpDel) + " where username=?";
jw.prepareStatement(sql);
jw.setString(1, username);
jw.executeUpdate();
jw.clearParameters();
//
sql = "select count(announceid) from " + BBSConst.TABLE_BBS1
+ " where boardID=" + forumID;
int NewAnnounceNum = jw.doIntSearch(sql);
//
sql = "select count(announceid) from " + BBSConst.TABLE_BBS1
+ " where ParentID=0 and boardID=" + forumID;
int NewTopicNum = jw.doIntSearch(sql);
//
sql = "update " + BBSConst.TABLE_BOARD + " set lastbbsnum="
+ NewAnnounceNum + ",lasttopicnum=" + NewTopicNum
+ " where boardID=" + forumID;
jw.executeUpdate(sql);
}
} catch (Exception e) {
log.error("删除用户所有帖子出错", e);
throw e;
} finally {
jw.close();
}
}
public void copyTopic(HttpServletRequest request) throws Exception {
int newForumID = ParamUtil.getInt(request, "newForumID");
JdbcWrapper jw = new JdbcWrapper();
try {
//
jw.setAutoClose(false);
if (forumID == newForumID) {
throw new Exception("不能在相同版面内进行转移操作。");
} else {
sql = "select boardID,announceid,Parentid from "
+ BBSConst.TABLE_BBS1 + " where announceid="
+ announceID + " and boardID=" + forumID;
jw.executeQuery(sql);
if (!jw.next()) {
throw new Exception("您选择的贴子并不存在。");
} else {
if (jw.getInt(3) != 0) {
throw new Exception("您必须选择一个主题,而不是贴子。");
}
}
}
String newtopic, username, body, dateandtime, ip, Expression;
int msgLength, announceid;
sql = "select topic,username,body,dateAndTime,length,ip,Expression from "
+ BBSConst.TABLE_BBS1 + " where announceid=" + announceID;
jw.executeQuery(sql);
if (!jw.next()) {
throw new Exception("没有此贴!");
}
newtopic = jw.get(1);// + "-->" + userName + "添加";
username = jw.get(2);
body = jw.get(3);
dateandtime = jw.get(4);
msgLength = jw.getInt(5);
ip = jw.get(6);
Expression = jw.get(7);
//
sql = "insert into "
+ BBSConst.TABLE_BBS1
+ "(boardID,parentID,child,userName,topic,body,dateandtime,hits,length,rootID,layer,orders,ip,Expression,locktopic,signflag,emailflag,times,isvote,istop,isbest) values("
+ newForumID + ",0,0,?,?,?,'" + dateandtime + "', 0,"
+ msgLength + ",0,1,0,'" + ip + "','" + Expression
+ "',0,0,0,0,0,0,0)";
jw.prepareStatement(sql);
jw.setString(1, username);
jw.setString(2, newtopic);
jw.setString(3, body);
jw.executeUpdate();
jw.clearParameters();
//
sql = "select announceID from " + BBSConst.TABLE_BBS1
+ " order by announceID desc";
announceid = jw.doIntSearch(sql);
//
sql = "update " + BBSConst.TABLE_BBS1 + " set rootID=" + announceid
+ ",times=" + announceid + " where announceID="
+ announceid;
jw.executeUpdate(sql);
//
sql = "select count(*) from " + BBSConst.TABLE_BBS1
+ " where rootID=" + rootID
+ " and TO_DAYS(dateandtime)=TO_DAYS(now())";
int todayNum = jw.doIntSearch(sql);
// 更新论坛贴子数据
lastCount(forumID);
lastCount(newForumID);
forumNumAdd(newForumID, 0, 1, todayNum, jw);
allForumNumAdd(todayNum, 1, 0, jw);
//
url = "dispbbs.jsp?forumID=" + newForumID + "&rootID=" + announceid
+ "&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();
} catch (Exception e) {
log.error("复制帖子出错", e);
throw e;
} finally {
jw.close();
}
ForumPropertiesManager.resetManager();
}
public void moveTopic(HttpServletRequest request) throws Exception {
int newForumID = ParamUtil.getInt(request, "newForumID");
JdbcWrapper jw = new JdbcWrapper();
try {
//
jw.setAutoClose(false);
if (forumID == newForumID) {
throw new Exception("不能在相同版面内进行转移操作。");
} else {
sql = "select boardID,announceid,Parentid from "
+ BBSConst.TABLE_BBS1 + " where announceid="
+ announceID + " and boardID=" + forumID;
jw.executeQuery(sql);
if (!jw.next()) {
throw new Exception("您选择的贴子并不存在。");
} else {
if (jw.getInt(3) != 0) {
throw new Exception("您必须选择一个主题,而不是贴子。");
}
}
}
String leavemessage = ParamUtil.getString(request, "leavemessage");
if (leavemessage == null || leavemessage.equals("")) {
throw new Exception("请选择相应的操作!");
}
if (leavemessage.equals("yes")) {
// ON ERROR RESUME NEXT
} else if (leavemessage.equals("no")) {
sql = "select topic from " + BBSConst.TABLE_BBS1
+ " where announceid=" + rootID;
String newtopic = jw.doSearch(sql);// + "-->" + userName +
// "转移";
//
sql = "update " + BBSConst.TABLE_BBS1
+ " set topic=? where announceid=" + rootID;
jw.prepareStatement(sql);
jw.setString(1, newtopic);
jw.executeUpdate();
jw.clearParameters();
//
sql = "update " + BBSConst.TABLE_BBS1 + " set boardID="
+ newForumID + " where rootID=" + rootID;
jw.prepareStatement(sql);
jw.executeUpdate();
//
sql = "select count(*) from " + BBSConst.TABLE_BBS1
+ " where rootID=" + rootID
+ " and TO_DAYS(dateandtime)=TO_DAYS(now())";
int todayNum = jw.doIntSearch(sql);
// 更新论坛贴子数据
lastCount(forumID);
forumNumSub(forumID, 0, 1, todayNum, jw);
lastCount(newForumID);
forumNumAdd(newForumID, 0, 1, todayNum, jw);
// 更新论坛数据结束
url = "dispbbs.jsp?forumID=" + newForumID + "&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();
ForumPropertiesManager.resetManager();
} else {
throw new Exception("请选择相应操作。");
}
} catch (Exception e) {
log.error("移动帖子出错", e);
throw e;
} finally {
jw.close();
}
}
// public void copyMSG() throws Exception{}
public void lockMSG() throws Exception {
sql = "update " + BBSConst.TABLE_BBS1
+ " set locktopic=1 where boardID=" + forumID + " and rootID="
+ rootID;
JdbcWrapper jw = new JdbcWrapper();
try {
jw.setAutoClose(false);
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 unlockMSG() throws Exception {
JdbcWrapper jw = new JdbcWrapper();
try {
jw.setAutoClose(false);
sql = "update " + BBSConst.TABLE_BBS1
+ " set locktopic=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();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -