Skip to content
Merged

Dev #205

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public String getName() {
@Override
@ScriptFunction(name = "isFlowManager",description = "是否为流程管理员")
public boolean isFlowManager() {
return flowManager;
return flowManager!=null && flowManager ;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ public boolean isEnableMergeable() {
return false;
}

/**
* 合并审批类型
*/
public RecordMergeStrategy.MergeType getMergeType() {
List<INodeStrategy> strategies = this.strategies;
for (INodeStrategy strategy : strategies) {
if (strategy instanceof RecordMergeStrategy) {
return ((RecordMergeStrategy) strategy).getMergeType();
}
}
return RecordMergeStrategy.MergeType.APPROVER;
}

/**
* 是否支持撤回
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
public class FlowRecordRepositoryMockImpl implements FlowRecordRepository {

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
public class FlowTodoMergeRepositoryMockImpl implements FlowTodoMergeRepository {

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ public class FlowTodoRecordRepositoryMockImpl implements FlowTodoRecordRepositor

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

@Override
public void save(FlowTodoRecord record) {
if (record.getId() > 0) {
cache.put(record.getId(), record);
} else {
long id = cache.size() + 1;
record.setId(id);
cache.put(id, record);
// 使用单调递增 id:删除后的 cache.size()+1 可能与已删除的 id 重复,
// 进而覆盖其他待办(多级流程中 B 待办删除后新建 C 待办会冲突)
record.setId(nextId++);
cache.put(record.getId(), record);
}
cacheByMageKey.put(record.getTodoKey(), record);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
public class SubProcessRepositoryMockImpl implements SubProcessRepository {

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

@Override
public synchronized void save(SubProcessRecord record) {
if (record.getId() == 0) {
record.setId(cache.size() + 1L);
// 使用单调递增 id:删除后(如有)的 cache.size()+1 可能与已删除的 id 重复,
// 进而覆盖其他记录
record.setId(nextId++);
}
cache.put(record.getId(), record);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
public class UrgeIntervalRepositoryMockImpl implements UrgeIntervalRepository {

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


@Override
Expand All @@ -23,9 +24,10 @@ public void save(UrgeInterval urgeInterval) {
if (urgeInterval.getId() > 0) {
cache.put(urgeInterval.getId(), urgeInterval);
} else {
long id = cache.size() + 1;
urgeInterval.setId(id);
cache.put(id, urgeInterval);
// 使用单调递增 id:删除后的 cache.size()+1 可能与已删除的 id 重复,
// 进而覆盖其他记录
urgeInterval.setId(nextId++);
cache.put(urgeInterval.getId(), urgeInterval);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@
public class WorkflowRuntimeRepositoryMockImpl implements WorkflowRuntimeRepository {

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
public class WorkflowVersionRepositoryMockImpl implements WorkflowVersionRepository {

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

@Override
public WorkflowVersion get(long id) {
Expand Down Expand Up @@ -56,9 +57,10 @@ public void save(WorkflowVersion workflowVersion) {
if (workflowVersion.getId() > 0) {
cache.put(workflowVersion.getId(), workflowVersion);
} else {
long id = cache.size() + 1;
workflowVersion.setId(id);
cache.put(id, workflowVersion);
// 使用单调递增 id:删除后的 cache.size()+1 可能与已删除的 id 重复,
// 进而覆盖其他版本
workflowVersion.setId(nextId++);
cache.put(workflowVersion.getId(), workflowVersion);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public void fillNewRecord(FlowSession session, FlowRecord flowRecord) {
flowRecord.setTitle(nodeStrategyManager.generateTitle(session));
flowRecord.setTimeoutTime(nodeStrategyManager.getTimeoutTime());
flowRecord.setMergeable(nodeStrategyManager.isEnableMergeable());
flowRecord.setMergeType(nodeStrategyManager.getMergeType());
flowRecord.newRecord();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.codingapi.flow.session.FlowAdvice;
import com.codingapi.flow.session.FlowSession;
import com.codingapi.flow.session.IRepositoryHolder;
import com.codingapi.flow.strategy.node.RecordMergeStrategy;
import com.codingapi.flow.workflow.Workflow;
import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down Expand Up @@ -229,6 +230,10 @@ public class FlowRecord {
* {@link FlowRecord#getTodoKey()}
*/
private boolean mergeable;
/**
* 合并审批类型,决定 {@link FlowRecord#getTodoKey()} 的合并依据
*/
private RecordMergeStrategy.MergeType mergeType = RecordMergeStrategy.MergeType.APPROVER;
/**
* 被干预的用户Id
*/
Expand Down Expand Up @@ -261,11 +266,23 @@ public class FlowRecord {

/**
* 数据合并的依据,当开启时值为固定值,否则为随机数据
* 相同的 {@link FlowRecord#currentOperatorId} {@link FlowRecord#workRuntimeId} {@link FlowRecord#nodeId}字段的数据合并到一条记录上。
* <p>合并依据由 {@link RecordMergeStrategy.MergeType} 决定:
* <ul>
* <li>APPROVER — 审批人合并,按 {@link FlowRecord#currentOperatorId}</li>
* <li>CREATOR — 发起人合并,按 {@link FlowRecord#createOperatorId}</li>
* <li>SUBMITTER — 提交人合并,按 {@link FlowRecord#submitOperatorId}</li>
* </ul>
* 相同依据字段 + {@link FlowRecord#workRuntimeId} + {@link FlowRecord#nodeId} 的数据合并到一条记录上。
*/
public String getTodoKey() {
if (mergeable) {
return String.format("%s-%s-%s", currentOperatorId, workRuntimeId, nodeId);
long mergeOperatorId;
switch (mergeType) {
case CREATOR -> mergeOperatorId = createOperatorId;
case SUBMITTER -> mergeOperatorId = submitOperatorId;
default -> mergeOperatorId = currentOperatorId;
}
return String.format("%s-%s-%s", mergeOperatorId, workRuntimeId, nodeId);
} else {
return String.valueOf(id);
}
Expand Down Expand Up @@ -550,6 +567,7 @@ public void notifyRecord(FlowSession flowSession) {
this.setTitle(nodeStrategyManager.generateTitle(flowSession));
this.setTimeoutTime(nodeStrategyManager.getTimeoutTime());
this.setMergeable(nodeStrategyManager.isEnableMergeable());
this.setMergeType(nodeStrategyManager.getMergeType());
this.update(flowSession, true);
this.clearNotify();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,63 @@
@AllArgsConstructor
public class RecordMergeStrategy extends BaseStrategy {

/**
* 合并审批类型
*/
public enum MergeType {
/**
* 审批人合并:以当前审批人(currentOperatorId)为合并依据
*/
APPROVER,
/**
* 发起人合并:以流程发起人(createOperatorId)为合并依据
*/
CREATOR,
/**
* 提交人合并:以流程提交人(submitOperatorId)为合并依据
*/
SUBMITTER
}

private boolean enable;

/**
* 合并类型,默认审批人合并(向后兼容)
*/
private MergeType mergeType = MergeType.APPROVER;

public RecordMergeStrategy(boolean enable) {
this.enable = enable;
this.mergeType = MergeType.APPROVER;
}
// 全参构造器 (boolean, MergeType) 由 @AllArgsConstructor 生成

@Override
public void copy(INodeStrategy target) {
this.enable = ((RecordMergeStrategy) target).enable;
RecordMergeStrategy recordMergeStrategy = (RecordMergeStrategy) target;
this.enable = recordMergeStrategy.enable;
this.mergeType = recordMergeStrategy.mergeType;
}

@Override
public Map<String, Object> toMap() {
Map<String, Object> map = super.toMap();
map.put("enable", enable);
map.put("mergeType", mergeType.name());
return map;
}

public static RecordMergeStrategy fromMap(Map<String, Object> map) {
RecordMergeStrategy strategy = IMapConvertor.fromMap(map, RecordMergeStrategy.class);
if (strategy == null) return null;
strategy.enable = (boolean) map.get("enable");
// 兼容旧数据:mergeType 缺失时默认审批人合并
Object mergeType = map.get("mergeType");
if (mergeType != null) {
strategy.setMergeType(MergeType.valueOf((String) mergeType));
} else {
strategy.setMergeType(MergeType.APPROVER);
}
return strategy;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ private static FlowRecord copy(FlowRecord record) {
record.getErrMessage(),
record.getTimeoutTime(),
record.isMergeable(),
record.getMergeType(),
record.getInterferedOperatorId(),
record.getInterferedOperatorName(),
record.getDelegateId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
public class FlowRecordRepositoryImpl implements FlowRecordRepository {

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

@Override
public FlowRecord get(long id) {
Expand All @@ -34,9 +35,10 @@ public void save(FlowRecord flowRecord) {
if (flowRecord.getId() > 0) {
cache.put(flowRecord.getId(), flowRecord);
} else {
long id = cache.size() + 1;
flowRecord.setId(id);
cache.put(id, flowRecord);
// 使用单调递增 id:删除后的 cache.size()+1 可能与已删除的 id 重复,
// 进而覆盖其他记录(mock 模式下 generateRecordId() 返回 0,id 由仓储分配)
flowRecord.setId(nextId++);
cache.put(flowRecord.getId(), flowRecord);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
public class FlowTodoMergeRepositoryImpl implements FlowTodoMergeRepository {

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ public class FlowTodoRecordRepositoryImpl implements FlowTodoRecordRepository {

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

@Override
public void save(FlowTodoRecord record) {
if (record.getId() > 0) {
cache.put(record.getId(), record);
} else {
long id = cache.size() + 1;
record.setId(id);
cache.put(id, record);
// 使用单调递增 id:删除后的 cache.size()+1 可能与已删除的 id 重复,
// 进而覆盖其他待办(多级流程中 B 待办删除后新建 C 待办会冲突)
record.setId(nextId++);
cache.put(record.getId(), record);
}
cacheByMageKey.put(record.getTodoKey(), record);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
public class UrgeIntervalRepositoryImpl implements UrgeIntervalRepository {

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


@Override
Expand All @@ -22,9 +23,10 @@ public void save(UrgeInterval urgeInterval) {
if (urgeInterval.getId() > 0) {
cache.put(urgeInterval.getId(), urgeInterval);
} else {
long id = cache.size() + 1;
urgeInterval.setId(id);
cache.put(id, urgeInterval);
// 使用单调递增 id:删除后的 cache.size()+1 可能与已删除的 id 重复,
// 进而覆盖其他记录
urgeInterval.setId(nextId++);
cache.put(urgeInterval.getId(), urgeInterval);
}
}
}
Loading
Loading