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

📄 boardservicecacheimp.java

📁 java论坛
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.laoer.bbscs.service.imp;

import java.util.*;

import org.apache.commons.logging.*;
import com.laoer.bbscs.bean.*;
import com.laoer.bbscs.comm.*;
import com.laoer.bbscs.dao.*;
import com.laoer.bbscs.exception.*;
import com.laoer.bbscs.service.*;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import java.io.File;

/**
 * <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 BoardServiceCacheImp
    implements BoardService {

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

  private BoardDAO boardDAO;

  private BoardPermissionDAO boardPermissionDAO;

  private UserGroupDAO userGroupDAO;

  private PermissionDAO permissionDAO;

  private RoleDAO roleDAO;

  private Cache boardCache;

  private ForumDAO forumDAO;

  private ForumHistoryDAO forumHistoryDAO;

  public BoardServiceCacheImp() {
  }

  /**
   * 保存或更新Board对象
   *
   * @param board Board
   * @return Board
   * @throws BbscsException
   * @todo Implement this com.laoer.bbscs.service.BoardService method
   */
  public Board saveBoard(Board board) throws BbscsException {
    try {
      board = this.getBoardDAO().saveBoard(board);
      this.getBoardCache().remove(board.getId()); //从Cache中清除
      return board;
    }
    catch (Exception ex) {
      logger.error(ex);
      throw new BbscsException(ex);
    }
  }

  /**
   *
   * @param board Board
   * @return Board
   * @throws BbscsException
   * @todo Implement this com.laoer.bbscs.service.BoardService method
   */
  public Board createBoard(Board board) throws BbscsException {
    try {
      Board pboard = this.getBoardDAO().getBoardByID(board.getParentID()); //取得父级版区
      if (pboard != null) { //父级版区存在
        List pboards = new ArrayList();
        //pboards = pboard.getParentIDs();
        pboards.addAll(pboard.getParentIDs());
        //System.out.println("pboards size:" + pboards.size());
        pboards.add(pboard.getId());
        board.setParentIDs(pboards); //设置父级版区列表字段
        board.setLevel(pboard.getLevel() + 1); //设置级别
      }
      board = this.getBoardDAO().saveBoard(board);

      if (pboard != null) {
        List pcboards = this.getBoardDAO().findBoardsByParentID(board.getParentID(), 1, 0,
            Constant.FIND_BOARDS_BY_ORDER); //取得父级半区的所有子版区列表
        //System.out.println("pcboards size:" + pcboards.size());
        //System.out.println("pboard.getParentIDs().size():" + pboard.getParentIDs().size());
        List cids = this.getBoardIDs(pcboards);
        pboard.setChildIDs(cids); //设置父级版区的所有子版区列表字段
        this.getBoardDAO().saveBoard(pboard);
      }

      //为版区增加用户组版区权限
      List gl = this.getUserGroupDAO().findUserGroupsAll(); //取得用户组列表
      BoardPermission bp;
      for (int i = 0; i < gl.size(); i++) {
        UserGroup ug = (UserGroup) gl.get(i);
        bp = new BoardPermission();
        bp.setBoardID(board.getId().longValue());
        bp.setGroupID(ug.getId().intValue());

        if (ug.getId().intValue() == 1) {
          bp.setPermissions(Constant.BOARD_PERMISSION_GROUP_LIST_1);
        }
        else if (ug.getId().intValue() == 2) {
          bp.setPermissions(Constant.BOARD_PERMISSION_GROUP_LIST_2);
        }
        else if (ug.getId().intValue() == 3) {
          bp.setPermissions(Constant.BOARD_PERMISSION_GROUP_LIST_3);
        }
        else if (ug.getId().intValue() == 4) {
          bp.setPermissions(Constant.BOARD_PERMISSION_GROUP_LIST_4);
        }
        else if (ug.getId().intValue() == 5) {
          bp.setPermissions(Constant.BOARD_PERMISSION_GROUP_LIST_5);
        }
        else if (ug.getId().intValue() == 6) {
          bp.setPermissions(Constant.BOARD_PERMISSION_GROUP_LIST_6);
        }
        else {
          bp.setPermissions(Constant.BOARD_PERMISSION_GROUP_LIST_1);
        }
        this.getBoardPermissionDAO().saveBoardPermission(bp);
      }
      return board;
    }
    catch (Exception ex) {
      logger.error(ex);
      throw new BbscsException(ex);
    }
  }

  /**
   * 更新Board对象
   *
   * @param board Board
   * @param oldParentID long
   * @return Board
   * @throws BbscsException
   * @todo Implement this com.laoer.bbscs.service.BoardService method
   */
  public Board updateBoard(Board board, long oldParentID) throws BbscsException {
    try {
      Board pboard = this.getBoardDAO().getBoardByID(board.getParentID());

      if (pboard != null) {
        List pboards = new ArrayList();
        //pboards = pboard.getParentIDs();
        pboards.addAll(pboard.getParentIDs());
        //System.out.println("pboards size:" + pboards.size());
        pboards.add(pboard.getId());
        board.setParentIDs(pboards);
        board.setLevel(pboard.getLevel() + 1);
      }
      board = this.getBoardDAO().saveBoard(board);

      if (pboard != null) {
        List pcboards = this.getBoardDAO().findBoardsByParentID(board.getParentID(), 1, 0,
            Constant.FIND_BOARDS_BY_ORDER);
        //System.out.println("pcboards size:" + pcboards.size());
        //System.out.println("pboard.getParentIDs().size():" + pboard.getParentIDs().size());
        List cids = this.getBoardIDs(pcboards);
        pboard.setChildIDs(cids);
        this.getBoardDAO().saveBoard(pboard);
      }
      Board pboardOld = this.getBoardDAO().getBoardByID(oldParentID);
      if (pboardOld != null) {
        List pcboards = this.getBoardDAO().findBoardsByParentID(pboardOld.getId().longValue(), 1, 0,
            Constant.FIND_BOARDS_BY_ORDER);
        List cids = this.getBoardIDs(pcboards);
        pboardOld.setChildIDs(cids);
        this.getBoardDAO().saveBoard(pboardOld);
      }
      this.getBoardCache().remove(board.getId()); //从Cache中清除
      return board;
    }
    catch (Exception ex) {
      logger.error(ex);
      throw new BbscsException(ex);
    }
  }

  /**
   * 根据ID取得Board对象
   *
   * @param id long
   * @return Board
   * @todo Implement this com.laoer.bbscs.service.BoardService method
   */
  public Board getBoardByID(long id) {
    Board board = (Board)this.getBoardCache().get(new Long(id));
    if (board == null) {
      board = this.getBoardDAO().getBoardByID(id);
      if (board != null) {
        //Map m = board.getBoardMaster();
        //m.size();
        board.getBoardMaster().size();
        //System.out.println(m.size());
        this.getBoardCache().add(board.getId(), board);
      }
    }
    return board;
  }

  /**
   * 根据parentID取得Board对象列表
   *
   * @param pid long
   * @return List
   * @todo Implement this com.laoer.bbscs.service.BoardService method
   */
  public List findBoardsByParentID(long pid) {
    return this.getBoardDAO().findBoardsByParentID(pid);
  }

  /**
   * 根据parentID取得Board对象列表
   *
   * @param pid long
   * @param useStat int
   * @param hidden int
   * @param orderType int
   * @return List
   * @todo Implement this com.laoer.bbscs.service.BoardService method
   */
  public List findBoardsByParentID(long pid, int useStat, int hidden, int orderType) {
    return this.getBoardDAO().findBoardsByParentID(pid, useStat, hidden, orderType);
  }

  /**
   * 生成版区树
   *
   * @param pid int
   * @param topList List
   * @return List
   * @todo Implement this com.laoer.bbscs.service.BoardService method
   */
  public List findBoardsAllTree(long pid, List topList) {
    List l = this.getBoardDAO().findBoardsByParentID(pid);
    //topList.addAll(l);
    for (int i = 0; i < l.size(); i++) {
      Board b = (Board) l.get(i);
      topList.add(b);
      this.findBoardsAllTree(b.getId().longValue(), topList);
    }
    return topList;
  }

  public List findBoardsAllTree(long pid, List topList, int useStat, int hidden, int orderType) {
    List l = this.getBoardDAO().findBoardsByParentID(pid, useStat, hidden, orderType);
    //topList.addAll(l);
    for (int i = 0; i < l.size(); i++) {
      Board b = (Board) l.get(i);
      topList.add(b);
      this.findBoardsAllTree(b.getId().longValue(), topList);
    }
    return topList;

  }

  /**
   * 根据parentID预取得Board序列
   *
   * @param pid long
   * @return int
   * @todo Implement this com.laoer.bbscs.service.BoardService method
   */
  public int getNextOrder(long pid) {
    return this.getBoardDAO().getNextOrder(pid);
  }

  /**
   * 取得帖子总数(主帖或全部)
   *
   * @param mainorall int
   * @param useStat int
   * @param hidden int
   * @return int
   * @todo Implement this com.laoer.bbscs.service.BoardService method
   */
  public int getPostSumNum(int mainorall, int useStat, int hidden) {
    return this.getBoardDAO().getPostSumNum(mainorall, useStat, hidden);
  }

  /**
   * 删除Board对象
   *
   * @param board Board
   * @throws BbscsException
   * @todo Implement this com.laoer.bbscs.service.BoardService method
   */
  public void removeBoard(Board board) throws BbscsException {
    try {
      Long lbid = board.getId();
      Board pboard = this.getBoardDAO().getBoardByID(board.getParentID()); //取得父版区

      this.getBoardDAO().removeBoard(board); //删除版区
      this.getBoardPermissionDAO().removeBoardPermissionsByBid(board.getId().longValue());

      if (pboard != null) { //父版区存在,对ChildIDs字段做矫正
        List pcboards = this.getBoardDAO().findBoardsByParentID(pboard.getId().longValue(), 1, 0,
            Constant.FIND_BOARDS_BY_ORDER);
        List cids = this.getBoardIDs(pcboards);
        pboard.setChildIDs(cids);
        this.getBoardDAO().saveBoard(pboard);
      }

      this.getBoardCache().remove(lbid);
    }
    catch (Exception ex) {
      logger.error(ex);
      throw new BbscsException(ex);

⌨️ 快捷键说明

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