package com.sinosoft.em.baobiao.xianlutingyun.dao; import java.io.IOException; import java.util.ArrayList; import java.util.List; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.Context; import org.apache.cxf.transport.http.AbstractHTTPDestination; import org.apache.log4j.Logger; import org.springframework.stereotype.Component; import com.persistence.service.PersistenceFactory; import com.persistence.service.exception.PersistenceException; import com.sinosoft.em.baobiao.xianlutingyun.dao.WaitDoDao; import com.sysmodel.datamodel.xmlmodel.ModelFactory; import com.system.push.MessagePush; public class DbServlet implements Filter{ private final Logger log = Logger.getLogger(getClass()); FilterConfig config =null; @Override public void init(FilterConfig arg0) throws ServletException { // TODO Auto-generated method stub config =arg0; } @Override public void destroy() { // TODO Auto-generated method stub } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { // TODO Auto-generated method stub System.out.println("开始执行"); String result=""; // String fd_id=request.getParameter("fd_id"); // String s =config.getInitParameter("fd_id"); chain.doFilter(request, response);//放行。让其走到下个链或目标资源中 System.out.println("执行完了"); WaitDoDao wd=new WaitDoDao(); // log.info("db_type===="+db_typ); // if("1".equals(db_typ)){ HttpServletRequest rq=(HttpServletRequest)request; String login_name = rq.getSession().getAttribute("User_Name") .toString(); String sql = "select a.user_id,b.role_id from sys_user_info a,sys_user_role_rel b where a.user_id=b.user_id and a.login_name='" + login_name + "'"; List list = new ArrayList(); try { list= PersistenceFactory.getInstance(ModelFactory.getSysmodel()) .getSearchResult(99, sql); if(list!=null&&list.size()>0){ String[]arr=list.get(0); result=wd.getDBNum(arr[0], arr[1], getDept(arr[0])); log.info("daiban==="+result); MessagePush.showMsg(null,arr[0],result,"getDbMsg"); } } catch (Exception e) { log.error(e.getMessage()); } // } } public String getDept(String userId){ String result=""; String sql="select b.dept_id,b.dept_type from sys_dept_user a,sys_department b where a.dept_id=b.dept_id and a.user_id='"+userId+"'"; List list = new ArrayList(); try { list= PersistenceFactory.getInstance(ModelFactory.getSysmodel()) .getSearchResult(99, sql); if(list!=null&&list.size()>0){ String[]arr=list.get(0); if("CORP".equals(arr[1])){ result=arr[1]; }else if("DEPT".equals(arr[1])){ result=getComp(arr[0]); } } } catch (Exception e) { log.error(e.getMessage()); } return result; } public String getComp(String dept_id){ String result=""; String sql="select a.dept_id,a.dept_type from sys_department a,sys_department b where a.dept_id=b.parent_id and b.dept_id='"+dept_id+"'"; List list = new ArrayList(); try { list= PersistenceFactory.getInstance(ModelFactory.getSysmodel()) .getSearchResult(99, sql); if(list!=null&&list.size()>0){ String[]arr=list.get(0); if("CORP".equals(arr[1])){ result=arr[0]; }else if("DEPT".equals(arr[1])){ getComp(arr[0]); } } } catch (Exception e) { log.error(e.getMessage()); } return result; } }