boardservicebycacheimp.java

来自「一个jsp写的bbs」· Java 代码 · 共 853 行 · 第 1/2 页

JAVA
853
字号
          }
          if (permission.getTypeID() == 3) {
            mapPermission[1].put(permission.getId(), permission);
          }
        }
      }
      return mapPermission;
    }
  }

  public Map[] getBoardMasterPermission(int roleID) {
    /**
         Map[] mapPermission = {new HashMap(), new HashMap()};
         Role role = this.getRoleDAO().findRoleByID(roleID);
         List permissions = role.getPermissions(); //取得角色的权限ID列表
         if (permissions != null && !permissions.isEmpty()) {
      List permissionList = this.getPermissionDAO().findPermissionnIDs(permissions); //取得权限列表
      for (int i = 0; i < permissionList.size(); i++) {
        Permission permission = (Permission) permissionList.get(i);
        if (permission.getTypeID() == 2) {
          mapPermission[0].put(permission.getResource() + "," + permission.getAction(),
                               permission);
        }
        if (permission.getTypeID() == 3) {
          mapPermission[1].put(permission.getId(), permission);
        }
      }
         }
         return mapPermission;
     */
    if (Constant.USE_PERMISSION_CACHE) {
      Map[] mapPermission = (Map[])this.getUserPermissionCache().get("R_" + String.valueOf(roleID));
      if (mapPermission == null) {
        mapPermission = new Map[2];
        mapPermission[0] = new HashMap();
        mapPermission[1] = new HashMap();
        Role role = this.getRoleDAO().findRoleByID(roleID);
        List permissions = role.getPermissions(); //取得角色的权限ID列表
        if (permissions != null && !permissions.isEmpty()) {
          List permissionList = this.getPermissionDAO().findPermissionnIDs(permissions); //取得权限列表
          for (int i = 0; i < permissionList.size(); i++) {
            Permission permission = (Permission) permissionList.get(i);
            if (permission.getTypeID() == 2) {
              mapPermission[0].put(permission.getResource() + "," + permission.getAction(),
                                   permission);
            }
            if (permission.getTypeID() == 3) {
              mapPermission[1].put(permission.getId(), permission);
            }
          }
        }
        this.getUserPermissionCache().add("R_" + String.valueOf(roleID), mapPermission);
      }
      return mapPermission;
    }
    else {
      Map[] mapPermission = {new HashMap(), new HashMap()};
      Role role = this.getRoleDAO().findRoleByID(roleID);
      List permissions = role.getPermissions(); //取得角色的权限ID列表
      if (permissions != null && !permissions.isEmpty()) {
        List permissionList = this.getPermissionDAO().findPermissionnIDs(permissions); //取得权限列表
        for (int i = 0; i < permissionList.size(); i++) {
          Permission permission = (Permission) permissionList.get(i);
          if (permission.getTypeID() == 2) {
            mapPermission[0].put(permission.getResource() + "," + permission.getAction(),
                                 permission);
          }
          if (permission.getTypeID() == 3) {
            mapPermission[1].put(permission.getId(), permission);
          }
        }
      }
      return mapPermission;
    }
  }

  public boolean isBoardMaster(Board board, String userName) {
    if (board.getBoardMaster().get(userName) == null) {
      return false;
    }
    else {
      return true;
    }
  }

  public List findBoardsInIDsInSameLevel(List ids, int useStat, int hidden) {
    //两种通常情况,从Cache中取Board对象,不查找数据库
    if (useStat == 1 && hidden == -1) {
      List blist = new ArrayList();
      if (ids != null && !ids.isEmpty()) {
        for (int i = 0; i < ids.size(); i++) {
          long bid = ( (Long) ids.get(i)).longValue();
          Board b = this.getBoardByID(bid);
          if (b != null) {
            if (b.getUseStat() == useStat) {
              blist.add(b);
            }
          }
        }
      }
      Collections.sort(blist, new BoardsOrdersComparator());
      return blist;
    }
    if (useStat == 1 && hidden == 0) {
      List blist = new ArrayList();
      if (ids != null && !ids.isEmpty()) {
        for (int i = 0; i < ids.size(); i++) {
          long bid = ( (Long) ids.get(i)).longValue();
          Board b = this.getBoardByID(bid);
          if (b != null) {
            if (b.getUseStat() == useStat && b.getIsHidden() == hidden) {
              blist.add(b);
            }
          }
        }
      }
      Collections.sort(blist, new BoardsOrdersComparator());
      return blist;
    }

    return this.getBoardDAO().findBoardsInIDs(ids, useStat, hidden);
  }

  public List findBoardsInIDs(List ids) {
    List blist = new ArrayList();
    if (ids != null && !ids.isEmpty()) {
      for (int i = 0; i < ids.size(); i++) {
        long bid = ( (Long) ids.get(i)).longValue();
        Board b = this.getBoardByID(bid);
        if (b != null) {
          blist.add(b);
        }
      }
    }
    return blist;
  }

  public List findParentBoards(List ids) {
    List blist = new ArrayList();
    if (ids != null && !ids.isEmpty()) {
      for (int i = 0; i < ids.size(); i++) {
        long bid = ( (Long) ids.get(i)).longValue();
        Board b = this.getBoardByID(bid);
        if (b != null) {
          blist.add(b);
        }
      }
    }
    return blist;
  }

  public void saveBoardsPostNumCount() throws BbscsException {
    int totalNum = 0;
    int totalMainNum = 0;
    List bl = this.getBoardSingleton().getBoardIdl();
    for (int i = 0; i < bl.size(); i++) {
      Board b = this.getBoardByID( ( (Long) bl.get(i)).longValue());
      if (b.getBoardType() == 3) {
        b.setMainPostNum(this.getForumDAO().getForumNum(b.getId().longValue(), 1, 0, 0) +
                         this.getForumHistoryDAO().getForumHistoryNum(b.getId().longValue(), 1, 0, 0));
        b.setPostNum(this.getForumDAO().getForumNum(b.getId().longValue(), -1, 0, 0) +
                     this.getForumHistoryDAO().getForumHistoryNum(b.getId().longValue(), -1, 0, 0));
        try {
          b = this.getBoardDAO().saveBoard(b);
          totalNum = totalNum + b.getPostNum();
          totalMainNum = totalMainNum + b.getMainPostNum();
          this.getBoardCache().remove(b.getId()); //从Cache中清除
        }
        catch (Exception ex1) {
          logger.error(ex1);
          throw new BbscsException(ex1);
        }
      }
      List bl2 = (List)this.getBoardSingleton().getBoardsIdm().get(b.getId());
      if (bl2 != null && !bl2.isEmpty()) {
        for (int j = 0; j < bl2.size(); j++) {
          Board b2 = this.getBoardByID( ( (Long) bl2.get(j)).longValue());
          if (b2.getBoardType() == 3) {
            b2.setMainPostNum(this.getForumDAO().getForumNum(b2.getId().longValue(), 1, 0, 0) +
                              this.getForumHistoryDAO().getForumHistoryNum(b2.getId().longValue(), 1, 0, 0));
            b2.setPostNum(this.getForumDAO().getForumNum(b2.getId().longValue(), -1, 0, 0) +
                          this.getForumHistoryDAO().getForumHistoryNum(b2.getId().longValue(), -1, 0, 0));
            try {
              b2 = this.getBoardDAO().saveBoard(b2);
              totalNum = totalNum + b2.getPostNum();
              totalMainNum = totalMainNum + b2.getMainPostNum();
              this.getBoardCache().remove(b2.getId()); //从Cache中清除
            }
            catch (Exception ex1) {
              logger.error(ex1);
              throw new BbscsException(ex1);
            }
          }
        }
      }
    }
    logger.info("postMainNum:" + totalMainNum + " postNum:" + totalNum);
    this.getSysStatService().savePostNum(totalMainNum, totalNum);
    logger.info("ForumCount end");

    /*
         List l = this.getBoardDAO().findBoardsNeedCount(1, 0);
         for (int i = 0; i < l.size(); i++) {
      Board b = (Board) l.get(i);
      b.setMainPostNum(this.getForumDAO().getForumNum(b.getId().longValue(), 1, 0, 0) +
                       this.getForumHistoryDAO().getForumHistoryNum(b.getId().longValue(), 1, 0, 0));
      b.setPostNum(this.getForumDAO().getForumNum(b.getId().longValue(), -1, 0, 0) +
                   this.getForumHistoryDAO().getForumHistoryNum(b.getId().longValue(), -1, 0, 0));
      try {
        this.getBoardDAO().saveBoard(b);
        this.getBoardCache().remove(b.getId()); //从Cache中清除
      }
      catch (Exception ex) {
        logger.error(ex);
        throw new BbscsException(ex);
      }
         }*/
  }

  public List findBoardsNeedCount(int useStat, int hidden) {
    return this.getBoardDAO().findBoardsNeedCount(useStat, hidden);
  }

  public List getBoardsNeedCount(List boardlist) {
    List boardNeedCount = new ArrayList();
    for (int i = 0; i < boardlist.size(); i++) {
      Board b = (Board) boardlist.get(i);
      if (b.getBoardType() == 3 || b.getBoardType() == 4) {
        boardNeedCount.add(b);
      }
    }
    return boardNeedCount;
  }

  public void createBoardListFileInForumCover(long bid) {
    List blist = this.getBoardDAO().findBoardsByParentID(bid, 1, 0, Constant.FIND_BOARDS_BY_ORDER);
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < blist.size(); i++) {
      Board b = (Board) blist.get(i);
      sb.append("<tr>");
      sb.append("<td width=\"20%\">·");
      sb.append("<a href=\"");
      sb.append(BBSCSUtil.getActionMappingURLWithoutPrefix("forum?action=index&bid=" + b.getId().longValue()));
      sb.append("\">");
      sb.append(b.getBoardName());
      sb.append("</a>");
      sb.append("&gt;&gt;</td>");
      sb.append("<td width=\"80%\">");
      List blist1 = this.getBoardDAO().findBoardsByParentID(b.getId().longValue(), 1, 0,
          Constant.FIND_BOARDS_BY_ORDER);
      for (int j = 0; j < blist1.size(); j++) {
        Board b1 = (Board) blist1.get(j);
        sb.append("·");
        sb.append("<a href=\"");
        sb.append(BBSCSUtil.getActionMappingURLWithoutPrefix("forum?action=index&bid=" + b1.getId().longValue()));
        sb.append("\">");
        sb.append(b1.getBoardName());
        sb.append("</a> ");
      }
      sb.append("</td>");
      sb.append("</tr>");
    }
    File blistfile = new File(BBSCSUtil.getIncludePath() + "ForumCover_BoardList_" + bid + ".html");
    try {
      FileUtils.writeStringToFile(blistfile, sb.toString(), Constant.CHARSET);
    }
    catch (IOException ex) {
      logger.error(ex);
    }
  }

  public void createBoardHotListFileInForumCover(long bid) {
    List bhotlist = this.findBoardsAllTree(bid, new ArrayList(), 1, 0, Constant.FIND_BOARDS_BY_ORDER);
    List bhlist = this.getBoardsNeedCount(bhotlist);
    StringBuffer sb = new StringBuffer();
    Collections.sort(bhlist, new BoardsMainPostNumComparator());
    int len = bhlist.size();
    if (len >= 10) {
      len = 10;
    }
    for (int i = 0; i < len; i++) {
      Board b = (Board) bhlist.get(i);
      sb.append("<tr>");
      sb.append("<td width=\"70%\">");
      sb.append("<a href=\"");
      sb.append(BBSCSUtil.getActionMappingURLWithoutPrefix("forum?action=index&bid=" + b.getId().longValue()));
      sb.append("\">");
      sb.append(b.getBoardName());
      sb.append("</a>");
      sb.append("</td>");
      sb.append("<td width=\"30%\">");
      sb.append(b.getMainPostNum());
      sb.append("</td>");
      sb.append("</tr>");
    }
    File bhotlistfile = new File(BBSCSUtil.getIncludePath() + "ForumCover_BoardHotList_" + bid + ".html");
    try {
      FileUtils.writeStringToFile(bhotlistfile, sb.toString(), Constant.CHARSET);
    }
    catch (IOException ex) {
      logger.error(ex);
    }
  }

  public void createBoardFileInForumCover() {
    List l = this.getBoardDAO().findBoardsByParentID(0);
    for (int i = 0; i < l.size(); i++) {
      Board b = (Board) l.get(i);
      if (b.getBoardType() == 0) {
        this.createBoardListFileInForumCover(b.getId().longValue());
        this.createBoardHotListFileInForumCover(b.getId().longValue());
      }
    }
  }

  public void removeBoardTag(Board board, String tagID) throws BbscsException {
    BoardTag bt = null;
    Iterator it = board.getBoardTag().iterator();
    while (it.hasNext()) {
      bt = (BoardTag) it.next();
      if (bt.getId().equals(tagID)) {
        board.getBoardTag().remove(bt);
        break;
      }
    }
    try {
      board = this.getBoardDAO().saveBoard(board);
      this.getBoardCache().remove(board.getId()); //从Cache中清除
      this.getForumDAO().updateForumsTag(tagID, "0", "");
      this.getForumHistoryDAO().updateForumsTag(tagID, "0", "");
    }
    catch (Exception ex) {
      logger.error(ex);
      throw new BbscsException(ex);
    }
  }

  public BoardDAO getBoardDAO() {
    return boardDAO;
  }

  public BoardPermissionDAO getBoardPermissionDAO() {
    return boardPermissionDAO;
  }

  public UserGroupDAO getUserGroupDAO() {
    return userGroupDAO;
  }

  public Cache getBoardCache() {
    return boardCache;
  }

  public PermissionDAO getPermissionDAO() {
    return permissionDAO;
  }

  public RoleDAO getRoleDAO() {
    return roleDAO;
  }

  public ForumDAO getForumDAO() {
    return forumDAO;
  }

  public ForumHistoryDAO getForumHistoryDAO() {
    return forumHistoryDAO;
  }

  public BoardSingleton getBoardSingleton() {
    return boardSingleton;
  }

  public SysStatService getSysStatService() {
    return sysStatService;
  }

  public Cache getUserPermissionCache() {
    return userPermissionCache;
  }

  public void setBoardDAO(BoardDAO boardDAO) {
    this.boardDAO = boardDAO;
  }

  public void setBoardPermissionDAO(BoardPermissionDAO boardPermissionDAO) {
    this.boardPermissionDAO = boardPermissionDAO;
  }

  public void setUserGroupDAO(UserGroupDAO userGroupDAO) {
    this.userGroupDAO = userGroupDAO;
  }

  public void setBoardCache(Cache boardCache) {
    this.boardCache = boardCache;
  }

  public void setPermissionDAO(PermissionDAO permissionDAO) {
    this.permissionDAO = permissionDAO;
  }

  public void setRoleDAO(RoleDAO roleDAO) {
    this.roleDAO = roleDAO;
  }

  public void setForumDAO(ForumDAO forumDAO) {
    this.forumDAO = forumDAO;
  }

  public void setForumHistoryDAO(ForumHistoryDAO forumHistoryDAO) {
    this.forumHistoryDAO = forumHistoryDAO;
  }

  public void setBoardSingleton(BoardSingleton boardSingleton) {
    this.boardSingleton = boardSingleton;
  }

  public void setSysStatService(SysStatService sysStatService) {
    this.sysStatService = sysStatService;
  }

  public void setUserPermissionCache(Cache userPermissionCache) {
    this.userPermissionCache = userPermissionCache;
  }
}

⌨️ 快捷键说明

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