b7e18e65c8d17e0d2feccd9461ca552011fcf557.svn-base 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package com.sinosoft.em.baobiao.xianlutingyun.dao;
  2. import java.io.IOException;
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import javax.servlet.Filter;
  6. import javax.servlet.FilterChain;
  7. import javax.servlet.FilterConfig;
  8. import javax.servlet.ServletException;
  9. import javax.servlet.ServletRequest;
  10. import javax.servlet.ServletResponse;
  11. import javax.servlet.http.HttpServletRequest;
  12. import javax.ws.rs.core.Context;
  13. import org.apache.cxf.transport.http.AbstractHTTPDestination;
  14. import org.apache.log4j.Logger;
  15. import org.springframework.stereotype.Component;
  16. import com.persistence.service.PersistenceFactory;
  17. import com.persistence.service.exception.PersistenceException;
  18. import com.sinosoft.em.baobiao.xianlutingyun.dao.WaitDoDao;
  19. import com.sysmodel.datamodel.xmlmodel.ModelFactory;
  20. import com.system.push.MessagePush;
  21. public class DbServlet implements Filter{
  22. private final Logger log = Logger.getLogger(getClass());
  23. FilterConfig config =null;
  24. @Override
  25. public void init(FilterConfig arg0) throws ServletException {
  26. // TODO Auto-generated method stub
  27. config =arg0;
  28. }
  29. @Override
  30. public void destroy() {
  31. // TODO Auto-generated method stub
  32. }
  33. @Override
  34. public void doFilter(ServletRequest request, ServletResponse response,
  35. FilterChain chain) throws IOException, ServletException {
  36. // TODO Auto-generated method stub
  37. System.out.println("开始执行");
  38. String result="";
  39. // String fd_id=request.getParameter("fd_id");
  40. // String s =config.getInitParameter("fd_id");
  41. chain.doFilter(request, response);//放行。让其走到下个链或目标资源中
  42. System.out.println("执行完了");
  43. WaitDoDao wd=new WaitDoDao();
  44. // log.info("db_type===="+db_typ);
  45. // if("1".equals(db_typ)){
  46. HttpServletRequest rq=(HttpServletRequest)request;
  47. String login_name = rq.getSession().getAttribute("User_Name")
  48. .toString();
  49. 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='"
  50. + login_name + "'";
  51. List<String[]> list = new ArrayList<String[]>();
  52. try {
  53. list= PersistenceFactory.getInstance(ModelFactory.getSysmodel())
  54. .getSearchResult(99, sql);
  55. if(list!=null&&list.size()>0){
  56. String[]arr=list.get(0);
  57. result=wd.getDBNum(arr[0], arr[1], getDept(arr[0]));
  58. log.info("daiban==="+result);
  59. MessagePush.showMsg(null,arr[0],result,"getDbMsg");
  60. }
  61. } catch (Exception e) {
  62. log.error(e.getMessage());
  63. }
  64. // }
  65. }
  66. public String getDept(String userId){
  67. String result="";
  68. 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+"'";
  69. List<String[]> list = new ArrayList<String[]>();
  70. try {
  71. list= PersistenceFactory.getInstance(ModelFactory.getSysmodel())
  72. .getSearchResult(99, sql);
  73. if(list!=null&&list.size()>0){
  74. String[]arr=list.get(0);
  75. if("CORP".equals(arr[1])){
  76. result=arr[1];
  77. }else if("DEPT".equals(arr[1])){
  78. result=getComp(arr[0]);
  79. }
  80. }
  81. } catch (Exception e) {
  82. log.error(e.getMessage());
  83. }
  84. return result;
  85. }
  86. public String getComp(String dept_id){
  87. String result="";
  88. 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+"'";
  89. List<String[]> list = new ArrayList<String[]>();
  90. try {
  91. list= PersistenceFactory.getInstance(ModelFactory.getSysmodel())
  92. .getSearchResult(99, sql);
  93. if(list!=null&&list.size()>0){
  94. String[]arr=list.get(0);
  95. if("CORP".equals(arr[1])){
  96. result=arr[0];
  97. }else if("DEPT".equals(arr[1])){
  98. getComp(arr[0]);
  99. }
  100. }
  101. } catch (Exception e) {
  102. log.error(e.getMessage());
  103. }
  104. return result;
  105. }
  106. }