⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 attachmentmanager.java

📁 OA典型例子
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.sure.oa.attachment;

/**
 * <p>Title: OA</p>
 * <p>Description: 国办项目</p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: surec</p>
 * @author mengzy
 * @version 1.0
 */

import com.jspsmart.upload.*;
import javax.servlet.jsp.*;
import javax.servlet.*;
import javax.servlet.http.*;
//javax.servlet.jsp.PageContext;
import java.sql.*;
import java.util.Properties;
import java.util.Vector;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Calendar;
import java.io.File;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.io.FileInputStream;
import com.sure.businessmodel.UpdateException;
import com.sure.businesslogic.AlreadyExistsException;
import com.sure.businesslogic.NotFoundException;
import com.sure.dataabstraction.DBManager;
import com.sure.dataabstraction.DBPoolException;
import com.sure.dataabstraction.*;
import com.sure.businessmodel.Page;
import com.sure.util.*;
import com.sure.oa.senddoc.*;
import com.sure.businessmodel.Page;
/**
 * status 状态位设定  0:正文 1:附件  10:盖章后正文  11:盖章后附件
 */
public class attachmentManager {
    public attachmentManager() {}
    public static  void  upload(PageContext pageContext,String docId) throws ServletException,SmartUploadException, IOException, DBPoolException, SQLException,Exception  {
          SmartUpload upload = new SmartUpload();//
          upload.initialize(pageContext);
          try {//非Mulitpart形式的提交会导致一个异常
            upload.upload();
          } catch(NegativeArraySizeException e) {}
          Request req = upload.getRequest();
          String action = req.getParameter("action");//upload或者delete
          String fileId = req.getParameter("fileId");//文件ID
          String unitId = req.getParameter("unitId");//用来构建上传路径目录“单位部门表Unit中的UnitId字段”
          String status = req.getParameter("status");//文件标识
          String docKind = req.getParameter("docKind");//文件类别0正式公文1其他
          String tableName=req.getParameter("tableName");//文件所对应的表名(发文表SendDocForm、SendDocLog;收文表RecvDocForm、RecvDocLog)
          String subdir = req.getParameter("subdir");
          String editbz = req.getParameter("editbz");
          String docstatus = req.getParameter("docstatus");
          if (fileId == null) { return ;}
          if (action != null && action.equals("delete")) {
             deleteAttachment(fileId,docId,docKind,docstatus,status);
            return ;
          }
          if (docKind.equals("1")){//如果为其他文种的话,则不需要盖章
             if (status.equals("0")){status="10";}else{status="11";}
          }
          attachment bean = new attachment();
          bean.setFileId(fileId);
          bean.setDocId(docId);
          bean.setStatus(status);
          bean.setTableName(tableName);
          com.jspsmart.upload.File file = upload.getFiles().getFile(0);
          if (!file.isMissing()) {
            Calendar cal = new GregorianCalendar();
            cal.setTime(new Date());
            String year = Integer.toString(cal.get(cal.YEAR));
            String month = Integer.toString(cal.get(cal.MONTH));
            String path="/upload/"+unitId+"/"+year+"/"+month+"/";
            String graphpath="\\upload\\"+unitId+"\\"+year+"\\"+month+"\\"+subdir;
            //System.out.println("editbz:"+editbz);
            if (editbz.equals("1")){
                SendDocForm sform=SendDocFormManager.getDoc(docId);
                subdir=sform.getDocNo();
                graphpath="\\upload\\"+unitId+"\\"+year+"\\"+month+"\\"+subdir;
                Vector v=getAttachmentList(docId);
                if (v.size()>0){
                  attachment att=(attachment)v.firstElement();
                  path=att.getPath();
                  subdir=att.getSite();
                }else {
                   initPath(graphpath);
                }
            }else{
              initPath(graphpath);
            }
            bean.setPath(path);
            bean.setSite(subdir);
            bean.setTitle(file.getFileName());
            bean.setFileName(file.getFileName());
            String file_etc=(file.getFileName()).substring((file.getFileName()).indexOf(".")+1);
            bean.setMimeType(getMimeType(file.getTypeMIME() + "/" + file.getSubTypeMIME(),file_etc));
            bean.setFileSize(file.getSize());
            saveAttachment(bean);
            file.saveAs(path+subdir+"/"+file.getFileName());
          }
    }

    /**
     * 保存文件盖章,正文(GW)上传,文件表改变标志,SendDocForm置标志,SendDocLog插入日志信息
     */
    public static  void  saveSeal(PageContext pageContext) throws ServletException,SmartUploadException, IOException, DBPoolException, SQLException,Exception  {
       SmartUpload upload = new SmartUpload();
       upload.initialize(pageContext);
       try {
            upload.upload();
       } catch(NegativeArraySizeException e) {}
       Request req = upload.getRequest();
       String docId = req.getParameter("docId");
       String unitId = req.getParameter("unitId");
       String userId = req.getParameter("userId");
       String userName = req.getParameter("userName");
       String sealName = req.getParameter("sealName");
       String trueName = req.getParameter("trueName");
       String printnumber = req.getParameter("printnumber");
       String fileSize = req.getParameter("fileSize");
       String fileType = req.getParameter("fileType");
       attachment bean = new attachment();
       bean.setFileId("0");
       bean.setDocId(docId);
       bean.setStatus("10");
       bean.setTableName("senddoc");
       Vector v = getListVector(docId, "0");
       attachment att = (attachment) v.get(0);
       String path = att.getPath();
       String site = att.getSite();
       bean.setTitle(trueName);
       bean.setFileName(trueName);
       bean.setPath(path);
       bean.setSite(site);
       bean.setMimeType(fileType);
       bean.setFileSize(fileSize);
       Seal(bean,docId,userId,userName,sealName,unitId,printnumber);
    }
    public static void  Seal(attachment bean,String docId,String userId,String userName,String sealName,String unitId,String printnumber) throws DBPoolException, SQLException ,NotFoundException{
        Connection conn=DBManager.getConnection();
        String where="where docId='"+docId+"' and status=1";
        try {
           conn.setAutoCommit(false);
           //attachment置位,写入盖章文件信息
           attachmentPersistent sbean=new attachmentPersistent(bean);
           sbean.persist(conn);
           attachmentPersistent.updateSeal(conn,where);
           SendDocForm form=SendDocFormManager.getDoc(docId);
           //SendDocForm置位,写入盖章信息
           form.setStatus("2");
           form.setSealTime(DateWrapper.getLongTime(new Date()));
           form.setSealName(sealName);
           form.setSealPerson(userName);
           form.setPrintnumber(printnumber);
           SendDocFormPersistent doc=new SendDocFormPersistent(form);
           doc.setRecordExists(true);
           doc.persist(conn);
           //SendDocLog写入日志信息
           SendDocLog log=new SendDocLog();
           log.setLogId(0);
           log.setDocId(docId);
           log.setOperateId("3");//3:盖章
           log.setOperateDate(DateWrapper.getLongTime(new Date()));
           log.setOperator(userName);
           log.setOperatorId(userId);
           log.setUnitId(unitId);
           log.setMemo(sealName);
           SendDocLogPersistent slog=new SendDocLogPersistent(log);
           slog.persist(conn);
           conn.commit();
        }
        catch (Exception e)
        {
           conn.rollback();
           e.printStackTrace();
        }
        finally {
           conn.setAutoCommit(true);
           conn.close();
        }
    }

    /**
     * 获得某个文件的详情
     */
    public static  attachment getAttachment(String fileId) throws DBPoolException, SQLException ,NotFoundException{
          Connection conn = DBManager.getConnection();
          String where="Where fileId='"+fileId+"'";
          try {
             return  (attachment)attachmentPersistent.load(conn, where).firstElement();
          }
          finally {
             conn.close();
          }
    }

    /**
     *修改:2004-3-4
     */
    public static  Page getList(String docId) throws DBPoolException, SQLException ,NotFoundException{
          Connection conn = DBManager.getConnection();
          String where="Where docId='"+docId+"' order by fileId";
          try {
             return  attachmentPersistent.load(conn, 1, 10, where);
          }
          finally {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -