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

📄 dbblackuser.java

📁 天乙代码src_531.rar 天乙代码src_531.rar 天乙代码src_531.rar 天乙代码src_531.rar
💻 JAVA
字号:
package com.laoer.bbscs.bbs.business;

import java.util.*;
import com.laoer.bbscs.db.*;
import com.laoer.bbscs.exception.ObjectException;
import com.laoer.bbscs.exception.ObjectNoExistException;
import org.apache.log4j.*;
import java.sql.*;
import com.laoer.bbscs.sysinfo.*;
import java.io.*;
import com.laoer.bbscs.util.*;
import com.laoer.bbscs.servlet.*;

/**
 * <p>Title: 天乙社区V5.0</p>
 * <p>Description: BBS-CS天乙社区V5.0</p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: laoer.com</p>
 * @author 龚天乙
 * @version 5.0
 */

public class DBBlackUser
    extends BlackUser
    implements DBInf {

  ResultSet rs = null;
  static Logger logger = Logger.getLogger(DBBlackUser.class.getName());

  private static final String INSERT_BLACKUSER = "insert into blackuser (ID,UserID,UserName,AtSite,AtBoard,AtBoards,Reason,OutTime,AddName) values (?,?,?,?,?,?,?,?,?)";
  private static final String LOAD_ATBOARDS =
      "select * from blackuser where AtBoards = ? and UserID = ?";
  private static final String LOAD_ATBOARDSS =
      "select * from blackuser where AtBoards = ?";
  private static final String LOAD_ATSITES =
      "select * from blackuser where AtSite = 1";
  private static final String LOAD_ATSITES_TOTAL =
      "select count(*) as total from blackuser where AtSite = 1";
  private static final String LOAD_ATBOARDSS_TIME =
      "select * from blackuser where AtBoards = ? and OutTime > ?";
  private static final String LOAD_ATSITE =
      "select * from blackuser where AtSite = 1 and UserID = ?";
  private static final String DEL_ATBOARDS =
      "delete from blackuser where AtBoards = ? and UserName = ?";
  private static final String DEL_ATSITE =
      "delete from blackuser where AtSite = 1 and UserName = ?";

  public DBBlackUser() {
  }

  public List getBlackUserList(TranContext aTranContext, String key) {
    TranContext myDBTrans = null;
    if (aTranContext == null) {
      myDBTrans = new TranContext();
    }
    else {
      myDBTrans = aTranContext;
    }
    try {
      List alist = null;
      alist = this.loadDBs(myDBTrans, key);
      return alist;
    }
    catch (ObjectException e) {
      logger.error(e);
      return (List) Sys.RESULT_NULL;
    }
    finally {
      if (aTranContext == null && myDBTrans != null) {
        myDBTrans.freeCon();
      }
    }
  }

  public int getBlackUser(TranContext aTranContext, String key, boolean isLoad) {
    TranContext myDBTrans = null;
    if (aTranContext == null) {
      myDBTrans = new TranContext();
    }
    else {
      myDBTrans = aTranContext;
    }
    try {
      this.loadDB(myDBTrans, key, isLoad);
      return Sys.RESULT_RIGHT;
    }
    catch (ObjectException e) {
      logger.error(e);
      return Sys.RESULT_OBJECTEXCEPTION;
    }
    catch (ObjectNoExistException e) {
      return Sys.RESULT_OBJECTNOEXISTEXCEPTION;
    }
    finally {
      if (aTranContext == null && myDBTrans != null) {
        myDBTrans.freeCon();
      }
    }
  }

  public int delBlackUser(TranContext aTranContext, String key) {
    TranContext myDBTrans = null;
    if (aTranContext == null) {
      myDBTrans = new TranContext();
    }
    else {
      myDBTrans = aTranContext;
    }
    try {
      this.delDB(myDBTrans, key);
      this.setBlackUserList(myDBTrans);
      UpMsg aUpMsg = new UpMsg(5);
      ServerSession.upMsg(aUpMsg);
      return Sys.RESULT_RIGHT;
    }
    catch (ObjectException e) {
      logger.error(e);
      return Sys.RESULT_OBJECTEXCEPTION;
    }
    finally {
      if (aTranContext == null && myDBTrans != null) {
        myDBTrans.freeCon();
      }
    }
  }

  public int createBlackUser(TranContext aTranContext) {
    TranContext myDBTrans = null;
    if (aTranContext == null) {
      myDBTrans = new TranContext();
    }
    else {
      myDBTrans = aTranContext;
    }
    try {
      this.insertDB(myDBTrans);
      if (! (this.myBlackUserInfo.getAtSite() == 1)) { //如果是系统黑名单,不用更新版区黑名单列表
        this.setBlackUserList(myDBTrans);
        UpMsg aUpMsg = new UpMsg(5);
        ServerSession.upMsg(aUpMsg);
      }
      return Sys.RESULT_RIGHT;
    }
    catch (ObjectException e) {
      logger.error(e);
      return Sys.RESULT_OBJECTEXCEPTION;
    }
    finally {
      if (aTranContext == null && myDBTrans != null) {
        myDBTrans.freeCon();
      }
    }
  }

  public void setBlackUserList(TranContext aTranContext) {
    TranContext myDBTrans = null;
    if (aTranContext == null) {
      myDBTrans = new TranContext();
    }
    else {
      myDBTrans = aTranContext;
    }
    try {
      logger.info("整理黑名单静态列表,每版有一个黑名单列表");
      Boards myBoards = BoardsFactory.getInstance();
      List alist = myBoards.getBoardsList(myDBTrans, "All");
      List bulist = null;
      BoardsInfo aBoardsInfo = null;
      Hashtable aht = new Hashtable();
      //BlackUserInfo aBlackUserInfo = new BlackUserInfo();
      //BlackUser aBlackUser = BlackUserFactory.getInstance();
      for (int i = 0; i < alist.size(); i++) {
        aBoardsInfo = (BoardsInfo) alist.get(i);
        this.myBlackUserInfo.setAtBoards(aBoardsInfo.getID());
        bulist = this.loadDBs(myDBTrans, "OutTime");
        aht.put(String.valueOf(aBoardsInfo.getID()), bulist);
        logger.info("加入[" + aBoardsInfo.getBoardsName() + "]黑名单列表");
      }
      BoardList.blackuserlist = aht;
    }
    catch (ObjectException e) {
      logger.error(e);
    }
    finally {
      if (aTranContext == null && myDBTrans != null) {
        myDBTrans.freeCon();
      }
    }
  }

  public int getBlackUserNum(TranContext aTranContext, String key) {
    TranContext myDBTrans = null;
    if (aTranContext == null) {
      myDBTrans = new TranContext();
    }
    else {
      myDBTrans = aTranContext;
    }
    try {
      int total = 0;
      if (key.equals("atSite")) {
        myDBTrans.prepareStatement(LOAD_ATSITES_TOTAL);
        rs = myDBTrans.executeQuery();
        if (rs.next()) {
          total = rs.getInt("total");
        }
        rs.close();
      }
      return total;
    }
    catch (SQLException e) {
      logger.error(e);
      return Sys.RESULT_ZERO;
    }
    finally {
      try {
        if (rs != null) {
          rs.close();
        }
      }
      catch (SQLException e) {
      }
      try {
        if (myDBTrans != null) {
          myDBTrans.close();
        }
      }
      catch (SQLException e) {
      }
      if (aTranContext == null && myDBTrans != null) {
        myDBTrans.freeCon();
      }
    }
  }

  public void loadDB(TranContext myDB, String key, boolean isLoad) throws
      ObjectException, ObjectNoExistException {
    try {
      if (key.equals("atBoards")) {
        myDB.prepareStatement(LOAD_ATBOARDS);
        myDB.setLong(1, this.myBlackUserInfo.getAtBoards());
        myDB.setLong(2, this.myBlackUserInfo.getUserID());
      }
      if (key.equals("atSite")) {
        myDB.prepareStatement(LOAD_ATSITE);
        myDB.setLong(1, this.myBlackUserInfo.getUserID());
      }
      rs = myDB.executeQuery();
      if (rs.next()) {
        if (isLoad) {
          this.myBlackUserInfo.setID(rs.getString("ID"));
          this.myBlackUserInfo.setUserID(rs.getLong("UsetID"));
          this.myBlackUserInfo.setUserName(rs.getString("UserName"));
          this.myBlackUserInfo.setAtSite(rs.getInt("AtSite"));
          this.myBlackUserInfo.setAtBoard(rs.getInt("AtBoard"));
          this.myBlackUserInfo.setAtBoards(rs.getInt("AtBoards"));
          this.myBlackUserInfo.setReason(rs.getString("Reason"));
          this.myBlackUserInfo.setOutTime(rs.getLong("OutTime"));
          this.myBlackUserInfo.setAddName(rs.getString("AddName"));
        }
      }
      else {
        throw new ObjectNoExistException();
      }
    }
    catch (SQLException e) {
      throw new ObjectException(e.toString());
    }
    finally {
      try {
        if (rs != null) {
          rs.close();
          rs = null;
        }
      }
      catch (SQLException e) {
      }
      try {
        if (myDB != null) {
          myDB.close();
        }
      }
      catch (SQLException e) {
      }
    }
  }

  public List loadDBs(TranContext myDB, String key) throws ObjectException {
    List alist = ListFactory.getInstance(2);
    BlackUserInfo aBlackUserInfo = null;
    try {
      if (key.equals("atBoardsList")) {
        myDB.prepareStatement(LOAD_ATBOARDSS);
        myDB.setLong(1, this.myBlackUserInfo.getAtBoards());
      }
      if (key.equals("OutTime")) {
        myDB.prepareStatement(LOAD_ATBOARDSS_TIME);
        myDB.setLong(1, this.myBlackUserInfo.getAtBoards());
        myDB.setLong(2, Util.getaLongTime());
      }
      if (key.equals("atSite")) {
        String strSQL = "select * from blackuser where AtSite = 1";
        this.pages.setTotals(this.getBlackUserNum(myDB, key));
        this.pages.doPageBreak();
        this.sListPageBreak = this.pages.getListPageBreak();
        this.pages.setSQL(strSQL);
        myDB.prepareStatement(this.pages.getSQLString("ID"));
      }
      rs = myDB.executeQuery();
      while (rs.next()) {
        aBlackUserInfo = new BlackUserInfo();
        aBlackUserInfo.setID(rs.getString("ID"));
        aBlackUserInfo.setUserID(rs.getLong("UserID"));
        aBlackUserInfo.setUserName(rs.getString("UserName"));
        aBlackUserInfo.setAtSite(rs.getInt("AtSite"));
        aBlackUserInfo.setAtBoard(rs.getInt("AtBoard"));
        aBlackUserInfo.setAtBoards(rs.getInt("AtBoards"));
        aBlackUserInfo.setReason(rs.getString("Reason"));
        aBlackUserInfo.setOutTime(rs.getLong("OutTime"));
        aBlackUserInfo.setAddName(rs.getString("AddName"));
        alist.add(aBlackUserInfo);
        aBlackUserInfo = null;
      }
      return alist;
    }
    catch (SQLException e) {
      throw new ObjectException(e.toString());
    }
    finally {
      try {
        if (rs != null) {
          rs.close();
          rs = null;
        }
      }
      catch (SQLException e) {
      }
      try {
        if (myDB != null) {
          myDB.close();
        }
      }
      catch (SQLException e) {
      }
    }
  }

  public void insertDB(TranContext myDB) throws ObjectException {
    try {
      myDB.prepareStatement(INSERT_BLACKUSER);
      myDB.setString(1, this.myBlackUserInfo.getID());
      myDB.setLong(2, this.myBlackUserInfo.getUserID());
      myDB.setString(3, this.myBlackUserInfo.getUserName());
      myDB.setInt(4, this.myBlackUserInfo.getAtSite());
      myDB.setLong(5, this.myBlackUserInfo.getAtBoard());
      myDB.setLong(6, this.myBlackUserInfo.getAtBoards());
      myDB.setString(7, this.myBlackUserInfo.getReason());
      myDB.setLong(8, this.myBlackUserInfo.getOutTime());
      myDB.setString(9, this.myBlackUserInfo.getAddName());
      myDB.executeUpdate();
    }
    catch (SQLException e) {
      throw new ObjectException(e.toString());
    }
    finally {
      try {
        if (myDB != null) {
          myDB.close();
        }
      }
      catch (SQLException e) {
      }
    }
  }

  public void updateDB(TranContext myDB, String key) throws ObjectException {
  }

  public void delDB(TranContext myDB, String key) throws ObjectException {
    try {
      if (key.equals("delatboards")) {
        myDB.prepareStatement(DEL_ATBOARDS);
        myDB.setLong(1, this.myBlackUserInfo.getAtBoards());
        myDB.setString(2, this.myBlackUserInfo.getUserName());
      }
      if (key.equals("delatsite")) {
        myDB.prepareStatement(DEL_ATSITE);
        myDB.setString(1, this.myBlackUserInfo.getUserName());
      }
      myDB.executeUpdate();
    }
    catch (SQLException e) {
      throw new ObjectException(e.toString());
    }
    finally {
      try {
        if (myDB != null) {
          myDB.close();
        }
      }
      catch (SQLException e) {
      }
    }
  }

}

⌨️ 快捷键说明

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