spring boot flowable多人前加签

1、前加签插件

java 复制代码
package com.xxx.flowable.cmd;

import com.xxx.auth.security.user.SecurityUser;
import com.xxx.commons.ApplicationContextHolder;
import com.google.common.collect.Lists;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.TaskService;
import org.flowable.engine.impl.cmd.NeedsActiveTaskCmd;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
import org.flowable.task.service.impl.persistence.entity.TaskEntityImpl;

import java.util.*;

/**
 *
 * @author HanKeQi
 * @date 2023/9/25
 */
public class BeforeDelegateTaskCmd extends NeedsActiveTaskCmd<Void> {


    private List<String> assignees;


    public BeforeDelegateTaskCmd(String taskId, Set<String> assignees) {
        super(taskId);
        this.assignees = Lists.newArrayList(assignees);
    }


    @Override
    protected Void execute(CommandContext commandContext, TaskEntity taskEntity) {
        if (CollectionUtils.isNotEmpty(this.assignees)){
        	// 根据自己方法回去bean
            TaskService taskService = ApplicationContextHolder.getBean(TaskService.class);
            assert taskService != null;
            TaskEntityImpl currentTask = (TaskEntityImpl)taskEntity;
            String parentTaskId = currentTask.getParentTaskId();
            //获取当前操作人,也可以传入
            String userId = SecurityUser.getUserId();
            if (StringUtils.isEmpty(parentTaskId)){
                currentTask.setOwner(userId);
                currentTask.setAssignee(null);
                currentTask.setCountEnabled(true);
                currentTask.setScopeType("before");
                taskService.saveTask(taskEntity);
                parentTaskId = taskEntity.getId();
            }

            for (String assignee: this.assignees) {
                String uuid = UUID.randomUUID().toString();
                TaskEntity task = (TaskEntity)taskService.newTask(uuid);
                task.setCategory(currentTask.getCategory());
                task.setDescription(currentTask.getDescription());
                task.setTenantId(currentTask.getTenantId());
                task.setOwner(userId);
                task.setAssignee(assignee);
//                task.setExecutionId(currentTask.getExecutionId());
                task.setName(String.format("加签%s", currentTask.getName()));
                task.setParentTaskId(currentTask.getId());
                task.setProcessDefinitionId(currentTask.getProcessDefinitionId());
                task.setProcessInstanceId(currentTask.getProcessInstanceId());
                task.setTaskDefinitionKey(String.format("dy_%s", currentTask.getTaskDefinitionKey()));
//                task.setPriority(currentTask.getPriority());
                task.setCreateTime(new Date());

                task.setStatus(currentTask.getStatus());
                task.setItemCode(currentTask.getItemCode());
                task.setApproveType(currentTask.getApproveType());
                task.setBussId(currentTask.getBussId());
                task.setBussName(currentTask.getBussName());


                taskService.saveTask(task);
            }

            //如果是候选人,需要删除运行时候选表种的数据。
            long candidateCount = taskService.createTaskQuery().taskId(parentTaskId).taskCandidateUser(userId).count();
            if (candidateCount > 0) {
                taskService.deleteCandidateUser(parentTaskId, userId);
            }

        }

        return null;
    }

}

2、Controller 处理

java 复制代码
package com.xxx.flowable.controller;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.flowable.engine.TaskService;
import org.flowable.task.api.Task;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Set;

/**
 * @author HanKeQi
 * @date 2023/9/28
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("flowable/test")
public class Test001Controller {

    private final TaskService taskService;

    @PostMapping
    public String submit(String taskId, Set<String> assignees){
        Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
        Task parentTask = null;
        String parentTaskId = task.getParentTaskId();
        if (StringUtils.isNotEmpty(parentTaskId)){
            parentTask = taskService.createTaskQuery().taskId(parentTaskId).singleResult();
            List<Task> subTasks = taskService.getSubTasks(parentTaskId);
            //处理最后一个的时候,一定要把任务返还给加签人
            if (!CollectionUtils.isEmpty(subTasks) && subTasks.size() == 1) {
                taskService.resolveTask(parentTaskId);
            }
        }
        //如果要获取变量请使用parentTask 获取传输变量
        return "ok";
    }
}
相关推荐
鸡鸭扣1 小时前
Docker:3、在VSCode上安装并运行python程序或JavaScript程序
运维·vscode·python·docker·容器·js
paterWang2 小时前
基于 Python 和 OpenCV 的酒店客房入侵检测系统设计与实现
开发语言·python·opencv
东方佑2 小时前
使用Python和OpenCV实现图像像素压缩与解压
开发语言·python·opencv
神秘_博士3 小时前
自制AirTag,支持安卓/鸿蒙/PC/Home Assistant,无需拥有iPhone
arm开发·python·物联网·flutter·docker·gitee
Moutai码农4 小时前
机器学习-生命周期
人工智能·python·机器学习·数据挖掘
brevity_souls4 小时前
Spring Boot 内置工具类
java·spring boot
luoluoal4 小时前
基于Spring Boot+Vue的宠物服务管理系统(源码+文档)
vue.js·spring boot·宠物
小钊(求职中)4 小时前
Java开发实习面试笔试题(含答案)
java·开发语言·spring boot·spring·面试·tomcat·maven
小白教程5 小时前
python学习笔记,python处理 Excel、Word、PPT 以及邮件自动化办公
python·python学习·python安装
武陵悭臾5 小时前
网络爬虫学习:借助DeepSeek完善爬虫软件,实现模拟鼠标右键点击,将链接另存为本地文件
python·selenium·网络爬虫·pyautogui·deepseek·鼠标右键模拟·保存链接为htm