📄 statemachinehelper.java
字号:
package cn.myapps.core.workflow.engine;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import javax.servlet.http.HttpServletRequest;
import cn.myapps.constans.Environment;
import cn.myapps.core.dynaform.document.ejb.Document;
import cn.myapps.core.dynaform.document.ejb.DocumentProcess;
import cn.myapps.core.user.action.WebUser;
import cn.myapps.core.workflow.FlowState;
import cn.myapps.core.workflow.element.Element;
import cn.myapps.core.workflow.element.FlowDiagram;
import cn.myapps.core.workflow.element.ManualNode;
import cn.myapps.core.workflow.element.Node;
import cn.myapps.core.workflow.element.SuspendNode;
import cn.myapps.core.workflow.storage.definition.ejb.BillDefiProcess;
import cn.myapps.core.workflow.storage.definition.ejb.BillDefiVO;
import cn.myapps.core.workflow.storage.runtime.ejb.ActorHIS;
import cn.myapps.core.workflow.storage.runtime.ejb.ActorRT;
import cn.myapps.core.workflow.storage.runtime.ejb.FlowStateRT;
import cn.myapps.core.workflow.storage.runtime.ejb.NodeRT;
import cn.myapps.core.workflow.storage.runtime.ejb.NodeRTProcess;
import cn.myapps.core.workflow.storage.runtime.ejb.RelationHIS;
import cn.myapps.core.workflow.storage.runtime.ejb.RelationHISProcess;
import cn.myapps.core.workflow.utility.FieldPermissionList;
import cn.myapps.util.DateUtil;
import cn.myapps.util.ProcessFactory;
import cn.myapps.util.property.DefaultProperty;
public class StateMachineHelper {
public boolean isDisplySubmit = false; // 是否显示提交按钮
public boolean isDisplyFlow = true; // 是否显示流程
private int flowState; // 流程状态
private static NodeRTProcess getNodeRTProcess() throws Exception {
return StateMachine.getNodeRTProcess();
}
private static BillDefiProcess getBillDefiProcess() throws Exception {
return StateMachine.getBillDefiProcess();
}
private RelationHISProcess getRelationHISProcess() throws Exception {
return StateMachine.getRelationHISProcess();
}
public StateMachineHelper() {
}
public StateMachineHelper(String docid, String flowid, Environment evt) {
if (evt != null) {
initFlowImage(flowid, docid, evt);
}
try {
flowState = getCurrFlowState(docid, flowid);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 初始化流程图
*
* @param flowid
* @param docid
* @param request
*/
private void initFlowImage(String flowid, String docid, Environment evt) {
try {
String path = DefaultProperty.getProperty("BILLFLOW_DIAGRAMPATH");
String imgPath = evt.getWebcontextRealPath(path + "/" + docid
+ ".jpg");
File file = new File(imgPath);
if (!file.exists()) {
BillDefiVO flowVO = (BillDefiVO) getBillDefiProcess().doView(
flowid);
FlowDiagram fd = flowVO.toFlowDiagram();
StateMachine.toJpegImage(docid, fd, evt);
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 根据当前用户获取当前流程所有开始节点的下一个手动节点(第一个节点)的列表
*
* @param docid
* @param flowid
* @param user
* @return
* @throws Exception
*/
public Collection getFirstNodeList(String docid, String flowid, WebUser user)
throws Exception {
BillDefiVO flowVO = null;
flowVO = (BillDefiVO) getBillDefiProcess().doView(flowid);
return StateMachine.getFirstNodeList(docid, flowVO, user);
}
/**
* 根据第一个节点获取开始节点
*
* @param flowid
* @param firstNode
* @return
* @throws Exception
*/
public Collection getStartNodeListByFirstNode(String flowid, Node firstNode)
throws Exception {
BillDefiVO flowVO = null;
flowVO = (BillDefiVO) getBillDefiProcess().doView(flowid);
return StateMachine.getStartNodeListByFirstNode(flowVO, firstNode);
}
/**
* 根据当前节点id获取下一节点列表
*
* @param docid
* @param flowid
* @param currid
* @param user
* @return
* @throws Exception
*/
public Collection getNextToNodeList(String docid, String flowid,
String currid, WebUser user) throws Exception {
BillDefiVO flowVO = null;
flowVO = (BillDefiVO) getBillDefiProcess().doView(flowid);
return StateMachine.getNextToNodeList(docid, flowVO, currid, user);
}
/**
* 根据当前节点id获取回退节点列表
*
* @param docid
* @param flowid
* @param currid
* @param user
* @return
* @throws Exception
*/
public Collection getBackToNodeList(String docid, String flowid,
String currid, WebUser user) throws Exception {
BillDefiVO flowVO = null;
flowVO = (BillDefiVO) getBillDefiProcess().doView(flowid);
return StateMachine.getBackToNodeList(docid, flowVO, currid, user);
}
public Collection getBackToNodeList(String docid, String flowid,
String currid, WebUser user, int flowState) throws Exception {
BillDefiVO flowVO = null;
flowVO = (BillDefiVO) getBillDefiProcess().doView(flowid);
return StateMachine.getBackToNodeList(docid, flowVO, currid, user,
flowState);
}
/**
* 获取当前流程状态
*
* @param docid
* @param flowid
* @return
* @throws Exception
*/
public static int getCurrFlowState(String docid, String flowid)
throws Exception {
return StateMachine.getCurrFlowState(docid, flowid);
}
/**
* 根据当前用户获取运行时节点
*
* @param docid
* @param flowid
* @param user
* @return
* @throws Exception
*/
public static NodeRT getCurrUserNodeRT(String docid, String flowid,
WebUser user) throws Exception {
return getNodeRTProcess().doView(docid, flowid, user);
}
public Node getCurrNode(String flowid, String nodeid) throws Exception {
BillDefiVO flowVO = null;
BillDefiProcess process = (BillDefiProcess) ProcessFactory
.createProcess(BillDefiProcess.class);
flowVO = (BillDefiVO) process.doView(flowid);
return StateMachine.getCurrNode(flowVO, nodeid);
}
/**
* 获取所有运行时节点
*
* @param docid
* @param flowid
* @return
* @throws Exception
*/
public Collection getAllNodeRT(String docid, String flowid)
throws Exception {
return StateMachine.getAllNodeRT(docid, flowid);
}
public boolean isPassed(String docid, BillDefiVO flowVO, NodeRT nodert)
throws Exception {
return StateMachine.isPassed(docid, flowVO, nodert);
}
/**
* 获取当前流程所有历史记录
*
* @param docid
* @param flowid
* @return
* @throws Exception
*/
public Collection getAllRelationHIS(String docid, String flowid)
throws Exception {
return getRelationHISProcess().doQuery(docid, flowid);
}
/**
* 根据进行挂起操作的用户获取运行时节点
*
* @param docid
* @param flowid
* @return
* @throws Exception
*/
public NodeRT getSuspendNodeRT(String docid, String flowid)
throws Exception {
// 获取最后一条历史记录
RelationHIS relationHIS = this.getRelationHISProcess().doViewLast(
docid, flowid);
// 此历史记录只有唯一用户历史记录
Collection actorhissList = relationHIS.getActorhiss();
ActorHIS actorhis = (ActorHIS) actorhissList.iterator().next();
// 获取所有NodeRT
Collection nodertList = this.getAllNodeRT(docid, flowid);
// 获取只有一个处理者的NodeRT列表
Collection newNodertList = new ArrayList();
for (Iterator iter = nodertList.iterator(); iter.hasNext();) {
NodeRT nodert = (NodeRT) iter.next();
Collection actorrtList = nodert.getActorrts();
if (actorrtList.size() == 1) {
newNodertList.add(nodert);
}
}
// 根据进行挂起操作的用户获取NodeRT
if (newNodertList != null) {
for (Iterator iter = newNodertList.iterator(); iter.hasNext();) {
NodeRT nodert = (NodeRT) iter.next();
ActorRT actort = (ActorRT) nodert.getActorrts().iterator()
.next();
if ((actorhis.getActorid()).equals(actort.getActorid())) {
return nodert;
}
}
}
return null;
}
// 判断当前用户是否可以保存文档
public static boolean isDocSaveUser(String docid, String flowid,
WebUser webUser) throws Exception {
int flowState = getCurrFlowState(docid, flowid);
if (flowState == FlowState.START) {
BillDefiVO flowVO = (BillDefiVO) getBillDefiProcess()
.doView(flowid);
Collection firstNodeList = StateMachine.getFirstNodeList(docid,
flowVO, webUser);
if (firstNodeList != null && !firstNodeList.isEmpty()) {
return true;
}
} else {
if (docid != null && !docid.equals("")) {
// 根据用户获取当前节点
NodeRT nodert = getCurrUserNodeRT(docid, flowid, webUser);
if (nodert != null) {
return true;
}
}
}
return false;
}
// 判断当前用户是否可编辑文档
public static boolean isDocEditUser(String docid, String flowid,
WebUser webUser) throws Exception {
NodeRT nodert = getCurrUserNodeRT(docid, flowid, webUser);
int flowState = getCurrFlowState(docid, flowid);
if (nodert != null || flowState == FlowState.START) {
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -