BlackListDaoImpl.java
资源名称:(J2EE)oa.rar [点击查看]
上传用户:lm2018
上传日期:2015-12-12
资源大小:30449k
文件大小:4k
源码类别:
Jsp/Servlet
开发平台:
Java
- package com.oa.module.email.dao;
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.List;
- 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.BlackListBean;
- import com.oa.module.email.blacklist.mapping.Tblacklist;
- import com.oa.module.email.company.TUser;
- import com.oa.module.office.user.Tuser;
- import com.oa.util.XPage;
- /**
- * 黑名单dao接口实现类
- * @author admin
- *
- */
- public class BlackListDaoImpl implements BlackListDao {
- private SessionFactory sf;
- public SessionFactory getSf() {
- return sf;
- }
- public void setSf(SessionFactory sf) {
- this.sf = sf;
- }
- /**
- * 根据用户id获取黑名单列表
- * @param id
- */
- public XPage getBlackList(int currentPage, int count,String id) {
- Session session = null;
- Transaction tx = null;
- Query query = null;
- XPage page = null;
- String hql = "select a from Tuser a where a.uno<>"+id;
- String path ="/blacklist?method=blackList&userid"+id+"&";
- try {
- session = sf.openSession();
- query = session.createQuery(hql);
- page = new XPage();
- page.setAllCount(query.list().size());
- page.setPath(path);
- page.setCount(count);
- page.setCurrentPage(currentPage);
- query.setFirstResult( (currentPage-1)*count);
- query.setMaxResults(count);
- List list = query.list();
- List temp = null;
- List tr= new ArrayList();
- hql = "select a from Tblacklist a where a.userid=:userid";
- query = session.createQuery(hql);
- query.setParameter("userid", id);
- temp = query.list();
- for (Iterator iter = list.iterator(); iter.hasNext();) {
- Tuser element = (Tuser) iter.next();
- TUser user = new TUser();
- BeanUtils.copyProperties(user, element);
- user.setIsBlackList("0");
- for(int i = 0 ;i<temp.size(); i++){
- if(element.getUno().equals( ((Tblacklist)temp.get(i)).getBlackuserid() )){
- user.setIsBlackList("1");
- break;
- }
- }
- tr.add(user);
- }
- page.setList(tr);
- } catch (Exception e) {
- e.printStackTrace();
- }finally{
- session.close();
- sf.close();
- }
- return page;
- }
- /**
- * 删除
- * @param parameter
- */
- public boolean delFromBlackList(String id) {
- Session session = null;
- Transaction tx = null;
- Query query = null;
- String hql = "select a from Tblacklist a where a.blackuserid=:id";
- try {
- session = sf.openSession();
- tx = session.beginTransaction();
- query = session.createQuery(hql);
- query.setParameter("id", id);
- List list = query.list();
- Tblacklist tb = (Tblacklist)list.get(0);
- session.delete(tb);
- tx.commit();
- session.flush();
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- tx.rollback();
- }finally{
- session.close();
- sf.close();
- }
- return false;
- }
- /**
- * 添加
- * @param id
- */
- public boolean addToBlackList(BlackListBean bean) {
- Session session = null;
- Transaction tx = null;
- try {
- session = sf.openSession();
- tx = session.beginTransaction();
- Tblacklist tb = new Tblacklist();
- BeanUtils.copyProperties(tb, bean);
- session.save(tb);
- tx.commit();
- session.flush();
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- tx.rollback();
- }finally{
- session.close();
- sf.close();
- }
- return false;
- }
- }