工作流Flowable实战 (六)自定义身份

本文档介绍了如何重写Flowable的工作流接口以适配系统的用户数据,并详细阐述了如何在前端和后端实现自定义审核人的功能。前端通过修改flowable-modeler源码增加新的分配选项,后端利用监听器监听任务创建事件,动态设置任务的审核人为发起人的上级领导。通过这种方式,实现了与系统用户数据的无缝对接和自定义审批流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


一、重写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
				}
			}
		}));
	}
}
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值