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

📄 meetdao.java

📁 基于J2EE的办公自动化系统。实现流程定义流程办理等。运用了hibernate+struts+spring框架综合运用的系统。
💻 JAVA
字号:
package com.oa.module.meet.meetdao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.sql.DataSource;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.hibernate3.HibernateTemplate;

import com.oa.module.meet.hibernate.Tmeet;
import com.oa.module.meet.hibernate.Tmeetinfo;
import com.oa.module.pub.ectomere.XPage;

public class MeetDao implements Interfer {
	private SessionFactory meet;

	private DriverManagerDataSource datasource;

	private DataSource ds = null;

	public SessionFactory getMeet() {
		return meet;
	}

	public void setMeet(SessionFactory meet) {
		this.meet = meet;
	}

	public DriverManagerDataSource getDatasource() {
		return datasource;
	}

	public void setDatasource(DriverManagerDataSource datasource) {
		this.datasource = datasource;
	}

	public DataSource getDs() {
		return ds;
	}

	public void setDs(DataSource ds) {
		this.ds = ds;
	}

	public XPage getItemlist(int currentPage, int count, Tmeet info) {
		String hql = "select a from Tmeet a where 1=1";
		String path = "meet.do?task=query&";
		XPage page = new XPage();
		// 开始设置xpage
		page.setCurrentPage(currentPage);
		page.setCount(count);

		// 动态的构建hql语句和xpage的path
		if (info != null) {
			if (info.getMtitle() != null && !info.getMtitle().trim().equals("")) {
				hql += " and a.mtitle like :mtitle";
				path += "mtitle=" + info.getMtitle() + "&";
			}
			if (info.getMid() != 0 && info.getMid() > 0) {
				hql += " and a.mid= :mid";
				path += " mid=" + info.getMid() + "&";
			}
			if (info.getMstarttime() != null
					&& !info.getMstarttime().trim().equals("")
					&& info.getMendtime() != null
					&& info.getMendtime().trim().equals("")) {
				hql += "and a.mstarttime=:mstarttime and a.mendtime=:mendtime";
				path += "mstarttime=" + info.getMstarttime() + "and"
						+ "mendtime=" + info.getMendtime() + "&";
			}
			if (info.getMstatus() != -1 && info.getMstatus() > -1) {
				hql += " and a.mstatus= :mstatus";
				path += " mstatus=" + info.getMstatus() + "&";
			}
			if (info.getRmid() != 0 && info.getRmid() > 0) {
				hql += " and a.rmid= :rmid";
				path += " rmid=" + info.getRmid() + "&";
			}
			if (info.getUno() != null && !info.getUno().trim().equals("")) {
				hql += " and a.munos like :munos where mstatus!='2'";
				path += "uno=" + info.getUno() + "&";
			}
		}
		// 设置分页路径
		page.setPath(path);

		Session session = null;
		Query query = null;
		List list = null;

		try {
			session = this.meet.openSession();
			query = session.createQuery(hql);

			// 设置查询参数
			if (info != null) {
				if (info.getMtitle() != null
						&& !info.getMtitle().trim().equals("")) {
					query.setParameter("mtitle", "%" + info.getMtitle() + "%");
				}
				if (info.getMid() != 0 && info.getMid() > 0) {
					query.setParameter("mid", new Long(info.getMid()));
				}
				if (info.getMstarttime() != null
						&& !info.getMstarttime().trim().equals("")
						&& info.getMendtime() != null
						&& info.getMendtime().trim().equals("")) {
					query.setParameter("mstarttime", info.getMstarttime());
					query.setParameter("mendtime", info.getMendtime());
				}
				if (info.getMstatus() != -1 && info.getMstatus() > -1) {
					query.setParameter("mstatus", new Long(info.getMstatus()));
				}
				if (info.getRmid() != 0 && info.getRmid() > 0) {
					query.setParameter("rmid", new Long(info.getRmid()));
				}
				if (info.getUno() != null && !info.getUno().trim().equals("")) {
					query.setParameter("munos",  "%" + info.getUno() + "%");
				}

			}
			// 获取总记录数
			int allcount = query.list().size();
			page.setAllCount(allcount);
			// 得到分页显示数据
			query.setFirstResult((currentPage - 1) * count);
			query.setMaxResults(count);
			list = query.list();
			page.setList(list);
			session.flush();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (session != null) {
				session.close();
			}
		}
		return page;
	}

	public boolean great(Tmeet tmeet) {
		HibernateTemplate ht = null;
		try {
			ht = new HibernateTemplate(this.meet);
			Tmeetinfo info = new Tmeetinfo();
			info.setRmid(tmeet.getRmid());
			info.setMistarttime(tmeet.getMstarttime());
			info.setMiendtime(tmeet.getMendtime());
			info.setMiunos(tmeet.getMunos());
			info.setMiinfo(tmeet.getMtitle());
			info.setMiaffixname(tmeet.getMaffixname());
			info.setMiaffixpath(tmeet.getMaffixpath());
			info.setMiisdel("0");
			if (tmeet.getMaffixname() != null) {
				info.setMaffix(1);
			} else {
				info.setMaffix(0);
			}
			info.setMeet(tmeet);
			tmeet.setInfo(info);
			ht.save(tmeet);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	public Tmeet getItemById(long mid) {
		Tmeet meet = null;
		HibernateTemplate ht = null;
		try {
			ht = new HibernateTemplate(this.meet);
			meet = (Tmeet) ht.get(Tmeet.class, new Long(mid));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return meet;
	}

	public List getuserlist(long mid) {
		List list = null;
		JdbcTemplate template = null;
		String sql = null;
		try {
			template = new JdbcTemplate(this.ds);
			sql = "select uno,uname from tuser where uno=" + mid;
			list = template.queryForList(sql);
		} catch (Exception e) {
			list = null;
			e.printStackTrace();
		}
		return list;
	}

	public List userlist() {
		List list = null;
		JdbcTemplate template = null;
		String sql = null;
		try {
			template = new JdbcTemplate(this.ds);
			sql = "select uno,uname from tuser where uislocked='0'";
			list = template.queryForList(sql);
		} catch (Exception e) {
			list = null;
			e.printStackTrace();
		}
		return list;
	}

	public List addrlist() {
		List list = null;
		JdbcTemplate tem = null;
		try {
			tem = new JdbcTemplate(this.ds);
			String sql = "select rmid,rname from tmeetroom";
			list = tem.queryForList(sql);
		} catch (Exception e) {
			list = null;
			e.printStackTrace();
		}
		return list;
	}

	public List roomlist(String tbegin, String tend, String rid) {
		List list = null;
		List uselist = null;
		JdbcTemplate template = null;
		String sql1 = null;
		String sql2 = null;
		try {
			template = new JdbcTemplate(this.ds);
			sql1 = "select a.rmid,a.rname from tmeetroom a where a.rstate not in (select b.rmid from tmeet b where b.mstatus>'0')";
			uselist = template.queryForList(sql1);// 查找可以使用的会议室
			System.out.println(uselist.size());
			sql2 = "select a.*,b.rname from tmeet a,tmeetroom b where a.mstatus>'2' and a.rmid=b.rmid";
			list = template.queryForList(sql2);
			System.out.println(list.size());
			for (int i = 0; i < list.size(); i++) {
				Map map = (Map) list.get(i);
				String begin = map.get("mstarttime").toString();
				String end = map.get("mendtime").toString();
				if (tbegin.compareTo(end) > 0 || tend.compareTo(begin) < 0) {
					Map tempmap = new HashMap();
					tempmap.put("rmid", map.get("rmid"));
					tempmap.put("rname", map.get("rname"));
					uselist.add(tempmap);
					System.out.println(uselist);
				}
			}
			if (rid != null && rid.equals("")) { //
				// 根据id查找会议室
				List list2 = null;
				String sql = null;
				try {
					sql = "select t.rmid,t.rname from tmeetroom t where t.rmid="
							+ rid;
					list2 = template.queryForList(sql);
				} catch (Exception e) {
					list = null;
					e.printStackTrace();
				}
				Map tmap = (Map) list2.get(0);
				uselist.add(tmap);
			}
		} catch (Exception e) {

			uselist = null;
			e.printStackTrace();
		}
		return uselist;
	}

	public List listbyid(long mid) {
		List list = null;
		JdbcTemplate template = null;
		String sql = null;
		try {
			template = new JdbcTemplate(this.ds);
			sql = "select t.*,tm.rname from tmeet t,tmeetroom tm "
					+ "where t.rmid=tm.rmid and t.mid=" + mid;
			list = template.queryForList(sql);
		} catch (Exception e) {
			list = null;
			e.printStackTrace();
		}
		return list;
	}

	public Map addmeet(String user) {
		Map map = null;
		List list = null;
		JdbcTemplate template = null;
		String sql = null;
		try {
			template = new JdbcTemplate(this.ds);
			sql = "select tu.uno,tu.uname from tuser tu where tu.uno=" + user;
			list = template.queryForList(sql);
			if (list.size() > 0) {
				map = (Map) list.get(0);
			} else {
				map = null;
			}
		} catch (Exception e) {
			list = null;
			e.printStackTrace();
		}
		return map;
	}

	public List listbymid(String mid) {
		List list = null;
		JdbcTemplate template = null;
		String sql = null;
		try {
			template = new JdbcTemplate(this.ds);
			sql = "select t.*,tm.rname from tmeet t,tmeetroom tm "
					+ "where t.rmid=tm.rmid and t.mid=" + mid;
			list = template.queryForList(sql);
		} catch (Exception e) {
			list = null;
			e.printStackTrace();
		}
		return list;
	}

	public boolean updatefile(HttpServletRequest request, String newfilepath,
			String newfilename, String mid) {
		Session session = null;
		String hql = null;
		Query query = null;
		int meetid = Integer.parseInt(mid);
		try {
			session = this.meet.openSession();
			hql = "update Tmeet set maffixname='" + newfilename
					+ "',maffixpath='" + newfilepath + "' where mid=" + meetid;
			query = session.createQuery(hql);
			query.executeUpdate();
			return true;
		} catch (Exception e1) {
			e1.printStackTrace();
		} finally {
			session.close();
		}

		return false;
	}

	public boolean update(Tmeet tmeet) {
		HibernateTemplate ht = null;
		try {
			ht = new HibernateTemplate(this.meet);
			Tmeetinfo info = new Tmeetinfo();
			info.setRmid(tmeet.getRmid());
			info.setMistarttime(tmeet.getMstarttime());
			info.setMiendtime(tmeet.getMendtime());
			info.setMiunos(tmeet.getMunos());
			info.setMiinfo(tmeet.getMtitle());
			info.setMiaffixname(tmeet.getMaffixname());
			info.setMiaffixpath(tmeet.getMaffixpath());
			info.setMiisdel("0");
			if (tmeet.getMaffixname() != null) {
				info.setMaffix(1);
			} else {
				info.setMaffix(0);
			}
			info.setMeet(tmeet);
			tmeet.setInfo(info);
			ht.update(tmeet);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	/**
	 * 修改会议为完成
	 */
	public boolean updatestatus1(HttpServletRequest request, String time) {
		boolean flag = false;
		Session session = null;
		String hql = null;
		Query query = null;
		try {
			session = this.meet.openSession();
			hql = "update Tmeet set mstatus='2' where mendtime<='" + time
					+ "' and  mSTATUS='1'";
			String hql2 = "update Tmeetinfo set Miisdel='2' where Miendtime<='"
					+ time + "' and  Miisdel='1'";
			query = session.createQuery(hql);
			query = session.createQuery(hql2);
			int i = query.executeUpdate();
			if (i > 0) {
				return true;
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			session.close();
		}

		return false;

	}

	/**
	 * 修改会议为开始
	 */
	public boolean updatestatus2(HttpServletRequest request, String time) {
		boolean flag = false;
		Session session = null;
		String hql = null;
		Query query = null;
		try {
			session = this.meet.openSession();
			hql = "update Tmeet set mstatus='1' where mstarttime<='" + time
					+ "' and  mSTATUS='0'";
			String hql2 = "update Tmeetinfo set Miisdel='1' where Mistarttime<='"
					+ time + "' and  Miisdel='0'";
			query = session.createQuery(hql);
			query = session.createQuery(hql2);
			int i = query.executeUpdate();
			if (i > 0) {
				return true;
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			session.close();
		}

		return false;
	}

	public boolean cancle(Tmeet meet) {
		boolean flag = false;
		HibernateTemplate th = null;
		try {
			th = new HibernateTemplate(this.meet);
			th.update(meet);
			flag = true;
		} catch (Exception e) {
			flag = false;
			e.printStackTrace();
		}
		return flag;
	}

	public List allroom() {
		List roomlist = null;
		JdbcTemplate template = null;
		String sql = null;
		try {
			template = new JdbcTemplate(this.ds);
			sql = "select t.rmid,t.rname from tmeetroom t ";
			roomlist = template.queryForList(sql);
		} catch (Exception e) {
			roomlist = null;
			e.printStackTrace();
		}
		return roomlist;
	}

}

⌨️ 快捷键说明

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