flowable中傳入審批人是list


 

 

 

 

 

 

package org.springblade.flow.engine.listener;

import org.flowable.engine.delegate.DelegateExecution;
import org.springframework.stereotype.Component;

import java.io.Serializable;

//判斷是否一票否決
@Component("multiInstance")
public class MultiInstanceCompleteTask implements Serializable {
    /**
     * 評估結果判定條件
     *
     * @param execution 分配執行實例
     */
    public boolean accessCondition(DelegateExecution execution) {
        //已完成的實例數
        int completedInstance = (int) execution.getVariable("nrOfCompletedInstances");
        //總實例數
        int nrOfInstances = (int) execution.getVariable("nrOfInstances");
        //否決判斷,一票否決
        if (execution.getVariable("pass") != null) {
            boolean pass = (boolean) execution.getVariable("pass");
            if (!pass) {
                //輸出方向為拒絕
                //一票否決其他實例沒必要做,結束
                return true;
            }
        }
        //所有實例任務未全部做完則繼續其他實例任務
        if (completedInstance != nrOfInstances) {
            return false;
        } else {
            //輸出方向為贊同
            //所有都做完了沒被否決,結束
            return true;
        }
    }

}
package org.springblade.flow.engine.listener;

import org.flowable.engine.delegate.DelegateExecution;
import org.springframework.stereotype.Component;

import java.io.Serializable;

//多實例任務節點完成條件
@Component("multiInstance")
public class MultiInstance implements Serializable {

    /**
     * 一票否決
     * 1、如果有駁回操作,則駁回當前任務節點。
     * 2、若已審批人數不等於總人數,則多實例任務繼續執行
     * 3、若已審批人數等於總人數,則結束當前任務節點,進入下一個任務節點。
     * @param execution 分配執行實例
     */
    public boolean vetoPower(DelegateExecution execution) {
        //已完成的實例數
        int completedInstance = (int) execution.getVariable("nrOfCompletedInstances");
        //總實例數
        int nrOfInstances = (int) execution.getVariable("nrOfInstances");
        //否決判斷,一票否決
        if (execution.getVariable("pass") != null) {
            boolean pass = (boolean) execution.getVariable("pass");
            if (!pass) {
                //輸出方向為拒絕
                //一票否決其他實例沒必要做,結束
                return true;
            }
        }
        //所有實例任務未全部做完則繼續其他實例任務
        if (completedInstance != nrOfInstances) {
            return false;
        } else {
            //輸出方向為贊同
            //所有都做完了沒被否決,結束
            return true;
        }
    }

    /**
     * 一票否決 + 少數服從多數
     * 1、如果有駁回操作,則駁回當前任務節點。
     * 2、若同意人數比例大於等於0.5,則結束當前任務節點,進入下一個任務節點。
     * 3、若不同意人數比例大於0.5,則駁回當前任務節點。
     * 4、否則多實例任務繼續執行
     * @param execution
     * @return
     */
    public boolean vetoPowerAndObeyMost(DelegateExecution execution) {
        //否決判斷,一票否決
        if (execution.getVariable("pass") != null) {
            boolean pass = (boolean) execution.getVariable("pass");
            if (!pass) {
                //輸出方向為拒絕
                //一票否決其他實例沒必要做,結束
                return true;
            }
        }
        //已完成的實例數
        int completedInstance = (int) execution.getVariable("nrOfCompletedInstances");
        //總實例數
        int nrOfInstances = (int) execution.getVariable("nrOfInstances");
        //獲取不同意的次數
        int rejectCount = (int)execution.getVariable("rejectCount");
        //獲取同意人的次數
        int agreeCount = (int)execution.getVariable("agreeCount");
        //所有實例任務未全部做完則繼續其他實例任務
        if (completedInstance != nrOfInstances) {
            //不同意的人數大於設置比例*總人數
            if (rejectCount*1.00/nrOfInstances>0.5){
                execution.setVariable("pass", false);
                return true;
            }
            if (agreeCount*1.00/nrOfInstances>=0.5){
                execution.setVariable("pass", true);
                return true;
            }
            return false;
        } else {
            //輸出方向為贊同
            //所有都做完了沒被否決,結束
            return true;
        }
    }

    /**
     * 少數服從多數
     * 1、若同意人數比例大於等於0.5,則結束當前任務節點,進入下一個任務節點。
     * 2、若不同意人數比例大於0.5,則駁回當前任務節點。
     * 3、否則多實例任務繼續執行
     * @param execution
     * @return
     */
    public boolean obeyMost(DelegateExecution execution) {
        //已完成的實例數
        int completedInstance = (int) execution.getVariable("nrOfCompletedInstances");
        //總實例數
        int nrOfInstances = (int) execution.getVariable("nrOfInstances");
        //獲取不同意的次數
        int rejectCount = (int)execution.getVariable("rejectCount");
        //獲取同意人的次數
        int agreeCount = (int)execution.getVariable("agreeCount");
        //所有實例任務未全部做完則繼續其他實例任務
        if (completedInstance != nrOfInstances) {
            //不同意的人數大於設置比例*總人數
            if (rejectCount*1.00/nrOfInstances>0.5){
                execution.setVariable("pass", false);
                return true;
            }
            if (agreeCount*1.00/nrOfInstances>=0.5){
                execution.setVariable("pass", true);
                return true;
            }
            return false;
        } else {
            //不同意的人數大於設置比例*總人數
            if (rejectCount*1.00/nrOfInstances>0.5){
                execution.setVariable("pass", false);
                return true;
            }
            if (agreeCount*1.00/nrOfInstances>=0.5){
                execution.setVariable("pass", true);
                return true;
            }
            return true;
        }
    }

    public boolean test(DelegateExecution execution,int i,String a){
        System.out.println("===========i====="+i);
        System.out.println("===========a====="+a);
        return false;
    }


}
package org.springblade.flow.engine.listener.task;

import org.flowable.engine.delegate.TaskListener;
import org.flowable.engine.impl.el.FixedValue;
import org.flowable.task.service.delegate.DelegateTask;
import org.springblade.core.tool.utils.Func;
import org.springframework.stereotype.Component;

//計算同意和拒絕數量
@Component("countAgreeAndRejectTaskListener")
public class CountAgreeAndRejectTaskListener implements TaskListener {

    private FixedValue agreeFlagText;
    private FixedValue agreeCountText;
    private FixedValue rejectCountText;

    @Override
    public void notify(DelegateTask delegateTask) {
        Boolean pass = (Boolean) delegateTask.getVariable(Func.toStr(agreeFlagText.getExpressionText(),"pass"));

        String agreeCountTextVariable = Func.toStr(agreeCountText.getExpressionText(),"agreeCount") ;
        // 校驗 agreeCountText 是否已經存在
        if (!delegateTask.hasVariable(agreeCountTextVariable)) {
            delegateTask.setVariable(agreeCountTextVariable, 0);
        }
        //ExecutionListner類中設置的同意計數變量
        int agreeCount = (int) delegateTask.getVariable(agreeCountTextVariable);

        String rejectCountTextVariable = Func.toStr(rejectCountText.getExpressionText(),"rejectCount") ;
        // 校驗 rejectCountText 是否已經存在
        if (!delegateTask.hasVariable(rejectCountTextVariable)) {
            delegateTask.setVariable(rejectCountTextVariable, 0);
        }
        //ExecutionListner類中設置的拒絕計數變量
        int rejectCount = (int) delegateTask.getVariable(rejectCountTextVariable);

        if (pass){
            //同意
            delegateTask.setVariable(agreeCountTextVariable, ++agreeCount);
        }
        else{
            //拒絕
            delegateTask.setVariable(rejectCountTextVariable, ++rejectCount);
        }
    }
}
package org.springblade.flow.engine.listener.execution;

import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.flowable.engine.impl.el.FixedValue;
import org.springblade.core.tool.utils.Func;
import org.springframework.stereotype.Component;

//設置初始值:同意、駁回計數初始化
@Component("initAgreeAndRejectExecutionListener")
public class InitAgreeAndRejectExecutionListener implements ExecutionListener {

    //頁面注入同意計數變量名稱
    private FixedValue agreeCountText;
    //頁面注入駁回計數變量名稱
    private FixedValue rejectCountText;

    @Override
    public void notify(DelegateExecution delegateExecution) {
        delegateExecution.setVariable(Func.toStr(agreeCountText.getExpressionText(),"agreeCount"),0);
        delegateExecution.setVariable(Func.toStr(rejectCountText.getExpressionText(),"rejectCount"),0);
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM