UserDAO.java
资源名称:(J2EE)oa.rar [点击查看]
上传用户:lm2018
上传日期:2015-12-12
资源大小:30449k
文件大小:6k
源码类别:
Jsp/Servlet
开发平台:
Java
- package com.oa.module.office.user;
- 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;
- public class UserDAO implements InUserDAO{
- private SessionFactory sfactory;
- private SessionFactory sessionFactory;
- private JdbcTemplate jdbcTemplate;//JDBC
- private HibernateTemplate ht = null;
- public XPage getUserlist(int currentPage, int count, Tuser info) {
- String content="select rownum as rnum,u.*, d.dname, p.pname from " +
- "(tuser u left join tdept d on u.did = d.did) " +
- "left join tparam p on u.uwork = p.pid where 1 = 1";
- String path="user.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);
- //动态的构建sql语句和xpage的path
- if(info!=null){
- if(info.getUname()!=null&&!info.getUname().trim().equals("")){
- sql+=" and m.uname like '%"+info.getUname()+"%'";
- path+="uname="+info.getUname()+"&";
- }
- if(info.getUtruename()!=null&&!info.getUtruename().trim().equals("")){
- sql+=" and m.utruename like '%"+info.getUtruename()+"%'";
- path+="utruename="+info.getUtruename()+"&";
- }if(info.getDid()!=null&&!info.getDid().trim().equals("")){
- sql+=" and m.did="+info.getDid();
- path+="did="+info.getDid()+"&";
- }
- }
- //设置分页路径
- 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 List getDept() {
- String hql = "select a from Tdept 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;
- }
- public List getWork() {
- String sql = "select * from tparam p left join ttype t on t.tid=p.tid where t.tid=2";
- List list = null;
- list = jdbcTemplate.queryForList(sql);
- return list;
- }
- public List getRole() {
- String sql = "select * from trole ";
- List list = null;
- list = jdbcTemplate.queryForList(sql);
- return list;
- }
- public boolean addList(Tuser info) {
- HibernateTemplate ht = new HibernateTemplate(this.sfactory);
- try {
- ht.save(info);
- } catch (Exception e) {
- return false;
- }
- return true;
- }
- public Tuser getUserById(String uno) {
- ///////
- HibernateTemplate ht = new HibernateTemplate(this.sfactory);
- Tuser user = null;
- try {
- user = (Tuser)ht.get(Tuser.class,uno);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return user;
- }
- public boolean editList(Tuser info) {
- HibernateTemplate ht = new HibernateTemplate(this.sfactory);
- try {
- ht.update(info);
- } catch (Exception e) {
- return false;
- }
- return true;
- }
- public boolean openUser(Tuser info) {
- HibernateTemplate ht = new HibernateTemplate(this.sfactory);
- try {
- ht.update(info);
- } catch (Exception e) {
- return false;
- }
- return true;
- }
- public boolean closeUser(Tuser info) {
- HibernateTemplate ht = new HibernateTemplate(this.sfactory);
- try {
- ht.update(info);
- } catch (Exception e) {
- return false;
- }
- return true;
- }
- public List getRList(String uno) {
- String sql = "select * from tuserrole ur left join trole r on ur.rid=r.rid where ur.uno="+uno;
- List list = null;
- list = jdbcTemplate.queryForList(sql);
- return list;
- }
- 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;
- }
- public SessionFactory getSessionFactory() {
- return sessionFactory;
- }
- public void setSessionFactory(SessionFactory sessionFactory) {
- this.sessionFactory = sessionFactory;
- }
- public boolean updatePwd(String uno, String pwd) {
- String sql = "update tuser set upwd = "+ pwd +" where uno = " + uno;
- try {
- jdbcTemplate.update(sql);
- return true;
- } catch (Exception e) {
- e.printStackTrace();
- return false;
- }
- }
- public boolean getUserByName(String uname) {
- List list = null;
- String sql = "select * from tuser where uname='"+uname+"'";
- list = jdbcTemplate.queryForList(sql);
- if(list.size()<=0){
- return false;
- }else{
- return true;
- }
- }
- public Tuser getUserForName(String uname) {
- String sql = "select a from Tuser a where a.uname=:uname";
- Session session = null;
- Query query = null ;
- List list = null;
- Tuser user = null;
- try {
- session = sfactory.openSession();
- query = session.createQuery(sql);
- query.setParameter("uname",uname);
- list = query.list();
- user = (Tuser)list.get(0);
- } catch (Exception e) {
- e.printStackTrace();
- }finally{
- session.close();
- sfactory.close();
- }
- return user;
- }
- public List getuser(){
- ht = new HibernateTemplate(this.sfactory);
- String hql="select a from Tuser a ";
- return ht.find(hql);
- }
- }