一、重写Flowable接口
系统中肯定有自己的一套用户,而flowable默认用户和用户组无法和自己系统中的用户统一,所以重写floeable用户和用户组接口,让flowable直接查自己的用户数据。
EditorUsersResource,EditorGroupsResource

二、自定义审核人
1、前端增加选项
flowable默认有分配给流程发起人,想自定义一个分配给流程发起人上级领导,如何实现。


修改flowable-modeler源码,此时页面中会多出一个选项。

1、后端监听
后端监听器监听任务的创建事件,动态赋值任务的审核人。
@Configuration
public class FlowableGlobListenerConfig implements ApplicationListener<ContextRefreshedEvent> {
@Autowired
private SpringProcessEngineConfiguration configuration;
@Autowired
private GlobalTaskCreatedListener globalTaskCreatedListener;
@Override
public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
FlowableEventDispatcher dispatcher = configuration.getEventDispatcher();
dispatcher.addEventListener(globalTaskCreatedListener, FlowableEngineEventType.TASK_CREATED);
}
}
@Component
@Slf4j
public class GlobalTaskCreatedListener implements FlowableEventListener {
@Autowired
private TaskService taskService;
@Autowired
private RuntimeService runtimeService;
@Autowired
private RepositoryService repositoryService;
@Override
public void onEvent(FlowableEvent event) {
FlowableEntityEventImpl entityEvent = (FlowableEntityEventImpl) event;
TaskEntity taskEntity = (TaskEntity) entityEvent.getEntity();
String processInstanceId = taskEntity.getProcessInstanceId();
BpmnModel bpmnModel = repositoryService.getBpmnModel(taskEntity.getProcessDefinitionId());
List<Process> processes = bpmnModel.getProcesses();
processes.forEach(process -> process.findFlowElementsOfType(UserTask.class).forEach(userTask -> {
if (StringUtil.equals(userTask.getId(), taskEntity.getTaskDefinitionKey()) && StringUtil.isNotBlank(userTask.getAssignee())) {
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
if (StringUtil.equals(userTask.getAssignee().toLowerCase(), FlowAssigneeEnum.INITIATOR.getKey())) {
taskService.setAssignee(taskEntity.getId(), processInstance.getStartUserId());
} else if (StringUtil.equals(userTask.getAssignee().toLowerCase(), FlowAssigneeEnum.SUPERIOR.getKey())) {
String startUserId = processInstance.getStartUserId();
User startUser = UserCache.getUser(Long.parseLong(startUserId));
startUser.getDeptId();
// TODO 自行实现获取上级领导用户id
}
}
}));
}
}
本文档介绍了如何重写Flowable的工作流接口以适配系统的用户数据,并详细阐述了如何在前端和后端实现自定义审核人的功能。前端通过修改flowable-modeler源码增加新的分配选项,后端利用监听器监听任务创建事件,动态设置任务的审核人为发起人的上级领导。通过这种方式,实现了与系统用户数据的无缝对接和自定义审批流程。
2616





