📄 topicdao.java
字号:
StringBuilder sbuf = new StringBuilder(adapter.Topic_GetLogInfo);
sbuf.append(" (");
for (int i=0; i<topicIds.length; i++)
{
pstmtUpdate.setString(1, topScope);
pstmtUpdate.setString(2, expiredate);
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)
{
addLogAndShortMsg(request, topics, action, conn);
}
conn.commit();
return "OK";
}
catch(Exception e)
{
conn.rollback();
throw e;
}
finally
{
dbManager.closePStatement(pstmtUpdate);
dbManager.closeConnection(conn);
}
}
/**
* Highlight forum topics
* @param
* request - HttpServletRequest
* @return none
* @throws SQLException
* @since 1.0
*/
public String highlightTopics(HttpServletRequest request) throws Exception
{
String[] topicIds = request.getParameterValues("topicID");
String lightcolor = request.getParameter("lightcolor");
String expiredate = PageUtils.getParam(request,"expiredate");
String action = null;
if (lightcolor != null && lightcolor.length() > 0)
{
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 "操作失败: 有效期值不是合法的日期";
}
}
else
{
action = "解除高亮";
expiredate = null;
}
PreparedStatement pstmtUpdate = null;
Connection conn = dbManager.getConnection();
try
{
conn.setAutoCommit(false);
pstmtUpdate = conn.prepareStatement(adapter.Topic_Highlight);
StringBuilder sbuf = new StringBuilder(adapter.Topic_GetLogInfo);
sbuf.append(" (");
for (int i=0; i<topicIds.length; i++)
{
pstmtUpdate.setString(1, lightcolor);
pstmtUpdate.setString(2, expiredate);
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)
{
addLogAndShortMsg(request, topics, action, conn);
}
conn.commit();
return "OK";
}
catch(Exception e)
{
conn.rollback();
throw e;
}
finally
{
dbManager.closePStatement(pstmtUpdate);
dbManager.closeConnection(conn);
}
}
public void checkExpireDate() throws Exception
{
Connection conn = dbManager.getConnection();
try
{
String currentDate = AppUtils.getCurrentDateStr();
ArrayList<Object> paramValues = new ArrayList<Object>();
paramValues.add(currentDate);
this.execUpdateSql(adapter.Topic_CheckTopExpireDate, paramValues, conn);
this.execUpdateSql(adapter.Topic_CheckHighExpireDate, paramValues, conn);
}
finally
{
dbManager.closeConnection(conn);
}
}
public void closeOverflowTopics() throws Exception
{
Connection conn = dbManager.getConnection();
try
{
int maxReplies =
ForumSetting.getInstance().getInt(ForumSetting.FUNCTIONS, "maxReplies");
ArrayList<Object> paramValues = new ArrayList<Object>();
paramValues.add(maxReplies);
this.execUpdateSql(adapter.Topic_CheckReplies, paramValues, conn);
}
finally
{
dbManager.closeConnection(conn);
}
}
private void addLogAndShortMsg(HttpServletRequest request,ArrayList<HashMap> topics,
String action, Connection conn) throws Exception
{
int count = topics.size();
String[] 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;
}
String reason = PageUtils.getParam(request,"reason");
String sendsms = request.getParameter("sendsms");
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(reason).append("。").toString();
}
String subject = "[系统消息]您发表的主题已被管理员" + action;
UserInfo userinfo = PageUtils.getSessionUser(request);
String fromUser = userinfo.userID;
ShortMsgDAO.getInstance().addShortMsgs(fromUser, userIDs, subject, messages, conn);
}
}
/**
* Re-stat posts info of topic
* @param
* topicID - Topic ID
* conn - DB connection
* @return none
* @throws SQLException
* @since 1.0
*/
public void statTopicPosts(String topicID, Connection conn) throws SQLException
{
PreparedStatement pstmtQuery = null;
PreparedStatement pstmtUpdate = null;
ResultSet rs = null;
try
{
int replies = 0;
String lastReplyID = null;
String lastUserID = null;
String lastNickname = null;
String lastPostTime = null;
pstmtQuery = conn.prepareStatement(adapter.Topic_StatReplies);
pstmtQuery.setString(1, topicID);
rs = pstmtQuery.executeQuery();
if (rs.next())
{
replies = rs.getInt("replies");
lastReplyID = rs.getString("lastReplyID");
if (replies > 0)
{
dbManager.closeResultSet(rs);
dbManager.closePStatement(pstmtQuery);
pstmtQuery = conn.prepareStatement(adapter.Topic_GetLastPost);
pstmtQuery.setString(1, lastReplyID);
rs = pstmtQuery.executeQuery();
if (rs.next())
{
lastUserID = rs.getString("userID");
lastNickname = rs.getString("nickname");
lastPostTime = rs.getString("createTime");
pstmtUpdate = conn.prepareStatement(adapter.Topic_ModReplies);
pstmtUpdate.setInt(1, replies);
pstmtUpdate.setString(2, lastUserID);
pstmtUpdate.setString(3, lastNickname);
pstmtUpdate.setString(4, lastPostTime);
pstmtUpdate.setString(5, topicID);
pstmtUpdate.executeUpdate();
}
}
}
if (replies == 0)
{
pstmtUpdate = conn.prepareStatement(adapter.Topic_ResetReplies);
pstmtUpdate.setString(1, topicID);
pstmtUpdate.executeUpdate();
}
}
finally
{
dbManager.closeResultSet(rs);
dbManager.closePStatement(pstmtQuery);
dbManager.closePStatement(pstmtUpdate);
}
}
/**
* Get topic title info
* @param
* topicID - topic ID
* @return TopicVO
* @throws SQLException
* @since 1.0
*/
public HashMap getTopic(String topicID) throws SQLException
{
ArrayList<Object> paramValues = new ArrayList<Object>();
paramValues.add(topicID);
ArrayList<HashMap> topics =
this.execSelectSql(adapter.Topic_GetTitle, paramValues);
if (topics != null && topics.size() > 0)
return topics.get(0);
else
return null;
}
/**
* Get topic & reply info to edit it
* @param
* topicID - topic ID
* @return TopicVO
* @throws SQLException
* @since 1.0
*/
public TopicVO getPostInfo(HttpServletRequest request, String topicID,
String replyID) throws SQLException
{
Connection conn = null;
PreparedStatement pstmtQuery = null;
ResultSet rs = null;
try
{
TopicVO aTopic = null;
boolean hasAttach = false;
if (replyID == null || replyID.length() == 0)
replyID = "0";
conn = dbManager.getConnection();
if (replyID.equals("0")) // It's a topic
{
pstmtQuery = conn.prepareStatement(adapter.Topic_Select);
pstmtQuery.setString(1, topicID);
rs = pstmtQuery.executeQuery();
if(rs.next())
{
aTopic = new TopicVO();
aTopic.to
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -