MeetAction.java
资源名称:(J2EE)oa.rar [点击查看]
上传用户:lm2018
上传日期:2015-12-12
资源大小:30449k
文件大小:21k
源码类别:
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.meet.struts.action;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.io.PrintWriter;
- import java.lang.reflect.InvocationTargetException;
- import java.util.ArrayList;
- import java.util.Enumeration;
- import java.util.HashMap;
- import java.util.Hashtable;
- import java.util.Iterator;
- import java.util.List;
- import java.util.Map;
- import java.util.Set;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- 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.struts.upload.FormFile;
- import com.oa.module.meet.hibernate.Tmeet;
- import com.oa.module.meet.meetdao.Interfer;
- import com.oa.module.meet.struts.form.MeetForm;
- import com.oa.module.pub.ectomere.XPage;
- import com.oa.util.PubUtil;
- import com.oa.util.ToolUtil;
- /**
- * MyEclipse Struts Creation date: 01-17-2008
- *
- * XDoclet definition:
- *
- * @struts.action path="/meet" name="meetForm"
- * input="/Jsp_file/meet/meetlist.jsp" parameter="task"
- * scope="request" validate="true"
- */
- public class MeetAction extends DispatchAction {
- // --------------------------------------------------------- Instance
- // Variables
- private Interfer meetinter;
- // --------------------------------------------------------- Methods
- /**
- * Method execute
- *
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return ActionForward
- */
- public ActionForward query(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- MeetForm meetForm = (MeetForm) form;
- String uno = request.getParameter("uno");
- int currentPage = 1;
- try {
- currentPage = Integer.parseInt(request.getParameter("currentPage"));
- } catch (Exception e) {
- currentPage = 1;
- }
- int count = 5;
- Tmeet info = new Tmeet();
- info.setUno(uno);
- // 拷贝查询参数
- try {
- BeanUtils.copyProperties(info, meetForm);
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- XPage itempage = meetinter.getItemlist(currentPage, count, info);
- request.setAttribute("meetpage", itempage);
- List addrlist = meetinter.addrlist();
- request.setAttribute("addrlist", addrlist);
- return mapping.findForward("meetlist");
- }
- /**
- * 添加会议处理
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- */
- public ActionForward add(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- MeetForm meetForm = (MeetForm) form;
- PrintWriter out = null;
- try {
- out = response.getWriter();
- } catch (IOException e1) {
- e1.printStackTrace();
- }
- Hashtable fileh = meetForm.getMultipartRequestHandler()
- .getFileElements();
- String filePath = "";
- String filenames = "";
- String filepaths = "";
- int i = 0;
- for (Enumeration e = fileh.keys(); e.hasMoreElements();) {
- filePath = "";
- filePath = servlet.getServletContext().getRealPath(
- "/upload/meetfile/");// 取当前系统路径
- String key = (String) e.nextElement();
- Set set = fileh.entrySet();
- Iterator iterator = set.iterator();
- while (iterator.hasNext()) {
- Map.Entry entry = (Map.Entry) iterator.next();
- if (entry.getValue() != "") {
- FormFile file = (FormFile) entry.getValue();
- if (file.getFileSize() > 5000000) {
- out
- .println("<script>alert('上传的附件大小不能大于5M');window.history.back();</script>");
- return null;
- }
- }
- }
- try {
- FormFile file = (FormFile) fileh.get(key);
- String filename = file.getFileName().trim();
- if (filename != null && !filename.equals("")) {
- filenames = filenames + filename + ",";
- String temp = filename.substring(filename.lastIndexOf("."),
- filename.length());
- String filepath = System.currentTimeMillis() + i + temp;
- filepaths = filepaths + filepath + ",";
- InputStream stream = file.getInputStream();
- filePath = filePath + "\" + filepath;
- OutputStream outstream = new FileOutputStream(filePath);
- int byteread = 0;
- byte[] buffer = new byte[8192];
- while ((byteread = stream.read(buffer, 0, 8192)) != -1) {
- outstream.write(buffer, 0, byteread);
- }
- meetForm.setMiaffix(1);
- outstream.close();
- stream.close();
- }
- } catch (Exception e1) {
- e1.printStackTrace();
- }
- i++;
- }
- if (!filenames.equals("") && !filepaths.equals("")) {
- filenames = filenames.substring(0, filenames.length() - 1);
- filepaths = filepaths.substring(0, filepaths.length() - 1);
- }
- meetForm.setMaffixname(filenames);
- meetForm.setMaffixpath(filepaths);
- String[] temp = request.getParameterValues("addmeet");
- String adduser = null;
- if (temp != null) {
- for (int t = 0; t < temp.length; t++) {
- if (adduser != null && !adduser.equals("")) {
- adduser = adduser + ',' + temp[t];
- } else {
- adduser = temp[t];
- }
- }
- }
- meetForm.setMunos(adduser);
- Tmeet meet = new Tmeet();
- try {
- BeanUtils.copyProperties(meet, meetForm);
- } catch (IllegalAccessException e1) {
- // TODO 自动生成 catch 块
- e1.printStackTrace();
- } catch (InvocationTargetException e1) {
- // TODO 自动生成 catch 块
- e1.printStackTrace();
- }
- boolean flag = meetinter.great(meet);
- if (flag) {
- return new ActionForward("/meet.do?task=query", true);
- } else {
- return mapping.getInputForward();
- }
- }
- /**
- * 修改时显示会议信息
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- */
- public ActionForward init(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- MeetForm meetForm = (MeetForm) form;
- Tmeet meet = meetinter.getItemById(meetForm.getMid());
- try {
- BeanUtils.copyProperties(meetForm, meet);
- } catch (IllegalAccessException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- }
- //
- // List listuser1 = meetinter.getuserlist(meetForm.getMid());
- // request.setAttribute("listuser1",listuser1);//主持 人
- List listuser = meetinter.userlist();
- request.setAttribute("listuser1", listuser);// 所有 员工
- List list = meetinter.listbyid(meetForm.getMid());
- if (list != null && list.size() > 0) {
- Map map = (Map) list.get(0);
- String temp = map.get("munos").toString();
- String[] user = temp.split(",");
- List addmeet = new ArrayList();
- for (int i = 0; i < user.length; i++) {
- Map tempadd = meetinter.addmeet(user[i]);
- addmeet.add(tempadd);
- System.out.println(addmeet);
- }
- request.setAttribute("addmeet", addmeet);
- meetForm.setRmid(Long.parseLong(map.get("rmid").toString()));
- List userlist = meetinter.userlist();
- for (int i = 0; i < user.length; i++) {
- for (int j = 0; j < userlist.size(); j++) {
- Map tempmap = (Map) userlist.get(j);
- String id = tempmap.get("uno").toString();
- if (user[i].equals(id)) {
- userlist.remove(j);
- break;
- }
- }
- }
- request.setAttribute("listuser", userlist);
- if (map.get("maffixname") != null && map.get("maffixpath") != null) {
- String fname = map.get("maffixname").toString();
- String fpath = map.get("maffixpath").toString();
- String[] fnames = fname.split(",");
- String[] fpaths = fpath.split(",");
- List filelist = new ArrayList();
- for (int i = 0; i < fpaths.length; i++) {
- Map tempmap = new HashMap();
- tempmap.put("maffixname", fnames[i]);
- tempmap.put("maffixpath", fpaths[i]);
- filelist.add(tempmap);
- }
- request.setAttribute("filelist", filelist);
- request.setAttribute("size", String.valueOf(fnames.length));
- }
- }
- meetForm.setTask("edit");
- return mapping.getInputForward();
- }
- /**
- * 会议详细信息
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- */
- public ActionForward look(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- MeetForm meetForm = (MeetForm) form;
- Tmeet meet = meetinter.getItemById(meetForm.getMid());
- try {
- BeanUtils.copyProperties(meetForm, meet);
- } catch (IllegalAccessException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- }
- //
- // List listuser1 = meetinter.getuserlist(meetForm.getMid());
- // request.setAttribute("listuser1",listuser1);//主持 人
- List listuser = meetinter.userlist();
- request.setAttribute("listuser1", listuser);// 所有 员工
- List list = meetinter.listbyid(meetForm.getMid());
- if (list != null && list.size() > 0) {
- Map map = (Map) list.get(0);
- String temp = map.get("munos").toString();
- String[] user = temp.split(",");
- List addmeet = new ArrayList();
- for (int i = 0; i < user.length; i++) {
- Map tempadd = meetinter.addmeet(user[i]);
- addmeet.add(tempadd);
- System.out.println(addmeet);
- }
- request.setAttribute("addmeet", addmeet);
- // meetForm.setMstarttime(map.get("mstarttime").toString());
- // meetForm.setMendtime(map.get("mendtime").toString());
- // meetForm.setMcontent(map.get("mcontent").toString());
- meetForm.setRmid(Long.parseLong(map.get("rmid").toString()));
- List userlist = meetinter.userlist();
- for (int i = 0; i < user.length; i++) {
- for (int j = 0; j < userlist.size(); j++) {
- Map tempmap = (Map) userlist.get(j);
- String id = tempmap.get("uno").toString();
- if (user[i].equals(id)) {
- userlist.remove(j);
- break;
- }
- }
- }
- request.setAttribute("listuser", userlist);
- if (map.get("maffixname") != null && map.get("maffixpath") != null) {
- String fname = map.get("maffixname").toString();
- String fpath = map.get("maffixpath").toString();
- String[] fnames = fname.split(",");
- String[] fpaths = fpath.split(",");
- List filelist = new ArrayList();
- for (int i = 0; i < fpaths.length; i++) {
- Map tempmap = new HashMap();
- tempmap.put("maffixname", fnames[i]);
- tempmap.put("maffixpath", fpaths[i]);
- filelist.add(tempmap);
- }
- request.setAttribute("filelist", filelist);
- request.setAttribute("size", String.valueOf(fnames.length));
- System.out.println(String.valueOf(fnames.length));
- }
- }
- List rlist = meetinter.allroom();
- request.setAttribute("roomlist", rlist);
- return mapping.findForward("look");
- }
- /**
- * 会议修改处理
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- */
- public ActionForward edit(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- MeetForm meetForm = (MeetForm) form;
- PrintWriter out = null;
- try {
- out = response.getWriter();
- } catch (IOException e1) {
- e1.printStackTrace();
- }
- String[] temp = request.getParameterValues("addmeet");
- String adduser = null;
- if (temp != null) {
- for (int t = 0; t < temp.length; t++) {
- if (adduser != null && !adduser.equals("")) {
- adduser = adduser + ',' + temp[t];
- } else {
- adduser = temp[t];
- }
- }
- }
- meetForm.setMunos(adduser);
- List meetlist = meetinter.listbymid(String.valueOf(meetForm.getMid()));
- Map map = (Map) meetlist.get(0);
- String oldname = (String) map.get("maffixname");
- String oldpath = (String) map.get("maffixpath");
- Hashtable fileh = meetForm.getMultipartRequestHandler()
- .getFileElements();
- String filePath = "";
- String filenames = "";
- String filepaths = "";
- int i = 0;
- for (Enumeration e = fileh.keys(); e.hasMoreElements();) {
- filePath = "";
- filePath = servlet.getServletContext().getRealPath(
- "/upload/meetfile/");// 取当前系统路径
- String key = (String) e.nextElement();
- Set set = fileh.entrySet();
- Iterator iterator = set.iterator();
- while (iterator.hasNext()) {
- Map.Entry entry = (Map.Entry) iterator.next();
- if (entry.getValue() != "") {
- FormFile file = (FormFile) entry.getValue();
- if (file.getFileSize() > 5000000) {
- out
- .println("<script>alert('上传的附件大小不能大于5M');window.history.back();</script>");
- return null;
- }
- }
- }
- try {
- FormFile file = (FormFile) fileh.get(key);
- String filename = file.getFileName().trim();
- if (filename != null && !filename.equals("")) {
- filenames = filenames + filename + ",";
- String temp1 = filename.substring(filename.lastIndexOf("."),
- filename.length());
- String filepath = System.currentTimeMillis() + i + temp1;
- filepaths = filepaths + filepath + ",";
- InputStream stream = file.getInputStream();
- filePath = filePath + "\" + filepath;
- OutputStream outstream = new FileOutputStream(filePath);
- int byteread = 0;
- byte[] buffer = new byte[8192];
- while ((byteread = stream.read(buffer, 0, 8192)) != -1) {
- outstream.write(buffer, 0, byteread);
- }
- outstream.close();
- stream.close();
- }
- } catch (Exception e1) {
- e1.printStackTrace();
- }
- i++;
- }
- if (!filenames.equals("") && !filepaths.equals("")) {
- filenames = filenames.substring(0, filenames.length() - 1);
- filepaths = filepaths.substring(0, filepaths.length() - 1);
- }
- oldname = oldname + "," + filenames;
- oldpath = oldpath + "," + filepaths;
- meetForm.setMaffixname(oldname);
- meetForm.setMaffixpath(oldpath);
- Tmeet meet = new Tmeet();
- try {
- BeanUtils.copyProperties(meet,meetForm);
- } catch (IllegalAccessException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- }
- boolean flag = meetinter.update(meet);
- if (flag) {
- return new ActionForward("/meet.do?task=query", true);
- } else {
- return mapping.getInputForward();
- }
- }
- /**
- * 会议取消处理
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- */
- public ActionForward delete(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- MeetForm meetForm = (MeetForm) form;
- String mid = request.getParameter("id");
- Tmeet meet = meetinter.getItemById(Integer.parseInt(mid));
- try {
- BeanUtils.copyProperties(meetForm, meet);
- } catch (IllegalAccessException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- }
- return mapping.findForward("cancle");
- }
- /**
- * 添加时显示信息
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- */
- public ActionForward addlist(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- MeetForm meetForm = (MeetForm) form;
- List listuser = meetinter.userlist();
- request.setAttribute("listuser", listuser);
- List listuser1 = meetinter.userlist();
- request.setAttribute("listuser1", listuser1);
- meetForm.setTask("add");
- return mapping.getInputForward();
- }
- /**
- * c处理取消的原因
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- */
- public ActionForward cancle(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- MeetForm meetForm = (MeetForm) form;
- meetForm.setMcancle(1);
- meetForm.setMstatus(3);
- Tmeet meet = new Tmeet();
- try {
- BeanUtils.copyProperties(meet,meetForm);
- } catch (IllegalAccessException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- }
- boolean flag=meetinter.cancle(meet);
- if(flag){
- return new ActionForward("/meet.do?task=query",true);
- }else{
- return mapping.getInputForward();
- }
- }
- /**
- * 刷新界面
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- */
- public ActionForward shuaxin(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- MeetForm meetForm = (MeetForm) form;
- return new ActionForward("/meet?task=query", true);
- }
- /**
- * 根据时间读取会议室
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- */
- public ActionForward roomlist(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- MeetForm meetForm = (MeetForm) form;
- PrintWriter out = null;
- try {
- out = response.getWriter();
- } catch (IOException e) {
- e.printStackTrace();
- }
- response.setContentType("text/xml");
- String tbegin = request.getParameter("tbegin");
- String tend = request.getParameter("tend");
- String rid = request.getParameter("rmid");
- List uselist = null;
- if (rid != null) {
- uselist = meetinter.roomlist(tbegin, tend, rid);
- } else {
- uselist = meetinter.roomlist(tbegin, tend, null);
- }
- out.print("<?xml version="1.0" encoding="GBK"?>");
- out.print("<rooms>");
- for (int i = 0; i < uselist.size(); i++) {
- Map temp = (Map) uselist.get(i);
- String rmid = temp.get("rmid").toString();
- String rname = temp.get("rname").toString();
- out.print("<room rid="");
- out.print(rmid);
- out.print("" rname="");
- out.print(rname);
- out.print("" />");
- }
- out.print("</rooms>");
- out.flush();
- out.close();
- return null;
- }
- /**
- * 删除附件
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- */
- public ActionForward delpath(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- MeetForm meetForm = (MeetForm) form;
- String path = request.getParameter("path");
- String name = request.getParameter("name");
- String mid = request.getParameter("rmid");
- List meetlist = meetinter.listbymid(mid);
- PrintWriter out = null;
- try {
- out = response.getWriter();
- } catch (IOException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- }
- String filePath = servlet.getServletContext().getRealPath(
- "/upload/meetfile/");// 取当前系统路径
- filePath = filePath + "\" + path;
- File file = new File(filePath);
- file.delete();
- Map meetmap = (Map) meetlist.get(0);
- meetmap.get("");
- String filepaths = (String) meetmap.get("maffixpath");
- String filenames = (String) meetmap.get("maffixname");
- String[] fpath = filepaths.split(",");
- String[] fname = filenames.split(",");
- String[] newstr = new String[fpath.length];
- String[] newstr2 = new String[fname.length];
- int i = 0;
- int m = 0;
- for (int j = 0; j < fpath.length; j++) {
- if (!path.equals(fpath[j])) {
- newstr[i] = fpath[j];
- i++;
- }
- if (!name.equals(fname[j])) {
- newstr2[m] = fname[j];
- m++;
- }
- }
- String newfilepath = "";
- String newfilename = "";
- for (int k = 0; k < newstr.length; k++) {
- if (newstr[k] != null && newstr2[k] != null) {
- newfilepath = newfilepath + newstr[k] + ",";
- newfilename = newfilename + newstr2[k] + ",";
- }
- }
- if (!newfilepath.equals("") && !newfilename.equals("")) {
- newfilepath = newfilepath.substring(0, newfilepath.length() - 1);
- newfilename = newfilename.substring(0, newfilename.length() - 1);
- }
- boolean flag1 = meetinter.updatefile(request, newfilepath, newfilename,
- mid);
- if (flag1) {
- out.print("<script>");
- out.print("alert('删除附件成功!');window.history.back();");
- out.print("</script>");
- out.flush();
- out.close();
- }
- return null;
- }
- /**
- * 根据时间修改会议状态
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- */
- public ActionForward updatestatus(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- MeetForm meetForm = (MeetForm) form;
- String time = PubUtil.getNowDate();
- meetinter.updatestatus1(request,time);//修改会议状态为完成
- meetinter.updatestatus2(request,time);//修改会议状态为开始
- return null;
- }
- public Interfer getMeetinter() {
- return meetinter;
- }
- public void setMeetinter(Interfer meetinter) {
- this.meetinter = meetinter;
- }
- }