📄 documentservice.java
字号:
package com.t60.oa.doc.service;
import java.util.*;
import com.t60.oa.po.DoucumentFolder;
import com.t60.oa.po.Floadpurview;
import hong.javanet.dao.HibernateUtil;
import org.hibernate.*;
import com.t60.oa.po.DoucumentEdition;
import java.io.File;
import org.apache.log4j.Logger;
public class DocumentService {
private String id;
private List result;
private String ownerFolderid;
private boolean state;
private String doucumentFolder;
private int editeId;
private int userId;//用户编号
private Set departmentId;//部门编号
private String [] ids; //用来批量删除
private String docPath;//文挡路径
private String affixFilePath;//附件路径
private static Logger log=Logger.getLogger(DocumentService.class);
/**
* 取得所有文件夹(树用到)
* @return List
*/
public void showAll() {
Session session = HibernateUtil.currentSession();
String hql = " from Floadpurview f where (f.user=? or f.department in (:dep)) and f.doucumentFile.typeDocument=1";
Query query = session.createQuery(hql);
query.setInteger(0,this.userId);
query.setParameterList("dep",this.departmentId); //这里是一个集合,要用参数命名
query.setCacheable(true);
this.result = query.list();
Iterator iter = result.iterator();
while (iter.hasNext()) {
Floadpurview item = (Floadpurview) iter.next();
Hibernate.initialize(item.getDoucumentFile());
}
this.result=DelFolpRepService.delFolpRep(this.result);//去重复权限记录
//HibernateUtil.closeSession();//不能关
}
/**
* 取得所有文件夹(第一层) 根据用户名,部门编号取得文档权限表的文档编号在取得文档相关信息
* @return List
*/
public void showAllFolder() {
Session session = HibernateUtil.currentSession();
//String hql = " from Floadpurview f where (f.user=? or f.department in (:dep)) and len(f.doucumentFile)=4";
String hql = " from Floadpurview f where (f.user=? or f.department in (:dep)) and len(f.doucumentFile)=4";
Query query = session.createQuery(hql);
query.setInteger(0,this.userId);
query.setParameterList("dep",this.departmentId);
this.result = query.list();
Iterator iter = result.iterator();
while (iter.hasNext()) {
Floadpurview item = (Floadpurview) iter.next();
Hibernate.initialize(item.getDoucumentFile().getEdite().getXm());//为了获得编辑人信息
Hibernate.initialize(item.getDoucumentFile().getOwner());//为了获得编辑人信息
}
this.result=DelFolpRepService.delFolpRep(this.result);//去重复权限记录
}
/**
* 取得所要的文件夹及文件
*
*/
public void showAllFolderAndFile() {
Session session = HibernateUtil.currentSession();
String hql = " from Floadpurview f where (f.user=? or f.department in (:dep)) and f.doucumentFile like :docId order by f.doucumentFile.typeDocument desc";
Query query = session.createQuery(hql);
query.setInteger(0, this.userId);
query.setParameterList("dep", this.departmentId);
query.setString("docId", ownerFolderid+"____");//四个下划线
this.result = query.list();
Iterator iter = result.iterator();
while (iter.hasNext()) {
Floadpurview item = (Floadpurview) iter.next();
Hibernate.initialize(item.getDoucumentFile().getEdite().getXm()); //为了获得编辑人信息
Hibernate.initialize(item.getDoucumentFile().getOwner()); //为了获得编辑人信息
}
this.showDocName(); //调用方法取得 文件/文件夹路径
this.result=DelFolpRepService.delFolpRep(this.result);//去重复权限记录
}
/**
* 取得文件/文件夹对应的路径
*/
public void showDocName(){
Session session=HibernateUtil.currentSession();
List result=new ArrayList();
for (int i = (this.id.length()/4)-1; i >=0 ; i--) { //先取父文件夹在取子文件夹
//query.setString(0,this.id.substring(0,(id.length()-4)*i));
String ids=this.id.substring(0,(id.length()-4*i));
DoucumentFolder doc=(DoucumentFolder) session.load(DoucumentFolder.class,ids);
result.add(doc.getName());//取得集合对象
//System.out.println(doc.getName());
}
Iterator iter = result.iterator();
this.docPath="";//设置初试值,否则空的时候显示null
while (iter.hasNext()) {
Object item = (Object) iter.next();
this.docPath=this.docPath+(String) item+"/";//取得文挡对应的路径
}
}
/**
* 编辑文件夹/文件
*/
public void modifyDoc() {
Session session = HibernateUtil.currentSession();
String hql="update DoucumentFolder set state=?,editeId=? where id=?";
Query query=session.createQuery(hql);
query.setBoolean(0,this.state);
query.setInteger(1,this.editeId);
query.setString(2,this.id);
query.setCacheable(true);
query.executeUpdate();
}
/**
* 查出最新版本的编辑人/
*
*/
public void findDoucumentEdition(){
Session session = HibernateUtil.currentSession();
//TOP不行
//String hql="select top 1*from BaseDoucumentEdition bd where bd.doucumentFolder=? order by bd.editDate desc";
String hql="from BaseDoucumentEdition bd where bd.doucumentFolder=? order by bd.editDate desc";
Query query=session.createQuery(hql);
query.setString(0,this.doucumentFolder);
query.setCacheable(true);
this.result=query.list();
}
/**
* 删除文件夹/及文件(支持多文件/文件夹操作)
*
*/
public void delDoc(){
Session session=HibernateUtil.currentSession();
String hqlDoc="delete DoucumentFolder where id like ?"; //不能给对象取别名//删除文档表
String hqlEdition="delete DoucumentEdition where doucumentFolder like ?";//删除版本
String hqlDocPur="delete Floadpurview where doucumentFile like ?";//删除文档权限表
Query queryDoc=session.createQuery(hqlDoc);
Query queryEdition=session.createQuery(hqlEdition);
Query queryDocPur=session.createQuery(hqlDocPur);
for (int i = 0; i < this.ids.length; i++) {
queryDoc.setString(0,ids[i]+"%");
queryEdition.setString(0,ids[i]+"%");//版本
queryDocPur.setString(0,ids[i]+"%");
//删除附件信息
String hqlfindDocEdition =
"from DoucumentEdition de where de.doucumentFolder like ?";
Query queryDelDocEdition=session.createQuery(hqlfindDocEdition);
queryDelDocEdition.setString(0,ids[i]+"%");
Iterator iter = queryDelDocEdition.list().iterator();
while (iter.hasNext()) {
DoucumentEdition item = (DoucumentEdition) iter.next();
String acc = item.getAccessories();
if (acc != null) {
String[] accs = acc.split(","); //根据','来取截取字符串用正则表达式,取得附件编号
String hqlAcc = "delete Accessories where id in (:accId)";
Query queryAcc = session.createQuery(hqlAcc);
queryAcc.setParameterList("accId", accs);
queryAcc.executeUpdate(); //删除附件信息
for (int j = 0; j < accs.length; j++) {
File file = new File(this.affixFilePath + accs[j]);
file.delete();
log.debug("删除物理磁盘文件成功!--->文件路径" + this.affixFilePath +
accs[j]);
}
}
}
///////////
queryDocPur.executeUpdate();//必须先执行(外键关联)
queryEdition.executeUpdate();//必须先执行(外键关联)
queryDoc.executeUpdate();
}
}
public List getResult() {
return result;
}
public String getId() {
return id;
}
public boolean isState() {
return state;
}
public String getDoucumentFolder() {
return doucumentFolder;
}
public int getEditeId() {
return editeId;
}
public String[] getIds() {
return ids;
}
public int getEmpId() {
return userId;
}
public Set getDepartmentId() {
return departmentId;
}
public String getOwnerFolderid() {
return ownerFolderid;
}
public String getDocPath() {
return docPath;
}
public String getAffixFilePath() {
return affixFilePath;
}
public void setResult(List result) {
this.result = result;
}
public void setId(String id) {
this.id = id;
}
public void setState(boolean state) {
this.state = state;
}
public void setDoucumentFolder(String doucumentFolder) {
this.doucumentFolder = doucumentFolder;
}
public void setEditeId(int editeId) {
this.editeId = editeId;
}
public void setIds(String[] ids) {
this.ids = ids;
}
public void setEmpId(int empId) {
this.userId = empId;
}
public void setDepartmentId(Set departmentId) {
this.departmentId = departmentId;
}
public void setOwnerFolderid(String ownerFolderid) {
this.ownerFolderid = ownerFolderid;
}
public void setDocPath(String docPath) {
this.docPath = docPath;
}
public void setAffixFilePath(String affixFilePath) {
this.affixFilePath = affixFilePath;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -