日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

Flowable节点跳转

發(fā)布時(shí)間:2025/3/21 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Flowable节点跳转 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

關(guān)鍵詞:Flowable任務(wù)節(jié)點(diǎn)跳轉(zhuǎn),Flowable節(jié)點(diǎn)跳轉(zhuǎn),Flowable任意節(jié)點(diǎn)跳轉(zhuǎn)。

在使用Flowable或者Activiti的時(shí)候,有時(shí)候我們并不期望他按照模板的定義進(jìn)行運(yùn)轉(zhuǎn),比如如下的一個(gè)流程圖:

正常的流程應(yīng)該是shareniu1-->shareniu2-->shareniu3-->shareniu4。

如果現(xiàn)在打算讓shareniu1跳轉(zhuǎn)到shareniu3,這個(gè)時(shí)候就需要繪制一根連線,并在連線中配置一些條件。其他的節(jié)點(diǎn)場(chǎng)景相似,但是實(shí)際項(xiàng)目開(kāi)發(fā),可能我們不想繪制太多的連線,就期望流程實(shí)例可以隨便的跳轉(zhuǎn),這個(gè)問(wèn)題也是我們本文重點(diǎn)要講解。

1.將上述的流程進(jìn)行部署。

數(shù)據(jù)庫(kù)的變化如下所示:

2.啟動(dòng)流程實(shí)例:

@Test

public void start1() {

runtimeService.startProcessInstanceByKey("jump");

}

act_ru_task表的數(shù)據(jù)如下:

這個(gè)時(shí)候,我們打算讓shareniu1直接跳轉(zhuǎn)到shareniu3,能跳轉(zhuǎn)過(guò)去嗎?我們不妨寫(xiě)一個(gè)命令類試一下。

3.任意節(jié)點(diǎn)跳轉(zhuǎn)實(shí)現(xiàn)代碼:

/*** * @author 分享牛 http://www.shareniu.com/*/ public class ShareniuCommonJumpTaskCmd implements Command<Void> {protected String taskId;protected String target;public ShareniuCommonJumpTaskCmd(String taskId, String target) {this.taskId = taskId;this.target = target;}public Void execute(CommandContext commandContext) {ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager();TaskEntityManager taskEntityManager = CommandContextUtil.getTaskEntityManager();TaskEntity taskEntity = taskEntityManager.findById(taskId);ExecutionEntity ee = executionEntityManager.findById(taskEntity.getExecutionId());Process process = ProcessDefinitionUtil.getProcess(ee.getProcessDefinitionId());FlowElement targetFlowElement = process.getFlowElement(target);ee.setCurrentFlowElement(targetFlowElement);FlowableEngineAgenda agenda = CommandContextUtil.getAgenda();agenda.planContinueProcessInCompensation(ee);taskEntityManager.delete(taskId);return null;}}

?

4.測(cè)試代碼:

接下來(lái),開(kāi)始測(cè)試,實(shí)例代碼如下:

@Test public void jump() {ManagementService managementService = processEngine.getManagementService();managementService.executeCommand(new ShareniuCommonJumpTaskCmd("2505","shareniu3")); }

act_ru_task表的數(shù)據(jù)如下:

?

通過(guò)這里可以看出,我們的命令類已經(jīng)生效了。那我們?cè)俅螆?zhí)行下上述代碼讓?shareniu3跳轉(zhuǎn)到shareniu2試下,實(shí)例代碼如下:

@Test public void jump() {ManagementService managementService = processEngine.getManagementService();managementService.executeCommand(new ShareniuCommonJumpTaskCmd("5002","shareniu2")); }

act_ru_task表的數(shù)據(jù)如下:

上述的命令類確實(shí)很好用的。

5.上述跳轉(zhuǎn)命令類的缺陷:

1.上述的命令類只適用于6.x版本的引擎。包括模板以及實(shí)例都是6.x版本。

2.只適用于常規(guī)節(jié)點(diǎn)的跳轉(zhuǎn)。(關(guān)于分支節(jié)點(diǎn)的跳轉(zhuǎn)、多實(shí)例節(jié)點(diǎn)的跳轉(zhuǎn)以及并行節(jié)點(diǎn)的跳轉(zhuǎn)后續(xù)文章會(huì)詳細(xì)說(shuō)明)。

3.上述的代碼適用于flowable6.1.2以后的版本。關(guān)于flowable6.1.2之前的版本思路一樣,只是代碼要稍微微調(diào)一下,部分代碼如下所示:

ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();

TaskEntityManager taskEntityManager = commandContext.getTaskEntityManager();

注意:flowable6.1.2只是對(duì)代碼所在的包進(jìn)行了調(diào)整,核心思想并沒(méi)有變化。

總結(jié)

以上是生活随笔為你收集整理的Flowable节点跳转的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。