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

📄 topicserviceimpl.java

📁 新技术论坛系统 v1.0 前后台管理的初始用户名 : admin 密码 123456
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	/**
	 * 根据主题编号取得主题信息(该主题包含内容)
	 * @param topicId
	 * @return
	 * @throws ServiceException
	 */
	public Topic getEditedTopic(int topicId) throws ServiceException{
		try{
			Topic topic = topicDAO.findTopic(topicId);
			List list = postDAO.findPosts(topicId,1);
			if(list!=null && list.size()>0){
				topic.setFirstPost(((Post)(list.toArray()[0])));
			}
			else{
				throw new ServiceException(null);
			}
			return topic;
		}
		catch(DAOException de){
			throw new ServiceException("查找主题topicId ['"+topicId+"'] 发生错误.");
		}
		catch(ServiceException se){
			throw new ServiceException("查找待修改的主题发生错误...");
		}
	}	
	
	/**
	 * 查看论坛贴子
	 * <ol>
	 * <li>更新贴子浏览次数</li>
	 * <li>列表主题对应的全部贴子</li>
	 * </ol>
	 * 
	 * @param topicId 贴子编号
	 * @param pagination 分页对象
	 * @return QueryResult 论坛贴子列表
	 * @throws ServiceException
	 */
	public QueryResult viewTopic(int topicId,Pagination pagination) throws ServiceException{		
		try {
			//更新贴子浏览次数
			topicDAO.updateTopicViews(topicId);
			QueryResult queryResult = postDAO.findPosts(topicId,pagination);
			List posts = queryResult.getItems();
			Object[] postArray = posts.toArray();
			Post post = null;
			for (int i = 0; i < postArray.length; i++) {
				post = (Post)postArray[i];
				// GUEST用户就不处理
				if(post.getUserId() != 0){
					post.setUser(userDAO.findUser(new Long(post.getUserId())));
				}
				else{
					// 设置Guest用户信息
					post.setUser(Symbols.getGuest());
				}
			}
			return queryResult;
		}
		catch(DAOException daoException){
			throw new ServiceException(daoException.getMessage());
		}	
	}	
	
	/**
	 * 根据论坛编号删除对应编号的帖子
	 * 
	 * @param forumId 论坛编号
	 */
	public void deleteTopicByForum(int forumId) throws ServiceException{
		try {
			topicDAO.deleteTopicByForum(forumId);
		}
		catch(DAOException daoException){
			throw new ServiceException(daoException.getMessage());
		}
	}
	
	/**
	 * 根据贴子状态列表贴子
	 * 
	 * @param forumId 论坛编号
	 * @param categoryId 类别编号 (-1,表示不设定CategoryId)
	 * @param orderMap 排序数组
	 * @param status 贴子状态 (1 精华, 2 锁定)
	 * @param pagination 分页对象
	 * @return QueryResult 帖子集合
	 * @throws ServiceException 
	 */
	public QueryResult getTopics(int forumId ,int categoryId, Map orderMap, int status, Pagination pagination) throws ServiceException {
		try {
			return topicDAO.findTopics(forumId,categoryId,orderMap,status,pagination);
		}
		catch(DAOException daoException){
			throw new ServiceException(daoException.getMessage());
		}
	} 
	
	/**
	 * 帖子检索 
	 * @param forumId 论坛编号
	 * @param type 检索类型
	 * @param keywordValue 关键子的值 
	 * @param time 时间段
	 * @param way 时间方向
	 * @param orderMap 排序信息
	 * @param pagination 分页
	 * @return
	 * @throws ServiceException
	 */
	public QueryResult searchTopics(int forumId, String type, String keyword, int time, String way, Map orderMap, Pagination pagination) throws ServiceException{
		try{
			String wayTime = null;
			if(time == 0){
				wayTime = "";
			}
			else{
				wayTime = DateUtil.getBeforeDate(DateUtil.getDate(),time);
			}
			return topicDAO.searchTopics(forumId,type,keyword,wayTime,way,orderMap,pagination);
		}
		catch(DAOException daoException){
			throw new ServiceException(daoException.getMessage());
		}
	}
	
	/**
	 * 取得制定论坛的贴子
	 * 
	 * @param forumId 论坛编号
	 * @param orderMap 排序数组
	 * @param pagination 分页对象
	 * @return QueryResult 论坛贴子列表
	 * @throws ServiceException
	 */
	public QueryResult getTopics(int forumId, Map orderMap, Pagination pagination) throws ServiceException{
		try{
			return topicDAO.findTopics(forumId,orderMap,pagination);
			/*List topics = queryResult.getItems();
			Object[] topicArray = topics.toArray();
			Topic topic = null;
			for (int i = 0; i < topicArray.length; i++) {
				topic = (Topic)topicArray[i];
				topic.setLastPost(postDAO.findPost(topic.getLastPostId()));
			}
			return queryResult;*/
		}
		catch(DAOException daoException){
			throw new ServiceException(daoException.getMessage());
		}
	}		

	/**
	 * 更新主题是否被删除状态
	 *
	 * @param topicId 主题编号
	 * @param isDelete 是否被删除
	 * isDelete 0 将主题丢弃到垃圾箱,1 主题状态正常
	 * @throws ServiceException
	 */
	public void updateTopicIsDelete(int topicId,int isDelete) throws ServiceException{
		try{
			topicDAO.updateTopicIsDelete(topicId,isDelete);
		}
		catch(DAOException daoException){
			throw new ServiceException(daoException.getMessage());
		}		
	}
	
	/**
	 * 更新主题状态
	 *
	 * @param topicId 主题编号
	 * @param status 是否被置顶
	 * status 1 精华贴,2 被锁定的贴子
	 * @throws ServiceException
	 */
	public void updateTopicStatus(int topicId,int status) throws ServiceException{
		try{
			if(status == 1){
				// 设置精华帖增加金钱数
				userDAO.updateMoney(topicDAO.findTopic(topicId).getUsername(),SystemConfig.getInstance().getIntPropertyValue(Symbols.MONEY,Symbols.MONEY_ELITE_TOPIC));				
			}
			topicDAO.updateTopicStatus(topicId,status);
		}
		catch(DAOException daoException){
			throw new ServiceException(daoException.getMessage());
		}			
	}	
	
	/**
	 * 更新主题是否被置顶
	 *
	 * @param topicId 主题编号
	 * @param isTop 是否被置顶
	 * isTop 1 置顶,0 主题状态正常
	 * @throws DAOException
	 */
	public void updateTopicIsTop(int topicId,int isTop) throws ServiceException{
		try{
			topicDAO.updateTopicIsTop(topicId,isTop);
		}
		catch(DAOException daoException){
			throw new ServiceException(daoException.getMessage());
		}		
	}

	/**
	 * 取得主题总数
	 * @return
	 * @throws ServiceException
	 */
	public int countTopic() throws ServiceException {
		try{
			return topicDAO.countTopic();
		}
		catch(DAOException daoException){
			throw new ServiceException(daoException.getMessage());
		}	
	}
	
	/**
	 * 移动主题
	 *
	 * @param ids 主题列表
	 * @param oldForumId 主题原来所在的论坛
	 * @param newForumId 主题所在新的论坛
	 * @throws DAOException
	 */
	public void moveTopic(int[] ids,int oldForumId,int newForumId) throws ServiceException{
		try{
			for (int i = 0; i < ids.length; i++) {
				// 主题
				topicDAO.moveTopic(ids[i],newForumId);
				// 帖子
				postDAO.movePost(ids[i],newForumId);
			}
		}
		catch(DAOException daoException){
			throw new ServiceException(daoException.getMessage());
		}	
	}	
	
	/**
	 * 取得最新评论的主题
	 * @param forumId 论坛编号
	 * @param dataNum 结果数
	 * @return List 主题列表
	 * @throws ServiceException
	 */
	public Topic getLastPostTopic(int forumId,int dataNum) throws ServiceException{
		try{
			List list = topicDAO.findTopic(forumId,dataNum);
			if(list!=null&&list.size()>0){
				return (Topic)list.toArray()[0];
			}
			else{
				return null;
			}
		}
		catch(DAOException daoException){
			throw new ServiceException(daoException.getMessage());
		}	
	}	

	/**
	 * 取得最新发表的帖子
	 * @param forumId 论坛编号
	 * @param num 信息数
	 * @return 主题数
	 * @throws ServiceException
	 */
	public List getNewlyTopics(int forumId,int num) throws ServiceException{
		try{
			return topicDAO.findNewlyTopics(forumId,num);
		}
		catch(DAOException daoException){
			throw new ServiceException(daoException.getMessage());
		}	
	}
	
}

⌨️ 快捷键说明

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