package com.web.base; import java.io.*; import java.util.*; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.apache.commons.lang.StringUtils; import org.apache.struts2.ServletActionContext; import org.apache.struts2.interceptor.ServletRequestAware; import org.apache.struts2.interceptor.SessionAware; import org.springframework.jdbc.core.JdbcTemplate; import com.opensymphony.xwork2.Action; import com.opensymphony.xwork2.ActionSupport; import com.web.displaytag.PageList; import com.web.event.service.EventStepService; import com.web.event.service.EventsService; import com.web.event.service.JcxxeventService; import com.web.event.service.JtcyqkeventService; import com.web.event.service.RhhjlbeventService; import com.web.event.service.RwqjleventService; import com.web.event.service.ShgxqkeventService; import com.web.event.service.SjfjbService; import com.web.event.service.SjyhxxbService; import com.web.event.vo.EventStep; import com.web.event.vo.Jcxxevent; import com.web.event.vo.Jtcyqkevent; import com.web.event.vo.Rhhjlbevent; import com.web.event.vo.Rwqjlevent; import com.web.event.vo.Shgxqkevent; import com.web.event.vo.Sjfjb; import com.web.sys.service.JcxxService; import com.web.sys.service.JtcyqkService; import com.web.sys.service.OpinfoService; import com.web.sys.service.PagemenuService; import com.web.sys.service.RhhjlbService; import com.web.sys.service.RwqjlService; import com.web.sys.service.ShgxqkService; import com.web.sys.service.SysUsersService; import com.web.sys.service.WordbookService; import com.web.sys.vo.Jcxx; import com.web.sys.vo.Jtcyqk; import com.web.sys.vo.Opinfo; import com.web.sys.vo.Pagemenu; import com.web.sys.vo.Rhhjlb; import com.web.sys.vo.Rwqjl; import com.web.sys.vo.Shgxqk; import com.web.sys.vo.SysUsers; import com.web.sys.vo.User; import com.web.utils.ExcelUtils; import com.web.utils.FacesUtils; import com.web.utils.Tools; public abstract class BaseAction extends ActionSupport implements Action, SessionAware, ServletRequestAware { public OpinfoService opinfoService; public JdbcTemplate jdbcTemplate; protected String returnPage = "list"; private JtcyqkeventService jtcyqkeventService; private RhhjlbeventService rhhjlbeventService; private RwqjleventService rwqjleventService; private ShgxqkeventService shgxqkeventService; private JcxxeventService jcxxeventService; // private List<Jtcyqkevent> jtcyqklist; // private List<Rhhjlbevent> rhhjlblist; // private List<Rwqjlevent> rwqjllist; // private List<Shgxqkevent> shgxqklist; // private List<Jcxxevent> jcxxlist; public JtcyqkService jtcyqkService; public RhhjlbService rhhjlbService; public RwqjlService rwqjlService; public ShgxqkService shgxqkService; public JcxxService jcxxService; public List jtcyqklist; public List rhhjlblist; public List rwqjllist; public List shgxqklist; public List jcxxlist; public void saveOpinfo(String message) { Date insertTime = new Date(System.currentTimeMillis()); Long userid = getLoginuser().getId(); String ip = getIpAddr(this.getRequest()); Opinfo opinfo = new Opinfo(); opinfo.setInsertTime(insertTime); opinfo.setIp(ip); opinfo.setMessage(message); opinfo.setUserid(userid); opinfoService.save(opinfo); } public int persize; public int PAGE_SIZE = 20; public int pageNumber=1; public String getSortOrder() { return this.getRequest().getParameter("sort"); } public String getSortOrderstr(String str) { String orderstr=str; if(FacesUtils.getValueInHashtableOfSession("sortstr")!=null) orderstr=FacesUtils.getValueInHashtableOfSession("sortstr").toString(); if(this.getRequest().getParameter("sort")!=null&&this.getRequest().getParameter("dir")!=null&&this.getRequest().getParameter("page")==null){ String sortdir="asc"; Object obj=FacesUtils.getValueInHashtableOfSession("sortdir"); if(obj!=null){ if(obj.toString().equals("asc")) sortdir="desc"; else sortdir="asc"; } FacesUtils.setValueInHashtableOfSession("sortdir", sortdir); orderstr=" order by t."+this.getSortOrder()+" "+sortdir; } return orderstr; } public abstract BaseService getService(); public abstract Object[] getSearchParam(); public abstract String getSortstr(); public String search() { if(persize==0) persize=20; PAGE_SIZE=persize; if(this.getSearch()!=null&&this.getSearch().equals("1")){ FacesUtils.clearValueInHashtableOfSessionKey("list"); FacesUtils.clearValueInHashtableOfSessionKey("pageNumber"); FacesUtils.clearValueInHashtableOfSessionKey("hql"); FacesUtils.clearValueInHashtableOfSessionKey("hql_count"); FacesUtils.clearValueInHashtableOfSessionKey("map"); FacesUtils.clearValueInHashtableOfSessionKey("sortstr"); FacesUtils.clearValueInHashtableOfSessionKey("ids"); FacesUtils.clearValueInHashtableOfSessionKey("sends"); } if(this.getRequest()!=null){ if (StringUtils.isNotEmpty(this.getRequest().getParameter("page"))) pageNumber = Integer.parseInt(this.getRequest().getParameter("page")); else{ Object obj=FacesUtils.getValueInHashtableOfSession("pageNumber",this.getSession()); if(obj!=null) pageNumber=(Integer)obj; } } String hql=null; String hql_count=null; Map map=null; Object obj1=FacesUtils.getValueInHashtableOfSession("hql"); Object obj2=FacesUtils.getValueInHashtableOfSession("hql_count"); Object obj3=FacesUtils.getValueInHashtableOfSession("map"); if(obj1!=null&&obj2!=null&&obj3!=null){ hql=obj1.toString(); hql_count=obj2.toString(); map=(Map)obj3; }else{ Object[] objs = this.getSearchParam(); hql=objs[0].toString(); hql_count=objs[1].toString(); map=(Map)objs[2]; } String sortstr=this.getSortstr(); int resultSize=this.getService().getPageSize(hql_count.toString(),map); if(pageNumber>Tools.ceil(resultSize, PAGE_SIZE)) pageNumber=Tools.ceil(resultSize, PAGE_SIZE); List list = this.getService().getPageData(hql+sortstr, map, pageNumber, PAGE_SIZE); PageList pageList = new PageList(); List pages = list; pageList.setPageNumber(pageNumber);// 设置当前页数 pageList.setList(pages);// 设置当前页列表 pageList.setObjectsPerPage(PAGE_SIZE);// 设置page size pageList.setFullListSize(resultSize); // 设置总页数 FacesUtils.setValueInHashtableOfSession("list", pageList); FacesUtils.setValueInHashtableOfSession("pageNumber", pageNumber); FacesUtils.setValueInHashtableOfSession("hql", hql); FacesUtils.setValueInHashtableOfSession("hql_count", hql_count); FacesUtils.setValueInHashtableOfSession("map", map); FacesUtils.setValueInHashtableOfSession("sortstr", sortstr); return returnPage; } public HttpServletRequest getRequest() { return this.request; } public HttpSession getSession() { //HttpServletRequest request = ServletActionContext.getRequest(); return this.request.getSession(); } public User getUserInSession() { Object obj = getSession().getAttribute("loginUser"); if (obj != null){ User user = (User) obj; return user; } else return null; } public String getIpAddr(HttpServletRequest request) { String ip = request.getHeader("x-forwarded-for"); if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("Proxy-Client-IP"); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getHeader("WL-Proxy-Client-IP"); } if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { ip = request.getRemoteAddr(); } return ip; } public Map session; public void setSession(Map session) { this.session = session; } public User getLoginuser() { return (User) session.get("loginUser"); } public HttpServletRequest request; public void setServletRequest(HttpServletRequest request) { this.request=request; } public String delete(){ search=null; getService().removes(ids); if(codes!=null) getService().removes(codes); return search(); } public abstract String edit(); public abstract String save(); public abstract String deleteForm(); public abstract void editForm(Long id); public Long[] ids; public String[] idss;//附件删除转换 public String[] codes; public String idsString; public Long[] getIds() { return ids; } public void setIds(Long[] ids) { this.ids = ids; } public String[] getCodes() { return codes; } public void setCodes(String[] codes) { this.codes = codes; } public String search; public String getSearch() { return search; } public void setSearch(String search) { this.search = search; } public void setOpinfoService(OpinfoService opinfoService) { this.opinfoService = opinfoService; } public WordbookService wordbookService; public void setWordbookService(WordbookService wordbookService) { this.wordbookService = wordbookService; } public void exportExcel(Map beans,String templateName,String filename) { try { HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-disposition", "attachment; filename=\"" + filename); ServletOutputStream outStream = response.getOutputStream(); ExcelUtils.exportExcel(beans, this.getText("template.path") + System.getProperty("file.separator") + templateName, outStream); response.getOutputStream().flush(); response.getOutputStream().close(); outStream.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public void exportAll() { if(getTemplateName()!=null){ String templateName=getTemplateName(); String sortstr=FacesUtils.getValueInHashtableOfSession("sortstr").toString(); String hql=FacesUtils.getValueInHashtableOfSession("hql").toString()+sortstr; Map map=(Map)FacesUtils.getValueInHashtableOfSession("map"); List list = this.getService().getPageData(hql, map); Map beans=new HashMap(); beans.put("list", list); String filename=templateName+Tools.getNowTime()+".xls"; exportExcel(beans, templateName+".xls", filename); //日志 String message=templateName+"报表导出"; saveOpinfo(message); } } public String getTemplateName(){ return null; } public int getPersize() { return persize; } public void setPersize(int persize) { this.persize = persize; } public void setJdbcTemplate(JdbcTemplate jdbcTemplate) { this.jdbcTemplate = jdbcTemplate; } public boolean getAdd(){ String menuKey=(String)FacesUtils.getValueInHashtableOfSession("menuKey"); if(StringUtils.isNotBlank(menuKey)){ Long pagemenuid=Long.valueOf(menuKey.trim()); List list=(List)session.get("add_pagemenus"); if(list!=null&&list.contains(pagemenuid)) return true; } return false; } public boolean getModify(){ String menuKey=(String)FacesUtils.getValueInHashtableOfSession("menuKey"); if(StringUtils.isNotBlank(menuKey)){ Long pagemenuid=Long.valueOf(menuKey.trim()); List list=(List)session.get("modify_pagemenus"); if(list!=null&&list.contains(pagemenuid)) return true; } return false; } public boolean getDelete(){ String menuKey=(String)FacesUtils.getValueInHashtableOfSession("menuKey"); if(StringUtils.isNotBlank(menuKey)){ Long pagemenuid=Long.valueOf(menuKey.trim()); List list=(List)session.get("delete_pagemenus"); if(list!=null&&list.contains(pagemenuid)) return true; } return false; } public boolean getConfirm(){ String menuKey=(String)FacesUtils.getValueInHashtableOfSession("menuKey"); if(StringUtils.isNotBlank(menuKey)){ Long pagemenuid=Long.valueOf(menuKey.trim()); List list=(List)session.get("confirm_pagemenus"); if(list!=null&&list.contains(pagemenuid)) return true; } return false; } public int getFiltertype(){ String menuKey=(String)FacesUtils.getValueInHashtableOfSession("menuKey"); if(StringUtils.isNotBlank(menuKey)){ Long pagemenuid=Long.valueOf(menuKey.trim()); Pagemenu pagemenu=pagemenuService.get(pagemenuid); return pagemenu.getFiltertype(); } return 0; } public List<String> getTagList(){ String menuKey=(String)FacesUtils.getValueInHashtableOfSession("menuKey"); if(StringUtils.isNotBlank(menuKey)){ Long pagemenuid=Long.valueOf(menuKey.trim()); Pagemenu pagemenu=pagemenuService.get(pagemenuid); if(pagemenu.getUsertags()!=null) return Arrays.asList(pagemenu.getUsertags()); } return null; } public EventStepService eventStepService; public EventsService eventsService; private PagemenuService pagemenuService; public SysUsersService sysusersService; public SjyhxxbService sjyhxxbService; public SjfjbService sjfjbService; public SysUsers sysUsers; public String selectUser(){ sysUsers=sysusersService.get(sysUsers.getUserid()); //人员基本信息 jtcyqklist = jtcyqkService.getByHql("from Jtcyqk t where t.qykrybh = ? ", new Object[]{sysUsers.getUserid()}); rhhjlblist = rhhjlbService.getByHql("from Rhhjlb t where t.qykrybh = ?", new Object[]{sysUsers.getUserid()}); rwqjllist = rwqjlService.getByHql("from Rwqjl t where t.qykrybh = ?", new Object[]{sysUsers.getUserid()}); shgxqklist = shgxqkService.getByHql("from Shgxqk t where t.qykrybh = ?", new Object[]{sysUsers.getUserid()}); jcxxlist = jcxxService.getByHql("from Jcxx t where t.qykrybh = ?", new Object[]{sysUsers.getUserid()}); return "edit"; } public String selectUser2(String eid){ //人员基本信息 jtcyqklist = jtcyqkeventService.getByHql("from Jtcyqkevent t where t.eid = ? ", new Object[]{eid}); rhhjlblist = rhhjlbeventService.getByHql("from Rhhjlbevent t where t.eid = ?", new Object[]{eid}); rwqjllist = rwqjleventService.getByHql("from Rwqjlevent t where t.eid = ?", new Object[]{eid}); shgxqklist = shgxqkeventService.getByHql("from Shgxqkevent t where t.eid = ?", new Object[]{eid}); jcxxlist = jcxxeventService.getByHql("from Jcxxevent t where t.eid = ?", new Object[]{eid}); return "edit"; } public SysUsers getSysUsers() { return sysUsers; } public void setSysUsers(SysUsers sysUsers) { this.sysUsers = sysUsers; } public void setSysusersService(SysUsersService sysusersService) { this.sysusersService = sysusersService; } public void setPagemenuService(PagemenuService pagemenuService) { this.pagemenuService = pagemenuService; } public void setSjyhxxbService(SjyhxxbService sjyhxxbService) { this.sjyhxxbService = sjyhxxbService; } public void setEventStepService(EventStepService eventStepService) { this.eventStepService = eventStepService; } public void setEventsService(EventsService eventsService) { this.eventsService = eventsService; } public List<EventStep> list; public List<EventStep> getList() { return list; } public void setList(List<EventStep> list) { this.list = list; } public List<Sjfjb> filelist; public List<Sjfjb> getFilelist() { return filelist; } public void setFilelist(List<Sjfjb> filelist) { this.filelist = filelist; } public File[] files; // 上传的文件 public String[] filesFileName; // 文件名称 public String[] filesContentType; // 文件类型 public int[] yxxzs; public File[] getFiles() { return files; } public void setFiles(File[] files) { this.files = files; } public String[] getFilesContentType() { return filesContentType; } public void setFilesContentType(String[] filesContentType) { this.filesContentType = filesContentType; } public String[] getFilesFileName() { return filesFileName; } public void setFilesFileName(String[] filesFileName) { this.filesFileName = filesFileName; } public int[] getYxxzs() { return yxxzs; } public void setYxxzs(int[] yxxzs) { this.yxxzs = yxxzs; } public void setSjfjbService(SjfjbService sjfjbService) { this.sjfjbService = sjfjbService; } public JtcyqkeventService getJtcyqkeventService() { return jtcyqkeventService; } public void setJtcyqkeventService(JtcyqkeventService jtcyqkeventService) { this.jtcyqkeventService = jtcyqkeventService; } public RhhjlbeventService getRhhjlbeventService() { return rhhjlbeventService; } public void setRhhjlbeventService(RhhjlbeventService rhhjlbeventService) { this.rhhjlbeventService = rhhjlbeventService; } public RwqjleventService getRwqjleventService() { return rwqjleventService; } public void setRwqjleventService(RwqjleventService rwqjleventService) { this.rwqjleventService = rwqjleventService; } public ShgxqkeventService getShgxqkeventService() { return shgxqkeventService; } public void setShgxqkeventService(ShgxqkeventService shgxqkeventService) { this.shgxqkeventService = shgxqkeventService; } public JcxxeventService getJcxxeventService() { return jcxxeventService; } public void setJcxxeventService(JcxxeventService jcxxeventService) { this.jcxxeventService = jcxxeventService; } public EventStepService getEventStepService() { return eventStepService; } public EventsService getEventsService() { return eventsService; } public SysUsersService getSysusersService() { return sysusersService; } public SjyhxxbService getSjyhxxbService() { return sjyhxxbService; } public SjfjbService getSjfjbService() { return sjfjbService; } public JtcyqkService getJtcyqkService() { return jtcyqkService; } public void setJtcyqkService(JtcyqkService jtcyqkService) { this.jtcyqkService = jtcyqkService; } public RhhjlbService getRhhjlbService() { return rhhjlbService; } public void setRhhjlbService(RhhjlbService rhhjlbService) { this.rhhjlbService = rhhjlbService; } public RwqjlService getRwqjlService() { return rwqjlService; } public void setRwqjlService(RwqjlService rwqjlService) { this.rwqjlService = rwqjlService; } public ShgxqkService getShgxqkService() { return shgxqkService; } public void setShgxqkService(ShgxqkService shgxqkService) { this.shgxqkService = shgxqkService; } public JcxxService getJcxxService() { return jcxxService; } public void setJcxxService(JcxxService jcxxService) { this.jcxxService = jcxxService; } public List<Jtcyqk> getJtcyqklist() { return jtcyqklist; } public void setJtcyqklist(List<Jtcyqk> jtcyqklist) { this.jtcyqklist = jtcyqklist; } public List<Rhhjlb> getRhhjlblist() { return rhhjlblist; } public void setRhhjlblist(List<Rhhjlb> rhhjlblist) { this.rhhjlblist = rhhjlblist; } public List<Rwqjl> getRwqjllist() { return rwqjllist; } public void setRwqjllist(List<Rwqjl> rwqjllist) { this.rwqjllist = rwqjllist; } public List<Shgxqk> getShgxqklist() { return shgxqklist; } public void setShgxqklist(List<Shgxqk> shgxqklist) { this.shgxqklist = shgxqklist; } public List<Jcxx> getJcxxlist() { return jcxxlist; } public void setJcxxlist(List<Jcxx> jcxxlist) { this.jcxxlist = jcxxlist; } public String[] getIdss() { return idss; } public void setIdss(String[] idss) { this.idss=idss; } public String getIdsString() { return idsString; } public void setIdsString(String idsString) { this.idsString = idsString; String[] ss = idsString.split(","); setIdss(ss); } }