topicoperimp.java

来自「jaguey,网上的一个朋友给我的」· Java 代码 · 共 243 行

JAVA
243
字号
package net.javapassion.jaguey.service.imp;

import java.util.List;
import java.util.Date;
import java.util.Iterator;
import net.javapassion.jaguey.core.Log;
import net.javapassion.jaguey.core.Config;
import net.javapassion.jaguey.util.DateUtil;
import net.javapassion.jaguey.domain.Topic;
import net.javapassion.jaguey.dao.TopicDao;
import net.javapassion.jaguey.service.TopicOper;

//版本: JagueyBBS 1.1
//功能: 论坛主题帖子业务逻辑实现
//作者: 赵程佳
//时间: 2006-02-11 16:37:37

public class TopicOperImp implements TopicOper {
	private TopicDao topicDao;
	
	//保存主题帖子
	public String saveTopic(Topic topic) {
		try {
			this.topicDao.saveTopic(topic);
			return "success";
		} catch (Exception ex) {
			Log.error(ex.getMessage(), ex);
			return "failed";
		}
	}
	
	//删除主题帖子
	public String deleteTopic(String topicId) {
		try {
			Topic topic = this.topicDao.getTopicById(topicId);
			if (topic != null) {
				this.topicDao.deleteTopic(topic);
				return "success";
			} else {
				return "can't find data";
			}
		} catch (Exception ex) {
			Log.error(ex.getMessage(), ex);
			return "failed";
		}
	}
	
	//获取特定版面某页的主题帖子
	public List getTopicByBoard(String boardId, int pageNumber) {
		try {
			return this.topicDao.getTopic(boardId, Integer.parseInt(Config.getInstance().getTopicrowspage().toString()), pageNumber);
		} catch (Exception ex) {
			Log.error(ex.getMessage(), ex);
			return null;
		}
	}
	
	//获取特定版面下的主题帖子的分页总页数
	public int getMaxPage(String boardId) {
		int rowsPage = Integer.parseInt(Config.getInstance().getTopicrowspage().toString());
		List maxRow = this.topicDao.getTopByBoard(boardId);
		int maxRowCount = maxRow.size();
		if (maxRowCount % rowsPage == 0) {
			return maxRowCount / rowsPage;
		} else {
			return maxRowCount / rowsPage + 1;
		}
	}
	
	//通过编号获取主题帖子
	public Topic getTopicById(String topicId) {
		try {
			Topic topic = this.topicDao.getTopicById(topicId);
			if (topic != null) {
				return topic;
			} else {
				Log.warn("Use topicId can't find Topic!");
				return null;
			}
		} catch (Exception ex) {
			Log.error(ex.getMessage(), ex);
			return null;
		}
	}
	
	//获取主题帖子总数量
	public int getCountTopic() {
		try {
			return this.topicDao.getTopicCount();
		} catch (Exception ex) {
			Log.error(ex.getMessage(), ex);
			return 0;
		}
	}
	
	//获取全部精华或非精华主题帖子
	public List getGoodTopics(Integer goodFlag) {
		try {
			return this.topicDao.getTopicByGood(goodFlag);
		} catch (Exception ex) {
			Log.error(ex.getMessage(), ex);
			return null;
		}
	}
	
	//通过用户获取精华主题帖子
	public List getGoodByUser(String userName) {
		try {
			return this.topicDao.getGoodByUser(userName);
		} catch (Exception ex) {
			Log.error(ex.getMessage(), ex);
			return null;
		}
	}
	
	//获取精华主题帖子总数量
	public int getCountGood() {
		try {
			List list = this.topicDao.getTopicByGood(Integer.valueOf(1));
			return list.size();
		} catch (Exception ex) {
			Log.error(ex.getMessage(), ex);
			return 0;
		}
	}
	
	//获取特定日期发表的主题帖子
	public List getTopicByDate(Date date) {
		try {
			return this.topicDao.getTopicByLikeApply(DateUtil.formatDate0(date));
		} catch (Exception ex) {
			Log.error(ex.getMessage(), ex);
			return null;
		}
	}
	
	//通过用户获取主题帖子
	public List getTopicByUser(String userName) {
		try {
			return this.topicDao.getTopicByUser(userName);
		} catch (Exception ex) {
			Log.error(ex.getMessage(), ex);
			return null;
		}
	}
	
	//获取特定版面的精华或非精华主题帖子
	public List getGoodByBoard(String boardId, Integer goodFlag) {
		try {
			return this.topicDao.getTopicByBoardGood(boardId, goodFlag);
		} catch (Exception ex) {
			Log.error(ex.getMessage(), ex);
			return null;
		}
	}
	
	//获取特定版面的置顶主题帖子
	public List getTopByBoard(String boardId) {
		try {
			return this.topicDao.getTopByBoard(boardId);
		} catch (Exception ex) {
			Log.error(ex.getMessage(), ex);
			return null;
		}
	}
	
	//获取特定版面的主题帖子数量
	public int getCountTopicByBoard(String boardId) {
		try {
			List list = this.topicDao.getTopicByBoard(boardId);
			return list.size();
		} catch (Exception ex) {
			Log.error(ex.getMessage(), ex);
			return 0;
		}
	}
	
	//获取特定版面的置顶主题帖子数量
	public int getCountTopByBoard(String boardId) {
		try {
			List list = this.topicDao.getTopByBoard(boardId);
			return list.size();
		} catch (Exception ex) {
			Log.error(ex.getMessage(), ex);
			return 0;
		}
	}
	
	//获取特定日期发表的主题帖子数量
	public int getCountTopicByDate() {
		try {
			List list = this.topicDao.getTopicByApply(new Date());
			return list.size();
		} catch (Exception ex) {
			Log.error(ex.getMessage(), ex);
			return 0;
		}
	}
	
	//创建主题帖子编号
	public String makeTopicId() {
		String topicId = "";
		try {
			List list = this.topicDao.getTopicByLikeId(DateUtil.formatDate7(new Date()));
			if (list.size() == 0) {
				return DateUtil.formatDate7(new Date()) + "000001";
			} else {
				Iterator it = list.iterator();
				int i = 1;
				while (it.hasNext()) {
					if (i == list.size()) {
						Topic topic = (Topic) it.next();
						topicId = String.valueOf(Integer.parseInt(topic.getTopicId().substring(6)) + 1);
						if (Integer.parseInt(topicId) != 1000000) {
							switch (topicId.length()) {
								case 1 : topicId = "00000" + topicId; break;
								case 2 : topicId = "0000" + topicId; break;
								case 3 : topicId = "000" + topicId; break;
								case 4 : topicId = "00" + topicId; break;
								case 5 : topicId = "0" + topicId; break;
							}
						} else {
							Log.info("The topicId have already exceed to allow max quantity!");
							topicId = "000000";
						}
					} else {
						i++;
						continue;
					}
				}
				return DateUtil.formatDate7(new Date()) + topicId;
			}
		} catch (Exception ex) {
			Log.error(ex.getMessage(), ex);
			return "";
		}
	}
	
	public void setTopicDao(TopicDao topicDao) {
		this.topicDao = topicDao;
	}
}

⌨️ 快捷键说明

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