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

📄 sysstatserviceimp.java

📁 java论坛
💻 JAVA
字号:
package com.laoer.bbscs.service.imp;

import java.util.*;
import java.io.*;
import com.laoer.bbscs.service.*;
import com.laoer.comm.util.*;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;

/**
 * <p>Title: Tianyi BBS</p>
 *
 * <p>Description: BBSCS</p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: Laoer.com</p>
 *
 * @author Gong Tianyi
 * @version 7.0
 */
public class SysStatServiceImp
    extends SysStatService {

  private static final Log logger = LogFactory.getLog(SysStatServiceImp.class);

  private String safePath;

  public SysStatServiceImp() {
    //load();
  }

  public void load() {
    Properties prop = new Properties();
    File f = new File(this.getSafePath() + "sysstat.properties");
    if (f.exists()) {
      try {
        FileInputStream fis = new FileInputStream(f);
        prop.load(fis);
        this.setOnlineNum(Integer.parseInt(prop.getProperty("onlineNum", "0").trim()));
        this.setAppearTime(Long.parseLong(prop.getProperty("appearTime", "0").trim()));
        this.setAllUserNum(Integer.parseInt(prop.getProperty("allUserNum", "0").trim()));
        this.setLastRegUser(prop.getProperty("lastRegUser", ""));
        this.setPostMainNum(Integer.parseInt(prop.getProperty("postMainNum", "0").trim()));
        this.setPostNum(Integer.parseInt(prop.getProperty("postNum", "0").trim()));
        this.setAppearTimeStr(Util.formatDateTime(new Date(this.getAppearTime())));
        fis.close();
      }
      catch (NumberFormatException ex) {
        logger.error(ex);
      }
      catch (FileNotFoundException ex) {
        logger.error(ex);
      }
      catch (IOException ex) {
        logger.error(ex);
      }
    }
    else {
      save();
    }
  }

  private void save() {
    String path = this.getSafePath() + "sysstat.properties";
    Properties prop = new Properties();
    prop.setProperty("onlineNum", String.valueOf(this.getOnlineNum()));
    prop.setProperty("appearTime", String.valueOf(this.getAppearTime()));
    prop.setProperty("allUserNum", String.valueOf(this.getAllUserNum()));
    prop.setProperty("lastRegUser", this.getLastRegUser());
    prop.setProperty("postNum", String.valueOf(this.getPostNum()));
    prop.setProperty("postMainNum", String.valueOf(this.getPostMainNum()));
    try {
      FileOutputStream fos = new FileOutputStream(path);
      prop.store(fos, "sysstat.properties");
      fos.close();
    }
    catch (FileNotFoundException ex) {
      logger.error(ex);
    }
    catch (IOException ex) {
      logger.error(ex);
    }
  }

  /**
   * saveAllUserNum
   *
   * @param allusernum int
   * @param lastreguser String
   * @todo Implement this com.laoer.bbscs.service.SysStatService method
   */
  public void saveAllUserNum(int allusernum, String lastreguser) {
    this.load();
    this.setAllUserNum(allusernum);
    this.setLastRegUser(lastreguser);
    this.save();
  }

  /**
   * saveOnline
   *
   * @param nowonlinenum int
   * @todo Implement this com.laoer.bbscs.service.SysStatService method
   */
  public void saveOnline(int nowonlinenum) {
    this.load();
    if (nowonlinenum > this.getOnlineNum()) {
      long atime = System.currentTimeMillis();
      this.setOnlineNum(nowonlinenum);
      this.setAppearTime(atime);
      this.setAppearTimeStr(Util.formatDateTime(new Date(atime)));
      this.save();
    }
  }

  /**
   * savePostNum
   *
   * @param main int
   * @param all int
   * @todo Implement this com.laoer.bbscs.service.SysStatService method
   */
  public void savePostNum(int main, int all) {
    this.load();
    this.setPostMainNum(main);
    this.setPostNum(all);
    this.save();
  }

  public String getSafePath() {
    return safePath;
  }

  public void setSafePath(String safePath) {
    this.safePath = safePath;
  }
}

⌨️ 快捷键说明

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