dddd

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="/common/common.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">

<LINK href="style/admin.css" type="text/css" rel="stylesheet">
<script language="javascript" src="script/public.js"></script>
<title>添加公文信息</title>
<script type="text/javascript">
function verdict(){
 if(document.getElementById("workflow").value ==""){
  alert("文檔流程不能爲空");
  document.getElementById("workflow").focus();
  return false;
 }

 if(document.getElementById("title").value==""){
  alert("公文名稱不能爲空!");
  document.getElementById("title").focus();
  return false;
 }
 if(document.getElementById("file").value!=" " &&
   document.getElementById("file").value.match(/^(.*)(/.)(.{1,8})$/)[3] != 'doc'){
  alert("文檔格試錯誤!");
  document.getElementById("file").focus();
  return false;
 }

}
//function verify(file){   
 // if(file.value.match(/^(.*)(/.)(.{1,8})$/)[3]   !=   'doc'){
 //alert("必需是doc文檔");  
 // }
//}
</script>
<style>
 .table{ border-right:silver 1px solid; border-top:silver 1px solid; border-left: silver 1xp solid; width:100%; border-bottom: silver 1px solid; border-collapse:collapse;} 
</style>
</head>
<body>
<center>
<form  name="form1" method="post" enctype="multipart/form-data" action="document!addDocument.action" onsubmit="return verdict()">
<TABLE cellSpacing=0 cellPadding=0 width="100%" align=center border=0>
  <TR height=28>
    <TD background=images/title_bg1.jpg align="left">   當前位置: 添加公文信息</TD></TR>
  <TR>
    <TD bgColor=#b1ceef height=1></TD></TR>
  <TR height=20>
    <TD background=images/shadow_bg.jpg></TD></TR></TABLE>
  <TABLE class="tableEdit" border="0" cellspacing="1" cellpadding="0"  width="100%">
   <TBODY> 
    <TR>
      <td>
     <!-- 主輸入域開始 -->
     <table width="561" height="105"
     border=1 cellPadding=5 cellSpacing=0 borderColor=silver rules=all  class="table" id=MyDataGrid singleValue="#FFFFFF" oldValue="#FFFFFF" IsNewQuery="False">
      <tr>
        <td align="right"  >公文所走流程:</td>
        <td align="left" >
          <select name="document.workflowId" id="workflow">
            <option value="">--請選擇--</option>
            <c:forEach items="${workflow}" var="flow">
             <option value="${flow.id }">${flow.name}</option>
            </c:forEach>
             </select><font color="#FF0000">&nbsp;*</font>
        </td>
       </tr>
      <tr>
        <td align="right"  >公文名稱:</td>   
       <td align="left" ><input type="text" name="document.title" id="title"><font color="#FF0000">&nbsp;*</font>
       </td>
      </tr>
      <tr>
        <td align="right" >公文附件:</td>
       <td align="left" >
                <input type="file" name="file" onchange="verify(this)" id="file" />
                <font color="#FF0000">*</font>
             </td>
         </tr>
      <tr>
        <td align="right">公文描述:</td>
       <td align="left" ><textarea name="document.description" cols="45" rows="6"></textarea></td>
       </tr>
     </table>
     <!-- 主輸入域結束 -->
     </td>
    </TR>
   </TBODY>
  </TABLE>
  <TABLE>
  <TR align="center">
   <TD colspan="3" bgcolor="#EFF3F7">
   <input type="submit" name="saveButton"
    class="MyButton" value="保存公文信息">
   <input type="button" class="MyButton"
    value="關閉窗口" onclick="window.close()">
   </TD>
  </TR>
</TABLE>
</form>
</center>
</body>
</html>

 

 

 

 

 

 

 

 

 

package com.oa.action;

import java.io.File;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import junit.test.Byte_File_Object;

import org.apache.struts2.ServletActionContext;
import com.oa.PagerModel;
import com.oa.bean.Document;
import com.oa.bean.TUser;
import com.oa.service.DocumentService;
import com.oa.service.WorkflowService;
import com.opensymphony.xwork2.ActionContext;

@SuppressWarnings("serial")
public class DocumentAction extends BaseAction {
 private int id;
 public Document document;
 private File file;
 private String fileFileName;
 @Resource private DocumentService documentService;
 @Resource private WorkflowService workflowService;
 @Override
 public String execute() throws Exception {
  TUser user=(TUser)ServletActionContext.getRequest().getSession().getAttribute("login");
  ServletActionContext.getRequest().setAttribute("pm", documentService.searchMyDocuments(user.getId()));
  return "index";
 }
 //點擊添加公文的時候,需要選擇相應的流程,此界面列出所有的流程以供選擇
 public String selectFlow()throws Exception{
  ServletActionContext.getRequest().setAttribute("workflow", workflowService.searchAllWorkflows());
  return "add_input";
 }
 //已審公文列表,顯示由當前登錄人員審覈的公文列表
 public String approvedList()throws Exception{
  System.out.println("----------------已審公文列表-------------------->");
  TUser user=(TUser)ServletActionContext.getRequest().getSession().getAttribute("login");
  PagerModel pm=this.documentService.searchApprovedDocuments(user.getId());
  ServletActionContext.getRequest().setAttribute("pm", pm);
  return "approved_list";
 }
 //查看公文的審批歷史
 public String approvedHistory()throws Exception{
  //request.setAttribute("historys", documentManager.searchApproveInfos(daf.getId()));
  List<?> historys=this.documentService.searchApproveInfos(id);
  ServletActionContext.getRequest().setAttribute("historys", historys);
  return "approve_history";
 }
 public String addDocument()throws Exception{
  System.out.println("----------------------添加公文---------------->");
  try {
   Document doc =new Document();
   //BeanUtils.copyProperties(doc,document);
   //System.out.println("公文我走流程: "+document.getWorkflowId());
   doc.setTitle(document.getTitle()); //名稱
   doc.setDescription(document.getDescription());//公文描述 
   System.out.println("文件名稱!"+fileFileName);
   doc.setFileName(fileFileName);
   System.out.println(Byte_File_Object.getBytesFromFile(file));
   if(file!=null){
    doc.setContent(Byte_File_Object.getBytesFromFile(file));
   }
   TUser user=(TUser)ServletActionContext.getRequest().getSession().getAttribute("login");
   documentService.addDocument(doc, document.getWorkflowId(), user.getId()); 
   
  } catch (RuntimeException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  return "add_success";
 } 
 //下載公文
 public String  download() throws Exception{
  System.out.println("----下載公文----"+id);
  Document document = documentService.findDocument(id);
  ServletActionContext.getResponse().reset();
  ServletActionContext.getResponse().setCharacterEncoding("application/x-download;charset=GBK");
  ServletActionContext.getResponse()
   .setHeader("Content-Disposition", "attachment;filename="
     +document.getFileName());
  ServletActionContext.getResponse().getOutputStream().write(document.getContent());
  
  ServletActionContext.getResponse().getOutputStream().flush();
  ServletActionContext.getResponse().getOutputStream().close();  
  return null;
 }
 /**
  *在我的公文或待審公文列表上,點擊提交,可打開提交的選擇界面
  * 在這個界面上,列出下一步所有可選的步驟,用戶可以選擇其中一個
  * 步驟進行提交操作。系統將按照用戶的選擇轉移到下一個節點
  */
 public String submitInput() throws Exception{
  System.out.println("提交公文!");  
  Document doc=documentService.findDocument(id);
  System.out.println(id);
  TUser user=(TUser)ServletActionContext.getRequest().getSession().getAttribute("login");
  List<?> transitions = workflowService.searchNextTransitions(user.getUsername(),doc.getProcessInstanceId());
  ServletActionContext.getRequest().setAttribute("steps", transitions); 
  ServletActionContext.getRequest().setAttribute("id", id);
  return "submit_input";
 }
 // 待審公文列表,顯示等待當前登錄人員審覈的公文列表
 public String approvingList()throws Exception{
  
  TUser user=(TUser)ServletActionContext.getRequest().getSession().getAttribute("login");
  System.out.println("-------------當前用戶代審批公文------------>"+user.getId());
  List<?>  documents=documentService.searchApprovingDocuments(user.getId());
  System.out.println(documents.size());
  ServletActionContext.getRequest().setAttribute("documents",documents);
  
  return "approving_list";
 }
 
 //提交公文
 public String submit()throws Exception{
  System.out.println("---提交公文---");
  TUser user=(TUser)ServletActionContext.getRequest().getSession().getAttribute("login");
  System.out.println("-------------------------"+id);
  System.out.println(document.getTransitionName());
  documentService.submitToWorkflow(
    user.getId(), id, document.getTransitionName());  
  return "add_success";
 }
 public int getId() {
  return id;
 }
 public void setId(int id) {
  this.id = id;
 }
 public Document getDocument() {
  return document;
 }
 public void setDocument(Document document) {
  this.document = document;
 }
 public File getFile() {
  return file;
 }
 public void setFile(File file) {
  this.file = file;
 }
 public String getFileFileName() {
  return fileFileName;
 }
 public void setFileFileName(String fileFileName) {
  this.fileFileName = fileFileName;
 }

 
}

 

 

package junit.test;


import java.io.*;

public class Byte_File_Object {
  /** *//**
     * 文件轉化爲字節數組
     * @Author Sean.guo
     * @EditTime 2007-8-13 上午11:45:28
     */
    public static byte[] getBytesFromFile(File f) {
        if (f == null) {
            return null;
        }
        try {
            FileInputStream stream = new FileInputStream(f);
            ByteArrayOutputStream out = new ByteArrayOutputStream(1000);
            byte[] b = new byte[1000];
            int n;
            while ((n = stream.read(b)) != -1)
                out.write(b, 0, n);
            stream.close();
            out.close();
            return out.toByteArray();
        } catch (IOException e) {
        }
        return null;
    }

    /** *//**
     * 把字節數組保存爲一個文件
     * @Author Sean.guo
     * @EditTime 2007-8-13 上午11:45:56
     */
    public static File getFileFromBytes(byte[] b, String outputFile) {
        BufferedOutputStream stream = null;
        File file = null;
        try {
            file = new File(outputFile);
            FileOutputStream fstream = new FileOutputStream(file);
            stream = new BufferedOutputStream(fstream);
            stream.write(b);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (stream != null) {
                try {
                    stream.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        }
        return file;
    }

    /** *//**
     * 從字節數組獲取對象
     * @Author Sean.guo
     * @EditTime 2007-8-13 上午11:46:34
     */
    public static Object getObjectFromBytes(byte[] objBytes) throws Exception {
        if (objBytes == null || objBytes.length == 0) {
            return null;
        }
        ByteArrayInputStream bi = new ByteArrayInputStream(objBytes);
        ObjectInputStream oi = new ObjectInputStream(bi);
        return oi.readObject();
    }

    /** *//**
     * 從對象獲取一個字節數組
     * @Author Sean.guo
     * @EditTime 2007-8-13 上午11:46:56
     */
    public static byte[] getBytesFromObject(Serializable obj) throws Exception {
        if (obj == null) {
            return null;
        }
        ByteArrayOutputStream bo = new ByteArrayOutputStream();
        ObjectOutputStream oo = new ObjectOutputStream(bo);
        oo.writeObject(obj);
        return bo.toByteArray();
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章