IEmailDaoImpl.java
资源名称:(J2EE)oa.rar [点击查看]
上传用户:lm2018
上传日期:2015-12-12
资源大小:30449k
文件大小:8k
源码类别:
Jsp/Servlet
开发平台:
Java
- package com.oa.module.email.dao;
- import java.util.Iterator;
- import java.util.List;
- import java.util.Set;
- import org.apache.commons.beanutils.BeanUtils;
- import org.hibernate.Query;
- import org.hibernate.Session;
- import org.hibernate.SessionFactory;
- import org.hibernate.Transaction;
- import com.oa.module.email.bean.ReceiveLetterBean;
- import com.oa.module.email.form.EmailForm;
- import com.oa.module.email.fujian.mapping.Tfujian;
- import com.oa.module.email.mapping.Tmailinfo;
- import com.oa.util.XPage;
- /**
- * 邮件dao接口实现类
- * @author admin
- *
- */
- public class IEmailDaoImpl implements IEmailDao {
- private SessionFactory sf;
- public SessionFactory getSf() {
- return sf;
- }
- public void setSf(SessionFactory sf) {
- this.sf = sf;
- }
- /**
- * 获取邮件列表
- * @param currentPage
- * @param bean
- */
- public XPage getEmailList(int currentPage, int count, ReceiveLetterBean bean) {
- XPage page = null;
- Session session = null;
- Query query = null;
- String hql = " select a from Tmailinfo a where 1=1";
- List list = null;
- String path = "email.do?method=receiveBox&";
- if(bean.getEmailtype()!=null && bean.getEmailtype().trim().equals("0")){//收件箱
- hql += " and a.receiveid =:receiveid and a.emailtype =:emailtype order by sendtime desc ";
- path += "receiveid="+bean.getReceiveid()+"&emailtype="+bean.getEmailtype()+"&";
- }else if(bean.getEmailtype()!= null && bean.getEmailtype().trim().equals("1")){ //草稿箱
- hql += " and a.emailtype =:emailtype and a.sendid =:sendid order by sendtime desc ";
- path += "sendid="+bean.getSendid()+"&emailtype="+bean.getEmailtype()+"&";
- }else if(bean.getEmailtype()!=null && bean.getEmailtype().trim().equals("2")){ //发件箱
- hql += " and a.sendid =:sendid and a.emailtype =:emailtype ";
- path += "sendid="+bean.getSendid()+"&emailtype="+bean.getEmailtype()+"&";
- }else if(bean.getEmailtype()!=null && bean.getEmailtype().trim().equals("3")){ //垃圾箱
- hql += " and a.receiveid =:receiveid and a.emailtype =:emailtype order by sendtime desc ";
- path += "receiveid="+bean.getReceiveid()+"&emailtype="+bean.getEmailtype()+"&";
- }
- try {
- page = new XPage();
- session = sf.openSession();
- query = session.createQuery(hql);
- if(bean.getEmailtype()!=null && bean.getEmailtype().trim().equals("0")){//收件箱
- query.setParameter("receiveid",bean.getReceiveid());
- query.setParameter("emailtype",bean.getEmailtype());
- }else if(bean.getEmailtype()!= null && bean.getEmailtype().trim().equals("1")){ //草稿箱
- query.setParameter("emailtype", bean.getEmailtype());
- query.setParameter("sendid", bean.getSendid());
- }else if(bean.getEmailtype()!=null && bean.getEmailtype().trim().equals("2")){ //发件箱
- query.setParameter("sendid", bean.getSendid());
- query.setParameter("emailtype", bean.getEmailtype());
- }else if(bean.getEmailtype()!=null && bean.getEmailtype().trim().equals("3")){ //发件箱
- query.setParameter("receiveid",bean.getReceiveid());
- query.setParameter("emailtype",bean.getEmailtype());
- }
- page.setAllCount(query.list().size());
- page.setCount(count);
- page.setCurrentPage(currentPage);
- page.setPath(path);
- query.setFirstResult((currentPage-1)*count);//从第几条开始=(currentPage-1)*count
- query.setMaxResults(count);//每页显示条数=count
- list = query.list();
- page.setList(list);
- session.flush();
- } catch (Exception e) {
- e.printStackTrace();
- } finally{
- session.close();
- sf.close();
- }
- return page;
- }
- /**
- * 根据邮件id获取邮件
- * @param emailid
- */
- public Tmailinfo getEmailByEmailid(String emailid) {
- Session session = null;
- Tmailinfo mail = null;
- try {
- session = sf.openSession();
- mail = (Tmailinfo)session.get(Tmailinfo.class, emailid);
- Set set = mail.getFujian();
- for (Iterator iter = set.iterator(); iter.hasNext();) {
- Tfujian a = (Tfujian) iter.next();
- a.getFujianid();
- }
- session.flush();
- } catch (Exception e) {
- e.printStackTrace();
- }finally{
- session.close();
- sf.close();
- }
- return mail;
- }
- /**
- * 修改email状态
- */
- public boolean UpdateEmail(EmailForm emailForm, int i) {
- Session session = null;
- Transaction tx = null;
- Tmailinfo mail = null;
- try {
- session = sf.openSession();
- tx = session.beginTransaction();
- mail = (Tmailinfo)session.load(Tmailinfo.class, emailForm.getEmailid());
- if(i==0){
- mail.setIsread("1");
- }else if(i!=0){
- mail.setEmailtype(emailForm.getEmailtype());
- }
- tx.commit();
- session.flush();
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- tx.rollback();
- } finally{
- session.close();
- sf.close();
- }
- return false;
- }
- /**
- * 添加邮件
- */
- public boolean addEamil(Tmailinfo mail) {
- Session session = null;
- Transaction tx = null;
- try {
- session = sf.openSession();
- tx = session.beginTransaction();
- session.save(mail);
- tx.commit();
- session.flush();
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- tx.rollback();
- }finally{
- session.close();
- sf.close();
- }
- return false;
- }
- //删除邮件
- public boolean delemail(String emailid){
- Session session = null;
- Transaction tx = null;
- try {
- session = sf.openSession();
- tx = session.beginTransaction();
- Tmailinfo mail = (Tmailinfo)session.load(Tmailinfo.class, emailid);
- session.delete(mail);
- tx.commit();
- session.flush();
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- tx.rollback();
- } finally{
- session.close();
- sf.close();
- }
- return false;
- }
- /**
- * 得到邮件类表
- * 是否已读
- */
- public XPage getIsReadList(int currentpage, int count, ReceiveLetterBean bean) {
- XPage page = new XPage();
- Session session = null;
- Query query = null;
- List list = null;
- String hql = "select a from Tmailinfo a where 1=1";
- String path = "email.do?method=isRead&emailtype="+bean.getEmailtype()+"&receiveid="+bean.getReceiveid()+"&read="+bean.getIsread()+"&";
- if(bean.getEmailtype()!=null && bean.getEmailtype().trim().equals("0")){//收件箱
- hql += " and a.receiveid =:receiveid and a.emailtype =:emailtype and a.isread=:isread order by sendtime desc ";
- }
- try {
- session = sf.openSession();
- query = session.createQuery(hql);
- if(bean.getEmailtype()!=null && bean.getEmailtype().trim().equals("0")){//收件箱
- query.setParameter("receiveid", bean.getReceiveid());
- query.setParameter("emailtype", bean.getEmailtype());
- query.setParameter("isread", bean.getIsread());
- }
- page.setAllCount(query.list().size());
- page.setCount(count);
- page.setCurrentPage(currentpage);
- page.setPath(path);
- query.setFirstResult((currentpage-1)*count);
- query.setMaxResults(count);
- list = query.list();
- page.setList(list);
- } catch (Exception e) {
- e.printStackTrace();
- } finally{
- session.close();
- sf.close();
- }
- return page;
- }
- /**
- * 得到用户黑名单记录
- * @param uno
- */
- public List getBlackListById(String uno) {
- Session session = null;
- Query query = null;
- List list = null;
- String hql = "select a from Tblacklist a where a.userid=:userid";
- try {
- session = sf.openSession();
- query = session.createQuery(hql);
- query.setParameter("userid", uno);
- list = query.list();
- session.flush();
- } catch (Exception e) {
- e.printStackTrace();
- }finally{
- session.close();
- sf.close();
- }
- return list;
- }
- /**
- * 获取用户
- */
- public List getUserList(String id) {
- Session session = null;
- Query query = null;
- List list = null;
- String hql = "select a from Tuser a where a.uno<>"+id;
- try {
- session = sf.openSession();
- query = session.createQuery(hql);
- list =query.list();
- } catch (Exception e) {
- e.printStackTrace();
- }finally{
- session.close();
- sf.close();
- }
- return list;
- }
- }