ChatDao.java
资源名称:(J2EE)oa.rar [点击查看]
上传用户:lm2018
上传日期:2015-12-12
资源大小:30449k
文件大小:5k
源码类别:
Jsp/Servlet
开发平台:
Java
- package com.oa.module.communicate.comm.chat;
- import java.util.List;
- import javax.servlet.http.HttpServletRequest;
- import javax.sql.DataSource;
- import org.hibernate.Query;
- import org.hibernate.Session;
- import org.hibernate.SessionFactory;
- import org.springframework.jdbc.core.JdbcTemplate;
- import org.springframework.jdbc.datasource.DriverManagerDataSource;
- import org.springframework.orm.hibernate3.HibernateTemplate;
- import com.oa.module.communicate.comm.Tchat;
- import com.oa.module.office.dept.Tdept;
- /**
- * 即使通讯 dao 实现
- * * @author admin
- *
- */
- public class ChatDao implements ChatIntefer {
- private SessionFactory chat;
- private DataSource ds = null;
- private DriverManagerDataSource datasource;
- public DataSource getDs() {
- return ds;
- }
- public void setDs(DataSource ds) {
- this.ds = ds;
- }
- public DriverManagerDataSource getDatasource() {
- return datasource;
- }
- public void setDatasource(DriverManagerDataSource datasource) {
- this.datasource = datasource;
- }
- public SessionFactory getChat() {
- return chat;
- }
- public void setChat(SessionFactory chat) {
- this.chat = chat;
- }
- public List selectalldept() {
- List list = null;
- JdbcTemplate template = null;
- String sql = null;
- try {
- template = new JdbcTemplate(this.ds);
- sql = "select t.did ,t.dname from tdept t where t.dflag='0'";
- list = template.queryForList(sql);
- } catch (Exception e) {
- list = null;
- e.printStackTrace();
- }
- return list;
- }
- public List selecttalluser() {
- List list = null;
- JdbcTemplate template = null;
- String sql = null;
- try {
- template = new JdbcTemplate(this.ds);
- sql = "select t.uno,t.did,t.uname from tuser t where t.uislocked='0'";
- list = template.queryForList(sql);
- } catch (Exception e) {
- list = null;
- e.printStackTrace();
- }
- return list;
- }
- public List read(String reciever) {
- List list = null;
- JdbcTemplate template = null;
- String sql = null;
- try {
- template = new JdbcTemplate(this.ds);
- sql = "select t.*,tu.uname from tchat t,tuser tu "
- + "where t.csendid=tu.uno and t.cisread=0 and t.caccepid="
- + reciever;
- list = template.queryForList(sql);
- } catch (Exception e) {
- list = null;
- e.printStackTrace();
- }
- return list;
- }
- public boolean updateisread(String id) {
- boolean flag = false;
- Session session = null;
- String hql = null;
- Query query = null;
- int chatid = Integer.parseInt(id);
- try {
- session = this.chat.openSession();
- hql = "update Tchat set cisread=1 where cid=" + id;
- query = session.createQuery(hql);
- int i = query.executeUpdate();
- if (i > 0) {
- flag = true;
- }
- } catch (Exception e) {
- flag = false;
- e.printStackTrace();
- } finally {
- session.close();
- }
- return flag;
- }
- public boolean save(Tchat chat) {
- HibernateTemplate template = null;
- boolean flag = false;
- try {
- template = new HibernateTemplate(this.chat);
- template.save(chat);
- flag = true;
- } catch (Exception e) {
- flag = false;
- e.printStackTrace();
- }
- return flag;
- }
- public List userbydept(String getter) {
- List list = null;
- JdbcTemplate template = null;
- String sql = null;
- try {
- template = new JdbcTemplate(this.ds);
- sql = "select t.uno,t.uname from tuser t where t.uislocked=0 and t.did="
- + getter;
- list = template.queryForList(sql);
- } catch (Exception e) {
- list = null;
- e.printStackTrace();
- }
- return list;
- }
- public List selecthistory(HttpServletRequest request, String id) {
- List meetinglist = null;
- JdbcTemplate template = null;
- String sql = null;
- String sqlcount = null;
- String url = "";
- String pagetool = "";
- try {
- template = new JdbcTemplate(this.ds);
- //开始进行分页
- PageDAO page = new PageDAO();
- //拿到每页显示多少条
- int pagesize = page.getPagesize();
- //拿到总的记录数
- sqlcount = "select 1 from tchat t,tuser tu,tuser tu2 " +
- "where t.cisread='1' and tu.uno=t.csendid and tu2.uno=t.caccepid and " +
- "(t.caccepid='"+id+"' or t.csendid='"+id+"') order by t.csendtime desc";
- int rscount = template.queryForList(sqlcount).size();
- page.setRscount(rscount);
- //拿到总页数
- page.getPageCount();
- //拿到当前页
- int currentpage = page.getCurrentPage(request);
- //产生工具条
- pagetool = page.pagetool(url);
- int begincount = (currentpage - 1) * pagesize + 1;
- int endcount = currentpage * pagesize;
- sql = "select * from (select t.*,rownum rn from";
- sql=sql+"(select t.*,tu.uname send,tu2.uname recieve from tchat t,tuser tu,tuser tu2 " +
- "where t.cisread='1' and tu.uno=t.csendid and tu2.uno=t.caccepid and " +
- "(t.caccepid='1' or t.csendid='1') order by t.csendtime desc) t ";
- sql = sql + "where rownum <= " + endcount + ") t where t.rn >= " + begincount + "";
- meetinglist = template.queryForList(sql);
- } catch (Exception e) {
- meetinglist = null;
- e.printStackTrace();
- }
- request.setAttribute("pagetool", pagetool);
- return meetinglist;
- }
- }