DeptDAO.java
资源名称:(J2EE)oa.rar [点击查看]
上传用户:lm2018
上传日期:2015-12-12
资源大小:30449k
文件大小:4k
源码类别:
Jsp/Servlet
开发平台:
Java
- package com.oa.module.office.dept;
- import java.util.List;
- import org.hibernate.Query;
- import org.hibernate.Session;
- import org.hibernate.SessionFactory;
- import org.springframework.jdbc.core.JdbcTemplate;
- import org.springframework.orm.hibernate3.HibernateTemplate;
- import com.oa.util.XPage;
- /**
- * 操作数据库的DAO类
- * @author czpeng
- *
- */
- public class DeptDAO implements InDeptDAO{
- private SessionFactory sfactory;
- //JDBC连接数据库方法
- private JdbcTemplate jdbcTemplate;//JDBC
- /* (非 Javadoc)
- * @see com.oa.module.office.dept.InDeptDAO#getDeptlist(int, int, com.oa.module.office.dept.Tdept)
- */
- public XPage getDeptlist(int currentPage, int count, Tdept info) {
- String content ="select rownum as rnum,d.*,u.uname from tdept d left join tuser u on d.uno=u.uno where 1=1";
- String path="dept.do?method=query&";
- String sql ="SELECT * FROM("+content+") m WHERE m.rnum<="+currentPage*count+ " AND m.rnum>"+(currentPage-1)*count;
- XPage page = new XPage();
- //开始设置xpage
- page.setCurrentPage(currentPage);
- page.setCount(count);
- //设置分页路径
- page.setPath(path);
- List list = null;
- List list1 = null;
- try {
- list1 = jdbcTemplate.queryForList(content);
- list = jdbcTemplate.queryForList(sql);
- int allcount = list1.size();
- page.setAllCount(allcount);
- page.setList(list);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return page;
- }
- public SessionFactory getSfactory() {
- return sfactory;
- }
- public void setSfactory(SessionFactory sfactory) {
- this.sfactory = sfactory;
- }
- public JdbcTemplate getJdbcTemplate() {
- return jdbcTemplate;
- }
- public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
- this.jdbcTemplate = jdbcTemplate;
- }
- /**
- * 获取全部用户信息
- * return list
- */
- public List getUser() {
- String hql = "select a from Tuser a where 1=1";
- List list = null;
- Session session = null;
- Query query = null;
- try {
- session = sfactory.openSession();
- query = session.createQuery(hql);
- list = query.list();
- session.flush();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- session.close();
- }
- return list;
- }
- /**
- * 添加用户信息
- * return boolean
- */
- public boolean addList(Tdept info) {
- HibernateTemplate ht = new HibernateTemplate(this.sfactory);
- try {
- ht.save(info);
- } catch (Exception e) {
- return false;
- }
- return true;
- }
- /**
- * 修改部门信息
- */
- public boolean editList(Tdept info) {
- HibernateTemplate ht = new HibernateTemplate(this.sfactory);
- try {
- ht.update(info);
- } catch (Exception e) {
- return false;
- }
- return true;
- }
- /**
- * 用部门编号查询部门
- */
- public Tdept getDeptById(String did) {
- HibernateTemplate ht = new HibernateTemplate(this.sfactory);
- Tdept dept = null;
- try {
- dept = (Tdept)ht.get(Tdept.class,did);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return dept;
- }
- /**
- * 部门恢复
- */
- public boolean openDept(Tdept info) {
- HibernateTemplate ht = new HibernateTemplate(this.sfactory);
- try {
- ht.update(info);
- } catch (Exception e) {
- return false;
- }
- return true;
- }
- /**
- * 部门冻结
- */
- public boolean closeDept(Tdept info) {
- HibernateTemplate ht = new HibernateTemplate(this.sfactory);
- try {
- ht.update(info);
- } catch (Exception e) {
- return false;
- }
- return true;
- }
- /**
- * 用部门名称查询用户信息
- */
- public boolean getDeptByName(String dname) {
- List list = null;
- String sql = "select * from tdept where dname='"+dname+"'";
- list = jdbcTemplate.queryForList(sql);
- if(list.size()<=0){
- return false;
- }else{
- return true;
- }
- }
- /**
- * 用部门编号查询用户信息
- */
- public boolean getUserForDid(String did) {
- List list = null;
- String sql = "select * from tdept d left join tuser u on d.did = u.did where u.uislocked='0' and d.did='"+did+"'";
- list = jdbcTemplate.queryForList(sql);
- if(list.size()<=0){
- return false;
- }else{
- return true;
- }
- }
- }