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

📄 affairreqaction.java

📁 基于J2EE的办公自动化系统。实现流程定义流程办理等。运用了hibernate+struts+spring框架综合运用的系统。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
//Created by MyEclipse Struts
// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_4.1.0/xslt/JavaClass.xsl

package com.oa.module.affair.affairreq;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.apache.struts.upload.FormFile;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
import com.oa.module.affair.affair.Transstep;
import com.oa.module.affair.affairdao.IAffair;
import com.oa.module.affair.affairtype.AffairTypeForm;
import com.oa.module.affair.affairtype.Transtype;
import com.oa.module.office.user.Tuser;

/**
 * 事务发起ACTION
 * @author admin
 *
 */
public class AffairReqAction extends DispatchAction {

	// --------------------------------------------------------- Instance Variables
	private IAffair affairdao ;
	private ReqPage reqpage;
	// --------------------------------------------------------- Methods

	/** 
	 * Method execute
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward init(
		ActionMapping mapping,
		ActionForm form,
		HttpServletRequest request,
		HttpServletResponse response) {
		AffairReqForm affairReqForm = (AffairReqForm) form;
		HttpSession httpsession  = request.getSession();
		PrintWriter out = null;
		try {
			out = response.getWriter();
		} catch (IOException e1) {
			// TODO 自动生成 catch 块
			e1.printStackTrace();
		}
		Tuser user = (Tuser)httpsession.getAttribute("user");
		if (user != null) {
			List list = affairdao.init(String.valueOf(user.getUno()));
			request.setAttribute("affair", list);
			return new ActionForward("/Jsp_file/affair/affairreq.jsp");
		} else {
			out.print("<script>alert('登录时间过期,请重新登录');"
					+ "window.top.location.href='" + request.getContextPath()
					+ "/Jsp_file/login/login.jsp';");
			out.print("</script>");
		}
		return null;
	}

	
	public ActionForward getReqList(
			ActionMapping mapping,
			ActionForm form,
			HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
			AffairReqForm affairReqForm = (AffairReqForm) form;	
			request.setCharacterEncoding("GBK");
			response.setCharacterEncoding("GBK");
			HttpSession httpsession  = request.getSession();
			Tuser user = (Tuser)httpsession.getAttribute("user");	
			PrintWriter out = null;
			try {
				out = response.getWriter();
			} catch (IOException e1) {
				// TODO 自动生成 catch 块
				e1.printStackTrace();
			}

			if (user != null) {				
				
				int currentPage = 1;
				try {
					currentPage = Integer.parseInt(request.getParameter("currentPage"));
				} catch (Exception e) {
					currentPage = 1;
				}
				int count = 10;
				String username = request.getParameter("reqUsername");
				String rgrade = request.getParameter("rgrade");
				String starttime = request.getParameter("starttime");
				String endtime = request.getParameter("endtime");
				Transreq reqbean = new Transreq();				
				reqbean.setReqUsername(username);				
				reqbean.setRstatus(rgrade);
				reqbean.setRstarttime(starttime);
				reqbean.setRendtime(endtime);				
				List reqList = affairdao.reqList(currentPage,count,reqbean,request);
				String sql =""; 
				String centent = "";				
				String path = request.getContextPath()+"/affairReq.do?task=getReqList&";
				sql ="select count(*) from transreq req";
				sql =sql + " inner join tuser usr on req.uno =  usr.uno ";
				sql =sql +" inner join transtype typ on typ.rtid = req.tno where 1=1 and req.rstatus = '0' ";

				if(username!=null&&!username.trim().equals("")){
					centent=centent+" and usr.utruename like '%"+username.trim()+"%'";
					path = path+"reqUsername="+username+"&";
				}
				if(rgrade !=null && !rgrade.trim().equals("")){
					centent=centent+" and req.rgrade ='"+rgrade.trim()+"'";
					path = path+"rgrade="+rgrade+"&";
				}
				if(starttime!=null &&!starttime.trim().equals("")){
					centent=centent+" and req.rlasttime between'"+starttime.trim()+"'";
					centent=centent+" and '"+endtime.trim()+"'";
					path = path+"starttime="+starttime+"&";
					path = path+"endtime="+endtime+"&";
				}
				sql =sql +centent;
				
				ReqPage reqpages = reqpage.getPage(currentPage,count,sql);
				reqpages.setPath(path);				
				request.setAttribute("reqList",reqList);				
				request.setAttribute("reqpage", reqpages);			
				return mapping.findForward("getlist");
								

			} else {
				out.print("<script>alert('登录时间过期,请重新登录');"
						+ "window.top.location.href='" + request.getContextPath()
						+ "/Jsp_file/login/login.jsp';");
				out.print("</script>");
			}
			return null;
		}
	
	public ActionForward transreq(
			ActionMapping mapping,
			ActionForm form,
			HttpServletRequest request,
			HttpServletResponse response) {
			AffairReqForm affairReqForm = (AffairReqForm) form;			
			PrintWriter out = null;
			try {
				out = response.getWriter();
			} catch (IOException e1) {
				// TODO 自动生成 catch 块
				e1.printStackTrace();
			}
			HttpSession httpsession  = request.getSession();
			Tuser user = (Tuser)httpsession.getAttribute("user");	
			if (user != null) {
				affairReqForm.setUno(user.getUno());
				affairReqForm.setRstatus("0");
				boolean flag = affairdao.AffairReq(affairReqForm ,request);				
				if (flag == true) {
					out.print("<script>alert('发起事务成功'); if (confirm('是否要继续发起事务?(选择否则返回首页)')){ window.location.href='"
							+ request.getContextPath()
							+ "/affairReq.do?task=init'}else {"
							+ "window.location.href='"
							+ request.getContextPath()
							+ "/login.do?method=main'}");
					out.print("</script>");				
				} else {
					out.print("<script>alert('发起事务失败');" + "window.history.back()");
					out.print("</script>");
				}
			} else {
				out.print("<script>alert('登录时间过期,请重新登录');"
						+ "window.top.location.href='" + request.getContextPath()
						+ "/Jsp_file/login/login.jsp';");
				out.print("</script>");
			}
			return null;
	
	}
	
	
	public ActionForward getProcessers(
			ActionMapping mapping,
			ActionForm form,
			HttpServletRequest request,
			HttpServletResponse response) {
			AffairReqForm affairReqForm = (AffairReqForm) form;
			String type = request.getParameter("type");
			String rtid = request.getParameter("rtid");
			String step = request.getParameter("step");
			Map affair = affairdao.getaffair(rtid);
			int steps = Integer.parseInt(affair.get("tstep").toString());
			String dir = servlet.getServletContext().getRealPath("upload")+"\\affairXml"+ File.separator+affair.get("txmlpath").toString();
			List stepList = affairdao.getSteps(dir, steps);
			Document doc = new Document();
			Map affairType = (Map) stepList.get(Integer.parseInt(step));			
			if (type.equals("role")) {
				Element root = new Element("role");
				if (affairType.get("roleid") != null&& !affairType.get("roleid").toString().equals("")) {
					
					String[] roleids = affairType.get("roleid").toString().split(",");
					String[] rolenames = affairType.get("rolename").toString().split(",");
					List list = affairdao.getroles(affairType.get("roleid").toString());
					Iterator iter = list.iterator();
					//以下出错
					for (int i = 0; i < roleids.length; i++) {
						Element roleid = new Element("roleid");
						roleid.setAttribute("id", roleids[i]);
						roleid.setAttribute("rolename", rolenames[i]);
						if (iter.hasNext()) {
							iter.next();
							String[] userids = ((Map) list.get(i)).get("userid").toString().split(",");
							String[] usernames = ((Map) list.get(i)).get("username").toString().split(",");
							for (int j = 0; j < userids.length; j++) {
								Element userid = new Element("userid");
								userid.setAttribute("id", userids[j]);
								userid.setAttribute("username", usernames[j]);
								roleid.addContent(userid);
							}
						}
						root.addContent(roleid);
					}
				}
				doc.addContent(root);

			} else {
				Element root = new Element("users");
				if (affairType.get("userid") != null
						&& !affairType.get("userid").toString().equals("")) {
					String[] userids = affairType.get("userid").toString().split(",");
					String[] usernames = affairType.get("username").toString().split(",");
					for (int i = 0; i < userids.length; i++) {
						Element userid = new Element("userid");
						userid.setAttribute("id", userids[i]);
						userid.setText(usernames[i]);
						root.addContent(userid);

					}
				}
				doc.addContent(root);

			}

			response.setContentType("application/xml;charset=GB2312");
			Format format = Format.getPrettyFormat();
			format.setEncoding("GB2312");
			XMLOutputter outer = new XMLOutputter(format);
			try {
				outer.output(doc, response.getWriter());
			} catch (IOException e) {
				// TODO 自动生成 catch 块
				e.printStackTrace();
			}

			return null;
			
		}
	public ActionForward gettoAudit(
			ActionMapping mapping,
			ActionForm form,
			HttpServletRequest request,
			HttpServletResponse response) {
			AffairReqForm affairReqForm = (AffairReqForm) form;	
			PrintWriter out = null;
			try {
				out = response.getWriter();
			} catch (IOException e1) {
				// TODO 自动生成 catch 块
				e1.printStackTrace();
			}
			HttpSession httpsession  = request.getSession();
			Tuser user = (Tuser)httpsession.getAttribute("user");
			if (user != null) {
									
				List auditlist = affairdao.getaudit(request);					
				request.setAttribute("audit", auditlist);
				return mapping.findForward("doaudit");
			} else {
				out.print("<script>alert('登录时间过期,请重新登录');"
						+ "window.top.location.href='" + request.getContextPath()
						+ "/Jsp_file/login/login.jsp';");
				out.print("</script>");
			}
			return null;
	}
	
	
	
	public ActionForward doaudit(
			ActionMapping mapping,
			ActionForm form,
			HttpServletRequest request,
			HttpServletResponse response) {
			AffairReqForm affairReqForm = (AffairReqForm) form;
			boolean flag = false;
			PrintWriter out = null;
			try {
				out = response.getWriter();
			} catch (IOException e1) {
				// TODO 自动生成 catch 块
				e1.printStackTrace();
			}
			HttpSession httpsession  = request.getSession();
			Tuser user = (Tuser)httpsession.getAttribute("user");							
			if (user != null) {
				request.setAttribute("userid",user.getUno());
				String rqid = request.getParameter("rqid");	
				String type = request.getParameter("type");
				FormFile file = affairReqForm.getFile();
				if (file.getFileName() != null && !file.getFileName().equals("")) {
					if (file.getFileSize() > 5 * 1024 * 1024) {
						out.print("<script>alert('附件大小不能大于5M')</script>");
						out.print("<script>window.history.back()</script>");
						return null;
					} else {
						String dir = getServlet().getServletContext().getRealPath("/")+ "upload/affair";
						String filename = file.getFileName();
						String filepath = "";						
						InputStream input;
						try {
							input = file.getInputStream();
							filepath = System.currentTimeMillis()+ filename.substring(filename.lastIndexOf("."), filename.length());

⌨️ 快捷键说明

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