项目地址:https://gitee.com/lwj/flowable.git 分支flowable-base
*业务场景:
收集每个员工的绩效考核信息;
收集一次组织活动的信息;
一个合同需要三个经理审批,可以是顺序的也可以是并行的;
一个合同计划审批有30个人审批,只需要其中70%的人审批通过即可。等等 *
1、任务多实例四个内置变量
属性 | 解释 |
---|---|
nrOfInstances | 一共有多少个实例 |
nrOfCompletedInstances | 已经完成的实例个数 |
nrOfActiveInstances | 未完成的实例个数 |
2、配置多实例
2.1、配置参数
2.2、配置候选人
2.3、配置结束条件
3、启动设置userList
public ReturnVo add(Leave leave, String sessionId) {
ReturnVo returnVo = new ReturnVo(ReturnCode.FAIL, "添加失败");
try {
String leaveId = UUIDGenerator.generate();
leave.setId(leaveId);
StartProcessInstanceVo startProcessInstanceVo = new StartProcessInstanceVo();
startProcessInstanceVo.setBusinessKey(leaveId);
User user = SecurityUtils.getCurrentUserObject();
startProcessInstanceVo.setCreator(user.getId());
startProcessInstanceVo.setCurrentUserCode(user.getId());
startProcessInstanceVo.setFormName("请假流程");
startProcessInstanceVo.setSystemSn("flow");
startProcessInstanceVo.setProcessDefinitionKey("leave");
Map<String, Object> variables = new HashMap<>();
variables.put("days", leave.getDays());
startProcessInstanceVo.setVariables(variables);
//设置三个人作为多实例的人员
List<String> userList = new ArrayList<>();
userList.add("00000005");
userList.add("00000006");
variables.put("userList", userList);
ReturnVo<ProcessInstance> returnStart = flowableProcessInstanceService.startProcessInstanceByKey(startProcessInstanceVo);
if (returnStart.getCode().equals(ReturnCode.SUCCESS)){
String processInstanceId = returnStart.getData().getProcessInstanceId();
leave.setProcessInstanceId(processInstanceId);
this.LeaveService.insertLeave(leave);
returnVo = new ReturnVo(ReturnCode.SUCCESS, "添加成功");
}else {
returnVo = new ReturnVo(returnStart.getCode(), returnStart.getMsg());
}
} catch (Exception e) {
logger.error("LeaveController-add:", e);
e.printStackTrace();
}
return returnVo;
}