AffairTypeAction.java
资源名称:(J2EE)oa.rar [点击查看]
上传用户:lm2018
上传日期:2015-12-12
资源大小:30449k
文件大小:15k
源码类别:
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.affairtype;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.io.PrintWriter;
- import java.io.UnsupportedEncodingException;
- import java.lang.reflect.InvocationTargetException;
- import java.util.List;
- import java.util.Map;
- import com.oa.module.affair.affairdao.IAffair;
- import com.oa.module.affair.affairdao.TAffair;
- import com.oa.module.affair.affairpower.Transpower;
- import com.oa.module.affair.affairtype.AffairTypeForm;
- import com.oa.module.office.role.RoleDAO;
- import com.oa.module.office.user.Tuser;
- import com.oa.module.office.user.UserDAO;
- import com.oa.util.ToolUtil;
- import com.oa.util.XPage;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.servlet.http.HttpSession;
- import org.apache.commons.beanutils.BeanUtils;
- 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.xalan.lib.Redirect;
- import org.jdom.Document;
- import org.jdom.Element;
- import org.jdom.output.Format;
- import org.jdom.output.XMLOutputter;
- import org.springframework.web.servlet.view.RedirectView;
- /**
- * 事务类别Action
- * MyEclipse Struts
- * Creation date: 01-20-2008
- *
- * XDoclet definition:
- * @struts.action path="/affairType" name="AffairTypeForm" input="/Jsp_file/affair/addtranstype.jsp" parameter="task" scope="request" validate="true"
- */
- public class AffairTypeAction extends DispatchAction {
- // --------------------------------------------------------- Instance Variables
- private IAffair affairdao ;
- private UserDAO userdao;
- private RoleDAO roledao;
- // --------------------------------------------------------- Methods
- public ActionForward getlist(
- ActionMapping mapping,
- ActionForm form,
- HttpServletRequest request,
- HttpServletResponse response) throws IllegalAccessException, InvocationTargetException{
- AffairTypeForm affairTypeForm = (AffairTypeForm) form;
- 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;
- Transtype typebean = new Transtype();
- try {
- BeanUtils.copyProperties(typebean, affairTypeForm);
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- XPage typepage = affairdao.gettypelist(currentPage, count, typebean);
- request.setAttribute("typepage", typepage);
- 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;
- }
- /**
- * Method execute
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return ActionForward
- * @throws InvocationTargetException
- * @throws IllegalAccessException
- * @throws IOException
- */
- public ActionForward addtype(
- ActionMapping mapping,
- ActionForm form,
- HttpServletRequest request,
- HttpServletResponse response) throws IllegalAccessException, InvocationTargetException{
- AffairTypeForm affairTypeForm = (AffairTypeForm) form;
- // TODO Auto-generated method stub
- String date = ToolUtil.getDate();
- String filename = System.currentTimeMillis() + ".xml";
- affairTypeForm.setTxmlpath(filename);
- affairTypeForm.setTtime(date);
- HttpSession httpsession = request.getSession();
- Tuser user = (Tuser)httpsession.getAttribute("user");
- affairTypeForm.setUno(user.getUno());
- String tstep = request.getParameter("tstep");
- int count = 0;
- if(tstep!=null){
- count = Integer.parseInt(tstep);
- }
- Transtype type = new Transtype();
- type.setTrid(request.getParameter("transroleid0"));
- BeanUtils.copyProperties(type, affairTypeForm);
- for (int i = 0; i < count; i++) {
- Transpower power = new Transpower();
- power.setTranstype(type);
- power.setTpid(i+1);
- power.setRqid(request.getParameter("roleid"+i));
- power.setUno(request.getParameter("userid"+i));
- type.getTranspower().add(power);
- }
- boolean flag = this.affairdao.addAffairType(type,request);
- ;
- String[] transroleid = request.getParameter("transroleid0").split(",");
- this.affairdao.addtyperole(type.getRtid(),transroleid);
- if (flag == true) {
- //把事务环节写到XML文件
- Document doc = new Document();
- Element root = new Element("steps");
- int stepCount = Integer.valueOf(request.getParameter("tstep")).intValue();
- for (int i = 0; i < stepCount; i++) {
- Element step = new Element("step");
- Element id = new Element("id");
- id.setText("" + (i + 1));
- Element userid = new Element("userid");
- userid.setText(request.getParameter("userid" + i));
- Element roleid = new Element("roleid");
- roleid.setText(request.getParameter("roleid" + i));
- step.addContent(id);
- step.addContent(userid);
- step.addContent(roleid);
- root.addContent(step);
- }
- doc.addContent(root);
- Format format = Format.getCompactFormat();
- format.setIndent(" ");
- format.setEncoding("gb2312");
- XMLOutputter out = new XMLOutputter(format);
- OutputStream fileout = null;
- String path = servlet.getServletContext().getRealPath("upload")+"/affairXml/" + File.separator + filename;
- try {
- fileout = new FileOutputStream(path);
- out.output(doc, fileout);
- response.getWriter().println("<script>alert('添加成功');");
- response.getWriter().println("</script>");
- affairTypeForm.setTask("getlist");
- return mapping.findForward("getlist");
- } catch (FileNotFoundException e) {
- try {
- response.getWriter().print("<script>alert('添加失败');window.history.back();</script>");
- } catch (IOException e1) {
- // TODO 自动生成 catch 块
- e1.printStackTrace();
- }
- // TODO 自动生成 catch 块
- e.printStackTrace();
- } catch (IOException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- }
- }
- return null;
- }
- public ActionForward edittype(
- ActionMapping mapping,
- ActionForm form,
- HttpServletRequest request,
- HttpServletResponse response) throws IllegalAccessException, InvocationTargetException{
- AffairTypeForm affairTypeForm = (AffairTypeForm) form;
- String transID = request.getParameter("rtid");
- boolean flag = this.affairdao.isused(transID);
- if (flag == true) {
- request.setAttribute("msg","该事务正在使用中,不能进行修改");
- return new ActionForward("/Jsp_file/msg.jsp");
- } else {
- Map transrole = affairdao.getrole(transID);
- Map affair = affairdao.getaffair(transID);
- int count = Integer.valueOf(affair.get("tstep").toString()).intValue();
- String dir = servlet.getServletContext().getRealPath("upload")+ "\affairXml" + File.separator+ affair.get("txmlpath").toString();
- List translist= affairdao.getSteps(dir, count);
- if(translist==null){
- request.setAttribute("msg","找不到该XML文件");
- return new ActionForward("/Jsp_file/msg.jsp");
- }else{
- request.setAttribute("translist", translist);
- affairTypeForm.setTname(affair.get("tname").toString());
- affairTypeForm.setRtid(Integer.parseInt(transID));
- request.setAttribute("transrole", transrole);
- request.setAttribute("rtid",transID);
- affairTypeForm.setTask("editedtype");
- }
- return mapping.findForward("edit");
- }
- }
- public ActionForward editedtype(
- ActionMapping mapping,
- ActionForm form,
- HttpServletRequest request,
- HttpServletResponse response) throws IllegalAccessException, InvocationTargetException{
- AffairTypeForm affairTypeForm = (AffairTypeForm) form;
- System.out.println("edited");
- String transID = request.getParameter("rtid");
- String filename = System.currentTimeMillis() + ".xml";
- String dir = servlet.getServletContext().getRealPath("upload")+ "\affairXml";
- affairTypeForm.setTxmlpath(filename);
- affairTypeForm.setRtid(Integer.parseInt(transID));
- //先删除后再重新添加
- boolean isdel = false;
- boolean flag0 = affairdao.deltyperole(transID);
- if(flag0){
- isdel = affairdao.delaffair(transID,dir);
- }
- if(isdel){
- String date = ToolUtil.getDate();
- affairTypeForm.setTtime(date);
- HttpSession httpsession = request.getSession();
- Tuser user = (Tuser)httpsession.getAttribute("user");
- affairTypeForm.setUno(user.getUno());
- String tstep = request.getParameter("tstep");
- int count = 0;
- if(tstep!=null){
- count = Integer.parseInt(tstep);
- }
- Transtype type = new Transtype();
- type.setTrid(request.getParameter("transroleid0"));
- BeanUtils.copyProperties(type, affairTypeForm);
- for (int i = 0; i < count; i++) {
- Transpower power = new Transpower();
- power.setTranstype(type);
- power.setTpid(i+1);
- power.setRqid(request.getParameter("roleid"+i));
- power.setUno(request.getParameter("userid"+i));
- type.getTranspower().add(power);
- }
- boolean flag = this.affairdao.addAffairType(type,request);
- String[] transroleid = request.getParameter("transroleid0").split(",");
- this.affairdao.addtyperole(type.getRtid(),transroleid);
- if (flag == true) {
- //把事务环节写到XML文件
- Document doc = new Document();
- Element root = new Element("steps");
- int stepCount = Integer.valueOf(request.getParameter("tstep")).intValue();
- for (int i = 0; i < stepCount; i++) {
- Element step = new Element("step");
- Element id = new Element("id");
- id.setText("" + (i + 1));
- Element userid = new Element("userid");
- userid.setText(request.getParameter("userid" + i));
- Element roleid = new Element("roleid");
- roleid.setText(request.getParameter("roleid" + i));
- step.addContent(id);
- step.addContent(userid);
- step.addContent(roleid);
- root.addContent(step);
- }
- doc.addContent(root);
- Format format = Format.getCompactFormat();
- format.setIndent(" ");
- format.setEncoding("gb2312");
- XMLOutputter out = new XMLOutputter(format);
- OutputStream fileout = null;
- String path = servlet.getServletContext().getRealPath("upload")+"\affairXml" + File.separator + filename;
- try {
- fileout = new FileOutputStream(path);
- out.output(doc, fileout);
- response.getWriter().println("<script>alert('修改成功');");
- response.getWriter().println("</script>");
- affairTypeForm.setTask("getlist");
- return mapping.findForward("query");
- } catch (FileNotFoundException e) {
- try {
- response.getWriter().print("<script>alert('修改失败');window.history.back();</script>");
- } catch (IOException e1) {
- // TODO 自动生成 catch 块
- e1.printStackTrace();
- }
- // TODO 自动生成 catch 块
- e.printStackTrace();
- } catch (IOException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- }
- }
- }
- return null;
- }
- public ActionForward deltype(
- ActionMapping mapping,
- ActionForm form,
- HttpServletRequest request,
- HttpServletResponse response) throws IllegalAccessException, InvocationTargetException{
- AffairTypeForm affairTypeForm = (AffairTypeForm) form;
- System.out.println("deltype");
- String transID = request.getParameter("rtid");
- String dir = servlet.getServletContext().getRealPath("upload")+ "/affairXml";
- affairTypeForm.setRtid(Integer.parseInt(transID));
- try {
- boolean isdel = false;
- boolean flag0 = affairdao.deltyperole(transID);
- if(flag0){
- isdel = affairdao.delaffair(transID,dir);
- }
- if(isdel){
- response.getWriter().println("<script>alert('删除成功');");
- response.getWriter().println("</script>");
- affairTypeForm.setTask("getlist");
- return mapping.findForward("query");
- }else{
- response.getWriter().print("<script>alert('删除失败');window.history.back();</script>");
- }
- }catch (IOException e) {
- try {
- response.getWriter().print("<script>alert('删除失败');window.history.back();</script>");
- } catch (IOException e1) {
- // TODO 自动生成 catch 块
- e1.printStackTrace();
- }
- // TODO 自动生成 catch 块
- e.printStackTrace();
- }
- return null;
- }
- public ActionForward getUserRole(
- ActionMapping mapping,
- ActionForm form,
- HttpServletRequest request,
- HttpServletResponse response) throws UnsupportedEncodingException {
- request.setCharacterEncoding("GBK");
- response.setCharacterEncoding("GBK");
- AffairTypeForm affairTypeForm = (AffairTypeForm) form;
- List list = null;
- String type = request.getParameter("type");
- String name = request.getParameter("name");
- if (type.equals("user")) {
- list = this.userdao.getuser();
- } else {
- list = this.roledao.getrole();
- }
- request.setAttribute("list", list);
- request.setAttribute("type", type);
- request.setAttribute("id", name);
- return new ActionForward("/Jsp_file/affair/roleuser.jsp");
- }
- public ActionForward checkname(
- ActionMapping mapping,
- ActionForm form,
- HttpServletRequest request,
- HttpServletResponse response) throws UnsupportedEncodingException {
- request.setCharacterEncoding("GBK");
- response.setCharacterEncoding("GBK");
- AffairTypeForm affairTypeForm = (AffairTypeForm) form;
- try {
- PrintWriter out = response.getWriter();
- String type = request.getParameter("type");
- String message = null;
- boolean flag = true;
- flag = this.affairdao.checkName(affairTypeForm);
- if(type!=null){
- if(type.equals("add")){
- if(flag){
- message ="<a style='color: red' >名称被使用了</a>";
- } else {
- message = "<a style='color: #00cc00' >名称可以使用</a>";
- }
- }else if(type.equals("edit")){
- String rtid = request.getParameter("rtid");
- Map bean = affairdao.getaffair(rtid);
- String oldname = (String) bean.get("tname");
- System.out.println(oldname);
- if(affairTypeForm.getTname().equals(oldname)){
- message = "<a style='color: #00cc00' >名称可以修改</a>";
- }else{
- if(flag){
- message ="<a style='color: red' >名称被使用了</a>";
- } else {
- message = "<a style='color: #00cc00' >名称可以使用</a>";
- }
- }
- }
- out.print(message);
- out.flush();
- out.close();
- }
- } catch (IOException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- }
- return null;
- }
- public IAffair getAffairdao() {
- return affairdao;
- }
- public void setAffairdao(IAffair affairdao) {
- this.affairdao = affairdao;
- }
- public UserDAO getUserdao() {
- return userdao;
- }
- public void setUserdao(UserDAO userdao) {
- this.userdao = userdao;
- }
- public RoleDAO getRoledao() {
- return roledao;
- }
- public void setRoledao(RoleDAO roledao) {
- this.roledao = roledao;
- }
- }