|| event.getType().equals(ActivitiEventType.TASK_ASSIGNED)) {
ActivitiEntityEvent entityEvent = (ActivitiEntityEvent) event;
Object entity = entityEvent.getEntity();
if (entity instanceof TaskEntity) {
TaskEntity taskEntity = (TaskEntity) entityEvent.getEntity();
Map<String, String> skipTasks = new HashMap<>();
skipTasks.put("usertask2", "user1"); // 预先设定
skipTasks.put("usertask4", "user1"); // 动态设定以
skipTasks.put("usertask5", "user1"); // 候选人
skipTasks.put("usertask6", "user1"); // 候选组
EngineServices engineServices = entityEvent.getEngineServices();
IdentityService identityService = engineServices.getIdentityService();
TaskService taskService = engineServices.getTaskService();
String taskDefinitionKey = taskEntity.getTaskDefinitionKey();
String userId = skipTasks.get(taskDefinitionKey);
if (userId == null) {
return;
}
System.out.println("key: " + taskDefinitionKey + ", userId=" + userId);
// 查询当前人的组
List<String> groupIds = new ArrayList<>();
List<Group> list = identityService.createGroupQuery().groupMember(userId).list();
for (Group group : list) {
groupIds.add(group.getId());
}
// 如果当前节点是需要跳过的,直接调用任务完成命令
if (event.getType().equals(ActivitiEventType.TASK_ASSIGNED)) {
if (userId != null) {
if (taskEntity.getAssignee().equals(userId)) {
skipTask(taskEntity, event);
}
}
}
// 创建事件用来处理候选的情况
if (event.getType().equals(ActivitiEventType.TASK_CREATED) && taskEntity.getAssignee() == null) {
Set<IdentityLink> candidates = taskEntity.getCandidates();
for (IdentityLink identityLink : candidates) {
// 处理候选人
if (identityLink.getUserId() != null && identityLink.getUserId().equals(userId)) {
// 必须删除link,否则报错
taskEntity.deleteUserIdentityLink(identityLink.getUserId(), "candidate");
// 签收触发TASK_ASSIGNED
taskService.claim(taskEntity.getId(), userId);
} else if (groupIds.contains(identityLink.getGroupId())) {
// 必须删除link,否则报错
taskEntity.deleteGroupIdentityLink(identityLink.getGroupId(), "candidate");
// 签收触发TASK_ASSIGNED
taskService.claim(taskEntity.getId(), userId);
}
}
}
}
} else {