package cn.leadingsoft.sjzx.system.flow;
import java.sql.Timestamp;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.text.SimpleDateFormat;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import cn.leadingsoft.sjzx.system.tfsjzxlcbz.TfSjzxLcbzForm;
import cn.leadingsoft.sjzx.system.tfsjzxwdlc.TfSjzxWdlcForm;
import cn.leadingsoft.sjzx.system.tfsjzxwdshjl.TfSjzxWdshjl;
import cn.leadingsoft.sjzx.system.tfsjzxwdshjl.TfSjzxWdshjlForm;
import cn.leadingsoft.sjzx.system.zhyywdxx.ZhyyWdxxForm;
public class FlowOperation extends HibernateUtils{
private static FlowOperation operation = null;
/**
* 编辑
*/
public static final String DOC_EDITE = "1";
/**
* 提交审核(待审核)
*/
public static final String DOC_AUDIT_PER = "2";
/**
* 审核拒绝
*/
public static final String DOC_AUDIT_REJ = "3";
/**
* 审核通过
*/
public static final String DOC_AUDIT_PAS = "4";
static Document document;
private FlowOperation(){}
public static FlowOperation getInstance(){
if(operation == null)
operation = new FlowOperation();
return operation;
}
/**
* 加载xml
*/
public static Document load(String filePath) throws DocumentException {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
SAXReader reader = new SAXReader();
document = reader.read(cl.getResourceAsStream(filePath));
return document;
}
public static Document loadByXmlStr(String xmlStr) throws DocumentException{
return DocumentHelper.parseText(xmlStr);
}
public void deployProcess(String xmlStr) throws Exception{
FlowOperation operation = FlowOperation.getInstance();
Session session = getTfSjzxWdlcHome().getCurrentSession();
Transaction trans = session.beginTransaction();
Document document = operation.loadByXmlStr(xmlStr);
try{
List rootElements = document.selectNodes("/TopFlow");
List transElements = document.selectNodes("/TopFlow/Procs/Proc/BaseProperties");
List stepElements = document.selectNodes("/TopFlow/Steps/Step/BaseProperties");
/*((TfSjzxWdlcHome)atx.getBean("system.tfSjzxWdlc.TfSjzxWdlcHomeProxy"))*/
TfSjzxWdlcForm processInstance = null;
for (Iterator it = rootElements.iterator(); it.hasNext();) {
Element elm = (Element) it.next();
SimpleDateFormat formter = new SimpleDateFormat("yyyyMMddhhmm");
String processNum = "P"+formter.format(new Date())/*elm.attributeValue("id")*/;
String processName = elm.attributeValue("text");
String processFileName = elm.attributeValue("filename");
log.info(processNum);
log.info(processName);
log.info(processFileName);
processInstance = new TfSjzxWdlcForm();
processInstance.setNum(processNum);
processInstance.setLcmc(processName);
processInstance.setFileName(processFileName);
processInstance.setLclx("1");
processInstance.setLcms("");
processInstance.setLczt("1");
session.save(processInstance);
}
for (Iterator it = transElements.iterator(); it.hasNext();) {
Element elm = (Element) it.next();
String nodeType = "Proc";
String nodeNum = elm.attributeValue("id");
String nodeName = elm.attributeValue("text");
String procType = elm.attributeValue("procType");
log.info(nodeNum);
log.info(nodeName);
log.info(procType);
TfSjzxLcbzForm taskNode = new TfSjzxLcbzForm();
taskNode.setNodenum(nodeNum);
taskNode.setNodename(nodeName);
taskNode.setTransactionfrom(procType);
taskNode.setNodeseria(1);
taskNode.setNodetype(nodeType);
taskNode.setProcessinstanceid(processInstance.getId());
taskNode.setAuditdepid(new Long(0));
taskNode.setAuditorid("3");
session.save(taskNode);
}
for (Iterator it = stepElements.iterator(); it.hasNext();) {
Element elm = (Element) it.next();
String nodeType = "Step";
String nodeNum = elm.attributeValue("id");
String nodeName = elm.attributeValue("text");
String transFrom = elm.attributeValue("from");
String transTo = elm.attributeValue("to");
log.info(nodeNum);
log.info(nodeName);
log.info(transFrom);
log.info(transTo);
TfSjzxLcbzForm taskNode = new TfSjzxLcbzForm();
taskNode.setNodenum(nodeNum);
taskNode.setNodename(nodeName);
taskNode.setTransactionfrom(transFrom);
taskNode.setTransactionto(transTo);
taskNode.setNodeseria(1);
taskNode.setNodetype(nodeType);
taskNode.setProcessinstanceid(processInstance.getId());
taskNode.setAuditdepid(new Long(0));
taskNode.setAuditorid("3");
session.save(taskNode);
}
trans.commit();
}catch(Exception e){
log.warn(e);
trans.rollback();
}finally{
session.flush();
session.close();
}
}
/**
* 启动流程
* @param processNum
*/
public TfSjzxWdshjlForm startProcess(Session currentSession,
Long processInstanceId,
ZhyyWdxxForm wdxx,
String auditTag
) throws Exception{
TfSjzxWdshjlForm taskInstance = null;
String hsql1 = "from TfSjzxLcbzForm where processInstanceId=:processInstanceId and transactionfrom='begin' and nodetype='Step'";
Query query1 = currentSession.createQuery(hsql1);
query1.setParameter("processInstanceId", processInstanceId);
List list1 = query1.list();//开始流程获取边(有可能多个,最终取一个)
if(list1 != null && !list1.isEmpty() &&list1.size() == 1){
Iterator list1_iter = list1.iterator();
while(list1_iter.hasNext()){
TfSjzxLcbzForm trans = (TfSjzxLcbzForm)list1_iter.next();
taskInstance = beginSaveTaskInstance(currentSession,
processInstanceId, wdxx, auditTag, trans);
}
}
return taskInstance;
}
public TfSjzxWdshjlForm startProcess(Session currentSession,
Long processInstanceId,
ZhyyWdxxForm wdxx,
Long nodeId,
String auditTag
) throws Exception{
String hsql1 = "from TfSjzxLcbzForm where processInstanceId=:processInstanceId and nodeid=:nodeId";
Query query1 = currentSession.createQuery(hsql1);
query1.setParameter("processInstanceId", processInstanceId);
query1.setParameter("nodeId", nodeId);
//开始流程获取边(根据用户取一个)
TfSjzxLcbzForm trans = (TfSjzxLcbzForm)query1.list().get(0);
TfSjzxWdshjlForm taskInstance = beginSaveTaskInstance(currentSession,
processInstanceId, wdxx, auditTag, trans);
return taskInstance;
}
private TfSjzxWdshjlForm beginSaveTaskInstance(Session currentSession,
Long processInstanceId, ZhyyWdxxForm wdxx, String auditTag,
TfSjzxLcbzForm trans) throws HibernateException {
String hsql2 = "from TfSjzxLcbzForm where processInstanceId=:processInstanceId and nodenum=:nodeNum and nodetype='Proc'";
String toNode = trans.getTransactionto();
TfSjzxWdshjlForm taskInstance = null;
Query query2 = currentSession.createQuery(hsql2);
query2.setParameter("processInstanceId", processInstanceId);
query2.setParameter("nodeNum", toNode);
List list2 = query2.list();//开始流程进行第一个任务节点
Iterator list2_iter = list2.iterator();
while(list2_iter.hasNext()){
TfSjzxLcbzForm taskNode = (TfSjzxLcbzForm)list2_iter.next();
taskInstance = new TfSjzxWdshjlForm();
taskInstance.setProcessinstanceid(processInstanceId);
taskInstance.setTasknodeid(taskNode.getNodeid());
taskInstance.setPooledactors("3");//审核人
taskInstance.setWdbh(wdxx.getWdbh());//文档编号
taskInstance.setWdmc(wdxx.getWdmc());
taskInstance.setWwfb(wdxx.getSfwwfb()!=null&&wdxx.getSfwwfb().equals("1")?"是":"否");
taskInstanc
- 1
- 2
前往页