Skip to content

Commit

Permalink
workflow运行时增加wfVars变量。 arg节点增加persist属性
Browse files Browse the repository at this point in the history
  • Loading branch information
entropy-cloud committed Oct 17, 2024
1 parent 8a68a3a commit e606df4
Show file tree
Hide file tree
Showing 25 changed files with 233 additions and 133 deletions.
22 changes: 22 additions & 0 deletions docs/user-guide/workflow.md
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
# 工作流

## 流程引擎后台变量

* wfRt: IWorkflowRuntime类型
* wf: IWorkflow类型
* wfVars: IWorkflowVarSet类型,对应于`wf.getGlobalVars()`

## 参数
arg定义具有persist属性,如果设置为true,则会保存到wfVars集合中,存储到`nop_wf_var`表中。

## 条件判断

```xml
<when>
<eq name="wfVars.day" value="${7}" />
<eq name="wfVars.day" value="@:7" />
</when>
```

条件判断中值如果不是字符串类型,则可以用表达式语法或者前缀引导语法来标识数值类型。


Binary file modified nop-wf/model/nop-wf.orm.xlsx
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,29 @@
*/
package io.nop.wf.core;

import io.nop.core.reflect.hook.IPropGetMissingHook;

import java.util.Map;
import java.util.Set;

/**
* 每个工作流实例都对应一个全局变量集合
*/
public interface IWorkflowVarSet {
public interface IWorkflowVarSet extends IPropGetMissingHook {
@Override
default Object prop_get(String propName) {
return getVar(propName);
}

@Override
default boolean prop_has(String propName) {
return containsVar(propName);
}

Set<String> getVarNames();

boolean containsVar(String varName);

Object getVar(String varName);

void removeVar(String varName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public interface NopWfCoreConstants extends _NopWfCoreConstants {

String VAR_WF = "wf";
String VAR_WF_RT = "wfRt";
String VAR_WF_VARS = "wfVars";
String VAR_WF_STEP = "wfStep";
String VAR_ACTOR_MODEL = "actorModel";
String VAR_SELECTED_ACTORS = "selectedActors";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ private IEvalScope newEvalScope() {
IEvalScope scope = serviceContext.getEvalScope().newChildScope();
scope.setLocalValue(null, NopWfCoreConstants.VAR_WF, wf);
scope.setLocalValue(null, NopWfCoreConstants.VAR_WF_RT, this);
scope.setLocalValue(null, NopWfCoreConstants.VAR_WF_VARS, wf.getGlobalVars());
return scope;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,9 @@ private void initArgs(IWorkflowArgumentsModel argsModel, Map<String, Object> arg
throw wfRt.newError(ERR_WF_EMPTY_ACTION_ARG)
.param(ARG_ACTION_NAME, actionName).param(ARG_ARG_NAME, name);
}
if (argModel.isPersist()) {
wf.getGlobalVars().setVar(name, args.get(name));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ public abstract class _WfArgVarModel extends io.nop.core.resource.component.Abst
*/
private java.lang.String _name ;

/**
*
* xml name: persist
*
*/
private boolean _persist = false;

/**
*
* xml name: schema
Expand All @@ -52,6 +59,13 @@ public abstract class _WfArgVarModel extends io.nop.core.resource.component.Abst
*/
private io.nop.xlang.xmeta.ISchema _schema ;

/**
*
* xml name: type
*
*/
private io.nop.core.type.IGenericType _type ;

/**
*
* xml name: description
Expand Down Expand Up @@ -128,6 +142,25 @@ public void setName(java.lang.String value){
}


/**
*
* xml name: persist
*
*/

public boolean isPersist(){
return _persist;
}


public void setPersist(boolean value){
checkAllowChange();

this._persist = value;

}


/**
*
* xml name: schema
Expand All @@ -148,6 +181,25 @@ public void setSchema(io.nop.xlang.xmeta.ISchema value){
}


/**
*
* xml name: type
*
*/

public io.nop.core.type.IGenericType getType(){
return _type;
}


public void setType(io.nop.core.type.IGenericType value){
checkAllowChange();

this._type = value;

}



@Override
public void freeze(boolean cascade){
Expand All @@ -169,7 +221,9 @@ protected void outputJson(IJsonHandler out){
out.putNotNull("displayName",this.getDisplayName());
out.putNotNull("mandatory",this.isMandatory());
out.putNotNull("name",this.getName());
out.putNotNull("persist",this.isPersist());
out.putNotNull("schema",this.getSchema());
out.putNotNull("type",this.getType());
}

public WfArgVarModel cloneInstance(){
Expand All @@ -185,7 +239,9 @@ protected void copyTo(WfArgVarModel instance){
instance.setDisplayName(this.getDisplayName());
instance.setMandatory(this.isMandatory());
instance.setName(this.getName());
instance.setPersist(this.isPersist());
instance.setSchema(this.getSchema());
instance.setType(this.getType());
}

protected WfArgVarModel newInstance(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@
"PMD.UnnecessaryFullyQualifiedName","PMD.EmptyControlStatement","java:S116","java:S101","java:S1128","java:S1161"})
public abstract class _WfAssignmentActorModel extends io.nop.core.resource.component.AbstractComponentModel {

/**
*
* xml name: actionName
*
*/
private java.lang.String _actionName ;

/**
*
* xml name: actorId
Expand All @@ -37,6 +30,13 @@ public abstract class _WfAssignmentActorModel extends io.nop.core.resource.compo
*/
private java.lang.String _actorModelId ;

/**
*
* xml name: actorName
*
*/
private java.lang.String _actorName ;

/**
*
* xml name: actorType
Expand Down Expand Up @@ -74,57 +74,57 @@ public abstract class _WfAssignmentActorModel extends io.nop.core.resource.compo

/**
*
* xml name: actionName
* xml name: actorId
*
*/

public java.lang.String getActionName(){
return _actionName;
public java.lang.String getActorId(){
return _actorId;
}


public void setActionName(java.lang.String value){
public void setActorId(java.lang.String value){
checkAllowChange();

this._actionName = value;
this._actorId = value;

}


/**
*
* xml name: actorId
*
* xml name: actorModelId
* actor节点的唯一标识
*/

public java.lang.String getActorId(){
return _actorId;
public java.lang.String getActorModelId(){
return _actorModelId;
}


public void setActorId(java.lang.String value){
public void setActorModelId(java.lang.String value){
checkAllowChange();

this._actorId = value;
this._actorModelId = value;

}


/**
*
* xml name: actorModelId
* actor节点的唯一标识
* xml name: actorName
*
*/

public java.lang.String getActorModelId(){
return _actorModelId;
public java.lang.String getActorName(){
return _actorName;
}


public void setActorModelId(java.lang.String value){
public void setActorName(java.lang.String value){
checkAllowChange();

this._actorModelId = value;
this._actorName = value;

}

Expand Down Expand Up @@ -239,9 +239,9 @@ public void freeze(boolean cascade){
protected void outputJson(IJsonHandler out){
super.outputJson(out);

out.putNotNull("actionName",this.getActionName());
out.putNotNull("actorId",this.getActorId());
out.putNotNull("actorModelId",this.getActorModelId());
out.putNotNull("actorName",this.getActorName());
out.putNotNull("actorType",this.getActorType());
out.putNotNull("assignForUser",this.isAssignForUser());
out.putNotNull("deptId",this.getDeptId());
Expand All @@ -258,9 +258,9 @@ public WfAssignmentActorModel cloneInstance(){
protected void copyTo(WfAssignmentActorModel instance){
super.copyTo(instance);

instance.setActionName(this.getActionName());
instance.setActorId(this.getActorId());
instance.setActorModelId(this.getActorModelId());
instance.setActorName(this.getActorName());
instance.setActorType(this.getActorType());
instance.setAssignForUser(this.isAssignForUser());
instance.setDeptId(this.getDeptId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,9 @@ public void setVars(Map<String, Object> vars) {
if (vars != null)
this.vars.putAll(vars);
}

@Override
public boolean containsVar(String varName) {
return vars.containsKey(varName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2118,7 +2118,7 @@ public IOrmEntitySet<io.nop.wf.dao.entity.NopWfOutput> getOutputs(){
}

private final OrmEntitySet<io.nop.wf.dao.entity.NopWfVar> _globalVars = new OrmEntitySet<>(this, PROP_NAME_globalVars,
io.nop.wf.dao.entity.NopWfVar.PROP_NAME_wfInstance, null,io.nop.wf.dao.entity.NopWfVar.class);
io.nop.wf.dao.entity.NopWfVar.PROP_NAME_wfInstance, io.nop.wf.dao.entity.NopWfVar.PROP_NAME_fieldName,io.nop.wf.dao.entity.NopWfVar.class);

/**
* 。 refPropName: wfInstance, keyProp: {rel.keyProp}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public void removeVar(String varName) {
}
}

@Override
public boolean containsVar(String varName) {
return set.prop_has(varName);
}

@Override
public void setVar(String varName, Object value) {
IOrmKeyValueTable item = (IOrmKeyValueTable) set.prop_make(varName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,9 @@
<on leftProp="wfId" rightProp="wfId"/>
</join>
</to-many>
<to-many cascadeDelete="true" name="globalVars" refEntityName="io.nop.wf.dao.entity.NopWfVar"
refPropName="wfInstance" tagSet="pub,cascade-delete">
<to-many cascadeDelete="true" keyProp="fieldName" name="globalVars"
refEntityName="io.nop.wf.dao.entity.NopWfVar" refPropName="wfInstance"
tagSet="pub,cascade-delete">
<join>
<on leftProp="wfId" rightProp="wfId"/>
</join>
Expand Down Expand Up @@ -706,7 +707,7 @@
<join>
<on leftProp="wfId" rightProp="wfId"/>
</join>
<ref-set/>
<ref-set keyProp="fieldName"/>
</to-one>
</relations>
</entity>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?xml version="1.0" encoding="UTF-8" ?>
<workflow x:extends="/nop/wf/base/oa.xwf" x:schema="/nop/schema/wf/wf.xdef" xmlns:x="/nop/schema/xdsl.xdef">
<start>
<arg name="day" type="Integer" mandatory="true" />
<arg name="assignee" type="String" mandatory="true" />
<arg name="day" type="Integer" mandatory="true" persist="true"/>
<arg name="assignee" type="String" mandatory="true" persist="true" />
</start>

<steps>
<step name="start">
<transition >
<to-step stepName="k004" label="7天长期" order="1">
<when>
<gt name="entity.day" value="${7}" />
<gt name="wfVars.day" value="${7}" />
</when>
</to-step>

Expand Down
Loading

0 comments on commit e606df4

Please sign in to comment.