• spring boot flowable多人前加签


    1、前加签插件

    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;
        }
    
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91

    2、Controller 处理

    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
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
  • 相关阅读:
    猿创征文|给设备做一个独立自主的小APP-实例详解
    【网络驱动】GMAC 系统框架
    android 13.0 SystemUI导航栏添加虚拟按键功能(二)
    influxdb2如何同时应用多个聚合函数
    无需编程经验,也能制作租车预约微信小程序,快速上手
    【雷达信号处理基础】第1讲 -- 雷达系统概述
    Hive工作原理
    FAISS+bge-large-zh在大语言模型LangChain本地知识库中的作用、原理与实践
    自监督直接和具体任务的结合(Task Related Self-Supervised Learning)的探索
    Windows10环境gradle安装与配置
  • 原文地址:https://blog.csdn.net/helenyqa/article/details/133376652