📄 topicdao.java
字号:
{
pstmtUpdate.setString(1, ids[0]); // SectionID
pstmtUpdate.setString(2, ids[1]); // BoardID
pstmtUpdate.setString(3, topicIds[i]);
pstmtUpdate.addBatch();
if (i > 0) sbuf.append(",");
sbuf.append("'").append(topicIds[i]).append("'");
}
sbuf.append(")");
ArrayList<HashMap> topics =
this.execSelectSql(sbuf.toString(), null, conn);
pstmtUpdate.executeBatch();
if (topics != null && topics.size() > 0)
{
int count = topics.size();
topicIds = new String[count];
String[] topicTitles = new String[count];
String[] boardIds = new String[count];
String[] boardNames = new String[count];
String[] userIDs = new String[count];
BoardVO aBoard = null;
CacheManager cache = CacheManager.getInstance();
BoardVO targetBoard = cache.getBoard(ids[0], ids[1]);
HashMap aTopic = null;
boolean hasValidUser = false;
for (int i=0; i<count; i++)
{
aTopic = topics.get(i);
topicIds[i] = (String)aTopic.get("TOPICID");
topicTitles[i] = (String)aTopic.get("TITLE");
userIDs[i] = (String)aTopic.get("USERID");
if (userIDs[i] != null && userIDs[i].length() > 0)
hasValidUser = true;
if (aBoard == null)
{
boardIds[i] = (String)aTopic.get("BOARDID");
aBoard = cache.getBoard(boardIds[i]);
}
boardIds[i] = aBoard.boardID;
boardNames[i] = aBoard.boardName;
}
if (aBoard != null)
{
HashMap<String,BoardVO> boardMap = new HashMap<String,BoardVO>();
boardMap.put(aBoard.boardID, aBoard);
boardMap.put(targetBoard.boardID, targetBoard);
BoardDAO.getInstance().getBoardStatInfo(boardMap, conn);
}
ActionLogDAO.getInstance().addModerateLog(
request, boardIds, boardNames, topicIds, topicTitles,
"0", "移动主题", reason, conn);
if (sendsms != null && sendsms.equals("yes") && hasValidUser)
{
if (reason.length() > 0)
reason = ", 原因是: " + reason;
String[] messages = new String[count];
for (int i=0; i<count; i++)
{
messages[i] = new StringBuilder("您发表的主题\"").append(topicTitles[i])
.append("\"已被管理员移动到版块\"").append(targetBoard.boardName)
.append("\"").append(reason)
.append("。").toString();
}
String subject = "[系统消息]您发表的主题已被管理员移动到另一个版块";
UserInfo userinfo = PageUtils.getSessionUser(request);
String fromUser = userinfo.userID;
ShortMsgDAO.getInstance().addShortMsgs(fromUser, userIDs, subject, messages, conn);
}
}
conn.commit();
return "OK";
}
catch(Exception e)
{
conn.rollback();
throw e;
}
finally
{
dbManager.closePStatement(pstmtUpdate);
dbManager.closeConnection(conn);
}
}
/**
* Close forum topics
* @param
* request - HttpServletRequest
* @return none
* @throws SQLException
* @since 1.0
*/
public String closeTopics(HttpServletRequest request) throws Exception
{
String[] topicIds = request.getParameterValues("topicID");
String reason = PageUtils.getParam(request,"reason");
String sendsms = request.getParameter("sendsms");
String state = request.getParameter("state");
String action = null;
if (state != null && state.equals("close"))
{
state = "C";
action = "关闭";
}
else
{
state = "N";
action = "打开";
}
PreparedStatement pstmtUpdate = null;
Connection conn = dbManager.getConnection();
try
{
conn.setAutoCommit(false);
pstmtUpdate = conn.prepareStatement(adapter.Topic_ModState);
StringBuilder sbuf = new StringBuilder(adapter.Topic_GetLogInfo);
sbuf.append(" (");
for (int i=0; i<topicIds.length; i++)
{
pstmtUpdate.setString(1, state);
pstmtUpdate.setString(2, topicIds[i]);
pstmtUpdate.addBatch();
if (i > 0) sbuf.append(",");
sbuf.append("'").append(topicIds[i]).append("'");
}
sbuf.append(")");
ArrayList<HashMap> topics =
this.execSelectSql(sbuf.toString(), null, conn);
pstmtUpdate.executeBatch();
if (topics != null && topics.size() > 0)
{
int count = topics.size();
topicIds = new String[count];
String[] topicTitles = new String[count];
String[] boardIds = new String[count];
String[] boardNames = new String[count];
String[] userIDs = new String[count];
BoardVO aBoard = null;
HashMap aTopic = null;
boolean hasValidUser = false;
for (int i=0; i<count; i++)
{
aTopic = topics.get(i);
topicIds[i] = (String)aTopic.get("TOPICID");
topicTitles[i] = (String)aTopic.get("TITLE");
userIDs[i] = (String)aTopic.get("USERID");
if (userIDs[i] != null && userIDs[i].length() > 0)
hasValidUser = true;
if (aBoard == null)
{
boardIds[i] = (String)aTopic.get("BOARDID");
CacheManager cache = CacheManager.getInstance();
aBoard = cache.getBoard(boardIds[i]);
}
boardIds[i] = aBoard.boardID;
boardNames[i] = aBoard.boardName;
}
ActionLogDAO.getInstance().addModerateLog(
request, boardIds, boardNames, topicIds, topicTitles,
"0", action + "主题", reason, conn);
if (sendsms != null && sendsms.equals("yes") && hasValidUser)
{
if (reason.length() > 0)
reason = ", 原因是: " + reason;
String[] messages = new String[count];
for (int i=0; i<count; i++)
{
messages[i] = new StringBuilder("您发表的主题\"").append(topicTitles[i])
.append("\"状态已被管理员更改为\"").append(action)
.append("\"").append(reason)
.append("。").toString();
}
String subject = "[系统消息]您发表的主题状态已被管理员更改为\"" + action + "\"";
UserInfo userinfo = PageUtils.getSessionUser(request);
String fromUser = userinfo.userID;
ShortMsgDAO.getInstance().addShortMsgs(fromUser, userIDs, subject, messages, conn);
}
}
conn.commit();
return "OK";
}
catch(Exception e)
{
conn.rollback();
throw e;
}
finally
{
dbManager.closePStatement(pstmtUpdate);
dbManager.closeConnection(conn);
}
}
/**
* Set forum topics as digest
* @param
* request - HttpServletRequest
* @return none
* @throws SQLException
* @since 1.0
*/
public String digestTopics(HttpServletRequest request) throws Exception
{
String[] topicIds = request.getParameterValues("topicID");
String isDigest = request.getParameter("isDigest");
int credits = ForumSetting.getInstance().getInt(ForumSetting.CREDITS, "digestTopic");
String action = null;
if (isDigest != null && isDigest.equals("T"))
action = "加入精华";
else
{
action = "解除精华";
credits = (-1) * credits;
}
PreparedStatement pstmtUpdate = null;
Connection conn = dbManager.getConnection();
try
{
conn.setAutoCommit(false);
pstmtUpdate = conn.prepareStatement(adapter.Topic_ModIsDigest);
StringBuilder sbuf = new StringBuilder(adapter.Topic_GetLogInfo);
sbuf.append(" (");
for (int i=0; i<topicIds.length; i++)
{
pstmtUpdate.setString(1, isDigest);
pstmtUpdate.setString(2, topicIds[i]);
pstmtUpdate.addBatch();
if (i > 0) sbuf.append(",");
sbuf.append("'").append(topicIds[i]).append("'");
}
sbuf.append(")");
ArrayList<HashMap> topics =
this.execSelectSql(sbuf.toString(), null, conn);
pstmtUpdate.executeBatch();
if (topics != null && topics.size() > 0)
{
if (credits != 0)
{
int count = topics.size();
String[] userIDs = new String[count];
HashMap aTopic = null;
boolean hasValidUser = false;
for (int i=0; i<count; i++)
{
aTopic = topics.get(i);
userIDs[i] = (String)aTopic.get("USERID");
if (userIDs[i] != null && userIDs[i].length() > 0)
hasValidUser = true;
}
if (hasValidUser)
{
UserDAO.getInstance().modifyCredits(userIDs, credits, conn);
}
}
addLogAndShortMsg(request, topics, action, conn);
}
conn.commit();
return "OK";
}
catch(Exception e)
{
conn.rollback();
throw e;
}
finally
{
dbManager.closePStatement(pstmtUpdate);
dbManager.closeConnection(conn);
}
}
/**
* Make forum topics on top
* @param
* request - HttpServletRequest
* @return none
* @throws SQLException
* @since 1.0
*/
public String topTopics(HttpServletRequest request) throws Exception
{
String[] topicIds = request.getParameterValues("topicID");
String topScope = request.getParameter("topScope");
String expiredate = PageUtils.getParam(request,"expiredate");
String action = null;
if (topScope != null && topScope.equals("N"))
{
action = "解除置顶";
expiredate = null;
}
else
{
action = "置顶";
if (expiredate.length() == 0)
expiredate = "2999-01-01 00:00:00";
else if (expiredate.length() <= 10)
expiredate = expiredate + " 23:55:00";
try
{
Timestamp.valueOf(expiredate); // Check date format
}
catch(Exception e)
{
return "操作失败: 有效期值不是合法的日期";
}
}
PreparedStatement pstmtUpdate = null;
Connection conn = dbManager.getConnection();
try
{
conn.setAutoCommit(false);
pstmtUpdate = conn.prepareStatement(adapter.Topic_ModTopScope);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -