flowable删除组成员

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;

/**
 * @author HanKeQi
 * @date 2024/1/31
 */
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'";
        //删除正在运行的identitylink
        runtimeService.createNativeExecutionQuery().sql(String.format(sql, "act_ru_identitylink", identityLinkEntityId, userId)).list();

        //删除历史的identitylink
        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;
    }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值