AffairReqAction.java
资源名称:(J2EE)oa.rar [点击查看]
上传用户:lm2018
上传日期:2015-12-12
资源大小:30449k
文件大小:23k
源码类别:
Jsp/Servlet
开发平台:
Java
- //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());
- OutputStream output = new FileOutputStream(dir + "/" + filepath);
- byte[] b = new byte[10240];
- int i = 0;
- while ((i = input.read(b, 0, 10240)) != -1) {
- output.write(b, 0, i);
- }
- } catch (FileNotFoundException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- } catch (IOException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- }
- affairReqForm.setSname(filename);
- affairReqForm.setSpath(filepath);
- }
- }
- //修改环节状态
- affairdao.setread(rqid);
- //// 审核通过并未完结该事务
- if (type.equals("noEnd")){
- //审核通过
- flag = affairdao.affairPass("noend", request, affairReqForm);
- }
- //审核通过并完结该事务
- if (type.equals("End")){
- //先插入 实际完结时间 到 步骤表
- flag = affairdao.affairPass("end", request, affairReqForm);
- }
- if (flag == true) {
- out.print("<script>alert('处理事务成功'); ");
- out.print("window.location.href='"+ request.getContextPath()+ "/affairReq.do?task=getReqList'");
- out.print("</script>");
- } else {
- out.print("<script>alert('处理事务失败');" + "window.history.back()");
- out.print("</script>");
- return null;
- }
- } else {
- out.print("<script>alert('登录时间过期,请重新登录');"
- + "window.top.location.href='" + request.getContextPath()
- + "/Jsp_file/login/login.jsp';");
- out.print("</script>");
- }
- return null;
- }
- public ActionForward doaudit2(
- 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());
- OutputStream output = new FileOutputStream(dir + "/" + filepath);
- byte[] b = new byte[10240];
- int i = 0;
- while ((i = input.read(b, 0, 10240)) != -1) {
- output.write(b, 0, i);
- }
- } catch (FileNotFoundException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- } catch (IOException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- }
- affairReqForm.setSname(filename);
- affairReqForm.setSpath(filepath);
- }
- }
- //修改环节状态
- affairdao.setread(rqid);
- //// 审核不通过返回上一环节
- if (type.equals("back")){
- //审核不通过
- flag = affairdao.affairPass("back", request, affairReqForm);
- }
- //审核不通过并完结该事务
- if (type.equals("nopass")){
- //先插入 实际完结时间 到 步骤表
- flag = affairdao.affairPass("nopass", request, affairReqForm);
- }
- if (flag == true) {
- out.print("<script>alert('处理事务成功'); ");
- out.print("window.location.href='"+ request.getContextPath()+ "/affairReq.do?task=showlList'");
- out.print("</script>");
- } else {
- out.print("<script>alert('处理事务失败');" + "window.history.back()");
- out.print("</script>");
- return null;
- }
- } else {
- out.print("<script>alert('登录时间过期,请重新登录');"
- + "window.top.location.href='" + request.getContextPath()
- + "/Jsp_file/login/login.jsp';");
- out.print("</script>");
- }
- return null;
- }
- public ActionForward getmyaffair(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 rgrade = request.getParameter("rgrade");
- String starttime = request.getParameter("starttime");
- String endtime = request.getParameter("endtime");
- request.setAttribute("uno",user.getUno());
- Transreq reqbean = new Transreq();
- reqbean.setRstatus(rgrade);
- reqbean.setRstarttime(starttime);
- reqbean.setRendtime(endtime);
- List reqList = affairdao.myarrairList(currentPage,count,reqbean,request);
- String sql ="";
- String centent = "";
- String path = request.getContextPath()+"/affairReq.do?task=getmyaffair&";
- sql ="select count(*) from transreq a left join transtype b on b.rtid = a.tno ";
- sql =sql +" left join tuser c on c.uno = a.uno where c.uno = '"+user.getUno()+"'";
- if(rgrade !=null && !rgrade.trim().equals("")){
- centent=centent+" and a.rgrade ='"+rgrade.trim()+"'";
- path = path+"rgrade="+rgrade+"&";
- }
- if(starttime!=null &&!starttime.trim().equals("")){
- centent=centent+" and a.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("reqLists",reqList);
- request.setAttribute("reqpage", reqpages);
- request.setAttribute("flag", "2");
- return mapping.findForward("getmyaffair");
- } else {
- out.print("<script>alert('登录时间过期,请重新登录');"
- + "window.top.location.href='" + request.getContextPath()
- + "/Jsp_file/login/login.jsp';");
- out.print("</script>");
- }
- return null;
- }
- public ActionForward myaffair(
- 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");
- request.setAttribute("uno",user.getUno());
- Transreq reqbean = new Transreq();
- reqbean.setReqUsername(username);
- reqbean.setRstatus(rgrade);
- reqbean.setRstarttime(starttime);
- reqbean.setRendtime(endtime);
- List reqList = affairdao.myreqList(currentPage,count,reqbean,request);
- String sql ="";
- String centent = "";
- String path = request.getContextPath()+"/affairReq.do?task=myaffair&";
- sql ="select count(*) from transstep a ";
- sql =sql + " left join transreq b on a.rqid = b.rqid ";
- sql =sql + " left join tuser c on b.uno = c.uno ";
- sql =sql +" left join transtype d on d.rtid = b.tno where a.sstatus<>'0' and c.uno = '"+user.getUno()+"'";
- if(username!=null&&!username.trim().equals("")){
- centent=centent+" and c.utruename like '%"+username.trim()+"%'";
- path = path+"reqUsername="+username+"&";
- }
- if(rgrade !=null && !rgrade.trim().equals("")){
- centent=centent+" and b.rgrade ='"+rgrade.trim()+"'";
- path = path+"rgrade="+rgrade+"&";
- }
- if(starttime!=null &&!starttime.trim().equals("")){
- centent=centent+" and b.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("getmyaffair");
- } else {
- out.print("<script>alert('登录时间过期,请重新登录');"
- + "window.top.location.href='" + request.getContextPath()
- + "/Jsp_file/login/login.jsp';");
- out.print("</script>");
- }
- return null;
- }
- public ActionForward showmyaffair(
- ActionMapping mapping,
- ActionForm form,
- HttpServletRequest request,
- HttpServletResponse response) {
- AffairReqForm affairReqForm = (AffairReqForm) form;
- String rqid = request.getParameter("rqid");
- String currentid = request.getParameter("currentid");
- 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);
- request.setAttribute("rqid",rqid);
- request.setAttribute("currentid",currentid);
- return new ActionForward("/Jsp_file/affair/affairdetail.jsp");
- } else {
- out.print("<script>alert('登录时间过期,请重新登录');"
- + "window.top.location.href='" + request.getContextPath()
- + "/Jsp_file/login/login.jsp';");
- out.print("</script>");
- }
- return null;
- }
- public IAffair getAffairdao() {
- return affairdao;
- }
- public void setAffairdao(IAffair affairdao) {
- this.affairdao = affairdao;
- }
- public ReqPage getReqpage() {
- return reqpage;
- }
- public void setReqpage(ReqPage reqpage) {
- this.reqpage = reqpage;
- }
- }