📄 boardservicecacheimp.java
字号:
package com.laoer.bbscs.service.imp;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.*;
import com.laoer.bbscs.bean.*;
import com.laoer.bbscs.exception.BbscsException;
import com.laoer.bbscs.service.BoardService;
import com.laoer.bbscs.service.Cache;
import com.laoer.bbscs.service.SysStatService;
import com.laoer.bbscs.dao.*;
import com.laoer.bbscs.comm.*;
public class BoardServiceCacheImp implements BoardService {
/**
* Logger for this class
*/
private static final Log logger = LogFactory.getLog(BoardServiceCacheImp.class);
private BoardDAO boardDAO;
private Cache sysListObjCache;
//private Cache boardCache;
private UserGroupDAO userGroupDAO;
private BoardPermissionDAO boardPermissionDAO;
private PermissionDAO permissionDAO;
private Cache userPermissionCache;
private RoleDAO roleDAO;
private ForumDAO forumDAO;
private ForumDAO forumHistoryDAO;
private SysStatService sysStatService;
public BoardDAO getBoardDAO() {
return boardDAO;
}
public void setBoardDAO(BoardDAO boardDAO) {
this.boardDAO = boardDAO;
}
//public Cache getBoardCache() {
// return boardCache;
//}
//public void setBoardCache(Cache boardCache) {
// this.boardCache = boardCache;
//}
public Cache getSysListObjCache() {
return sysListObjCache;
}
public void setSysListObjCache(Cache sysListObjCache) {
this.sysListObjCache = sysListObjCache;
}
public UserGroupDAO getUserGroupDAO() {
return userGroupDAO;
}
public void setUserGroupDAO(UserGroupDAO userGroupDAO) {
this.userGroupDAO = userGroupDAO;
}
public BoardPermissionDAO getBoardPermissionDAO() {
return boardPermissionDAO;
}
public void setBoardPermissionDAO(BoardPermissionDAO boardPermissionDAO) {
this.boardPermissionDAO = boardPermissionDAO;
}
public PermissionDAO getPermissionDAO() {
return permissionDAO;
}
public void setPermissionDAO(PermissionDAO permissionDAO) {
this.permissionDAO = permissionDAO;
}
public Cache getUserPermissionCache() {
return userPermissionCache;
}
public void setUserPermissionCache(Cache userPermissionCache) {
this.userPermissionCache = userPermissionCache;
}
public RoleDAO getRoleDAO() {
return roleDAO;
}
public void setRoleDAO(RoleDAO roleDAO) {
this.roleDAO = roleDAO;
}
public ForumDAO getForumDAO() {
return forumDAO;
}
public void setForumDAO(ForumDAO forumDAO) {
this.forumDAO = forumDAO;
}
public ForumDAO getForumHistoryDAO() {
return forumHistoryDAO;
}
public void setForumHistoryDAO(ForumDAO forumHistoryDAO) {
this.forumHistoryDAO = forumHistoryDAO;
}
public SysStatService getSysStatService() {
return sysStatService;
}
public void setSysStatService(SysStatService sysStatService) {
this.sysStatService = sysStatService;
}
@SuppressWarnings("unchecked")
public Board createBoard(Board board) throws BbscsException {
try {
Board pboard = this.getBoardDAO().getBoardByID(board.getParentID()); // 取得父级版区
if (pboard != null) { // 父级版区存在
List pboards = new ArrayList();
pboards.addAll(pboard.getParentIDs());
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, -1,
Constant.FIND_BOARDS_BY_ORDER); // 取得父级半区的所有子版区列表
List cids = this.getBoardIDs(pcboards);
pboard.setChildIDs(cids); // 设置父级版区的所有子版区列表字段
this.getBoardDAO().saveBoard(pboard);
//bbscs8.5//this.getBoardCache().remove(pboard.getId());
}
this.clearBoradListSysListCache(board.getParentID());
// 为版区增加用户组版区权限
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());
switch (ug.getId().intValue()) {
case 1:
bp.setPermissions(Constant.BOARD_PERMISSION_GROUP_LIST_1);
break;
case 2:
bp.setPermissions(Constant.BOARD_PERMISSION_GROUP_LIST_2);
break;
case 3:
bp.setPermissions(Constant.BOARD_PERMISSION_GROUP_LIST_3);
break;
case 4:
bp.setPermissions(Constant.BOARD_PERMISSION_GROUP_LIST_4);
break;
case 5:
bp.setPermissions(Constant.BOARD_PERMISSION_GROUP_LIST_5);
break;
case 6:
bp.setPermissions(Constant.BOARD_PERMISSION_GROUP_LIST_6);
break;
default:
bp.setPermissions(Constant.BOARD_PERMISSION_GROUP_LIST_1);
}
this.getBoardPermissionDAO().saveBoardPermission(bp);
}
return board;
} catch (Exception e) {
logger.error(e);
throw new BbscsException(e);
}
}
/*
* public List findBoardIdsByParentID(long pid, int useStat, int hidden, int
* orderType) { return null; }
*/
@SuppressWarnings("unchecked")
public List findBoardsAllTree(long pid, List topList, int useStat, int hidden, int orderType) {
List l = this.getBoardDAO().findBoardsByParentID(pid, useStat, hidden, orderType);
for (int i = 0; i < l.size(); i++) {
Board b = (Board) l.get(i);
topList.add(b);
this.findBoardsAllTree(b.getId().longValue(), topList, useStat, hidden, orderType);
}
return topList;
}
public List findBoardsByParentID(long pid, int useStat, int hidden, int orderType) {
List l = (List) this.getSysListObjCache().get(
"[B][" + pid + "][" + useStat + "][" + hidden + "][" + orderType + "]");
if (l == null) {
// l = this.getBoardDAO().findBoardsByParentID(pid, useStat, hidden,
// orderType);
l = this.getBoardDAO().findBoardIdsByParentID(pid, useStat, hidden, orderType);
this.getSysListObjCache().add("[B][" + pid + "][" + useStat + "][" + hidden + "][" + orderType + "]", l);
}
List<Board> bl = new ArrayList<Board>();
if (l != null && !l.isEmpty()) {
for (int i = 0; i < l.size(); i++) {
// Board b = this.getBoardByID(((Long)l.get(i)).longValue());
Board b = this.getBoardByID((Long) l.get(i));
if (b != null) {
bl.add(b);
}
}
}
return bl;
}
public List findBoardsInIDs(List ids) {
List<Board> l = new ArrayList<Board>();
if (ids != null && !ids.isEmpty()) {
for (int i = 0; i < ids.size(); i++) {
// Board b = this.getBoardByID(((Long) ids.get(i)).longValue());
Board b = this.getBoardByID((Long) ids.get(i));
if (b != null) {
l.add(b);
}
}
}
return l;
}
public Board getBoardByID(long id) {
/*//bbscs8.5//
Board board = (Board) this.getBoardCache().get(new Long(id));
if (board == null) {
board = this.getBoardDAO().getBoardByID(id);
if (board != null) {
// board.getBoardMaster().size();
this.getBoardCache().add(board.getId(), board);
}
}
return board;
//bbscs8.5//*/
return this.getBoardDAO().getBoardByID(id);
}
public Map[] getBoardMasterPermission(int roleID) {
if (Constant.USE_PERMISSION_CACHE) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -