Skip to content

Commit

Permalink
新增模拟角色直接分配处理人并自动完成逻辑bug修复
Browse files Browse the repository at this point in the history
  • Loading branch information
qmdx committed Sep 1, 2024
1 parent fdd19d8 commit f00d9f5
Show file tree
Hide file tree
Showing 16 changed files with 184 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import com.aizuda.bpm.engine.*;
import com.aizuda.bpm.engine.assist.Assert;
import com.aizuda.bpm.engine.cache.FlowCache;
import com.aizuda.bpm.engine.handler.CreateTaskHandler;
import com.aizuda.bpm.engine.handler.ConditionNodeHandler;
import com.aizuda.bpm.engine.handler.CreateTaskHandler;
import com.aizuda.bpm.engine.handler.FlowJsonHandler;
import com.aizuda.bpm.engine.handler.impl.SimpleCreateTaskHandler;
import com.aizuda.bpm.engine.handler.impl.SimpleConditionNodeHandler;
import com.aizuda.bpm.engine.handler.impl.SimpleCreateTaskHandler;
import com.aizuda.bpm.engine.impl.DefaultProcessModelParser;
import com.aizuda.bpm.engine.model.NodeModel;
import com.aizuda.bpm.engine.model.ProcessModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,9 @@ else if (TaskType.agentReturn.eq(flwTask.getTaskType())) {
hisTask.setTaskType(TaskType.agentAssist);
}

// 会签情况处理其它任务 排除完成情况
if (PerformType.countersign.eq(flwTask.getPerformType()) && TaskState.complete.ne(taskState.getValue())) {
// 会签情况处理其它任务 排除完成及自动跳过情况,自动跳过是当前任务归档非所有任务归档
if (PerformType.countersign.eq(flwTask.getPerformType()) && TaskState.complete.ne(taskState.getValue())
&& TaskState.autoJump.ne(taskState.getValue())) {
List<FlwTask> flwTaskList = taskDao.selectListByParentTaskId(flwTask.getParentTaskId());
flwTaskList.forEach(t -> {
FlwHisTask ht = FlwHisTask.of(t);
Expand Down Expand Up @@ -1077,10 +1078,12 @@ protected List<FlwTask> saveTask(FlwTask flwTask, PerformType performType, List<

// 分配参与者
this.assignTask(newFlwTask.getInstanceId(), newFlwTask.getId(), actorType, t);

// 创建任务监听
this.taskNotify(EventType.create, () -> newFlwTask, nodeModel, flowCreator);
});

// 所有任务创建后,创建任务监听,避免后续任务因为监听逻辑导致未创建情况
flwTasks.forEach(t -> this.taskNotify(EventType.create, () -> t, nodeModel, flowCreator));

// 返回创建的任务列表
return flwTasks;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/
package com.aizuda.bpm.mybatisplus.mapper;

import com.aizuda.bpm.engine.assist.Assert;
import com.aizuda.bpm.engine.entity.FlwTask;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
*/
package com.aizuda.bpm.solon.adaptive;

import com.aizuda.bpm.engine.TaskReminder;
import com.aizuda.bpm.engine.TaskService;
import com.aizuda.bpm.engine.assist.DateUtils;
import com.aizuda.bpm.engine.assist.ObjectUtils;
import com.aizuda.bpm.engine.core.FlowLongContext;
import com.aizuda.bpm.engine.entity.FlwTask;
import com.aizuda.bpm.engine.scheduling.JobLock;
import com.aizuda.bpm.engine.scheduling.RemindParam;
import com.aizuda.bpm.engine.TaskReminder;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.aizuda.bpm.engine.FlowLongEngine;
import com.aizuda.bpm.engine.FlowLongScheduler;
import com.aizuda.bpm.engine.scheduling.JobLock;
import com.aizuda.bpm.engine.TaskReminder;
import com.aizuda.bpm.engine.scheduling.JobLock;
import com.aizuda.bpm.spring.autoconfigure.FlowLongProperties;
import com.aizuda.bpm.spring.event.TaskEvent;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.aizuda.bpm.spring.example.config;

import com.aizuda.bpm.engine.core.FlowLongContext;
import com.aizuda.bpm.engine.TaskReminder;
import com.aizuda.bpm.engine.core.FlowLongContext;
import com.aizuda.bpm.engine.entity.FlwTask;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Component;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2023-2025 Licensed under the AGPL License
*/
package test.mysql;

import com.aizuda.bpm.engine.entity.FlwHisInstance;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

/**
* 测试自动跳转
*/
@Slf4j
public class TestAutoSkip extends MysqlTest {

@BeforeEach
public void before() {
processId = this.deployByResource("test/autoSkip.json", testCreator);
}

@Test
public void test() {
// 考勤管理员【角色】不走认领逻辑,通过任务参与者提供类直接分配处理人员
flowLongEngine.startInstanceById(processId, testCreator).ifPresent(instance -> {

// 非自动完成 test002 操作执行任务
executeActiveTasks(instance.getId(), test2Creator);

FlwHisInstance hisInstance = flowLongEngine.queryService().getHistInstance(instance.getId());
Assertions.assertEquals(1, hisInstance.getInstanceState());
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public void testKey() {
// 人事审批
this.executeActiveTasks(instance.getId(), test2Creator);

FlwHisInstance histInstance = flowLongEngine.queryService().getHistInstance(instance.getId());
Assertions.assertEquals("条件路由", histInstance.getCurrentNodeName());
FlwHisInstance hisInstance = flowLongEngine.queryService().getHistInstance(instance.getId());
Assertions.assertEquals("条件路由", hisInstance.getCurrentNodeName());
});
}

Expand All @@ -50,8 +50,8 @@ public void testArgs() {
// 领导审批
this.executeActiveTasks(instance.getId(), testCreator, args);

FlwHisInstance histInstance = flowLongEngine.queryService().getHistInstance(instance.getId());
Assertions.assertEquals("领导审批结束", histInstance.getCurrentNodeName());
FlwHisInstance hisInstance = flowLongEngine.queryService().getHistInstance(instance.getId());
Assertions.assertEquals("领导审批结束", hisInstance.getCurrentNodeName());
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@

import com.aizuda.bpm.engine.QueryService;
import com.aizuda.bpm.engine.TaskService;
import com.aizuda.bpm.engine.core.FlowCreator;
import com.aizuda.bpm.engine.entity.FlwTask;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public void testEnd() {

this.executeActiveTasks(instance.getId(), testCreator, args);

FlwHisInstance histInstance = flowLongEngine.queryService().getHistInstance(instance.getId());
Assertions.assertEquals("领导审批结束", histInstance.getCurrentNodeName());
FlwHisInstance hisInstance = flowLongEngine.queryService().getHistInstance(instance.getId());
Assertions.assertEquals("领导审批结束", hisInstance.getCurrentNodeName());
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package test.mysql;

import com.aizuda.bpm.engine.assist.Assert;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ public void test() {
// test3 领导审批同意
this.executeActiveTasks(instance.getId(), test3Creator);
// 抄送人力资源,流程自动结束
FlwHisInstance histInstance = flowLongEngine.queryService().getHistInstance(instance.getId());
Assertions.assertEquals(1, histInstance.getInstanceState());
FlwHisInstance hisInstance = flowLongEngine.queryService().getHistInstance(instance.getId());
Assertions.assertEquals(1, hisInstance.getInstanceState());

// V2: test3 领导审批同意
this.executeActiveTasks(instanceV2.getId(), testCreator);

FlwHisInstance histInstanceV2 = flowLongEngine.queryService().getHistInstance(instanceV2.getId());
Assertions.assertEquals(1, histInstanceV2.getInstanceState());
FlwHisInstance hisInstanceV2 = flowLongEngine.queryService().getHistInstance(instanceV2.getId());
Assertions.assertEquals(1, hisInstanceV2.getInstanceState());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
package test.mysql.config;

import com.aizuda.bpm.engine.FlowLongEngine;
import com.aizuda.bpm.spring.autoconfigure.FlowLongAutoConfiguration;
import com.baomidou.mybatisplus.core.MybatisConfiguration;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
Expand Down Expand Up @@ -67,4 +68,14 @@ private DataSourceTransactionManager createTransactionManager(Environment enviro
public TestTaskAccessStrategy taskAccessStrategy() {
return new TestTaskAccessStrategy();
}

@Bean
public TestTaskActorProvider testTaskActorProvider() {
return new TestTaskActorProvider();
}

@Bean
public TestTaskListener testTaskListener(FlowLongEngine flowLongEngine) {
return new TestTaskListener(flowLongEngine);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package test.mysql.config;

import com.aizuda.bpm.engine.core.Execution;
import com.aizuda.bpm.engine.core.FlowCreator;
import com.aizuda.bpm.engine.core.enums.NodeSetType;
import com.aizuda.bpm.engine.entity.FlwTaskActor;
import com.aizuda.bpm.engine.impl.GeneralTaskActorProvider;
import com.aizuda.bpm.engine.model.NodeModel;

import java.util.Arrays;
import java.util.List;

/**
* 测试任务参与者提供处理类
*/
public class TestTaskActorProvider extends GeneralTaskActorProvider {

@Override
public List<FlwTaskActor> getTaskActors(NodeModel nodeModel, Execution execution) {
if (NodeSetType.role.eq(nodeModel.getSetType())) {

// 测试用例 TestAutoSkip 测试角色自动分配处理人员
if ("100100".equals(nodeModel.getNodeAssigneeList().get(0).getId())) {
return Arrays.asList(
FlwTaskActor.ofFlowCreator(FlowCreator.of("test001", "测试001")),
FlwTaskActor.ofFlowCreator(FlowCreator.of("test002", "测试002"))
);
}
}
return super.getTaskActors(nodeModel, execution);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package test.mysql.config;

import com.aizuda.bpm.engine.FlowLongEngine;
import com.aizuda.bpm.engine.core.FlowCreator;
import com.aizuda.bpm.engine.core.enums.EventType;
import com.aizuda.bpm.engine.core.enums.NodeApproveSelf;
import com.aizuda.bpm.engine.core.enums.NodeSetType;
import com.aizuda.bpm.engine.entity.FlwTask;
import com.aizuda.bpm.engine.listener.TaskListener;
import com.aizuda.bpm.engine.model.NodeAssignee;
import com.aizuda.bpm.engine.model.NodeModel;
import lombok.AllArgsConstructor;

import java.util.List;
import java.util.Objects;
import java.util.function.Supplier;

/**
* 测试任务监听处理器
*/
@AllArgsConstructor
public class TestTaskListener implements TaskListener {
private FlowLongEngine flowLongEngine;

@Override
public boolean notify(EventType eventType, Supplier<FlwTask> supplier, NodeModel nodeModel,
FlowCreator flowCreator) {
if (EventType.create.eq(eventType)) {
// 创建任务时候,判断是否自动审批通过
Integer approveSelf = nodeModel.getApproveSelf();
if (NodeApproveSelf.AutoSkip.eq(approveSelf)) {
FlwTask flwTask = supplier.get();
if (NodeSetType.specifyMembers.eq(nodeModel.getSetType())) {
// 普通成员情况
List<NodeAssignee> nodeAssigneeList = nodeModel.getNodeAssigneeList();
if (nodeAssigneeList.stream().anyMatch(t -> Objects.equals(t.getId(), flowCreator.getCreateId()))) {
return flowLongEngine.autoJumpTask(flwTask.getId(), flowCreator);
}
} else if (NodeSetType.role.eq(nodeModel.getSetType())) {
// 角色情况
flowLongEngine.queryService().getActiveTaskActorsByTaskId(flwTask.getId()).flatMap(flwTaskActorList -> flwTaskActorList.stream()
.filter(t -> Objects.equals(t.getActorId(), flowCreator.getCreateId()))
.findFirst()).ifPresent(taskActor -> flowLongEngine.autoJumpTask(taskActor.getTaskId(), flowCreator));
return true;
}
}
}
return true;
}
}
33 changes: 33 additions & 0 deletions flowlong-spring-boot-starter/src/test/resources/test/autoSkip.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"key": "autoSkip",
"name": "自动跳过审批",
"nodeConfig": {
"nodeName": "发起人",
"nodeKey": "flk1725161262899",
"type": 0,
"childNode": {
"nodeName": "审核人",
"nodeKey": "flk1724860316169",
"callProcess": null,
"type": 1,
"setType": 3,
"nodeAssigneeList": [
{
"id": "100100",
"name": "考勤管理员"
}
],
"examineLevel": 1,
"directorLevel": 1,
"selectMode": 1,
"termAuto": false,
"term": 0,
"termMode": 1,
"examineMode": 2,
"directorMode": 0,
"typeOfApprove": 1,
"remind": false,
"approveSelf": 1
}
}
}

0 comments on commit f00d9f5

Please sign in to comment.