Skip to content

Commit 1243dc0

Browse files
authored
Merge pull request #205 from codingapi/dev
Dev
2 parents b22c8c0 + d0110d2 commit 1243dc0

25 files changed

Lines changed: 1028 additions & 42 deletions

flow-engine-example/src/main/java/com/codingapi/example/entity/User.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public String getName() {
7272
@Override
7373
@ScriptFunction(name = "isFlowManager",description = "是否为流程管理员")
7474
public boolean isFlowManager() {
75-
return flowManager;
75+
return flowManager!=null && flowManager ;
7676
}
7777

7878
@Override

flow-engine-framework/src/main/java/com/codingapi/flow/manager/NodeStrategyManager.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ public boolean isEnableMergeable() {
4949
return false;
5050
}
5151

52+
/**
53+
* 合并审批类型
54+
*/
55+
public RecordMergeStrategy.MergeType getMergeType() {
56+
List<INodeStrategy> strategies = this.strategies;
57+
for (INodeStrategy strategy : strategies) {
58+
if (strategy instanceof RecordMergeStrategy) {
59+
return ((RecordMergeStrategy) strategy).getMergeType();
60+
}
61+
}
62+
return RecordMergeStrategy.MergeType.APPROVER;
63+
}
64+
5265
/**
5366
* 是否支持撤回
5467
*/

flow-engine-framework/src/main/java/com/codingapi/flow/mock/repository/FlowRecordRepositoryMockImpl.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
public class FlowRecordRepositoryMockImpl implements FlowRecordRepository {
1111

1212
private final Map<Long, FlowRecord> cache = new HashMap<>();
13+
private long nextId = 1;
1314

1415
@Override
1516
public FlowRecord get(long id) {
@@ -45,9 +46,10 @@ public void save(FlowRecord flowRecord) {
4546
if (flowRecord.getId() > 0) {
4647
cache.put(flowRecord.getId(), flowRecord);
4748
} else {
48-
long id = cache.size() + 1;
49-
flowRecord.setId(id);
50-
cache.put(id, flowRecord);
49+
// 使用单调递增 id:删除后的 cache.size()+1 可能与已删除的 id 重复,
50+
// 进而覆盖其他记录(mock 模式下 generateRecordId() 返回 0,id 由仓储分配)
51+
flowRecord.setId(nextId++);
52+
cache.put(flowRecord.getId(), flowRecord);
5153
}
5254
}
5355

flow-engine-framework/src/main/java/com/codingapi/flow/mock/repository/FlowTodoMergeRepositoryMockImpl.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@
1010
public class FlowTodoMergeRepositoryMockImpl implements FlowTodoMergeRepository {
1111

1212
private final Map<Long, FlowTodoMerge> cache = new HashMap<>();
13+
private long nextId = 1;
1314

1415
private void save(FlowTodoMerge relation) {
1516
if (relation.getId() > 0) {
1617
cache.put(relation.getId(), relation);
1718
} else {
18-
long id = cache.size() + 1;
19-
relation.setId(id);
20-
cache.put(id, relation);
19+
// 使用单调递增 id:删除后的 cache.size()+1 可能与已删除的 id 重复,
20+
// 进而覆盖其他记录
21+
relation.setId(nextId++);
22+
cache.put(relation.getId(), relation);
2123
}
2224
}
2325

flow-engine-framework/src/main/java/com/codingapi/flow/mock/repository/FlowTodoRecordRepositoryMockImpl.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ public class FlowTodoRecordRepositoryMockImpl implements FlowTodoRecordRepositor
1111

1212
private final Map<Long, FlowTodoRecord> cache = new HashMap<>();
1313
private final Map<String, FlowTodoRecord> cacheByMageKey = new HashMap<>();
14+
private long nextId = 1;
1415

1516
@Override
1617
public void save(FlowTodoRecord record) {
1718
if (record.getId() > 0) {
1819
cache.put(record.getId(), record);
1920
} else {
20-
long id = cache.size() + 1;
21-
record.setId(id);
22-
cache.put(id, record);
21+
// 使用单调递增 id:删除后的 cache.size()+1 可能与已删除的 id 重复,
22+
// 进而覆盖其他待办(多级流程中 B 待办删除后新建 C 待办会冲突)
23+
record.setId(nextId++);
24+
cache.put(record.getId(), record);
2325
}
2426
cacheByMageKey.put(record.getTodoKey(), record);
2527
}

flow-engine-framework/src/main/java/com/codingapi/flow/mock/repository/SubProcessRepositoryMockImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@
1010
public class SubProcessRepositoryMockImpl implements SubProcessRepository {
1111

1212
private final Map<Long, SubProcessRecord> cache = new LinkedHashMap<>();
13+
private long nextId = 1;
1314

1415
@Override
1516
public synchronized void save(SubProcessRecord record) {
1617
if (record.getId() == 0) {
17-
record.setId(cache.size() + 1L);
18+
// 使用单调递增 id:删除后(如有)的 cache.size()+1 可能与已删除的 id 重复,
19+
// 进而覆盖其他记录
20+
record.setId(nextId++);
1821
}
1922
cache.put(record.getId(), record);
2023
}

flow-engine-framework/src/main/java/com/codingapi/flow/mock/repository/UrgeIntervalRepositoryMockImpl.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
public class UrgeIntervalRepositoryMockImpl implements UrgeIntervalRepository {
1010

1111
private final Map<Long, UrgeInterval> cache = new HashMap<>();
12+
private long nextId = 1;
1213

1314

1415
@Override
@@ -23,9 +24,10 @@ public void save(UrgeInterval urgeInterval) {
2324
if (urgeInterval.getId() > 0) {
2425
cache.put(urgeInterval.getId(), urgeInterval);
2526
} else {
26-
long id = cache.size() + 1;
27-
urgeInterval.setId(id);
28-
cache.put(id, urgeInterval);
27+
// 使用单调递增 id:删除后的 cache.size()+1 可能与已删除的 id 重复,
28+
// 进而覆盖其他记录
29+
urgeInterval.setId(nextId++);
30+
cache.put(urgeInterval.getId(), urgeInterval);
2931
}
3032
}
3133
}

flow-engine-framework/src/main/java/com/codingapi/flow/mock/repository/WorkflowRuntimeRepositoryMockImpl.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@
99
public class WorkflowRuntimeRepositoryMockImpl implements WorkflowRuntimeRepository {
1010

1111
private final Map<Long, WorkflowRuntime> cache = new HashMap<>();
12+
private long nextId = 1;
1213

1314
@Override
1415
public void save(WorkflowRuntime workflowRuntime) {
1516
if (workflowRuntime.getId() > 0) {
1617
cache.put(workflowRuntime.getId(), workflowRuntime);
1718
} else {
18-
long id = cache.size() + 1;
19-
workflowRuntime.setId(id);
20-
cache.put(id, workflowRuntime);
19+
// 使用单调递增 id:删除后的 cache.size()+1 可能与已删除的 id 重复,
20+
// 进而覆盖其他记录(WorkflowRuntime id 被 FlowRecord.workRuntimeId 引用)
21+
workflowRuntime.setId(nextId++);
22+
cache.put(workflowRuntime.getId(), workflowRuntime);
2123
}
2224
}
2325

flow-engine-framework/src/main/java/com/codingapi/flow/mock/repository/WorkflowVersionRepositoryMockImpl.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
public class WorkflowVersionRepositoryMockImpl implements WorkflowVersionRepository {
1212

1313
private final Map<Long, WorkflowVersion> cache = new HashMap<>();
14+
private long nextId = 1;
1415

1516
@Override
1617
public WorkflowVersion get(long id) {
@@ -56,9 +57,10 @@ public void save(WorkflowVersion workflowVersion) {
5657
if (workflowVersion.getId() > 0) {
5758
cache.put(workflowVersion.getId(), workflowVersion);
5859
} else {
59-
long id = cache.size() + 1;
60-
workflowVersion.setId(id);
61-
cache.put(id, workflowVersion);
60+
// 使用单调递增 id:删除后的 cache.size()+1 可能与已删除的 id 重复,
61+
// 进而覆盖其他版本
62+
workflowVersion.setId(nextId++);
63+
cache.put(workflowVersion.getId(), workflowVersion);
6264
}
6365
}
6466
}

flow-engine-framework/src/main/java/com/codingapi/flow/node/BaseAuditNode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public void fillNewRecord(FlowSession session, FlowRecord flowRecord) {
8383
flowRecord.setTitle(nodeStrategyManager.generateTitle(session));
8484
flowRecord.setTimeoutTime(nodeStrategyManager.getTimeoutTime());
8585
flowRecord.setMergeable(nodeStrategyManager.isEnableMergeable());
86+
flowRecord.setMergeType(nodeStrategyManager.getMergeType());
8687
flowRecord.newRecord();
8788
}
8889

0 commit comments

Comments
 (0)