⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 actionlogdao.java

📁 EasyJForum 是一个基于 Java 技术的免费社区论坛软件系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.hongshee.ejforum.data;

/**
 * <p>Title: ActionLogDAO.java</p>
 * <p>Description: Forum action log data access object</p>
 * <p>Copyright: Hongshee Software (c) 2007</p>
 * @author jackie du
 * @version 1.0
 */

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
//import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.logging.Logger;

import javax.servlet.http.HttpServletRequest;

import com.hongshee.ejforum.data.UserDAO.UserInfo;
import com.hongshee.ejforum.util.MyLogger;
import com.hongshee.ejforum.util.PageUtils;
import com.hongshee.ejforum.util.AppUtils;
import com.hongshee.ejforum.common.CacheManager;
import com.hongshee.ejforum.common.ForumSetting;
import com.hongshee.ejforum.data.BoardDAO.BoardVO;
import com.hongshee.ejforum.data.GroupDAO.GroupVO;

public class ActionLogDAO extends EntityDAO
{
    private static Logger logger = MyLogger.getLogger(ActionLogDAO.class.getName());
    
    private static ActionLogDAO _dao = null;

    protected ActionLogDAO()
    {}

    public static ActionLogDAO getInstance()
    {
        if (_dao == null)
        {
            _dao = new ActionLogDAO();
        }
        return _dao;
    } 

    public void addErrorLog(HttpServletRequest request, String action, String errorInfo)
    {
        Connection conn = null;
        PreparedStatement pstmtInsert = null;
        try
        {
            String userID = null;
            UserInfo userinfo = PageUtils.getSessionUser(request);
            if (userinfo != null)
                userID = userinfo.userID;
            else
                userID = "Guest";
            
            conn = dbManager.getConnection();
            pstmtInsert = conn.prepareStatement(adapter.ErrorLog_Insert);
            pstmtInsert.setString(1, userID);
            pstmtInsert.setString(2, request.getRemoteAddr());
            pstmtInsert.setString(3, action);
            if (errorInfo != null && errorInfo.length() > 100)
                pstmtInsert.setString(4, errorInfo.substring(0,95) + "...");
            else
                pstmtInsert.setString(4, errorInfo);
            pstmtInsert.executeUpdate();
        }
        catch(Exception se)
        {
            logger.warning("ActionLogDAO.addErrorLog - " + se.toString());
        }
        finally
        {
            dbManager.closePStatement(pstmtInsert);
            dbManager.closeConnection(conn);
        }
    }
    
    public void addAdminLog(HttpServletRequest request, String action, 
                                        String remark, Connection conn)
    {
        PreparedStatement pstmtInsert = null;
        try
        {
            UserInfo userinfo = PageUtils.getSessionUser(request);
            String groupName = null;
            CacheManager cache = CacheManager.getInstance();
            GroupVO aGroup = cache.getGroup(userinfo.groupID);
            if (aGroup != null)
                groupName = aGroup.groupName;
            else
                groupName = "";
            
            pstmtInsert = conn.prepareStatement(adapter.AdminLog_Insert);
            pstmtInsert.setString(1, userinfo.userID);
            pstmtInsert.setString(2, groupName);
            pstmtInsert.setString(3, request.getRemoteAddr());
            pstmtInsert.setString(4, action);
            if (remark != null && remark.length() > 40)
                pstmtInsert.setString(5, remark.substring(0,35) + "...");
            else
                pstmtInsert.setString(5, remark);
            pstmtInsert.executeUpdate();
        }
        catch(Exception se)
        {
            logger.warning("ActionLogDAO.addAdminLog - " + se.toString());
        }
        finally
        {
            dbManager.closePStatement(pstmtInsert);
        }
    }

    public void addModerateLog(HttpServletRequest request, 
                               String[] boardIDs, String[] boardNames, 
                               String[] topicIDs, String[] topicTitles, String replyID,
                               String action, String remark, Connection conn)
    {
        PreparedStatement pstmtInsert = null;
        try
        {
            UserInfo userinfo = PageUtils.getSessionUser(request);
            String groupName = null;
            CacheManager cache = CacheManager.getInstance();
            GroupVO aGroup = cache.getGroup(userinfo.groupID);
            if (aGroup != null)
                groupName = aGroup.groupName;
            else
                groupName = "";
            
            pstmtInsert = conn.prepareStatement(adapter.ModerateLog_Insert);
            for (int i=0; i<topicIDs.length; i++)
            {
                pstmtInsert.setString(1, userinfo.userID);
                pstmtInsert.setString(2, groupName);
                pstmtInsert.setString(3, request.getRemoteAddr());
                pstmtInsert.setString(4, boardIDs[i]);
                pstmtInsert.setString(5, boardNames[i]);
                pstmtInsert.setString(6, topicIDs[i]);

                if (topicTitles[i] != null && topicTitles[i].length() > 100)
                    pstmtInsert.setString(7, topicTitles[i].substring(0,95) + "...");
                else
                    pstmtInsert.setString(7, topicTitles[i]);
                
                pstmtInsert.setString(8, replyID);
                pstmtInsert.setString(9, action);
                
                if (remark != null && remark.length() > 40)
                    pstmtInsert.setString(10, remark.substring(0,35) + "...");
                else
                    pstmtInsert.setString(10, remark);
                
                pstmtInsert.addBatch();
            }
            pstmtInsert.executeBatch();
        }
        catch(Exception se)
        {
            logger.warning("ActionLogDAO.addModerateLog - " + se.toString());
        }
        finally
        {
            dbManager.closePStatement(pstmtInsert);
        }
    }

    public void addCreditsLog(String fromUser, String toUser, int credits,
                              String action, Connection conn)
    {
        PreparedStatement pstmtInsert = null;
        try
        {
            pstmtInsert = conn.prepareStatement(adapter.CreditsLog_Insert);
            pstmtInsert.setString(1, toUser);
            pstmtInsert.setString(2, fromUser);
            pstmtInsert.setInt(3, credits);
            pstmtInsert.setString(4, action);
            pstmtInsert.executeUpdate();
        }
        catch(Exception se)
        {
            logger.warning("ActionLogDAO.addCreditsLog - " + se.toString());
        }
        finally
        {
            dbManager.closePStatement(pstmtInsert);
        }
    }

    public void addCensorLog(String userID, 
                             String boardID, String boardName, 
                             String topicID, String topicTitle, String replyID,
                             String reason, Connection conn)
    {
        PreparedStatement pstmtInsert = null;
        try
        {
            pstmtInsert = conn.prepareStatement(adapter.CensorLog_Insert);
            pstmtInsert.setString(1, userID);
            pstmtInsert.setString(2, boardID);
            pstmtInsert.setString(3, boardName);
            pstmtInsert.setString(4, topicID);
            pstmtInsert.setString(5, topicTitle);
            pstmtInsert.setString(6, replyID);
            
            if (reason != null && reason.length() > 40)
             pstmtInsert.setString(7, reason.substring(0,35) + "...");
            else
             pstmtInsert.setString(7, reason);
            
            pstmtInsert.executeUpdate();
        }
        catch(Exception se)
        {
            logger.warning("ActionLogDAO.addCensorLog - " + se.toString());
        }
        finally
        {
            dbManager.closePStatement(pstmtInsert);
        }
    }
    
    public String addReportLog(HttpServletRequest request, UserInfo userinfo) 
                                                             throws Exception
    {
        String reason = PageUtils.getParam(request,"reason");
        String topicID = PageUtils.getParam(request,"topicID");
        String replyID = PageUtils.getParam(request,"replyID");
        if (replyID.length() == 0)
            replyID = "0";
        
        PreparedStatement pstmtInsert = null;
        Connection conn = dbManager.getConnection();
        try
        {
            ArrayList<HashMap> topics = null;
            if (!replyID.equals("0")) // reply
            {
                ArrayList<Object> paramValues = new ArrayList<Object>();
                paramValues.add(replyID);
                topics = this.execSelectSql(adapter.Reply_GetLogInfo, paramValues, conn);
            }
            else
            {
                StringBuilder sbuf = new StringBuilder(adapter.Topic_GetLogInfo);
                sbuf.append(" (");
                sbuf.append("'").append(topicID).append("'");
                sbuf.append(")");
                topics = this.execSelectSql(sbuf.toString(), null, conn);
            }
            
            if (topics != null && topics.size() > 0)
            {
                HashMap aTopic = topics.get(0);
                String topicTitle = (String)aTopic.get("TITLE");
                if (topicTitle != null && topicTitle.length() > 100)
                    topicTitle = topicTitle.substring(0,95) + "...";
                
                String reportedUser = (String)aTopic.get("USERID");

                String boardID = (String)aTopic.get("BOARDID");
                CacheManager cache = CacheManager.getInstance();
                BoardVO aBoard = cache.getBoard(boardID);
                String boardName = aBoard.boardName;
                
                String userID = (userinfo == null ? "" : userinfo.userID);

                pstmtInsert = conn.prepareStatement(adapter.ReportLog_Insert);
                pstmtInsert.setString(1, userID);
                pstmtInsert.setString(2, reportedUser);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -