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

📄 forumschedulerunit.java

📁 cwbbs 云网论坛源码
💻 JAVA
字号:
package com.redmoon.forum;import cn.js.fan.kernel.BaseSchedulerUnit;import cn.js.fan.db.Conn;import cn.js.fan.web.Global;import java.sql.ResultSet;import java.sql.SQLException;import org.apache.log4j.Logger;import java.util.Date;import java.sql.PreparedStatement;import com.redmoon.forum.message.MessageDb;import cn.js.fan.util.ResKeyException;import cn.js.fan.util.DateUtil;import cn.js.fan.util.StrUtil;import com.cloudwebsoft.framework.util.LogUtil;public class ForumSchedulerUnit extends BaseSchedulerUnit {    public static int refreshOnlineInterval = 5;     public static long lastRefreshOnlineIntervalTime;    public static long lastClearUserMessageInerval = System.currentTimeMillis();    public static long lastClearTmpAttachmentTime = System.currentTimeMillis();    public static long clearUserMessageInterval = 24 * 60 * 60 * 1000;     public static long clearTmpAttachmentInterval = 4 * 60 * 60 * 1000;     public static int message_expire_day = 150;     static {        initParam();    }    public ForumSchedulerUnit() {        lastTime = System.currentTimeMillis();        interval = 600000;         lastRefreshOnlineIntervalTime = System.currentTimeMillis();        lastClearUserMessageInerval = System.currentTimeMillis();        name = "Forum Scheduler";    }    public static void initParam() {        Config cfg = Config.getInstance();        refreshOnlineInterval = cfg.getIntProperty("forum.refreshOnlineInterval") * 60 * 1000;        message_expire_day = cfg.getIntProperty("forum.message_expire_day");        clearUserMessageInterval = cfg.getIntProperty("interval_clear_message") * 60 * 60 * 1000;    }        public void OnTimer(long curTime) {                try {            if (curTime - lastTime >= interval) {                action();                lastTime = curTime;            }            if (curTime - lastRefreshOnlineIntervalTime >=                refreshOnlineInterval) {                OnlineUserDb oud = new OnlineUserDb();                oud.refreshOnlineUser();                lastRefreshOnlineIntervalTime = curTime;            }            if (curTime - lastClearUserMessageInerval >=                clearUserMessageInterval) {                clearMessageExpired(message_expire_day);                lastClearUserMessageInerval = curTime;            }            if (curTime - lastClearTmpAttachmentTime >=                clearTmpAttachmentInterval) {                clearTmpAttachment();                lastClearTmpAttachmentTime = curTime;            }        }        catch (Throwable e) {                        LogUtil.getLog(getClass()).error("OnTimer:" + StrUtil.trace(e));        }    }    public void clearMessageExpired(int expireDay) {        MessageDb md = new MessageDb();        md.clearMessageExpired(expireDay);    }    public synchronized void action() {        refreshColor();        refreshBold();        refreshLevel();    }        public void clearTmpAttachment() {        java.util.Date today = new Date();        Date d2 = DateUtil.addDate(today, -2);        Date d10 = DateUtil.addDate(today, -10);                String sql = "select id from sq_message_attach where msgId=-1 and UPLOAD_DATE>? and UPLOAD_DATE<?";                Conn conn = new Conn(Global.defaultDB);        ResultSet rs = null;        try {            PreparedStatement ps = conn.prepareStatement(sql);            ps.setString(1, "" + d10.getTime());            ps.setString(2, "" + d2.getTime());            rs = conn.executePreQuery();                        while (rs.next()) {                long id = rs.getLong(1);                LogUtil.getLog(getClass()).info("clearTmpAttachment: Delete temp attchment id=" + id);                Attachment att = new Attachment(id);                att.delTmpAttach();            }        } catch (SQLException e) {            LogUtil.getLog(getClass()).error("clearTmpAttachment:" + e.getMessage());        } finally {            if (conn != null) {                conn.close();                conn = null;            }        }    }    public void refreshBold() {        MsgDb md = new MsgDb();        String sql = "select id from sq_message where isBold=1 and boldExpire<?";                Conn conn = new Conn(Global.defaultDB);        ResultSet rs = null;        try {            PreparedStatement ps = conn.prepareStatement(sql);            ps.setString(1, "" + System.currentTimeMillis());            rs = conn.executePreQuery();            while (rs.next()) {                long id = rs.getLong(1);                                md = md.getMsgDb(id);                try {                    md.ChangeBold("", 0, new Date(), "127.0.0.1");                } catch (ResKeyException e) {                    LogUtil.getLog(getClass()).error("refreshBold:" + e.getMessage());                }            }        } catch (SQLException e) {            LogUtil.getLog(getClass()).error("refreshBold:" + e.getMessage());        } finally {            if (conn != null) {                conn.close();                conn = null;            }        }    }    public void refreshLevel() {        MsgDb md = new MsgDb();        String sql = "select id from sq_message where msg_level>" + MsgDb.LEVEL_NONE + " and level_expire<?";                Conn conn = new Conn(Global.defaultDB);        ResultSet rs = null;        try {            PreparedStatement ps = conn.prepareStatement(sql);            ps.setString(1, "" + System.currentTimeMillis());            rs = conn.executePreQuery();            while (rs.next()) {                long id = rs.getLong(1);                                md = md.getMsgDb(id);                try {                    md.setOnTop(MsgDb.LEVEL_NONE, null);                } catch (ResKeyException e) {                    LogUtil.getLog(getClass()).error("action:" + e.getMessage());                }            }        } catch (SQLException e) {            LogUtil.getLog(getClass()).error("refreshBold:" + e.getMessage());        } finally {            if (conn != null) {                conn.close();                conn = null;            }        }    }    public void refreshColor() {        MsgDb md = new MsgDb();        String sql = "select id from sq_message where color<>'' and colorExpire<?";                Conn conn = new Conn(Global.defaultDB);        ResultSet rs = null;        try {            PreparedStatement ps = conn.prepareStatement(sql);            ps.setString(1, "" + System.currentTimeMillis());            rs = conn.executePreQuery();                        while (rs.next()) {                long id = rs.getLong(1);                                md = md.getMsgDb(id);                try {                    md.ChangeColor("", "", new Date(), "127.0.0.1");                } catch (ResKeyException e) {                    LogUtil.getLog(getClass()).error("refreshColor:" + e.getMessage());                }            }        } catch (SQLException e) {            LogUtil.getLog(getClass()).error("refreshColor1:" + e.getMessage());        } finally {            if (conn != null) {                conn.close();                conn = null;            }        }    }}

⌨️ 快捷键说明

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