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

📄 userdao.java

📁 一个oa系统
💻 JAVA
字号:
package com.oa.db;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.HibernateException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;


public class UserDAO extends HibernateDaoSupport{

	public List QueryAllUsername() {// 查询所有在职或试用员工的用户名
		List list = null;		
		try {
			String status = "离职";
			String status2 = "临时用户";
			list =this.getHibernateTemplate().find("select username from User where staffstatus!=? and staffstatus!=?",new Object[]{status,status2});
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}
	
	public List QueryAllRealname() {// 查询所有在职或试用员工的真实
		List list = null;		
		try {
			String status = "离职";
			String status2 = "临时用户";
			list =this.getHibernateTemplate().find("select realname from User where staffstatus!=? and staffstatus!=?",new Object[]{status,status2});
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}
	
	public List QueryAllRealname2() {// 查询所有在职或试用员工的真实
		List list = null;		
		try {
			String status = "离职";
			String status2 = "临时用户";
			list =this.getHibernateTemplate().find("from User where staffstatus!=? and (staffstatus=? or departmentid=?)",new Object[]{status,status2,4});
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}


	public int ByUsernameQueryId(String username) {// 通过用户名查询员工id
		int id = 0;
		List list = null;
		try {
			list = this.getHibernateTemplate().find("from User where username=?",username);	
			if(list!=null&&list.size()!=0){
			  // for(int i=0;i<list.size();i++){
					User vo = (User)list.get(0);
					id = vo.getId();
			  // }
			}
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return id;
	}
	
	public List ByUsernameQueryUser(String username) {// 通过用户名查询员工
		List list = null;
		try {
			list = this.getHibernateTemplate().find("from User where username=?",username);	
		} catch (HibernateException e) {
			// TODO Auto-generated catch block   
			e.printStackTrace();
		}
		return list;
	}
	
	public String ByUsernameQueryValidate(String uname) {// 通过用户名查询员工状态
		String  staffstatus = "";
		List list = null;
		try {
			list = this.getHibernateTemplate().find("from User where username=?",uname);
			if (list!= null && list.size()!= 0) {
				User vo = (User)list.get(0);
				staffstatus = vo.getStaffstatus();
			}
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return staffstatus;
	}
	
	public int ValidatePwd(String uname, String upwd) {// 登录时验证密码是否正确
		List list = null;
		try {
		//	list = this.getHibernateTemplate().find("from User where username='"+uname+"' and userpwd='"+upwd+"'");
			list = this.getHibernateTemplate().find("from User where username=? and userpwd=?",new Object[]{uname,upwd});
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if (list != null && list.size() != 0) {
			return 1;
		} else {
			return 0;
		}
	}
	
	public void Loginnum(String username) {// 通过用户名查询员工信息
		int num = 0;
		List list = null;
		try {
			list = this.getHibernateTemplate().find("from User where username=?",username);
			if (list != null && list.size() != 0) {
			User vo = (User)list.get(0);
			num = vo.getLoginnum();
			num++;
			vo.setLoginnum(num);
			this.getHibernateTemplate().update(vo);
			}
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public int Save(User vo) {// 保存用户信息
		List list = null;
		int id = 0;
		try {
			this.getHibernateTemplate().save(vo);
			list = this.getHibernateTemplate().find("from User where username=?",vo.getUsername());
			if(list!=null&&list.size()!=0){
				User uo = (User)list.get(0);
				id = uo.getId();
			}
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return id;
	}
	
	public void Update(User vo) {// 更新用户信息
		try {
			this.getHibernateTemplate().update(vo);
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	public List ByIdQueryUser(int id) {// 通过用户名查询员工
		List list = null;
		try {
			list = this.getHibernateTemplate().find("from User where id=?",id);	
		} catch (HibernateException e) {
			// TODO Auto-generated catch block   
			e.printStackTrace();
		}
		return list;
	}
	
	public List ByDepartmentidQueryUser(int departmentid) {// 通过部门id查询员工
		List list = null;
		try {
			list = this.getHibernateTemplate().find("from User where departmentid=? and staffstatus!=?",new Object[]{departmentid,"离职"});	
		} catch (HibernateException e) {
			// TODO Auto-generated catch block   
			e.printStackTrace();
		}
		return list;
	}
	
	public List ByDepartmentidQueryUser2(int departmentid) {// 通过部门id查询员工
		List list = null;
		try {
			list = this.getHibernateTemplate().find("select id from User where departmentid=? and staffstatus!=?",new Object[]{departmentid,"离职"});	
		} catch (HibernateException e) {
			// TODO Auto-generated catch block   
			e.printStackTrace();
		}
		return list;
	}
	
	public User findById( java.lang.Integer id) {
        try {
        	User instance = (User) getHibernateTemplate().get("com.oa.db.User", id);
            return instance;
        } catch (RuntimeException re) {
            throw re;
        }
    }
	
	public List QueryAllUser() {// 查询所有在职或试用员工
		List list = null;		
		try {
			String status = "离职";
			list =this.getHibernateTemplate().find("from User where staffstatus!=?",status);
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}
	
	public List QueryAllUser2() {// 查询所有在职或试用员工
		List list = null;		
		try {
			String status = "离职";
			list =this.getHibernateTemplate().find("from User where staffstatus!=? group by departmentid",status);
		} catch (HibernateException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return list;
	}
	
	public List ByUsernameAndRealnameQueryUser(String username,String realname) {// 通过用户名和真实姓名查询员工
		List list = null;
		try {
			list = this.getHibernateTemplate().find("from User where username like ? and realname like ?",new Object[]{"%"+username+"%","%"+realname+"%"});	
		} catch (HibernateException e) {
			// TODO Auto-generated catch block   
			e.printStackTrace();
		}
		return list;
	}
	
	public void updateUserPassword(User user){//修改用户密码
		try {
			getHibernateTemplate().update(user);
		} catch (HibernateException e) {
			// TODO: handle exception
			e.printStackTrace();
		}		
	}
	
	public ArrayList<User> findMartDeptAllEmp(User user) {
		// TODO 自动生成方法存根
		ArrayList<User> list = new ArrayList<User>();
		
		ArrayList<User> list2 = new ArrayList<User>();

		String[] use1 = new String[2];
		use1[0] = "" + 4;
		use1[1] = "离职";
		String sql1 = "from User where departmentid=? and staffstatus!= ?";

		String[] use = new String[3];
		use[0] = "" + 4;
		use[1] = "离职";
		use[2] = user.getUsername();
		String sql = "from User where departmentid=? and staffstatus!= ? and direct_superior=?";

		if (user.getPostid() == 8) {
			list = (ArrayList<User>) getHibernateTemplate().find(sql1, use1);
		}
		if (user.getPostid() == 9) {
			list = (ArrayList<User>) getHibernateTemplate().find(sql, use);
			if (list.size() != 0) {
				for(int z = 0;z < list.size();z++) {
					ArrayList<User> list1 = new ArrayList<User>();
					User user1 = new User();
					user1 = list.get(z);
					if (user1.getPostid() == 6) {
						String[] use2 = new String[3];
						use2[0] = "" + 4;
						use2[1] = "离职";
						use2[2] = user1.getUsername();
						String sql2 = "from User where departmentid=? and staffstatus!=? and direct_superior=?";
						list1 = (ArrayList<User>) getHibernateTemplate().find(
								sql2, use2);
					}
					if (list1.size() != 0) {
						for(int j = 0;j< list1.size();j++){
							list2.add(list1.get(j));
							
						}
					}
				}
			}
			if (list2.size() != 0) {
				for(int i = 0;i < list2.size();i++){
					list.add(list2.get(i));
				}
			}

		}
		if (user.getPostid() == 6) {
			String[] use3 = new String[3];
			use3[0] = "" + 4;
			use3[1] = "离职";
			use3[2] = user.getUsername();
			String sql3 = "from User where departmentid=? and staffstatus!=? and direct_superior=?";
			list = (ArrayList<User>) getHibernateTemplate().find(sql3, use3);
		}
		return list;
	}


}

⌨️ 快捷键说明

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