📄 forumadmin.java
字号:
int forumID;
try {
forumID = ParamUtil.getInt(request, "boardid");
} catch (Exception e) {
throw new Exception("请您选择您要修改的论坛ID");
}
String sql = "delete from " + BBSConst.TABLE_BOARD + " where boardid="
+ forumID;
JdbcWrapper jw = new JdbcWrapper();
try {
jw.setAutoClose(false);
jw.executeUpdate(sql);
sql = "delete from " + BBSConst.TABLE_BBS1 + " where boardid="
+ forumID;
jw.executeUpdate(sql);
CacheManager.getCache(ENV.FORUM).remove(forumID + "");
} catch (Exception e) {
log.error("删除论坛信息出错", e);
throw e;
} finally {
jw.close();
}
}
/**
* 删除论坛分类信息
*
* @param request
* @throws Exception
*/
public static void dell(HttpServletRequest request) throws Exception {
checkAdmin(request);
int ID;
try {
ID = ParamUtil.getInt(request, "id");
} catch (Exception e) {
throw new Exception("请您选择您要删除的分类的ID");
}
JdbcWrapper jw = new JdbcWrapper();
try {
jw.setAutoClose(false);
String sql = "delete from " + BBSConst.TABLE_CLASS + " where id="
+ ID;
jw.executeUpdate(sql);
sql = "select boardid from " + BBSConst.TABLE_BOARD
+ " where class=" + ID;
jw.executeQuery(sql);
while (jw.next()) {
sql = "delete from " + BBSConst.TABLE_BBS1 + " where boardid="
+ jw.getInt(1);
jw.executeUpdate(sql);
CacheManager.getCache(ENV.FORUM).remove(jw.getInt(1) + "");
}
sql = "delete from " + BBSConst.TABLE_BOARD + " where class=" + ID;
jw.executeUpdate(sql);
CacheManager.getCache(ENV.GATEWAY).remove(ID + "");
} catch (Exception e) {
log.error("删除论坛分类信息出错", e);
throw e;
} finally {
jw.close();
}
}
/**
* 修改论坛分类顺序
*
* @param request
* @throws Exception
*/
public static void updateOrders(HttpServletRequest request)
throws Exception {
checkAdmin(request);
int newID;
try {
newID = ParamUtil.getInt(request, "newid");
} catch (Exception e) {
throw new Exception("请您选择您想要更新的类别!");
}
int ID;
try {
ID = ParamUtil.getInt(request, "id");
} catch (Exception e) {
throw new Exception("请您选择您想要更新的类别!");
}
String className = ParamUtil.getString(request, "classname", "");
if ("".equals(className)) {
throw new Exception("请输入论坛类别名称!");
}
if (newID == ID) {
return;
}
JdbcWrapper jw = new JdbcWrapper();
try {
jw.setAutoClose(false);
String sql = "select id from " + BBSConst.TABLE_CLASS
+ " where id=" + newID;
if (jw.isExists(sql)) {
throw new Exception("您输入的序号和其他分类序号相同,请重新输入。");
}
sql = "update " + BBSConst.TABLE_CLASS + " set id=" + newID
+ ",class=? where id=" + ID;
jw.prepareStatement(sql);
jw.setString(1, className);
jw.executeUpdate();
sql = "update " + BBSConst.TABLE_BOARD + " set class=" + newID
+ " where class=" + ID;
jw.executeUpdate(sql);
} catch (Exception e) {
log.error("修改论坛类别出错", e);
throw e;
} finally {
jw.close();
}
}
/**
* 添加论坛分类
*
* @param request
* @throws Exception
*/
public static void saveClass(HttpServletRequest request) throws Exception {
checkAdmin(request);
String classname = ParamUtil.getString(request, "classname");
if (classname == null)
throw new Exception("请您输入您想添加分类的名字!");
String sql = "insert into " + BBSConst.TABLE_CLASS
+ "(class) values(?)";
JdbcWrapper jw = new JdbcWrapper();
try {
jw.prepareStatement(sql);
jw.setString(1, classname);
jw.executeUpdate();
} catch (Exception e) {
log.error("添加论坛分类出错", e);
throw e;
} finally {
jw.close();
}
}
/**
* 更新论坛数据
*
* @return
* @throws Exception
*/
public String update() throws Exception {
String sql = "select boardid,boardtype from " + BBSConst.TABLE_BOARD;
JdbcWrapper jw = new JdbcWrapper();
StringBuffer sb = new StringBuffer();
try {
jw.setAutoClose(false);
jw.executeQuery(sql);
//
if (!jw.next()) {
throw new Exception("论坛还没有版面,请先添加版面。");
}
//
String newuser = newuser();
do {
sql = "Select count(announceid) from " + BBSConst.TABLE_BBS1
+ " where boardid=" + jw.getInt(1);
int allArticle = jw.doIntSearch(sql);
//
sql = "Select count(announceid) from " + BBSConst.TABLE_BBS1
+ " where boardid=" + jw.getInt(1) + " and parentID=0";
int allTopic = jw.doIntSearch(sql);
//
sql = "select Max(announceid) from " + BBSConst.TABLE_BBS1
+ " where boardid=" + jw.getInt(1);
String tmpID = jw.doSearch(sql);
String userName = "", dateandtime = "";
if (tmpID == null) {
userName = "无";
dateandtime = DateUtil.getLocalDate();
} else {
sql = "select username,dateandtime from "
+ BBSConst.TABLE_BBS1 + " where announceid="
+ tmpID;
JdbcWrapper _jw = new JdbcWrapper(sql);
if (_jw.next()) {
userName = _jw.getString(1);
dateandtime = _jw.getString(2);
}
}
//
sql = "update " + BBSConst.TABLE_BOARD + " set lastpostuser='"
+ userName + "',lastposttime='" + dateandtime
+ "',lastbbsnum=" + allArticle + ",lasttopicnum="
+ allTopic + ",TodayNum=" + todays(jw.getInt(1), jw)
+ " where boardid=" + jw.getInt(1);
jw.executeUpdate(sql);
sb.append("更新论坛数据成功," + jw.getString(2) + "共有" + allArticle
+ "篇贴子," + allTopic + "篇主题,今日有"
+ todays(jw.getInt(1), jw) + "篇帖子。<br>");
} while (jw.next());
//
sql = "update " + BBSConst.TABLE_CONFIG + " set TopicNum="
+ titlenum(jw) + ",BbsNum=" + gettipnum(jw) + ",TodayNum="
+ alltodays(jw) + ",UserNum=" + allusers(jw)
+ ",lastUser=?";
jw.prepareStatement(sql);
jw.setString(1, newuser);
jw.executeUpdate();
} catch (Exception e) {
log.error("更新论坛信息出错", e);
throw e;
} finally {
jw.close();
}
ForumPropertiesManager.resetManager();
return sb.toString();
}
public int todays(int boardid, JdbcWrapper jw) throws Exception {
return jw.doIntSearch("Select count(announceid) from "
+ BBSConst.TABLE_BBS1
+ " Where to_days(dateandtime)=to_days(now()) and boardid="
+ boardid);
}
public int alltodays(JdbcWrapper jw) throws Exception {
return jw.doIntSearch("Select count(announceid) from "
+ BBSConst.TABLE_BBS1
+ " Where to_days(dateandtime)=to_days(now())");
}
public int allusers(JdbcWrapper jw) throws Exception {
return jw.doIntSearch("Select count(userid) from "
+ BBSConst.TABLE_USER);
}
public String newuser() throws Exception {
JdbcWrapper _jw = new JdbcWrapper("Select username from "
+ BBSConst.TABLE_USER + " order by userid desc limit 0,1");
String newuser = "没有会员";
if (_jw.next()) {
newuser = _jw.getString(1);
}
return newuser;
}
public int gettipnum(JdbcWrapper jw) throws Exception {
return jw.doIntSearch("Select Count(announceID) from "
+ BBSConst.TABLE_BBS1);
}
public int titlenum(JdbcWrapper jw) throws Exception {
return jw.doIntSearch("Select Count(announceID) from "
+ BBSConst.TABLE_BBS1 + " where parentID=0");
}
public static void addMaster(String masters, JdbcWrapper jw)
throws Exception {
String[] arr = masters.split("\\|");
String sql;
for (int i = 0; i < arr.length; i++) {
sql = "select userID from " + BBSConst.TABLE_USER
+ " where userName='" + arr[i] + "'";
if (!jw.isExists(sql)) {
throw new Exception("没有发现此用户" + arr[i]);
}
sql = "update " + BBSConst.TABLE_USER
+ " set userclass=19 where username=?";
jw.prepareStatement(sql);
jw.setString(1, arr[i]);
jw.executeUpdate();
}
}
public static void delMaster(String masters, JdbcWrapper jw)
throws Exception {
String[] arr = masters.split("\\|");
String sql;
for (int i = 0; i < arr.length; i++) {
// 检查在其它版块是否版主
sql = " select boardmaster from " + BBSConst.TABLE_BOARD
+ " where boardmaster like '%" + arr[i] + "%'";
if (!jw.isExists(sql)) {
sql = "update " + BBSConst.TABLE_USER
+ " set userclass=18 where username=?";
jw.prepareStatement(sql);
jw.setString(1, arr[i]);
jw.executeUpdate();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -