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

📄 logindao.java

📁 基于J2EE的办公自动化系统。实现流程定义流程办理等。运用了hibernate+struts+spring框架综合运用的系统。
💻 JAVA
字号:
package com.oa.module.login;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.jdbc.core.JdbcTemplate;


import com.ibatis.sqlmap.engine.transaction.Transaction;
import com.oa.module.office.user.Tuser;
import com.oa.util.PubUtil;



public class LoginDAO {

	private JdbcTemplate jdbcTemplate;
	
	private SessionFactory sessionFactory;
	
	
	public String checkLogin(LoginForm loginForm,HttpServletRequest request) {
		String message = null;
		Session session = null; 
		String contextPath = request.getContextPath();
		String hql="select a from Tuser a where a.uname='"+loginForm.getUname()+"'"; 
		try{ 
			session = this.sessionFactory.openSession(); 
			Query query =session.createQuery(hql);
			int i = query.list().size(); 
			if(i>0){
				String password = ((Tuser)query.list().get(0)).getUpwd();
				if(!loginForm.getUpwd().equals(password)){
					message = "<script>alert('该用户密码出错!');history.back();</script>";
				}
				HttpSession httpsession = request.getSession();
				String getcount = (String)httpsession.getAttribute(loginForm.getUname().trim());
				if (getcount!=null){
					int count =PubUtil.parseInt(getcount);
					if (count == 2){//比较是否已2次出错了
						//设置返回消息
						message = "<script>alert('密码三次错误,系统将自动关闭!');top.opener=null;top.window.close();</script>";
					}else{
						count = count+1;
						httpsession.setAttribute(loginForm.getUname(),String.valueOf(count));//把新的错误信息放入session
					}
				}else{
					httpsession.setAttribute(loginForm.getUname(),String.valueOf(1));//把新的错误信息放入session
				}
			}else{
				message = "<script>alert('该用户名不存在!');window.location.href='"+contextPath+"/Jsp_file/login/login.jsp';</script>";
			}
		}catch(Exception e){
			  e.printStackTrace(); 
		}finally{ 
			if(session!=null){ 
				session.close(); 
			}
		} 
		return message;
	}

	public Tuser getUser(String uname) {
		Tuser user =null;
		Session session = null;
		String hql = "from Tuser where uname= :uname";
		try {
			session = this.sessionFactory.openSession();
			Query query = session.createQuery(hql);
			query.setParameter("uname",uname);
			user =(Tuser)query.list().get(0);
			return user;
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			if(session!=null){
				session.close();
			}
		}
		return null;
	}
	
	public List getPmenu(String uname) {
		String sql = " select fun.* from tuser use"+
					 " left join tuserrole ur on ur.uno=use.uno"+
					 " left join trole ro on ro.rid=ur.rid"+
					 " left join trolefunction rf on rf.rid=ro.rid"+
					 " left join tfunction fun on fun.fid=rf.fid"+
					 " where fun.fpid=0 and use.uname='"+uname+"'";
		List list=null;
		try {
			 list =this.jdbcTemplate.queryForList(sql); 
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}
	
	public List getCmenu(String uname) {
		String sql = " select fun.* from tuser use"+
					 " left join tuserrole ur on ur.uno=use.uno"+
					 " left join trole ro on ro.rid=ur.rid"+
					 " left join trolefunction rf on rf.rid=ro.rid"+
					 " left join tfunction fun on fun.fid=rf.fid"+
					 " where fun.fpid<>0 and use.uname='"+uname+"'";
		List list=null;
		try {
		list =this.jdbcTemplate.queryForList(sql); 
		} catch (Exception e) {
		e.printStackTrace();
		}
		return list;
	}
	/**
	 * 获取有效公告信息
	 * @param nowdate 
	 * @return
	 */
	public List getAffiche(String nowdate) {
		String sql = " select a.*,use.uname from taffiche a" +
					 " left join tuser use on use.uno=a.funo" +
					 " where astate='1' and areal_time>='"+nowdate+
					 "' order by asend_time desc";
		try {
		List list = this.jdbcTemplate.queryForList(sql);
		return list;
		} catch (Exception e) {
		e.printStackTrace();
		}
		return null;
	}

	public Map getHints(String uno) {
		String sql = "select * from thints where uno = '"+uno+"'";
		try {
			Map hints = (Map) this.jdbcTemplate.queryForMap(sql);
			return hints;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public List getEmail(String uno) {
		String sql = "select * from tmailinfo order by sendtime desc";
		try {
			List idlist = this.jdbcTemplate.queryForList(sql);
			List newlist = new ArrayList();
			for (Iterator iter = idlist.iterator(); iter.hasNext();) {
				if(newlist.size()>=10){
					break;
				}
				Map affair = (Map) iter.next();
				String receiveid = (String) affair.get("receiveid");
				String[] ids = receiveid.split(",");
				for (int i = 0; i < ids.length; i++) {
					if(uno.equals(ids[i])){
						newlist.add(affair);
						break;
					}
				}
			}
			return newlist;
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return null;
	}
	
	public List getEmail() {
		String sql = "select receiveid from tmailinfo t where isread = '0' and emailtype = '0'";
		try {
			List list = this.jdbcTemplate.queryForList(sql);
			return list;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public List getAffair(String uno) {
		
		return null;
	}
	
	public List getAffair() {
		String sql = "select uno from transstep  where sstatus = '0'";
		try {
			List list = this.jdbcTemplate.queryForList(sql);
			return list;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public List getMeeting(String uno) {
		String sql = "select * from tmeet order by mendtime desc";
		try {
			List idlist = this.jdbcTemplate.queryForList(sql);
			List newlist = new ArrayList();
			for (Iterator iter = idlist.iterator(); iter.hasNext();) {
				if(newlist.size()>=10){
					break;
				}
				Map affair = (Map) iter.next();
				String munos = (String) affair.get("munos");
				String[] unos = munos.split(",");
				for (int i = 0; i < unos.length; i++) {
					if(uno.equals(unos[i])){
						newlist.add(affair);
						break;
					}
				}
			}
			return newlist;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public List getMeeting() {
		String sql = " select munos from tmeet where mstatus<>2";
		try {
			List list = this.jdbcTemplate.queryForList(sql);
			return list;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	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 void setonline(String str, Tuser user) {
		Connection conn = null;
		Statement st = null;
		Session session = null;
		session = sessionFactory.openSession();		
		conn =session.connection();
		String sql = "update tuser set uisonline = '"+str+"' where uno = " +user.getUno();

		try {
			conn.setAutoCommit(false);//设置不自动提交
			st = conn.createStatement();
			st.execute(sql);
			conn.commit();//提交事务	
		} catch (SQLException e) {
			try {
				conn.rollback();//事务回顾
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			e.printStackTrace();
		}finally{
			try {
				st.close();
				conn.close();
			} catch (SQLException e) {
				// TODO 自动生成 catch 块
				e.printStackTrace();
			}
		}		
	}


}

⌨️ 快捷键说明

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