flowable 實現(xiàn)投票功能

最近想做一個投票節(jié)點,具體需求是這樣的

  • 流程同意到一定比例時,往下走
  • 如果流程不同意時,即返回指定的任何節(jié)點.
    注意:流程引擎是我用flowable進(jìn)行改造的,有些是需要重寫節(jié)點的行為,現(xiàn)在只說關(guān)鍵的地方,供大家參考.
  1. 流程定義-投票的行為
    生成的流程定義如下:
<userTask id="N5" name="審批" flowable:async="true" flowable:assignee="1,2,3">
      <multiInstanceLoopCharacteristics isSequential="false" flowable:collection="{starmark_emptycollection}" flowable:elementVariable="starmark_atuser">
        <completionCondition>${voteMultiInstanceService.completeTask(execution,'22','N6')}</completionCondition>
      </multiInstanceLoopCharacteristics>
    </userTask>

其中voteMultiInstanceService是一個決策判斷的bean類

  1. 流程判斷是否達(dá)到同意或不同意的標(biāo)準(zhǔn)
@Service("voteMultiInstanceService")
public class VoteMultiInstanceService implements Serializable {

    @Autowired
    private RuntimeService runtimeService;

    public boolean completeTask(DelegateExecution execution, String voteRate, String voteRefuseNode) {
        //所有人員審批
        int nrOfInstances = (Integer) execution.getVariable("nrOfInstances"); //總的會簽任務(wù)數(shù)量
        int nrOfCompletedInstances = (Integer) execution.getVariable("nrOfCompletedInstances"); //總的會簽任務(wù)數(shù)量---已執(zhí)行
        int vote_pass_count = execution.getVariable("starmark_vote_pass_count") == null ? 0 : (Integer) execution.getVariable("starmark_vote_pass_count"); //總的會簽任務(wù)數(shù)量---已執(zhí)行的
        int voteRateInteger = Integer.parseInt(voteRate);

        if (((float) vote_pass_count / nrOfInstances * 100.0) >= voteRateInteger) {
            return true;
        }
        //不同意
        if ( ((float)(nrOfCompletedInstances - vote_pass_count) / nrOfInstances) * 100.0 > (100 - voteRateInteger)) {
            execution.setVariableLocal("starmark_voteRefuseNode",voteRefuseNode);
            return true;
        }
        return false;
    }
}
  1. 流程不同意時,返回指定的節(jié)點
    按上所示,流程不同意時,流程設(shè)置了一個變量starmark_voteRefuseNode,如果該變量有值,就需要流轉(zhuǎn)到指定的節(jié)點
    這個時候,需要重寫ParallelMultiInstanceBehavior的cleanupMiRoot,具體重寫如下:
  protected void cleanupMiRoot(DelegateExecution execution) {
        // Delete multi instance root and all child executions.
        // Create a fresh execution to continue

        ExecutionEntity multiInstanceRootExecution = (ExecutionEntity) getMultiInstanceRootExecution(execution);
        String voteRefuseNode=execution.getVariableLocal("starmark_voteRefuseNode")==null?"":execution.getVariableLocal("starmark_voteRefuseNode")+"";
        FlowElement flowElement = multiInstanceRootExecution.getCurrentFlowElement();
        ExecutionEntity parentExecution = multiInstanceRootExecution.getParent();

        ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager();
        Collection<String> executionIdsNotToSendCancelledEventsFor = execution.isMultiInstanceRoot() ? null : Collections.singletonList(execution.getId());
        executionEntityManager.deleteChildExecutions(multiInstanceRootExecution, null, executionIdsNotToSendCancelledEventsFor, DELETE_REASON_END, true, flowElement);
        executionEntityManager.deleteRelatedDataForExecution(multiInstanceRootExecution, DELETE_REASON_END);
        executionEntityManager.delete(multiInstanceRootExecution);

        ExecutionEntity newExecution = executionEntityManager.createChildExecution(parentExecution);
        //投票節(jié)點
        if(StringUtils.isEmpty(voteRefuseNode)) {
            //正常流轉(zhuǎn)
            newExecution.setCurrentFlowElement(flowElement);
            super.leave(newExecution);
        } else {
            //不同意時,返回指定節(jié)點
            org.flowable.bpmn.model.Process process = ProcessDefinitionUtil.getProcess(newExecution.getProcessDefinitionId());
            FlowElement targetFlowElement = process.getFlowElement(voteRefuseNode);
            newExecution.setCurrentFlowElement(targetFlowElement);
            FlowableEngineAgenda agenda = CommandContextUtil.getAgenda();
            agenda.planContinueProcessInCompensation(newExecution);
        }
    }

至此,投票功能已完成

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末勃刨,一起剝皮案震驚了整個濱河市争占,隨后出現(xiàn)的幾起案子贮尉,更是在濱河造成了極大的恐慌辱挥,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,651評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件洋闽,死亡現(xiàn)場離奇詭異颊郎,居然都是意外死亡带射,警方通過查閱死者的電腦和手機微渠,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,468評論 3 392
  • 文/潘曉璐 我一進(jìn)店門搭幻,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人逞盆,你說我怎么就攤上這事檀蹋。” “怎么了云芦?”我有些...
    開封第一講書人閱讀 162,931評論 0 353
  • 文/不壞的土叔 我叫張陵俯逾,是天一觀的道長。 經(jīng)常有香客問我舅逸,道長桌肴,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,218評論 1 292
  • 正文 為了忘掉前任堡赔,我火速辦了婚禮识脆,結(jié)果婚禮上设联,老公的妹妹穿的比我還像新娘善已。我一直安慰自己,他們只是感情好离例,可當(dāng)我...
    茶點故事閱讀 67,234評論 6 388
  • 文/花漫 我一把揭開白布换团。 她就那樣靜靜地躺著,像睡著了一般宫蛆。 火紅的嫁衣襯著肌膚如雪艘包。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,198評論 1 299
  • 那天耀盗,我揣著相機與錄音想虎,去河邊找鬼。 笑死叛拷,一個胖子當(dāng)著我的面吹牛舌厨,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播忿薇,決...
    沈念sama閱讀 40,084評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼裙椭,長吁一口氣:“原來是場噩夢啊……” “哼躏哩!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起揉燃,我...
    開封第一講書人閱讀 38,926評論 0 274
  • 序言:老撾萬榮一對情侶失蹤扫尺,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后炊汤,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體正驻,經(jīng)...
    沈念sama閱讀 45,341評論 1 311
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,563評論 2 333
  • 正文 我和宋清朗相戀三年抢腐,在試婚紗的時候發(fā)現(xiàn)自己被綠了拨拓。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,731評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡氓栈,死狀恐怖渣磷,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情授瘦,我是刑警寧澤醋界,帶...
    沈念sama閱讀 35,430評論 5 343
  • 正文 年R本政府宣布,位于F島的核電站提完,受9級特大地震影響形纺,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜徒欣,卻給世界環(huán)境...
    茶點故事閱讀 41,036評論 3 326
  • 文/蒙蒙 一逐样、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧打肝,春花似錦脂新、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,676評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至断医,卻和暖如春滞乙,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背鉴嗤。 一陣腳步聲響...
    開封第一講書人閱讀 32,829評論 1 269
  • 我被黑心中介騙來泰國打工斩启, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人醉锅。 一個月前我還...
    沈念sama閱讀 47,743評論 2 368
  • 正文 我出身青樓兔簇,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子男韧,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,629評論 2 354

推薦閱讀更多精彩內(nèi)容

  • Swift1> Swift和OC的區(qū)別1.1> Swift沒有地址/指針的概念1.2> 泛型1.3> 類型嚴(yán)謹(jǐn) 對...
    cosWriter閱讀 11,097評論 1 32
  • feisky云計算朴摊、虛擬化與Linux技術(shù)筆記posts - 1014, comments - 298, trac...
    不排版閱讀 3,844評論 0 5
  • 這是16年5月份編輯的一份比較雜亂適合自己觀看的學(xué)習(xí)記錄文檔,今天18年5月份再次想寫文章此虑,發(fā)現(xiàn)簡書還為我保存起的...
    Jenaral閱讀 2,752評論 2 9
  • ReentrantLock 介紹 一個可重入的互斥鎖甚纲,它具有與使用{synchronized}方法和語句訪問的隱式...
    tomas家的小撥浪鼓閱讀 4,049評論 1 4
  • “不羨神仙一年只一天韭寸,只恨人間不夠千年春哨。” 前幾日恩伺,無意間看到了網(wǎng)友剪輯仙劍三里紫萱的短片赴背,配的是這首...
    EllenKaren閱讀 964評論 0 0