📄 statemachine.java
字号:
// 获取所有开始结点
Collection startNodeList = fd.getStartNodeList();
for (Iterator iter = startNodeList.iterator(); iter.hasNext();) {
StartNode startNode = (StartNode) iter.next();
Collection nextNodeList = fd.getNextNodeList(startNode.id);
for (Iterator iter2 = nextNodeList.iterator(); iter2.hasNext();) {
Node nextNode = (Node) iter2.next();
if (nextNode instanceof ManualNode) {
ManualNode manualNode = (ManualNode) nextNode;
// UserID
NameList nameList = NameList.parser(manualNode.namelist);
if (nameList.isContains(new NameNode("U" + user.getId()))) {
rtn.add(manualNode);
}
// RolesID
Collection roles = user.getRoles();
if (roles != null) {
for (Iterator iter3 = roles.iterator(); iter3.hasNext();) {
RoleVO role = (RoleVO) iter3.next();
String roleid = role.getId();
if (nameList.isContains(new NameNode("R" + roleid))) {
rtn.add(manualNode);
}
}
}
// DeptsID
Collection depts = user.getDepartments();
if (depts != null) {
for (Iterator iter4 = depts.iterator(); iter4.hasNext();) {
DepartmentVO dept = (DepartmentVO) iter4.next();
String deptid = dept.getId();
if (nameList.isContains(new NameNode("D" + deptid))) {
rtn.add(manualNode);
}
}
}
}
}
}
return rtn;
}
/**
* 获取开始结点列表
*/
public static Collection getStartNodeListByFirstNode(BillDefiVO flowVO,
Node firstNode) {
ArrayList rtn = new ArrayList();
String flow = flowVO.getFlow();
WFRunner wfr = new WFRunner(flow);
FlowDiagram fd = wfr.getFlowDiagram();
// 获取所有endnodeid为firstNode的开始结点列表
Collection ems = fd.getAllElements();
for (Iterator iter = ems.iterator(); iter.hasNext();) {
Element element = (Element) iter.next();
if (element instanceof Relation) {
Relation r = (Relation) element;
if (r.endnodeid != null && r.endnodeid.equals(firstNode.id)) {
Element em = fd.getElementByID(r.startnodeid);
if (em != null && em instanceof StartNode) {
rtn.add(em);
}
}
}
}
return rtn;
}
/**
* 获取下一步结点列表
*
* @return Collection of ManualNodes、AutoNodes、...
*/
public static Collection getNextToNodeList(String docid, BillDefiVO flowVO,
String currid, WebUser user) {
FlowDiagram fd = flowVO.toFlowDiagram();
// 获取所有下一结点
Collection nextNodeList = fd.getNextNodeList(currid);
return nextNodeList;
}
/**
* 获取回退结点列表
*
* @return Collection of NodeHises
* @throws Exception
*/
public static Collection getBackToNodeList(String docid, BillDefiVO flowVO,
String currid, WebUser user) throws Exception {
return getBackToNodeList(docid, flowVO, currid, user, 0);
}
public static Collection getBackToNodeList(String docid, BillDefiVO flowVO,
String currid, WebUser user, int flowState) throws Exception {
ArrayList rtn = new ArrayList();
FlowDiagram fd = flowVO.toFlowDiagram();
// 获取当前NodeRT
NodeRT currNodeRT = (NodeRT) getNodeRTProcess().doView(docid,
flowVO.getId(), user);
Collection hisList = null;
if (flowState != FlowState.SUSPEND) {
hisList = getPassedToNodeList(new TreeMap(), docid, flowVO, "",
currNodeRT.getNodeid());
} else {
hisList = getRelationHISProcess().queryRelationHIS(docid,
flowVO.getId(), currNodeRT.getNodeid());
}
for (Iterator iter = hisList.iterator(); iter.hasNext();) {
RelationHIS r = (RelationHIS) iter.next();
String sid = r.getStartnodeid();
Element em = fd.getElementByID(sid);
if (em instanceof ManualNode && !sid.equals(currid))
rtn.add(em);
}
return rtn;
}
/**
* 获取所有经过的节点
*
* @param docid
* @param flowid
* @param currid
* @return
* @throws Exception
*/
public static Collection getPassedToNodeList(TreeMap tmp, String docid,
BillDefiVO flowVO, String startnodeid, String endnodeid)
throws Exception {
FlowDiagram fd = flowVO.toFlowDiagram();
// 获取所有终点为当前NodeRT的RelationHIS
Collection rhs = getRelationHISProcess().queryRelationHIS(docid,
flowVO.getId(), endnodeid);
if (rhs != null && !rhs.isEmpty()) {
for (Iterator iter = rhs.iterator(); iter.hasNext();) {
RelationHIS his = (RelationHIS) iter.next();
String snodeid = his.getStartnodeid();
String enodeid = his.getEndnodeid();
Element em = fd.getElementByID(snodeid);
// 检验历史记录是否重复,不重复则把历史记录保存的tmp中
if ((!tmp.isEmpty() && tmp.get(his.getId()) != null)
|| em instanceof StartNode) {
continue;
} else {
tmp.put(his.getId(), his);
// 递归查找上一节点的历史记录
getPassedToNodeList(tmp, docid, flowVO, enodeid, snodeid);
}
}
}
return tmp.values();
}
private static boolean isPreviousNode(BillDefiVO flowVO,
String startnodeid, String endnodeid) {
FlowDiagram fd = flowVO.toFlowDiagram();
Relation relation = fd.getRelation(startnodeid, endnodeid);
if (relation != null) {
return true;
} else {
return false;
}
}
/**
* 去除重复的历史记录
*
* @param colls
* @return
*/
private static Collection removeDuplicateHIS(Collection colls) {
Collection tmp = new ArrayList();
// 去掉重复
out: for (Iterator iter = colls.iterator(); iter.hasNext();) {
RelationHIS r = (RelationHIS) iter.next();
boolean flag = false;
if (tmp.size() == 0) {
flag = true;
} else {
for (Iterator iterator = tmp.iterator(); iterator.hasNext();) {
RelationHIS tmpr = (RelationHIS) iterator.next();
if ((tmpr.getStartnodeid()).equals(r.getStartnodeid())
&& (tmpr.getEndnodeid()).equals(r.getEndnodeid())) {
continue out;
} else {
continue;
}
}
flag = true;
}
if (flag == true) {
tmp.add(r);
}
}
return tmp;
}
/**
* 去掉重复的Node
*
* @param colls
* @return
*/
public static Collection removeDuplicateNode(Collection colls) {
return removeDuplicateNode(colls, null);
}
/**
* 去掉重复和当前的Node
*
* @param colls
* @return
*/
public static Collection removeDuplicateNode(Collection colls, Node currNode) {
Collection tmp = new ArrayList();
out: for (Iterator iter = colls.iterator(); iter.hasNext();) {
Node node = (Node) iter.next();
for (Iterator iterator = tmp.iterator(); iterator.hasNext();) {
Node tmpNode = (Node) iterator.next();
if (tmp.size() == 0) {
tmp.add(node);
} else {
if ((node.id).equals(tmpNode.id)) {
continue out;
} else if (currNode != null) {
if ((currNode.id).equals(node.id)) {
continue out;
}
} else {
continue;
}
}
}
tmp.add(node);
}
return tmp;
}
public static Node getCurrNode(BillDefiVO flowVO, String nodeid) {
String flow = flowVO.getFlow();
WFRunner wfr = new WFRunner(flow);
FlowDiagram fd = wfr.getFlowDiagram();
Element element = fd.getElementByID(nodeid);
Node currnode = null;
if (element instanceof Node) {
currnode = (Node) element;
}
return currnode;
}
/**
* 删除运行时节点
*
* @param docid
* @param flowid
* @throws Exception
*/
public static void removeAllNodeRT(String docid, String flowid)
throws Exception {
Collection nodertList = getAllNodeRT(docid, flowid);
for (Iterator iter = nodertList.iterator(); iter.hasNext();) {
NodeRT nodert = (NodeRT) iter.next();
getNodeRTProcess().doRemove(nodert.getId());
}
}
public static Collection getAllNodeRT(String docid, String flowid)
throws Exception {
return getNodeRTProcess().doQuery(docid, flowid);
}
public static FlowStateRT getFlowStateRT(String docid, String flowid)
throws Exception {
return getFlowStateRTProcess().findFlowStateRTByDocidAndFlowid(docid,
flowid);
}
public static int getCurrFlowState(String docid, String flowid)
throws Exception {
FlowStateRT flowStateRT = getFlowStateRT(docid, flowid);
if (flowStateRT != null) {
return flowStateRT.getState();
}
return FlowState.START;
}
private static void changeFlowState(String docid, BillDefiVO flowVO,
int type) throws Exception, ClassNotFoundException {
// 获取当前FlowStateRT
FlowStateRT state = getFlowStateRTProcess()
.findFlowStateRTByDocidAndFlowid(docid, flowVO.getId());
if (state == null) {
state = new FlowStateRT();
state.setId(Sequence.getSequence());
state.setDocid(docid);
state.setFlowid(flowVO.getId());
state.setState(type);
getFlowStateRTProcess().doCreate(state);
} else {
state.setState(type);
getFlowStateRTProcess().doUpdate(state);
}
}
private static RelationHIS changeRelationHIS(String docid,
BillDefiVO flowVO, NodeRT start, Node end, WebUser user,
Date actionTime, String attitude) throws Exception {
RelationHIS rhis = changeRelationHIS(docid, flowVO, start.getNodeid(),
start.getName(), end.id, end.name, user, actionTime, attitude);
return rhis;
}
private static void changeRelationHIS(String docid, BillDefiVO flowVO,
Node start, NodeRT end, WebUser user, Date actionTime,
String attitude) throws Exception {
changeRelationHIS(docid, flowVO, start.id, start.name, end.getNodeid(),
end.getName(), user, actionTime, attitude);
}
private static void changeRelationHIS(String docid, BillDefiVO flowVO,
Node start, Node end, WebUser user, Date actionTime, String attitude)
throws Exception {
changeRelationHIS(docid, flowVO, start.id, start.name, end.id,
end.name, user, actionTime, attitude);
}
private static void changeRelationHIS(String docid, BillDefiVO flowVO,
NodeRT start, NodeRT end, WebUser user, Date actionTime,
String attitude) throws Exception {
changeRelationHIS(docid, flowVO, start.getNodeid(), start.getName(),
end.getNodeid(), end.getName(), user, actionTime, attitude);
}
private static RelationHIS changeRelationHIS(String docid,
BillDefiVO flowVO, String startnodeid, String startnodename,
String endnodeid, String endnodename, WebUser user,
Date actionTime, String attitude) throws Exception {
// 找到当前RelationHIS
/*
* RelationHIS rhis =
* getRelationHISProcess().findRelHISByCondition(docid, startnodeid,
* endnodeid, false);
*/
RelationHIS rhis = new RelationHIS();
rhis.setId(Sequence.getSequence());
rhis.setFlowid(flowVO.getId());
rhis.setDocid(docid);
rhis.setStartnodeid(startnodeid);
rhis.setStartnodename(startnodename);
rhis.setEndnodeid(endnodeid);
rhis.setEndnodename(endnodename);
rhis.setIspassed(false);
rhis.setActiontime(actionTime);
rhis.setAttitude(attitude); // 审批意见
rhis.getActorhiss().add(new ActorHIS(user));
getRelationHISProcess().doCreate(rhis);
/*
* if (rhis == null) { } else { rhis.getActorhiss().add(new
* ActorHIS(user)); getRelationHISProcess().doUpdate(rhis); }
*/
return rhis;
}
/**
* 检验当前节点是否可以通过
*
* @param docid
* @param flowVO
* @param nodert
* @return
* @throws Exception
*/
public static boolean isPassed(String docid, BillDefiVO flowVO,
NodeRT nodert) throws Exception {
FlowDiagram fd = flowVO.toFlowDiagram();
Node node = (Node) fd.getElementByID(nodert.getNodeid());
if (node instanceof ManualNode) {
ManualNode manualNode = (ManualNode) node;
NameList nameList = manualNode.toNameList();
if (nameList.isMatchCondition(nodert)) {
return true;
}
}
return false;
}
/**
* 生成流程图
*
* @author Administrator
*
* To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
public static void toJpegImage(String docid, FlowDiagram fd, Environment evt)
throws Exception {
String path = DefaultProperty.getProperty("BILLFLOW_DIAGRAMPATH");
String filepath = evt.getWebcontextRealPath(path);
File dir = new File(filepath);
if (!dir.exists()) {
dir.mkdirs();
}
filepath = filepath + docid + ".jpg";
File file = new File(filepath);
fd.toJpegImage(file);
}
private static void changeFlowImage(String docid, String flowid,
FlowDiagram fd) throws Exception {
Collection hisList = getRelationHISProcess().doQuery(docid, flowid);
for (Iterator iter = hisList.iterator(); iter.hasNext();) {
RelationHIS rhis = (RelationHIS) iter.next();
Relation relation = fd
.getRelation(rhis.startnodeid, rhis.endnodeid);
if (relation != null) {
relation.ispassed = true;
}
}
Collection nodeRTList = getNodeRTProcess().queryNodeRTByDocidAndFlowid(
docid, flowid);
for (Iterator iter = nodeRTList.iterator(); iter.hasNext();) {
NodeRT nodert = (NodeRT) iter.next();
if (nodert != null) {
Node node = (Node) fd.getElementByID(nodert.getNodeid());
node._iscurrent = true;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -