📄 downdocformmanager.java
字号:
package com.sure.oa.down;
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;
import com.sure.oa.down.downLoadFileManager;
import com.sure.oa.down.downLoadFile;
import java.io.File;
import com.sure.oa.down.downLoadFilePersistent;
/**
* <p>Title: OA</p>
* <p>Description: 国办项目</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: sure</p>
* @author chg
* @version 1.0
* status 下载文件状态Status:1:可以阅读文件 2:已经删除文件
*/
public class downDocFormManager {
public downDocFormManager() {
}
/**
* 根据docID获得一个下载文件的主信息
* @param docId
* @return
* @throws SQLException
* @throws DBPoolException
* @throws NotFoundException
*/
public static downDocForm getDoc(String docId) throws SQLException,DBPoolException, NotFoundException {
Connection cn = DBManager.getConnection();
try {
String where = "Where docId = " + docId ;
Vector beans = downDocFormPersistent.load(cn, where);
downDocForm bean = (downDocForm)beans.firstElement();
return bean;
} catch (SQLException sqle) {
throw new NotFoundException();
} finally {
cn.close();
}
}
public static downDocForm 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 ;
downDocFormPersistent.delete(cn, where);
}catch (SQLException sqle) {
throw new NotFoundException();
} finally {
cn.close();
}
}
/**
* 保存下载文件主信息
* @param u
*/
public int saveDoc(downDocForm down) throws SQLException,DBPoolException, UpdateException, NotFoundException {
Connection cn = DBManager.getConnection();
int docId = down.getDocId().intValue();
Integer status = down.getStatus();
int retval = 0;
try{
downDocFormPersistent doc = new downDocFormPersistent(down);
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;
}
/**
* 保存下载文件信息并更新downLoadFile表中的记录
* @param u
*/
public downDocForm saveDocAndUpdataDownLoadFile(downDocForm downDoc,String sessionId,String docNo,String xiugai) throws SQLException,DBPoolException, UpdateException, NotFoundException {
downDocForm rtnForm = new downDocForm();
Connection cn = DBManager.getConnection();
int docId = downDoc.getDocId().intValue();
Integer status = downDoc.getStatus();
int retval = 0;
try{
cn.setAutoCommit(false);
downDocFormPersistent doc = new downDocFormPersistent(downDoc);
if (docId == 0){
}else{
doc.setRecordExists(true);
}
doc.persist(cn);
retval = doc.getBean().getDocId().intValue();
rtnForm = doc.getBean();
//修改downLoadFile表
String oldDocId = "";
if (docId == 0){
oldDocId = sessionId;
}else{
if(xiugai.equals("xiugai")){
oldDocId = String.valueOf(retval);
}
}
if(docId == 0 || (docId != 0 && xiugai.equals("xiugai"))){
String where = "where docId='" + oldDocId + "'";
String initpath = downLoadFileManager.getUploadPath();
Vector v = downLoadFileManager.getDownLoadFileList(oldDocId);
if (v.size() > 0) {
downLoadFile bean = (downLoadFile) v.firstElement();
File file = new File(initpath + bean.getPath());
File file1 = new File(initpath + bean.getPath() + docNo);
//System.out.println("原路径:"+initpath + bean.getPath() + bean.getSite());
//System.out.println("现在路径:"+initpath + bean.getPath() + docNo);
file.renameTo(file1);
downLoadFilePersistent.updateDownLoadFile(cn, retval, where, docNo);
}
}
cn.commit();
}finally {
cn.setAutoCommit(true);
cn.close();
return rtnForm;
}
}
/**
* 获得下载文件(所有文件)列表
*/
public Page getHoleList(int start,String cxtj) throws SQLException,NotFoundException,DBPoolException {
Connection cn = DBManager.getConnection();
try{
String where = "where status in (1) "+cxtj+" order by docID desc";
Page p = downDocFormPersistent.load(cn, start, 10, where);
return p;
}finally {
cn.close();
}
}
/**
* 获得下载文件(直属于某个单位的所有文件)列表
*/
public Page getUnitHoleList(int start,String unitId,String cxtj) throws SQLException,NotFoundException,DBPoolException {
Connection cn = DBManager.getConnection();
try{
UnitManager um = new UnitManager();
Unit u = um.getUnit(Integer.parseInt(unitId)) ;
String allfatherId = u.getAllFatherId() ;
String topFatherId = allfatherId.substring(0,1) ;
int topUnit =Integer.parseInt(topFatherId) ;
String where = "where status in (1) and unitId = "+ topUnit+cxtj+" order by docID desc";
//System.out.println("downDocFormManager: where = "+where);
Page p = downDocFormPersistent.load(cn, start, 10, where);
return p;
}finally {
cn.close();
}
}
/**
* 判断文件是否有重复
*/
public static boolean getDocCf(String unitId,String docTitle,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 docTitle="+docTitle+" and status in(0,1,2,3,4,5)"+sql;
//System.out.println(where);
Vector v = downDocFormPersistent.load(cn, where);
boolean hasExist = (v.size() > 0);
if (hasExist) {
return false ;
}
}
finally
{
cn.close();
}
return true ;
}
/**
* 获得某个单位在某个时间段内的下载文件数量
*/
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 = downDocFormPersistent.load(cn,where);
return v.size();
}finally {
cn.close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -