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

📄 senddocformmanager.java

📁 OA典型例子
💻 JAVA
字号:
package com.sure.oa.senddoc;

import com.sure.businessmodel.Page;
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.oa.orgnization.*;
import com.sure.oa.recvdoc.*;
import com.sure.util.*;
import java.sql.SQLException;
import java.sql.Connection;
import java.util.Vector;
import java.util.List;
import java.util.Iterator;
import java.util.Date;

/**
 * <p>Title: OA</p>
 * <p>Description: 国办项目</p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: sure</p>
 * @author mengzy
 * @version 1.0
 * status   公文状态Status:0:草稿  1:待盖章  2:待发送  3:已发送  4:已重发  5:已归档
 * 10:草稿时删除 11:待盖章时删除 12:待发送时删除 13:已发送时删除

 */

public class SendDocFormManager {

  public SendDocFormManager() {
  }
  /**
   * 根据docID获得一个发文的主信息
   * @param docId
   * @return
   * @throws SQLException
   * @throws DBPoolException
   * @throws NotFoundException
   */
  public static  SendDocForm getDoc(String docId) throws SQLException,DBPoolException, NotFoundException {
      Connection cn = DBManager.getConnection();
      try {
          String where = "Where docId = " + docId ;
          Vector beans = SendDocFormPersistent.load(cn, where);
          SendDocForm bean = (SendDocForm)beans.firstElement();
          return bean;
      } catch (SQLException sqle) {
          throw new  NotFoundException();
      } finally {
          cn.close();
      }
  }
  public static  SendDocForm getDoc(int docId) throws SQLException,DBPoolException, NotFoundException {
    return getDoc(Integer.toString(docId));
  }
  /**
  * 删除一个发文主信息
  * @param docId
  */
 public void  delDoc(int docId) throws SQLException,DBPoolException, NotFoundException {
     Connection cn = DBManager.getConnection();
     try {
        String where = "Where docId = " + docId ;
        SendDocFormPersistent.delete(cn, where);
     }catch (SQLException sqle) {
         throw new NotFoundException();
     } finally {
         cn.close();
     }
 }

 /**
   * 保存发文主信息
   * @param u
   */
  public int saveDoc(SendDocForm u) throws SQLException,DBPoolException, UpdateException, NotFoundException {
      Connection cn = DBManager.getConnection();
      int docId = u.getDocId().intValue();
      String docKind = u.getDocKind();
      String status = u.getStatus();
      if(docKind.equals("1")){
         if (status.equals("1")){u.setStatus("2");}
      }
      int retval = 0;
      try{
          SendDocFormPersistent doc = new SendDocFormPersistent(u);
          if (docId == 0){
          }else{
            doc.setRecordExists(true);
          }
          cn.setAutoCommit(false);
          doc.persist(cn);
          cn.commit();
          cn.setAutoCommit(true);
          retval = doc.getBean().getDocId().intValue();
      }finally {
          cn.close();
      }
    return retval;
  }

  /**
   * 获得草稿文件列表
   */
  public Page getCaoGaoList(int start, int unitId,String cxtj) throws SQLException,NotFoundException,DBPoolException {
      Connection cn = DBManager.getConnection();
      try{
          String where = "where createUnitId='" + unitId + "' and status in ('0')  "+cxtj+" order by createDate desc";
          Page p = SendDocFormPersistent.load(cn, start, 15, where);
          return p;
      }finally {
          cn.close();
      }
  }

  /**
   * 获得未盖章文件列表
   */
   public Page getAllUnSignList(int start, int unitId,String cxtj) throws SQLException,NotFoundException,DBPoolException {
     Connection cn = DBManager.getConnection();
     try{
         String where = "where createUnitId='" + unitId + "' and status in ('1') "+cxtj+" order by createDate desc";
         //System.out.println(where);
         Page p = SendDocFormPersistent.load(cn, start, 15, where);
         return p;
     }finally {
         cn.close();
     }
   }

   /**
    * 获得待发送发文(所有文件)列表
    */
   public Page getUnSendList(int start, int unitId,String cxtj) throws SQLException,NotFoundException,DBPoolException {
       Connection cn = DBManager.getConnection();
       try{
           String where = "where createUnitId='" + unitId + "' and status in ('2') "+cxtj+" order by createDate desc";
           Page p = SendDocFormPersistent.load(cn, start, 15, where);
           return p;
       }finally {
           cn.close();
       }
   }

   /**
    * 获得已发送发文(所有文件)列表
    */
  public Page getSendedList(int start, int unitId,String cxtj) throws SQLException,NotFoundException,DBPoolException {
       Connection cn = DBManager.getConnection();
       try{
           String where = "where createUnitId='" + unitId + "' and status in ('3','4') "+cxtj+" order by createDate desc";
           Page p = SendDocFormPersistent.load(cn, start, 15, where);
           return p;
       }finally {
           cn.close();
       }
  }
  /**
 * 获得已发送发文(所有文件)列表
 */
public Vector getSendedList(int unitId,String cxtj) throws SQLException,NotFoundException,DBPoolException {
    Connection cn = DBManager.getConnection();
    try{
        String where = "where createUnitId='" + unitId + "' and status in ('3','4') "+cxtj+" order by createDate desc";
        Vector p = SendDocFormPersistent.load(cn, where);
        return p;
    }finally {
        cn.close();
    }
}
  /**
    * 获得发文(所有文件)列表
    */

  public Page getHoleList(int start, int unitId,String cxtj) throws SQLException,NotFoundException,DBPoolException {
         Connection cn = DBManager.getConnection();
         try{
             String where = "where createUnitId='" + unitId + "' and status in ('0','1','2','3','4') "+cxtj+" order by docID desc";
             Page p = SendDocFormPersistent.load(cn, start, 15, where);
             return p;
         }finally {
             cn.close();
         }
    }

  /**
   * 获得发文删除记录(0:所有的发文删除记录 10:草稿时删除 11:待盖章时删除 12:待发送时删除 13:已发送时删除)
   */
  public Page getDeleteList(int start, int unitId,int status,String cxtj) throws SQLException,
             NotFoundException,DBPoolException {
     Connection cn = DBManager.getConnection();
     String where = "where createUnitId='" + unitId + "' and status in ('"+status+"') "+cxtj+" order by docID desc";
     if(status==0) { where = "where createUnitId='" + unitId + "' and status in ('10','11','12','13')  "+cxtj+" order by docID desc";}
     try{
         Page p = SendDocFormPersistent.load(cn, start, 15, where);
         return p;
     }finally {
         cn.close();
     }
   }

  /**
   * 公文发送保存(sendDocForm置位,senddoclog追加记录,receiveDocForm插入记录,RecvPermission追加授权记录)
   */
  public static void  send(String docId,String receiveunit,String printnumber,String userName,String userId,String unitName,String unitId,String sfcf) throws SQLException,
      DBPoolException, UpdateException,NotFoundException{
      Connection cn = DBManager.getConnection();
      try{
         cn.setAutoCommit(false);
         //发文主表置位(3:已发送),插入发送人和发送时间
         SendDocForm form=getDoc(docId);
         if (sfcf.equals("1")){
            form.setStatus("4");
         }else{
            form.setStatus("3");
         }
         form.setSendPerson(userName);
         form.setSendTime(DateWrapper.getLongTime(new Date()));
         SendDocFormPersistent sp=new SendDocFormPersistent(form);
         sp.setRecordExists(true);
         sp.persist(cn);
         //SendDocLog追加发送记录
         SendDocLog slog=new SendDocLog();
         slog.setLogId(0);
         slog.setDocId(docId);
         if (sfcf.equals("1")){
           slog.setOperateId("5");
         }else{
           slog.setOperateId("4");
         }
         slog.setOperateDate(DateWrapper.getLongTime(new Date()));
         slog.setOperator(userName);
         slog.setOperatorId(userId);
         slog.setUnitId(unitId);
         slog.setMemo(receiveunit+";"+printnumber);
         SendDocLogPersistent slogs=new SendDocLogPersistent(slog);
         slogs.setRecordExists(false);
         slogs.persist(cn);
         int sendlogId=slogs.getBean().getLogId().intValue(); //发文日志ID
         //RecvDocForm插入记录
         RecvDocForm rcform=changeRecvDocForm(form,docId,unitName,userName);
         RecvDocFormPersistent rp=new RecvDocFormPersistent(rcform);
         rp.setRecordExists(false);
         rp.persist(cn);
         int rcvId=rp.getBean().getDocId().intValue();
         //RecvPermission追加收文权限
         String strIds[] = StringUtils.split(receiveunit, ",");
         String strNums[] = StringUtils.split(printnumber, ",");
         RecvPermission rper=new RecvPermission();
         RecvPermissionPersistent srper;
         for(int i = 0; i < strIds.length; i++){
            rper.setPermissionId(0);
            rper.setDocId(Integer.toString(rcvId));
            rper.setPrintNumber(strNums[i]);
            rper.setStatus("0");
            rper.setUnitId(strIds[i]);
            rper.setSendlogId(Integer.toString(sendlogId));
            rper.setTransId(RecvPermissionManager.generateTransID(cn,docId,Integer.parseInt(strNums[i])));
            srper=new RecvPermissionPersistent(rper);
            srper.setRecordExists(false);
            srper.persist(cn);
         }
         cn.commit();
      } catch(Exception e) {
          cn.rollback();
          e.printStackTrace();
      } finally {
          cn.setAutoCommit(true);
          cn.close();
      }
  }
  /**
   * 由SendDocForm 封装一个RecvDocForm
   */
  public static  RecvDocForm changeRecvDocForm(SendDocForm form,String docId,String unitName,String userName){
     RecvDocForm rcform=new RecvDocForm();
     rcform.setDocId(0);
     rcform.setDocKind(form.getDocKind());
     rcform.setSendDocId(docId);
     rcform.setDocTitle(form.getDocTitle());
     rcform.setCreateDate(form.getCreateDate());
     rcform.setCreator(form.getCreator());
     rcform.setCreateUnitId(form.getCreateUnitId());
     rcform.setDocNoPre(form.getDocNoPre());
     rcform.setYearNo(form.getYearNo());
     rcform.setWaterNo(form.getWaterNo());
     rcform.setSecret(form.getSecret());
     rcform.setEmergency(form.getEmergency());
     rcform.setSubject(form.getSubject());
     rcform.setPublishDate(form.getPublishDate());
     rcform.setPublishPerson(form.getPublishPerson());
     rcform.setAllSignPerson(form.getAllSignPerson());
     rcform.setDealPerson(form.getDealPerson());
     rcform.setCheckPerson(form.getCheckPerson());
     rcform.setPrintUnit(form.getPrintUnit());
     rcform.setPrintDate(form.getPrintDate());
     rcform.setMainDealunit(form.getMainDealunit());
     rcform.setAllUnit(form.getCombineUnit());
     rcform.setSaveTime(form.getSaveTime());
     rcform.setSendTo(form.getSendTo());
     rcform.setCc(form.getCc());
     rcform.setReportTo(form.getReportTo());
     rcform.setInerTo(form.getInerTo());
     rcform.setSealName(form.getSealName());
     rcform.setSendUnitId(form.getCreateUnitId().toString());
     rcform.setSendUnitName(unitName);
     rcform.setSendTime(DateWrapper.getLongTime(new Date()));
     rcform.setSendPerson(userName);
     rcform.setPrintnumber(form.getPrintnumber());
     rcform.setFilePages(form.getFilePages());
     rcform.setAttachmentPages(form.getAttachmentPages());
     rcform.setMemo(form.getDocMemo());
     return  rcform;
  }
  /**
   * 判断文号是否有重复
   */
  public static  boolean   getDocNoCf(String unitId,String docNoPre,String yearNo,String waterNo,int docId) throws SQLException,DBPoolException, NotFoundException {
     Connection cn = DBManager.getConnection();
     String sql="";
     if (!(docId==0)){sql="and docId<>"+docId+"";}
     try{
       String where = "where createUnitId='"+unitId+"' and  docNoPre='"+docNoPre+"' and yearNo='"+yearNo+"' and waterNo='"+waterNo+"' and status in('0','1','2','3','4','5')"+sql;
       //System.out.println(where);
       Vector v = SendDocFormPersistent.load(cn, where);
       boolean  hasExist = (v.size() > 0);
       if (hasExist) {
          return  false ;
       }
     }
     finally
     {
       cn.close();
     }
     return  true ;
 }

 /**
   * 获得待盖章(或加密)文件个数
   */
  public static int  getUnSealNumber(int unitId) throws SQLException,NotFoundException,DBPoolException {
    Connection cn = DBManager.getConnection();
    try{
        String where = "where createUnitId='" + unitId + "' and status in ('1')  order by docID desc";
        Vector v = SendDocFormPersistent.load(cn,where);
        return  v.size();
    }finally {
        cn.close();
    }
  }
  /**
   * 获得待发送文件个数
   */
  public static int  getUnSendNumber(int unitId) throws SQLException, NotFoundException,DBPoolException {
       Connection cn = DBManager.getConnection();
       try{
           String where = "where createUnitId='" + unitId + "' and status in ('2')  order by docID desc";
           Vector v = SendDocFormPersistent.load(cn,where);
           return  v.size();
       }finally {
           cn.close();
       }
 }

 /**
   * 获得某个单位在某个时间段内的发文数量
   */
  public static int  getSendNumber(String unitId,String year,String month,String day) throws SQLException, NotFoundException,DBPoolException {
       Connection cn = DBManager.getConnection();
       try{
           String where = "where createUnitId='" + unitId + "' and status in ('3','4')  ";
           if (!year.equals("")){
              where=where+"and year(sendtime)='"+year+"'  ";
           }
           if (!month.equals("")){
              where=where+"and month(sendtime)='"+month+"'  ";
           }
           if (!day.equals("")){
              where=where+"and day(sendtime)='"+day+"'  ";
           }
           Vector v = SendDocFormPersistent.load(cn,where);
           return  v.size();
       }finally {
           cn.close();
       }
 }
}

⌨️ 快捷键说明

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