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" οnsubmit="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" οnchange="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="关闭窗口" οnclick="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();
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值