DocumentAction.java
资源名称:oa.rar [点击查看]
上传用户:kimgenplus
上传日期:2016-06-05
资源大小:20877k
文件大小:11k
源码类别:
OA系统
开发平台:
Java
- package com.bjsxt.oa.web.actions;
- import java.util.Date;
- import java.util.HashMap;
- 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.commons.beanutils.ConvertUtils;
- import org.apache.struts.action.ActionForm;
- import org.apache.struts.action.ActionForward;
- import org.apache.struts.action.ActionMapping;
- import org.apache.struts.upload.FormFile;
- import com.bjsxt.oa.managers.DocumentManager;
- import com.bjsxt.oa.managers.FormManager;
- import com.bjsxt.oa.managers.SystemException;
- import com.bjsxt.oa.managers.WorkflowManager;
- import com.bjsxt.oa.model.ApproveInfo;
- import com.bjsxt.oa.model.Document;
- import com.bjsxt.oa.model.DocumentProperty;
- import com.bjsxt.oa.model.FieldType;
- import com.bjsxt.oa.model.FlowForm;
- import com.bjsxt.oa.model.FormField;
- import com.bjsxt.oa.web.forms.DocumentActionForm;
- public class DocumentAction extends BaseAction {
- private DocumentManager documentManager;
- private WorkflowManager workflowManager;
- private FormManager formManager;
- public void setDocumentManager(DocumentManager documentManager) {
- this.documentManager = documentManager;
- }
- public void setWorkflowManager(WorkflowManager workflowManager) {
- this.workflowManager = workflowManager;
- }
- //公文管理主界面,显示我的公文列表
- @Override
- protected ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
- request.setAttribute("pm", documentManager.searchMyDocuments(currentUser(request).getId()));
- return mapping.findForward("index");
- }
- /**
- * 已审公文列表,显示由当前登录人员审核的公文列表
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- * @throws Exception
- */
- public ActionForward approvedList(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
- request.setAttribute("pm", documentManager.searchApprovedDocuments(currentUser(request).getId()));
- return mapping.findForward("approved_list");
- }
- /**
- * 待审公文列表,显示等待当前登录人员审核的公文列表
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- * @throws Exception
- */
- public ActionForward approvingList(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
- request.setAttribute("documents", documentManager.searchApprovingDocuments(currentUser(request).getId()));
- return mapping.findForward("approving_list");
- }
- /**
- * 在待审公文列表上,针对某个文档,可以点击打开审批界面,对此文档进行审批
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- * @throws Exception
- */
- public ActionForward approveInput(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
- return mapping.findForward("approve_input");
- }
- /**
- * 用户输入审批信息之后,点击保存,对文档进行审批操作
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- * @throws Exception
- */
- public ActionForward approve(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
- DocumentActionForm daf = (DocumentActionForm)form;
- String comment = daf.getApproveInfo();
- int documentId = daf.getId();
- int approverId = currentUser(request).getId();
- ApproveInfo approveInfo = new ApproveInfo();
- approveInfo.setApproveTime(new Date());
- approveInfo.setComment(comment);
- documentManager.addApproveInfo(approveInfo, documentId, approverId);
- return mapping.findForward("pub_add_success");
- }
- /**
- * 在我的公文或待审公文列表上,点击提交,可打开提交的选择界面
- * 在这个界面上,列出下一步所有可选的步骤,用户可以选择其中一个
- * 步骤进行提交操作。系统将按照用户的选择转移到下一个节点
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- * @throws Exception
- */
- public ActionForward submitInput(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
- DocumentActionForm daf = (DocumentActionForm)form;
- Document doc = documentManager.findDocument(daf.getId());
- List transitions = workflowManager.searchNextTransitions(currentUser(request).getUsername(),doc.getProcessInstanceId());
- request.setAttribute("steps", transitions);
- return mapping.findForward("submit_input");
- }
- /**
- * 用户选择了其中一个步骤,点击提交
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- * @throws Exception
- */
- public ActionForward submit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
- DocumentActionForm daf = (DocumentActionForm)form;
- // workflowManager.flowToNextStep(
- // currentUser(request).getUsername(),
- // doc.getProcessInstanceId(),
- // daf.getTransitionName());
- //
- documentManager.submitToWorkflow(currentUser(request).getId(), daf.getId(), daf.getTransitionName());
- return mapping.findForward("pub_add_success");
- }
- /**
- * 查看公文的审批历史
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- * @throws Exception
- */
- public ActionForward approvedHistory(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
- DocumentActionForm daf = (DocumentActionForm)form;
- request.setAttribute("historys", documentManager.searchApproveInfos(daf.getId()));
- return mapping.findForward("approve_history");
- }
- public ActionForward del(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
- DocumentActionForm daf = (DocumentActionForm)form;
- documentManager.delDocument(daf.getId());
- return mapping.findForward("pub_del_success");
- }
- /**
- * 点击添加公文的时候,需要选择相应的流程,此界面列出所有的流程以供选择
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- * @throws Exception
- */
- public ActionForward selectFlow(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
- request.setAttribute("workflows", workflowManager.searchAllWorkflows());
- return mapping.findForward("select_flow");
- }
- /**
- * 选择了流程之后(即点击流程名称),需要打开公文录入界面
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- * @throws Exception
- */
- public ActionForward addInput(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
- return mapping.findForward("add_input");
- }
- /**
- * 添加公文的操作
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return
- * @throws Exception
- */
- public ActionForward add(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
- DocumentActionForm daf = (DocumentActionForm)form;
- Document document = new Document();
- BeanUtils.copyProperties(document, daf);
- //处理Map的数据
- //将ActionForm中的Map的数据,按照表单定义对应的类型来进行转换,并设置到document对象即可
- if(daf.getProps().isEmpty()){
- document.setProps(null);
- }else{
- int workflowId = daf.getWorkflowId();
- //流程对应的表单定义
- FlowForm flowForm = formManager.findForm(workflowId);
- if(flowForm == null){
- document.setProps(null);
- }else{
- Map documentProps = new HashMap();
- //拿到表单定义对应的所有的域定义
- Set fields = flowForm.getFields();
- for (Iterator iter = fields.iterator(); iter.hasNext();) {
- FormField field = (FormField) iter.next();
- String propertyName = field.getFieldName();
- FieldType propertyType = field.getFieldType();
- //根据表单的属性名称,从Map中将界面上传过来的原始值拿出来
- Object source = daf.getProps().get(propertyName);
- Object target = null;
- if(source != null){
- //对于输入的字符串
- if(source instanceof String && !propertyType.getType().equals("java.io.File")){
- Class targetClass = Class.forName(propertyType.getType());
- //利用ConvertUtils工具,将从界面上传过来的字符串
- //转换为FormFiled对应的FieldType所指定类型的对象
- target = ConvertUtils.convert((String)source, targetClass);
- }
- //如果表单域是上传文件
- if(propertyType.getType().equals("java.io.File")){
- //注意:如果界面上传的是文件,struts可以自动转换为FormFile
- //类型的对象!!!!
- FormFile ff = (FormFile)source;
- target = ff.getFileData();
- }
- //现在,需要将target的值赋予document对象
- if(target == null){
- throw new SystemException("无法处理输入的值!");
- }
- DocumentProperty dp = new DocumentProperty();
- String type = propertyType.getType();
- if(type.equals("java.io.File")){
- dp.setJava_io_File((byte[])target);
- }
- if(type.equals("java.lang.Integer")){
- dp.setJava_lang_Integer((Integer)target);
- }
- if(type.equals("java.lang.String")){
- dp.setJava_lang_String((String)target);
- }
- documentProps.put(propertyName, dp);
- }
- }
- //将documentProps对象赋予document对象的props属性
- document.setProps(documentProps);
- }
- }
- if(daf.getContentFile() != null){
- document.setContent(daf.getContentFile().getFileData());
- }
- documentManager.addDocument(document, daf.getWorkflowId(), currentUser(request).getId());
- return mapping.findForward("pub_add_success");
- }
- //下载公文附件
- public ActionForward download(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
- DocumentActionForm daf = (DocumentActionForm)form;
- Document document = documentManager.findDocument(daf.getId());
- response.reset();
- response.setContentType("application/x-download;charset=GBK");
- response.setHeader("Content-Disposition", "attachment;filename=temp.doc");
- response.getOutputStream().write(document.getContent());
- response.getOutputStream().flush();
- response.getOutputStream().close();
- //指示struts,不要对返回值进行处理
- return null;
- }
- public void setFormManager(FormManager formManager) {
- this.formManager = formManager;
- }
- }