📄 forummsgadmin.java
字号:
package com.bcxy.bbs.forum.admin;
/**
* Title:
* Description:
* Copyright:
* Company: www.liyunet.com
*
* @author lishujiang
* @version 1.0
*/
import java.sql.ResultSet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.bcxy.bbs.database.DBConnect;
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.Format;
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.SqlQuery;
import com.bcxy.util.DateUtil;
public class ForumMSGAdmin {
int forumID, rootID, announceID;
String userName, sql, url, action;
User theUser;
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("请输入被帖子删除用户名。");
DBConnect dbc = null;
try {
dbc = new DBConnect();
sql = "Select Count(announceID) from bbs1 where boardID=" + forumID
+ " and username=?";
dbc.prepareStatement(sql);
dbc.setString(1, username);
ResultSet rs = dbc.executeQuery();
rs.next();
int titlenum = rs.getInt(1);
rs.close();
//
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 bbs1 set locktopic=2 where boardID=" + forumID
+ " and username=?";
dbc.prepareStatement(sql);
dbc.setString(1, username);
dbc.executeUpdate();
sql = "update user set article=article-" + titlenum
+ ",userWealth=userWealth-" + (titlenum * wealthDel)
+ ",userEP=userEP-" + (titlenum * epDel)
+ ",userCP=userCP-" + (titlenum * cpDel)
+ " where username=?";
dbc.prepareStatement(sql);
dbc.setBytes(1, username.getBytes("GBK"));
dbc.executeUpdate();
//
sql = "select count(announceid) from bbs1 where boardID="
+ forumID;
rs = dbc.executeQuery(sql);
rs.next();
int NewAnnounceNum = rs.getInt(1);
rs.close();
//
sql = "select count(announceid) from bbs1 where ParentID=0 and boardID="
+ forumID;
rs = dbc.executeQuery(sql);
rs.next();
int NewTopicNum = rs.getInt(1);
rs.close();
//
sql = "update board set lastbbsnum=" + NewAnnounceNum
+ ",lasttopicnum=" + NewTopicNum + " where boardID="
+ forumID;
dbc.executeUpdate();
}
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
dbc.close();
}
}
public void copyTopic(HttpServletRequest request) throws Exception {
int newForumID = ParamUtil.getInt(request, "newForumID");
DBConnect dbc = null;
ResultSet rs;
try {
dbc = new DBConnect();
if (forumID == newForumID) {
dbc.close();
throw new Exception("不能在相同版面内进行转移操作。");
} else {
sql = "select boardID,announceid,Parentid from bbs1 where announceid="
+ announceID + " and boardID=" + forumID;
dbc.prepareStatement(sql);
rs = dbc.executeQuery();
if (!rs.next()) {
dbc.close();
throw new Exception("您选择的贴子并不存在。");
} else {
// rs.next();
if (rs.getInt(3) != 0) {
dbc.close();
throw new Exception("您必须选择一个主题,而不是贴子。");
}
}
}
String newtopic, username, body, dateandtime, ip, Expression;
int msgLength, announceid;
sql = "select topic,username,body,dateAndTime,length,ip,Expression from bbs1 where announceid="
+ announceID;
rs = dbc.executeQuery(sql);
if (!rs.next()) {
dbc.close();
throw new Exception("没有此贴!");
}
// rs.next();
newtopic = rs.getString(1) + "-->" + userName + "添加";
username = rs.getString(2);
body = rs.getString(3);
dateandtime = rs.getString(4);
msgLength = rs.getInt(5);
ip = rs.getString(6);
Expression = rs.getString(7);
rs.close();
//
sql = "insert into bbs1(boardID,parentID,child,userName,topic,\n body,dateandtime,hits,length,rootID,layer,orders,ip,Expression,locktopic,signflag,emailflag,times,isvote,istop,isbest) \n values("
+ newForumID
+ ",0,0,?,?,?,'"
+ dateandtime
+ "', 0,"
+ msgLength
+ ",0,1,0,'"
+ ip
+ "','"
+ Expression
+ "',\n 0,0,0,0,0,0,0)";
dbc.prepareStatement(sql);
dbc.setString(1, username);
dbc.setString(2, newtopic);
dbc.setString(3, body);
dbc.executeUpdate();
sql = "select announceID from bbs1 order by announceID desc";
rs = dbc.executeQuery(sql);
rs.next();
announceid = rs.getInt(1);
rs.close();
sql = "update bbs1 set rootID=" + announceid + ",times="
+ announceid + " where announceID=" + announceid;
dbc.executeUpdate(sql);
int postNum, todayNum;
sql = "select count(*) from bbs1 where rootID=" + rootID;
dbc.prepareStatement(sql);
rs = dbc.executeQuery();
rs.next();
postNum = rs.getInt(1);
rs.close();
sql = "select count(*) from bbs1 where rootID=" + rootID
+ " and TO_DAYS(dateandtime)=TO_DAYS(now())";
rs = dbc.executeQuery(sql);
rs.next();
todayNum = rs.getInt(1);
rs.close();
// '更新论坛贴子数据
lastCount(forumID);
lastCount(newForumID);
forumNumAdd(newForumID, 0, 1, todayNum, dbc);
allForumNumAdd(todayNum, 1, 0, dbc);
url = "dispbbs.jsp?forumID=" + newForumID + "&rootID=" + announceid
+ "&announceID=" + announceid;
sql = "insert into log (l_username,l_content,l_url,l_addtime) values (?,?,'"
+ url + "','" + DateUtil.getLocalDate() + "')";
dbc.prepareStatement(sql);
dbc.setString(1, userName);
dbc.setString(2, "拷贝帖子");
dbc.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
dbc.close();
}
ForumPropertiesManager.resetManager();
}
public void moveTopic(HttpServletRequest request) throws Exception {
int newForumID = ParamUtil.getInt(request, "newForumID");
DBConnect dbc = null;
ResultSet rs;
try {
dbc = new DBConnect();
if (forumID == newForumID) {
dbc.close();
throw new Exception("不能在相同版面内进行转移操作。");
} else {
sql = "select boardID,announceid,Parentid from bbs1 where announceid="
+ announceID + " and boardID=" + forumID;
dbc.prepareStatement(sql);
rs = dbc.executeQuery();
if (!rs.next()) {
dbc.close();
throw new Exception("您选择的贴子并不存在。");
} else {
// rs.next();
if (rs.getInt(3) != 0) {
dbc.close();
throw new Exception("您必须选择一个主题,而不是贴子。");
}
}
}
String leavemessage = ParamUtil.getString(request, "leavemessage");
if (leavemessage == null || leavemessage.equals("")) {
dbc.close();
throw new Exception("请选择相应的操作!");
}
if (leavemessage.equals("yes")) {
// 'ON ERROR RESUME NEXT
}
else if (leavemessage.equals("no")) {
String newtopic;
sql = "select topic from bbs1 where announceid=" + rootID;
dbc.prepareStatement(sql);
rs = dbc.executeQuery();
rs.next();
newtopic = rs.getString(1) + "-->" + userName + "转移";
rs.close();
sql = "update bbs1 set topic=? where announceid=" + rootID;
dbc.prepareStatement(sql);
dbc.setString(1, newtopic);
dbc.executeUpdate();
sql = "update bbs1 set boardID=" + newForumID
+ " where rootID=" + rootID;
dbc.prepareStatement(sql);
dbc.executeUpdate();
int postNum, todayNum;
sql = "select count(*) from bbs1 where rootID=" + rootID;
dbc.prepareStatement(sql);
rs = dbc.executeQuery();
rs.next();
postNum = rs.getInt(1);
rs.close();
sql = "select count(*) from bbs1 where rootID=" + rootID
+ " and TO_DAYS(dateandtime)=TO_DAYS(now())";
rs = dbc.executeQuery(sql);
rs.next();
todayNum = rs.getInt(1);
rs.close();
// '更新论坛贴子数据
lastCount(forumID);
forumNumSub(forumID, 0, 1, todayNum, dbc);
lastCount(newForumID);
forumNumAdd(newForumID, 0, 1, todayNum, dbc);
// allForumNumSub(todayNum,1,0,dbc);
// '更新论坛数据结束
url = "dispbbs.jsp?forumID=" + newForumID + "&rootID=" + rootID
+ "&announceID=" + rootID;
sql = "insert into log (l_username,l_content,l_url,l_addtime) values (?,?,'"
+ url + "','" + DateUtil.getLocalDate() + "')";
dbc.prepareStatement(sql);
dbc.setString(1, userName);
dbc.setString(2, "转移主题");
dbc.executeUpdate();
ForumPropertiesManager.resetManager();
} else {
throw new Exception("请选择相应操作。");
}
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
dbc.close();
}
}
// public void copyMSG() throws Exception{}
public void lockMSG() throws Exception {
sql = "update bbs1 set locktopic=1 where boardID=" + forumID
+ " and rootID=" + rootID;
DBConnect dbc = null;
try {
dbc = new DBConnect();
dbc.executeUpdate(sql);
url = "dispbbs.jsp?forumID=" + forumID + "&rootID=" + rootID
+ "&announceID=" + rootID;
sql = "insert into log (l_username,l_content,l_url,l_addtime) values (?,?,'"
+ url + "','" + DateUtil.getLocalDate() + "')";
dbc.prepareStatement(sql);
dbc.setString(1, userName);
dbc.setString(2, "锁定帖子");
dbc.executeUpdate();
// 清除缓存
CacheManager.getCache(ENV.FORUM_TOPIC).remove(
String.valueOf(rootID));
CacheManager.getCache(ENV.FORUM_NEWS).remove(
String.valueOf(rootID));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -