Class TaskServiceImpl

  • All Implemented Interfaces:
    TaskService

    public class TaskServiceImpl
    extends java.lang.Object
    implements TaskService
    任务执行业务类

    官网尊重知识产权,不允许非法使用,后果自负

    Since:
    1.0
    Author:
    hubin
    • Method Detail

      • updateCurrentNode

        protected void updateCurrentNode​(FlwTask flwTask)
        更新当前执行节点信息
        Parameters:
        flwTask - 当前所在执行任务
      • executeTask

        public FlwTask executeTask​(java.lang.Long taskId,
                                   FlowCreator flowCreator,
                                   java.util.Map<java.lang.String,​java.lang.Object> args,
                                   TaskState taskState,
                                   TaskEventType eventType)
        执行任务
        Specified by:
        executeTask in interface TaskService
        Parameters:
        taskId - 任务ID
        flowCreator - 任务创建者
        args - 执行参数
        taskState - 任务状态
        eventType - 执行事件
        Returns:
        FlwTask
      • forceCompleteAllTask

        public boolean forceCompleteAllTask​(java.lang.Long instanceId,
                                            FlwTask currentFlwTask,
                                            FlowCreator flowCreator,
                                            InstanceState instanceState,
                                            TaskEventType eventType)
        强制完成所有任务
        Specified by:
        forceCompleteAllTask in interface TaskService
        Parameters:
        instanceId - 流程实例ID
        currentFlwTask - 当前任务
        flowCreator - 处理人员
        instanceState - 流程实例最终状态
        eventType - 监听事件类型
        Returns:
        true 成功 false 失败
      • forceCompleteTask

        public boolean forceCompleteTask​(FlwTask flwTask,
                                         FlowCreator flowCreator,
                                         TaskState taskState,
                                         TaskEventType eventType)
        Description copied from interface: TaskService
        强制完成某个任务
        Specified by:
        forceCompleteTask in interface TaskService
        Parameters:
        flwTask - 审批任务
        flowCreator - 处理人员
        taskState - 流任务状态
        eventType - 监听事件类型
        Returns:
        true 成功 false 失败
      • executeJumpTask

        public java.util.Optional<java.util.List<FlwTask>> executeJumpTask​(java.lang.Long taskId,
                                                                           java.lang.String nodeKey,
                                                                           FlowCreator flowCreator,
                                                                           java.util.Map<java.lang.String,​java.lang.Object> args,
                                                                           java.util.function.Function<FlwTask,​Execution> executionFunction,
                                                                           TaskType taskTye)
        执行节点跳转任务
        Specified by:
        executeJumpTask in interface TaskService
        Parameters:
        taskId - 任务ID
        nodeKey - 跳转至目标节点key
        flowCreator - 任务创建者
        args - 任务参数
        executionFunction - 执行函数
        taskTye - 任务类型,仅支持 jump rejectJump routeJump
        Returns:
        当前 flowCreator 所在的任务
      • getAllowedFlwTask

        protected FlwTask getAllowedFlwTask​(java.lang.Long taskId,
                                            FlowCreator flowCreator,
                                            java.util.Map<java.lang.String,​java.lang.Object> args,
                                            TaskState taskState)
        获取执行任务并验证合法性
        Parameters:
        taskId - 任务ID
        flowCreator - 任务创建者
        args - 执行参数
        taskState - TaskState
        Returns:
        流程任务
      • moveToHisTask

        protected boolean moveToHisTask​(FlwTask flwTask,
                                        TaskState taskState,
                                        FlowCreator flowCreator)
        迁移任务至历史表
        Parameters:
        flwTask - 执行任务
        taskState - 任务状态
        flowCreator - 任务创建者
        Returns:
        true 成功 false 失败
      • moveToHisTaskActor

        protected void moveToHisTaskActor​(java.util.List<FlwTaskActor> taskActors)
        迁移任务参与者至历史表
        Parameters:
        taskActors - 任务参与者列表
      • completeActiveTasksByInstanceId

        public boolean completeActiveTasksByInstanceId​(java.lang.Long instanceId,
                                                       FlowCreator flowCreator)
        完成指定实例ID活动任务
        Specified by:
        completeActiveTasksByInstanceId in interface TaskService
        Parameters:
        instanceId - 实例ID
        flowCreator - 处理人员
        Returns:
        true 成功 false 失败
      • updateTaskById

        public void updateTaskById​(FlwTask flwTask,
                                   FlowCreator flowCreator)
        更新任务对象的 finishTime、createBy、expireTime、version、variable
        Specified by:
        updateTaskById in interface TaskService
        Parameters:
        flwTask - 任务对象
        flowCreator - 处理人员
      • viewTask

        public boolean viewTask​(java.lang.Long taskId,
                                FlowCreator flowCreator)
        查看任务设置为已阅状态
        Specified by:
        viewTask in interface TaskService
        Parameters:
        taskId - 任务ID
        flowCreator - 处理人员
        Returns:
        true 成功 false 失败
      • claimRole

        public FlwTask claimRole​(java.lang.Long taskId,
                                 FlowCreator flowCreator)
        Description copied from interface: TaskService
        角色根据 任务ID 认领任务,删除其它任务参与者
        Specified by:
        claimRole in interface TaskService
        Parameters:
        taskId - 任务ID
        flowCreator - 任务认领者
        Returns:
        Task 任务对象
      • claimDepartment

        public FlwTask claimDepartment​(java.lang.Long taskId,
                                       FlowCreator flowCreator)
        Description copied from interface: TaskService
        部门根据 任务ID 认领任务,删除其它任务参与者
        Specified by:
        claimDepartment in interface TaskService
        Parameters:
        taskId - 任务ID
        flowCreator - 任务认领者
        Returns:
        Task 任务对象
      • claim

        protected FlwTask claim​(java.lang.Long taskId,
                                AgentType agentType,
                                TaskEventType eventType,
                                FlowCreator flowCreator)
        根据 任务ID 认领任务,删除其它任务参与者
        Parameters:
        taskId - 任务ID
        agentType - 代理人类型
        eventType - 流程引擎监听类型
        flowCreator - 任务认领者
        Returns:
        Task 任务对象
      • transferTask

        public boolean transferTask​(FlowCreator flowCreator,
                                    FlowCreator assigneeFlowCreator)
        Description copied from interface: TaskService
        参与者的所有任务【离职转办】给指定办理人

        用于任务参与者离职

        Specified by:
        transferTask in interface TaskService
        Parameters:
        flowCreator - 任务参与者
        assigneeFlowCreator - 指定办理人
        Returns:
        true 成功 false 失败
      • assigneeTask

        public boolean assigneeTask​(java.lang.Long taskId,
                                    TaskType taskType,
                                    FlowCreator flowCreator,
                                    java.util.List<FlowCreator> assigneeFlowCreators,
                                    java.util.Map<java.lang.String,​java.lang.Object> args,
                                    java.util.function.Function<FlwTask,​java.lang.Boolean> check)
        根据 任务ID 分配任务给指定办理人、重置任务类型
        Specified by:
        assigneeTask in interface TaskService
        Parameters:
        taskId - 任务ID
        taskType - 任务类型
        flowCreator - 任务参与者
        assigneeFlowCreators - 指定办理人列表
        args - 任务参数
        check - 校验函数,可以根据 dbFlwTask.getAssignorId() 是否存在判断为重发分配
        Returns:
        true 成功 false 失败
      • getAllowedFlwTaskActor

        protected FlwTaskActor getAllowedFlwTaskActor​(java.lang.Long taskId,
                                                      FlowCreator flowCreator)
        获取指定 任务ID 合法参与者对象
        Parameters:
        taskId - 任务ID
        flowCreator - 任务参与者
        Returns:
        任务参与者
      • resolveTask

        public boolean resolveTask​(java.lang.Long taskId,
                                   FlowCreator flowCreator)
        根据 任务ID 解决委派任务
        Specified by:
        resolveTask in interface TaskService
        Parameters:
        taskId - 任务ID
        flowCreator - 任务参与者
        Returns:
        true 成功 false 失败
      • reclaimTask

        public java.util.Optional<java.util.List<FlwTask>> reclaimTask​(java.lang.Long taskId,
                                                                       FlowCreator flowCreator)
        拿回任务、根据历史任务ID撤回下一个节点的任务、恢复历史任务
        Specified by:
        reclaimTask in interface TaskService
        Parameters:
        taskId - 任务ID(当前节点的父任务ID属于历史任务)
        flowCreator - 任务创建者
        Returns:
        拿回任务
      • resume

        public boolean resume​(java.lang.Long instanceId,
                              java.lang.String nodeKey,
                              FlowCreator flowCreator)
        唤醒撤回或拒绝终止历史任务
        Specified by:
        resume in interface TaskService
        Parameters:
        instanceId - 历史实例ID
        nodeKey - 节点key历史任务
        flowCreator - 任务唤醒者
        Returns:
        true 成功 false 失败
      • withdrawTask

        public java.util.Optional<java.util.List<FlwTask>> withdrawTask​(java.lang.Long taskId,
                                                                        FlowCreator flowCreator)
        撤回指定的任务
        Specified by:
        withdrawTask in interface TaskService
        Parameters:
        taskId - 待撤回历史任务ID
        flowCreator - 任务创建者
        Returns:
        Task 任务对象
      • rejectTask

        public java.util.Optional<java.util.List<FlwTask>> rejectTask​(FlwTask currentFlwTask,
                                                                      FlowCreator flowCreator,
                                                                      java.util.Map<java.lang.String,​java.lang.Object> args)
        Description copied from interface: TaskService
        根据当前任务对象驳回至上一步处理
        Specified by:
        rejectTask in interface TaskService
        Parameters:
        currentFlwTask - 当前任务对象
        flowCreator - 任务创建者
        args - 任务参数
        Returns:
        Task 任务对象
      • undoHisTask

        protected java.util.Optional<java.util.List<FlwTask>> undoHisTask​(java.lang.Long hisTaskId,
                                                                          FlowCreator flowCreator,
                                                                          TaskType taskType,
                                                                          java.util.function.Consumer<FlwHisTask> hisTaskConsumer)
        撤回历史任务
        Parameters:
        hisTaskId - 历史任务ID
        flowCreator - 任务创建者
        taskType - 任务类型
        hisTaskConsumer - 历史任务业务处理
        Returns:
        任务参与者
      • assignTask

        protected void assignTask​(java.lang.Long instanceId,
                                  java.lang.Long taskId,
                                  int actorType,
                                  FlwTaskActor taskActor)
        对指定的任务分配参与者。参与者可以为用户、部门、角色
        Parameters:
        instanceId - 实例ID
        taskId - 任务ID
        actorType - 参与者类型 0,用户 1,角色 2,部门
        taskActor - 任务参与者
      • createNewTask

        public java.util.List<FlwTask> createNewTask​(java.lang.Long taskId,
                                                     TaskType taskType,
                                                     PerformType performType,
                                                     java.util.List<FlwTaskActor> taskActors,
                                                     FlowCreator flowCreator,
                                                     java.util.function.Function<FlwTask,​Execution> executionFunction)
        根据已有任务、参与者创建新的任务

        适用于动态转派,动态协办等处理且流程图中不体现节点情况

        Specified by:
        createNewTask in interface TaskService
        Parameters:
        taskId - 主办任务ID
        taskType - 任务类型
        performType - 参与类型
        taskActors - 参与者集合
        flowCreator - 任务创建者
        executionFunction - 执行函数
        Returns:
        创建任务集合
      • createCcTask

        public boolean createCcTask​(NodeModel taskModel,
                                    FlwTask flwTask,
                                    java.util.List<NodeAssignee> ccUserList,
                                    FlowCreator flowCreator)
        创建抄送任务

        默认不校验是否重复抄送

        Specified by:
        createCcTask in interface TaskService
        Parameters:
        taskModel - 任务模型
        flwTask - 当前任务
        flowCreator - 任务创建者
        ccUserList - 抄送任务分配到任务的人或角色列表
      • getTimeoutOrRemindTasks

        public java.util.List<FlwTask> getTimeoutOrRemindTasks()
        获取超时或者提醒的任务
        Specified by:
        getTimeoutOrRemindTasks in interface TaskService
        Returns:
        任务列表
      • getTaskModel

        public NodeModel getTaskModel​(java.lang.Long taskId)
        获取任务模型
        Specified by:
        getTaskModel in interface TaskService
        Parameters:
        taskId - 任务ID
        Returns:
        节点模型
      • createTask

        public java.util.List<FlwTask> createTask​(NodeModel nodeModel,
                                                  Execution execution,
                                                  java.util.function.Function<FlwTask,​FlwTask> taskFunction)
        创建 task 根据 model 决定是否分配参与者
        Specified by:
        createTask in interface TaskService
        Parameters:
        nodeModel - 节点模型
        execution - 执行对象
        taskFunction - 任务处理函数,如果自定义 CreateTaskHandler 可用于控制任务创建属性设置
        Returns:
        任务列表
      • moveToHisTaskTrigger

        protected boolean moveToHisTaskTrigger​(FlwTask flwTask,
                                               FlowCreator flowCreator)
        触发器任务归档
      • createTaskBase

        protected FlwTask createTaskBase​(NodeModel nodeModel,
                                         Execution execution)
        根据模型、执行对象、任务类型构建基本的task对象
        Parameters:
        nodeModel - 节点模型
        execution - 执行对象
        Returns:
        Task任务对象
      • saveTask

        protected java.util.List<FlwTask> saveTask​(FlwTask flwTask,
                                                   PerformType performType,
                                                   java.util.List<FlwTaskActor> taskActors,
                                                   Execution execution,
                                                   NodeModel nodeModel)
        保存任务及参与者信息
        Parameters:
        flwTask - 流程任务对象
        performType - 参与类型 PerformType
        taskActors - 参与者ID集合
        execution - 流程执行处理类 Execution
        nodeModel - 流程节点模型对象 NodeModel
        Returns:
        流程任务列表
      • assignActorType

        protected int assignActorType​(int actorType,
                                      java.lang.Integer dbActorType)
        优先使用数据库参与者类型
      • isAllowed

        public FlwTaskActor isAllowed​(FlwTask flwTask,
                                      java.lang.String userId)
        根据 taskId、createId 判断创建人是否允许执行任务
        Specified by:
        isAllowed in interface TaskService
        Parameters:
        flwTask - 流程任务
        userId - 用户ID
        Returns:
        true 允许 false 不允许
      • addTaskActor

        public boolean addTaskActor​(java.lang.Long taskId,
                                    PerformType performType,
                                    java.util.List<FlwTaskActor> taskActors,
                                    FlowCreator flowCreator)
        向指定的任务ID添加参与者
        Specified by:
        addTaskActor in interface TaskService
        Parameters:
        taskId - 任务ID
        taskActors - 参与者列表
        performType - 参与类型 PerformType
        flowCreator - 执行操作人员
        Returns:
        true 成功 false 失败
      • getTaskActorsByTaskId

        protected java.util.List<FlwTaskActor> getTaskActorsByTaskId​(java.lang.Long taskId)
      • removeTaskActor

        public boolean removeTaskActor​(java.lang.Long taskId,
                                       java.util.List<java.lang.String> actorIds,
                                       FlowCreator flowCreator)
        Description copied from interface: TaskService
        对指定的任务ID删除参与者【减签】
        Specified by:
        removeTaskActor in interface TaskService
        Parameters:
        taskId - 任务ID
        actorIds - 参与者ID列表
        flowCreator - 执行操作人员
        Returns:
        true 成功 false 失败
      • changeTaskActor

        public boolean changeTaskActor​(java.lang.Long taskId,
                                       FlwTaskActor taskActor)
        Description copied from interface: TaskService
        修改 taskId 任务办理人为指定 taskActor 参与者
        Specified by:
        changeTaskActor in interface TaskService
        Parameters:
        taskId - 任务ID
        taskActor - 参与者
        Returns:
        true 成功 false 失败
      • endCallProcessTask

        public void endCallProcessTask​(java.lang.Long callProcessId,
                                       java.lang.Long callInstanceId)
        Description copied from interface: TaskService
        结束调用外部流程任务
        Specified by:
        endCallProcessTask in interface TaskService
        Parameters:
        callProcessId - 调用外部流程定义ID
        callInstanceId - 调用外部流程实例ID
      • cascadeRemoveByInstanceIds

        public boolean cascadeRemoveByInstanceIds​(java.util.List<java.lang.Long> instanceIds)
        级联删除表 flw_his_task_actor, flw_his_task, flw_task_actor, flw_task
        Specified by:
        cascadeRemoveByInstanceIds in interface TaskService
        Parameters:
        instanceIds - 流程实例ID列表