flowable删除组成员
package com.newdata.flowable.cmd;
import com.newdata.commons.exception.BusinessException;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.flowable.engine.impl.cmd.NeedsActiveTaskCmd;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.identitylink.api.IdentityLinkType;
import org.flowable.identitylink.service.impl.persistence.entity.IdentityLinkEntity;
import org.flowable.identitylink.service.impl.persistence.entity.IdentityLinkEntityManager;
import org.flowable.task.service.TaskService;
import org.flowable.task.service.TaskServiceConfiguration;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
import org.flowable.task.service.impl.persistence.entity.TaskEntityImpl;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.stream.Collectors;
public class DeleteCandidateUserCmd extends NeedsActiveTaskCmd<Void> {
protected String assignee;
public DeleteCandidateUserCmd(String taskId, String assignee) {
super(taskId);
this.assignee = assignee;
}
@Override
protected Void execute(CommandContext commandContext, TaskEntity taskEntity) {
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);
IdentityLinkEntityManager identityLinkEntityManager = processEngineConfiguration.getIdentityLinkServiceConfiguration().getIdentityLinkEntityManager();
List<IdentityLinkEntity> identityLinks = taskEntity.getIdentityLinks();
List<IdentityLinkEntity> collect = identityLinks.stream().filter(o -> assignee.equals(o.getUserId())).collect(Collectors.toList());
if (CollectionUtils.isEmpty(collect)){
throw new BusinessException("未找到需要删除人员");
}
IdentityLinkEntity identityLinkEntity = collect.get(0);
String identityLinkEntityId = identityLinkEntity.getId();
String userId = identityLinkEntity.getUserId();
String id = taskEntity.getId();
String processInstanceId = taskEntity.getProcessInstanceId();
identityLinkEntityManager.deleteTaskIdentityLink(id, identityLinks, userId, null, IdentityLinkType.CANDIDATE);
RuntimeService runtimeService = processEngineConfiguration.getRuntimeService();
String sql = "DELETE FROM %s WHERE ID_='%s' and USER_ID_='%s'";
runtimeService.createNativeExecutionQuery().sql(String.format(sql, "act_ru_identitylink", identityLinkEntityId, userId)).list();
runtimeService.createNativeExecutionQuery().sql(String.format(sql, "act_hi_identitylink", identityLinkEntityId, userId)).list();
TaskServiceConfiguration taskServiceConfiguration = processEngineConfiguration.getTaskServiceConfiguration();
TaskService taskService = taskServiceConfiguration.getTaskService();
TaskEntityImpl taskEntityImpl = (TaskEntityImpl)taskEntity;
taskEntityImpl.setIdentityLinkCount(taskEntityImpl.getIdentityLinkCount() - 1);
taskService.updateTask(taskEntityImpl, false);
return null;
}
}