activiti实战读书笔记——第十章 之 子流程

时光总嘲笑我的痴心妄想 提交于 2019-12-06 09:10:40


1、开始事件中运用了两个自定义的表单类型bigtext和double

<startEvent id="startevent1" name="startevent1" activiti:initiator="applyUserId">
      <extensionElements>
        <activiti:formProperty id="dueDate" name="到货期限" type="date" datePattern="yyyy-MM-dd" required="true"></activiti:formProperty>
        <activiti:formProperty id="listing" name="物品清单" type="bigtext" required="true"></activiti:formProperty>
        <activiti:formProperty id="amountMoney" name="总金额" type="double" required="true"></activiti:formProperty>
      </extensionElements>
    </startEvent>



需要编写表单类型类并加入到processEngineConfiguration中:

public class BigtextFormType extends StringFormType {

	@Override
	public String getName(){
		return "bigtext";
	}

}
public class DoubleFormType extends AbstractFormType {

	@Override
	public String getName() {
		return "double";
	}

	@Override
	public Object convertFormValueToModelValue(String formValue) {
		return new Double(formValue);
	}

	@Override
	public String convertModelValueToFormValue(Object modelValue) {
		return Objects.toString(modelValue);
	}

}



List<AbstractFormType> customFormTypes = new ArrayList<AbstractFormType>();
		customFormTypes.add(new BigtextFormType());
		customFormTypes.add(new DoubleFormType());
		processEngineConfiguration.setCustomFormTypes(customFormTypes);



并在start-process-form.jsp和task-form.jsp中加入相关类型的显示处理:

<%-- 文本或者数字类型 --%>
				<c:if test="${fp.type.name == 'string' || fp.type.name == 'long' || fp.type.name == 'double'}">
					<label class="control-label" for="${fp.id}">${fp.name}:</label>
					<div class="controls">
						<input type="text" id="${fp.id}" name="${fp.id}" data-type="${fp.type.name}" value="" />
					</div>
				</c:if>
				
				<%-- 大文本 --%>
				<c:if test="${fp.type.name == 'bigtext'}">
					<label class="control-label" for="${fp.id}">${fp.name}:</label>
					<div class="controls">
						<textarea id="${fp.id}" name="${fp.id}" data-type="${fp.type.name}" ${required}></textarea>
					</div>
				</c:if>



2、在指向付费子流程的sequenceFlow中添加了监听器用于设置usage变量:

<sequenceFlow id="flow22" name="进入付费子流程" sourceRef="contactSupplier" targetRef="subprocessPay">
      <extensionElements>
        <activiti:executionListener event="take" expression="${execution.setVariable('usage', listing)}"></activiti:executionListener>
      </extensionElements>
    </sequenceFlow>



3、子流程使用标签subProcess,内部也是一个完成的流程。在其中除了空结束事件(正常结束)外还定义了两个异常结束事件
<endEvent id="errorendevent1" name="TerminateEndEvent">
        <errorEventDefinition errorRef="PAYMENT_REJECT"></errorEventDefinition>
      </endEvent>

      <endEvent id="errorendevent2" name="End">
        <errorEventDefinition errorRef="PAYMENT_REJECT"></errorEventDefinition>
      </endEvent>

外部与异常边界事件关联

<boundaryEvent id="boundaryerror1" name="Error" attachedToRef="subprocessPay">
      <errorEventDefinition errorRef="PAYMENT_REJECT"></errorEventDefinition>
    </boundaryEvent>



4、act_ru_execution表为运行实例表

运行流程后查看此表有两条流程实例ID相同的记录,一个ID与流程实例ID相同时主流程,另一个为子流程,它的parent_id_不空,指向主流程的实例ID。

5、act_hi_procinst表为历史流程实例表

其中只有一条关于主流程的记录,而无子流程记录。

6、在子流程中的一些用户任务使用了amountMoney变量,而在子流程中并未设置此变量。查看act_hi_varinst表,子流程可以共享主流程的所有变量,而且子流程在获取数据时使用主流程的执行实例ID(parent_id_字段)查询变量。



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!