📄 replydao.java
字号:
try
{
conn.setAutoCommit(false);
updateReply(request, userinfo, replyID, subject, content, attachCount, conn);
String postUserID = (String)request.getAttribute("postuser");
int totalCredits = 0;
if (attachCount >= 0) // if deleted all attachments, attachCount = 0
{
AttachDAO.getInstance()
.updateAttaches(attaches, postUserID, topicID, replyID, conn);
int credits = ForumSetting.getInstance().getInt(ForumSetting.CREDITS, "upload");
if (credits > 0)
{
String oldCount =
(String)request.getSession().getAttribute("attachCount");
// attachCount = attaches.size();
if (oldCount != null)
attachCount = attachCount - Integer.valueOf(oldCount);
totalCredits = credits * attachCount;
}
}
String userID = (userinfo == null ? "" : userinfo.userID);
if (totalCredits != 0 && userID.length() > 0 && userID.equalsIgnoreCase(postUserID))
{
ArrayList<Object> paramValues = new ArrayList<Object>();
paramValues.add(totalCredits);
paramValues.add(userID);
this.execUpdateSql(adapter.User_IncCredits, paramValues, conn);
if (userinfo != null)
userinfo.credits = userinfo.credits + totalCredits;
}
String topicTitle = null;
if (badwords.length() > 1)
{
ArrayList<Object> paramValues = new ArrayList<Object>();
paramValues.add(replyID);
ArrayList<HashMap> replies =
this.execSelectSql(adapter.Reply_GetLogInfo, paramValues, conn);
if (replies != null && replies.size() > 0)
{
HashMap aReply = replies.get(0);
topicTitle = (String)aReply.get("TITLE");
ActionLogDAO.getInstance().addCensorLog(
userID, aBoard.boardID, aBoard.boardName, topicID, topicTitle,
replyID, badwords.toString(), conn);
}
}
if (userID.length() > 0 && !userID.equalsIgnoreCase(postUserID))
{
if (topicTitle == null)
{
ArrayList<Object> paramValues = new ArrayList<Object>();
paramValues.add(replyID);
ArrayList<HashMap> replies =
this.execSelectSql(adapter.Reply_GetLogInfo, paramValues, conn);
if (replies != null && replies.size() > 0)
{
HashMap aReply = replies.get(0);
topicTitle = (String)aReply.get("TITLE");
}
}
// Add moderator log
if (subject != null)
{
String[] topicIds = new String[1];
String[] topicTitles = new String[1];
String[] boardIds = new String[1];
String[] boardNames = new String[1];
topicIds[0] = topicID;
topicTitles[0] = topicTitle;
boardIds[0] = aBoard.boardID;
boardNames[0] = aBoard.boardName;
ActionLogDAO.getInstance().addModerateLog(
request, boardIds, boardNames, topicIds, topicTitles,
replyID, "编辑帖子", "", conn);
}
}
conn.commit();
result = "OK";
}
catch(Exception e)
{
conn.rollback();
throw e;
}
finally
{
dbManager.closeConnection(conn);
}
return result;
}
/**
* Update a reply
* @param
* request - HttpServletRequest
* replyID - Reply ID
* attachCount - Attachment count
* conn - DB Connection
* @return Reply ID
* @throws SQLException
* @since 1.0
*/
private void updateReply(HttpServletRequest request, UserInfo userinfo,
String replyID, String subject, String content,
int attachCount, Connection conn) throws SQLException
{
PreparedStatement pstmtUpdate = null;
try
{
String isHidePost = (String)request.getAttribute("isHidePost");
if (isHidePost == null || isHidePost.length() == 0)
isHidePost = "F";
pstmtUpdate = conn.prepareStatement(adapter.Reply_Update);
pstmtUpdate.setString(1, subject);
pstmtUpdate.setString(2, content);
pstmtUpdate.setString(3, isHidePost);
pstmtUpdate.setInt(4, attachCount);
pstmtUpdate.setString(5, replyID);
pstmtUpdate.executeUpdate();
}
finally
{
dbManager.closePStatement(pstmtUpdate);
}
}
/**
* Delete forum reply
* @param
* request - HttpServletRequest
* @return none
* @throws SQLException
* @since 1.0
*/
public String deleteReply(HttpServletRequest request, String replyID) throws Exception
{
String reason = PageUtils.getParam(request,"reason");
String sendsms = request.getParameter("sendsms");
PreparedStatement pstmtUpdate = null;
Connection conn = dbManager.getConnection();
try
{
conn.setAutoCommit(false);
ArrayList<Object> paramValues = new ArrayList<Object>();
paramValues.add(replyID);
ArrayList<HashMap> replies =
this.execSelectSql(adapter.Reply_GetLogInfo, paramValues, conn);
pstmtUpdate = conn.prepareStatement(adapter.Reply_Delete);
pstmtUpdate.setString(1, replyID);
pstmtUpdate.executeUpdate();
if (replies != null && replies.size() > 0)
{
String[] replyIds = new String[1];
String[] topicIds = new String[1];
String[] topicTitles = new String[1];
String[] boardIds = new String[1];
String[] boardNames = new String[1];
String[] userIDs = new String[1];
int[] attaches = new int[1];
HashMap aReply = replies.get(0);
replyIds[0] = replyID;
userIDs[0] = (String)aReply.get("USERID");
topicIds[0] = (String)aReply.get("TOPICID");
topicTitles[0] = (String)aReply.get("TITLE");
attaches[0] = Integer.parseInt((String)aReply.get("ATTACHES"));
if (topicTitles[0] != null && topicTitles[0].length() > 50)
topicTitles[0] = topicTitles[0].substring(0,35) + "...";
boolean hasValidUser = false;
if (userIDs[0] != null && userIDs[0].length() > 0)
hasValidUser = true;
boardIds[0] = (String)aReply.get("BOARDID");
CacheManager cache = CacheManager.getInstance();
BoardVO aBoard = cache.getBoard(boardIds[0]);
boardNames[0] = aBoard.boardName;
TopicDAO.getInstance().statTopicPosts(topicIds[0], conn);
synchronized(aBoard)
{
aBoard.replies = aBoard.replies - 1;
}
UserInfo userinfo = PageUtils.getSessionUser(request);
int replyCredits = ForumSetting.getInstance().getInt(ForumSetting.CREDITS, "newReply");
String moduserinfo = request.getParameter("moduserinfo");
if (moduserinfo == null || !moduserinfo.equals("no"))
{
UserDAO.getInstance().decPostsAndCredits(
userIDs, attaches, userinfo, replyCredits, conn);
}
TrashBoxDAO.getInstance().addTrashes(
boardIds, boardNames, topicIds, topicTitles, replyIds,
userIDs, userinfo.userID, conn);
ActionLogDAO.getInstance().addModerateLog(
request, boardIds, boardNames, topicIds, topicTitles,
replyID, "删除回复", reason, conn);
if (sendsms != null && sendsms.equals("yes") && hasValidUser)
{
if (reason.length() > 0)
reason = ", 原因是: " + reason;
String[] messages = new String[1];
messages[0] = new StringBuilder("您在主题\"").append(topicTitles[0])
.append("\"发表的回复已被删除").append(reason)
.append("。").toString();
String subject = "[系统消息]您发表的回复因故被删除";
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 reply as the best topic reply
* @param
* request - HttpServletRequest
* @return none
* @throws SQLException
* @since 1.0
*/
public String setBestReply(HttpServletRequest request, UserInfo userinfo) throws Exception
{
String replyID = request.getParameter("replyID");
String reason = PageUtils.getParam(request,"reason");
String sendsms = request.getParameter("sendsms");
String isBest = request.getParameter("isBest");
String action = null;
if (isBest != null && isBest.equals("T"))
action = "设为最佳回复";
else
{
isBest = "F";
action = "取消最佳回复设定";
}
PreparedStatement pstmtUpdate = null;
Connection conn = dbManager.getConnection();
try
{
conn.setAutoCommit(false);
ArrayList<Object> paramValues = new ArrayList<Object>();
paramValues.add(replyID);
ArrayList<HashMap> replies =
this.execSelectSql(adapter.Reply_GetLogInfo, paramValues, conn);
pstmtUpdate = conn.prepareStatement(adapter.Reply_SetIsBest);
pstmtUpdate.setString(1, isBest);
pstmtUpdate.setString(2, replyID);
pstmtUpdate.executeUpdate();
if (replies != null && replies.size() > 0)
{
String[] topicIDs = new String[1];
String[] topicTitles = new String[1];
String[] userIDs = new String[1];
HashMap aReply = replies.get(0);
topicIDs[0] = (String)aReply.get("TOPICID");
topicTitles[0] = (String)aReply.get("TITLE");
userIDs[0] = (String)aReply.get("USERID");
String oldIsBest = (String)aReply.get("ISBEST");
String reward = (String)aReply.get("REWARD");
int credits = 0;
if (reward != null && reward.length() > 0)
credits = Integer.parseInt(reward);
if (credits <= 0)
credits = ForumSetting.getInstance().getInt(ForumSetting.CREDITS, "bestReply");
if (credits > 0 && !isBest.equalsIgnoreCase(oldIsBest))
{
String fromUser = null;
String toUser = null;
if (isBest.equals("T"))
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -