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

📄 actionlogdao.java

📁 EasyJForum 是一个基于 Java 技术的免费社区论坛软件系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                pstmtInsert.setString(3, boardID);
                pstmtInsert.setString(4, boardName);
                pstmtInsert.setString(5, topicID);
                pstmtInsert.setString(6, topicTitle);
                pstmtInsert.setString(7, replyID);
                
                if (reason != null && reason.length() > 40)
                 pstmtInsert.setString(8, reason.substring(0,35) + "...");
                else
                 pstmtInsert.setString(8, reason);

                pstmtInsert.executeUpdate();
                
                // Send mail to administrators
                String mailEvents = 
                    ForumSetting.getInstance().getString(ForumSetting.FUNCTIONS, "mailEvents");
                if (mailEvents.indexOf("report") >= 0)
                {
                    ArrayList<OptionVO> users = 
                        UserDAO.getInstance().getReportHandlers(aBoard, conn);
                    if (users != null && users.size() > 0)
                    {
                        String[] toAddress = new String[users.size()];
                        for (int i=0; i<toAddress.length; i++)
                        {
                            toAddress[i] = users.get(i).value;
                        }
                        
                        String forumName = ForumSetting.getInstance().getForumName();
                        StringBuilder sbuf = new StringBuilder();
                        sbuf.append("用户名:").append(userID).append("<br>\n");
                        sbuf.append("被举报用户:").append(reportedUser).append("<br>\n");
                        sbuf.append("论坛版块:").append(boardName).append("<br>\n");
                        sbuf.append("主题:").append("<A href=\"")
                            .append(PageUtils.getRootPath(request.getRequestURL().toString()))
                            .append(request.getContextPath()).append("/topic-")
                            .append(request.getParameter("sid"))
                            .append('-').append(boardID).append('-').append(topicID);
                        if (replyID.equals("0"))
                            sbuf.append("-1.html\">").append(topicTitle);
                        else
                            sbuf.append("-r").append(replyID).append(".html#rid")
                                .append(replyID).append("\">").append(topicTitle)
                                .append(" (RID:").append(replyID).append(")");
                        sbuf.append("</A><br>\n");
                        sbuf.append("举报原因:").append(reason).append("<br><br>\n");
                        sbuf.append("更多信息请在后台管理中查阅用户举报记录。");
                        sbuf.append(PageUtils.getSysMailFooter(request));
                        
                        String subject = forumName + "用户举报信息";
                        AppUtils.sendMail(toAddress, subject, sbuf.toString());
                    }
                }
            }
            return "OK";
        }
        finally
        {
            dbManager.closePStatement(pstmtInsert);
            dbManager.closeConnection(conn);
        }
    }
    
    public void cleanExpiredLogs() throws Exception
    {
        int keepMonths = 
            ForumSetting.getInstance().getInt(ForumSetting.FUNCTIONS, "logKeepMonths");
        if (keepMonths <= 0) return;
        
        Connection conn = dbManager.getConnection();
        try
        {
            Calendar cal = Calendar.getInstance();
            cal.add(Calendar.MONTH, (-1)*keepMonths);

            SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
            String expireDate = dateFormatter.format(cal.getTime());
            ArrayList<Object> paramValues = new ArrayList<Object>();
            paramValues.add(expireDate);

            this.execUpdateSql(adapter.AdminLog_Delete, paramValues, conn);
            this.execUpdateSql(adapter.ModerateLog_Delete, paramValues, conn);
            this.execUpdateSql(adapter.ErrorLog_Delete, paramValues, conn);
            this.execUpdateSql(adapter.CensorLog_Delete, paramValues, conn);
            this.execUpdateSql(adapter.ReportLog_Delete, paramValues, conn);
            this.execUpdateSql(adapter.CreditsLog_Delete, paramValues, conn);
        }
        finally
        {
            dbManager.closeConnection(conn);
        }
    }
    
    /**
     * Get log info list
     * @param 
     *      request - HttpServletRequest
     * @return Log info list
     * @throws SQLException
     * @since 1.0
     */
    public Object[] getLogList(String logName, String action, String strPageNo, String strPageRows) 
                                                                                throws SQLException
    {
        Object[] result = new Object[2];
        String countSql = null;
        String querySql = null;
        if (logName.equals("admin"))
        {
            countSql = "select COUNT(*) from ejf_admin_log";
            querySql = "select * from ejf_admin_log";
        }
        else if (logName.equals("credits"))
        {
            countSql = "select COUNT(*) from ejf_credits_log";
            querySql = "select * from ejf_credits_log";
        }
        else if (logName.equals("report"))
        {
            countSql = "select COUNT(*) from ejf_report_log";
            querySql = "select * from ejf_report_log";
        }
        else if (logName.equals("censor"))
        {
            countSql = "select COUNT(*) from ejf_censor_log";
            querySql = "select * from ejf_censor_log";
        }
        else if (logName.equals("moderator"))
        {
            countSql = "select COUNT(*) from ejf_moderator_log";
            querySql = "select * from ejf_moderator_log";
        }
        else if (logName.equals("error"))
        {
            countSql = "select COUNT(*) from ejf_error_log";
            querySql = "select * from ejf_error_log";
        }

        ArrayList<Object> paramValues = new ArrayList<Object>();
        
        String whereSql = "";
        if (action != null && action.length() > 0)
        {
            if (action.indexOf('*') >= 0)
            {
                if (logName.equals("report") || logName.equals("censor"))
                    whereSql = " where reason like ?";
                else
                    whereSql = " where action like ?";
                paramValues.add(action.replace('*', '%'));
            }
            else
            {
                if (logName.equals("report") || logName.equals("censor"))
                    whereSql = " where reason=?";
                else
                    whereSql = " where action=?";
                paramValues.add(action);
            }
        }
        
        countSql = countSql + whereSql;
        querySql = querySql + whereSql;
        
        int pageNo = 1;
        try
        {
            pageNo = Integer.parseInt(strPageNo);
        }
        catch(Exception e){ /* Ignored */ }
        
        if (pageNo < 1)
            pageNo = 1;

        int pageRows = 20;
        try
        {
            pageRows = Integer.parseInt(strPageRows);
        }
        catch(Exception e){ /* Ignored */ }
        
        if (pageRows < 1)
            pageRows = 1;

        int totalCount = 0;
        Connection conn = null;
        PreparedStatement pstmtQuery = null;
        ResultSet rs = null;
        try
        {
            conn = dbManager.getConnection();
            totalCount = this.execSelectCountSql(countSql, paramValues, conn);
            
            if (totalCount > 0)
            {
                querySql = adapter.getPageQuerySql(
                            new StringBuilder(querySql).append(" order by createTime DESC"),
                            pageNo, pageRows, totalCount);
                ArrayList<HashMap> logList = this.execSelectSql(querySql, paramValues);
                
                result[1] = logList;
            }
        }
        finally
        {
            dbManager.closeResultSet(rs);
            dbManager.closePStatement(pstmtQuery);
            dbManager.closeConnection(conn);
        }
        // Get result page code
        if (totalCount > 0)
        {
            result[0] = PageUtils.getPageHTMLStr(totalCount, pageNo, pageRows, 0);
        }        
        return result;
    }

    /**
     * Get credits log info of an user
     * @param 
     *      request - HttpServletRequest
     * @return Log info list
     * @throws SQLException
     * @since 1.0
     */
    public Object[] getCreditsLogs(String userID, String action, int pageNo, int pageRows) 
                                                                  throws SQLException
    {
        Object[] result = new Object[2];
        String querySql = "select * from ejf_credits_log";
        String countSql = "select COUNT(*) from ejf_credits_log";

        if (action != null && action.equals("dec"))
        {
            querySql = querySql + " where fromUser=?";
            countSql = countSql + " where fromUser=?";
        }
        else
        {
            querySql = querySql + " where userID=?";
            countSql = countSql + " where userID=?";
        }
        
        int totalCount = 0;
        Connection conn = null;
        PreparedStatement pstmtQuery = null;
        ResultSet rs = null;
        try
        {
            conn = dbManager.getConnection();

            ArrayList<Object> paramValues = new ArrayList<Object>();
            paramValues.add(userID);
            totalCount = this.execSelectCountSql(countSql, paramValues, conn);
            
            if (totalCount > 0)
            {
                querySql = adapter.getPageQuerySql(
                        new StringBuilder(querySql).append(" order by createTime DESC"),
                        pageNo, pageRows, totalCount);
                ArrayList<HashMap> logList = this.execSelectSql(querySql, paramValues);
                
                result[1] = logList;
            }
        }
        finally
        {
            dbManager.closeResultSet(rs);
            dbManager.closePStatement(pstmtQuery);
            dbManager.closeConnection(conn);
        }
        // Get result page code
        if (totalCount > 0)
        {
            result[0] = PageUtils.getPageHTMLStr(totalCount, pageNo, pageRows, 0);
        }        
        return result;
    }
    
}

⌨️ 快捷键说明

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