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

📄 infodao.java

📁 一个oa系统
💻 JAVA
字号:
package com.oa.companyculture.db;

import java.util.List;

import org.hibernate.HibernateException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class InfoDao extends HibernateDaoSupport {

	/**
	 * 根据论坛id查询贴子
	 * 
	 * @param id
	 * @return list
	 */
	public List findLastTie() {
		 List list = null;
			try {  
				list = (List) this.getHibernateTemplate().find("from Info group by submodulelistid order by id desc");
			} catch (HibernateException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		return list;
	}
	public List findById(int id){
		 List list = null;
			try {  
			list = (List)this.getHibernateTemplate().find("from Info where submodulelistid=?",id);
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}
	/**
	 * 发布新的帖子
	 * 
	 * @param info
	 */
	public void addInfo(Info info) {
		try {  
				this.getHibernateTemplate().saveOrUpdate(info);
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * 根据帖子的Id查询帖子内容
	 * 
	 * @param id
	 * @return list
	 */
	public List findByTieId(int id) {
		List list = null;
		try {
			list = (List) this.getHibernateTemplate().find("from Info where id=?", id);
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

	/**
	 * 根据论坛的id统计本模块的帖子总数
	 * 
	 * @param id
	 * @return
	 */
	public int findCountByTId(int id) {
		List list = null;
		int count = 0;
		try {
			list = (List) this.getHibernateTemplate().find("select count(*) from Info where submodulelistid=?", id);		
			String str = list.get(0).toString();
			count = Integer.parseInt(str);
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return count;
	}

	/**
	 * 每当一个帖子被查看后,增加此贴的点击数
	 * 
	 * @param id
	 */
	public void addBrowerNum(int id) {
		List list = null;
		try {
			list = (List) this.getHibernateTemplate().find("from Info where id=?", id);
			if (list != null && list.size() != 0) {
				Info info = (Info) list.get(0);
				int browernum = info.getBrowernum();
				browernum++;
				info.setBrowernum(browernum);
				this.getHibernateTemplate().update(info);
			}
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * 每当一个帖子被回复后,增加此帖的回复数
	 * 
	 * @param id
	 */
	public void addRevertNum(int id) {
		List list = null;
		try {
			list = (List) this.getHibernateTemplate().find("from Info where id=?", id);
			if (list != null && list.size() != 0) {
				Info info = (Info) list.get(0);
				int revertnum = info.getRevertnum();
				revertnum++;
				info.setRevertnum(revertnum);
				this.getHibernateTemplate().update(info);
			}
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * 当一个帖子的回复被删除掉,其回复数减一
	 * 
	 * @param id
	 */
	public void deleteRevertNum(int id) {
		List list = null;
		try {
			list = (List) this.getHibernateTemplate().find("from Info where id=?", id);
			if (list != null && list.size() != 0) {
				Info info = (Info) list.get(0);
				int revertnum = info.getRevertnum();
				revertnum--;
				info.setRevertnum(revertnum);
				this.getHibernateTemplate().update(info);
			}
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * 根据论坛版块的id及当天的日期统计总共有多少新贴
	 * 
	 * @param id
	 * @param date
	 * @return counts
	 */
	public int findByIdAndDate(int id, String date) {
		int counts = 0;
		List list = null;
		try {
			list = (List) this.getHibernateTemplate().find("select count(*) from Info where submodulelistid=" + id + " AND infodate LIKE '" + "%" + date + "%'");
			String str = list.get(0).toString();
			counts = Integer.parseInt(str);
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return counts;
	}
	
	public List findNums(String date){
		List list = null;
		try {
			list = (List)this.getHibernateTemplate().find("select count(*),submodulelistid from Info where infodate LIKE '" + "%" + date + "%' group by submodulelistid");
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}
	/**
	 * 根据论坛id查询次论坛最后发表的帖子
	 * 
	 * @param id
	 * @param date
	 * @return
	 */
	public List findLastByIdAndDate(int id, String date) {
		List list = null;
		try {
			list = (List) this.getHibernateTemplate().find("from Info where id=(select max(id) from Info where submodulelistid=" + id + ")");
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}

	/**
	 * 根据时间统计今天共发多少新贴
	 * 
	 * @param date
	 * @return
	 */
	public int findByDate(String date) {
		int counts = 0;
		List list = null;
		try {
			list = (List) this.getHibernateTemplate().find("select count(*) from Info where infodate like ?","%" + date + "%");
			String str = list.get(0).toString();
			counts = Integer.parseInt(str);
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return counts;
	}

	/**
	 * 统计总共有多少帖子
	 * 
	 * @return
	 */
	public int findAllCounts() {
		int counts = 0;
		List list = null;
		try {
			list = (List) this.getHibernateTemplate().find("select count(*) from Info");
			String str = list.get(0).toString();
			counts = Integer.parseInt(str);
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return counts;
	}

	/**
	 * 根据帖子ID查询发布人
	 * 
	 * @param id
	 * @return
	 */
	public String findIssueNameByTieId(int id) {
		List list = null;
		try {
			list = (List) this.getHibernateTemplate().find("from Info where id=?", id);
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
			if (list != null && list.size() != 0) {
				Info info = (Info) list.get(0);
				String issueman = info.getIssuename();
				return issueman;
			} else {
				return null;
			}
	}

	/**
	 * 根据帖子的id删除帖子
	 * 
	 * @param id
	 */
	public void deleteById(int id) {
		List list = null;
		try {
			list = (List) this.getHibernateTemplate().find("from Info where id=?", id);
			if (list != null && list.size() != 0) {
				Info info = (Info) list.get(0);
				this.getHibernateTemplate().delete(info);
			}
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * 修改帖子信息
	 * 
	 * @param info
	 */
	public void updateInfo(Info info) {
		try {
			this.getHibernateTemplate().update(info);
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * 查询最后六条帖子记录
	 * 
	 * @return
	 */
	public List findTopSix() {
		List list = null;
		try {
		    list = (List) this.getHibernateTemplate().find("from Info order by id");
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if (list != null && list.size() != 0) {
			return list;
		} else {
			return null;
		}
	}
}

⌨️ 快捷键说明

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