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); } }