From 35d2efc508f45feeb73700b27d810b42c88795cb Mon Sep 17 00:00:00 2001
From: lorne <1991wangliang@gmail.com>
Date: Fri, 4 Jul 2025 09:15:07 +0800
Subject: [PATCH 1/4] fix #121
---
.../example-app/example-app-cmd-domain/pom.xml | 2 +-
example/example-app/example-app-cmd-meta/pom.xml | 2 +-
example/example-app/example-app-query/pom.xml | 2 +-
example/example-app/pom.xml | 2 +-
.../example-domain/example-domain-leave/pom.xml | 2 +-
.../example-domain/example-domain-user/pom.xml | 2 +-
example/example-domain/pom.xml | 2 +-
example/example-infra/example-infra-flow/pom.xml | 2 +-
example/example-infra/example-infra-jpa/pom.xml | 2 +-
.../example-infra/example-infra-security/pom.xml | 2 +-
example/example-infra/pom.xml | 2 +-
example/example-interface/pom.xml | 2 +-
example/example-server/pom.xml | 2 +-
example/pom.xml | 2 +-
pom.xml | 2 +-
springboot-starter-data-authorization/pom.xml | 2 +-
springboot-starter-data-fast/pom.xml | 2 +-
springboot-starter-flow/pom.xml | 2 +-
.../springboot/flow/service/FlowService.java | 15 +++++++++------
springboot-starter-security/pom.xml | 2 +-
springboot-starter/pom.xml | 2 +-
springboot-starter/src/main/resources/banner.txt | 2 +-
22 files changed, 30 insertions(+), 27 deletions(-)
diff --git a/example/example-app/example-app-cmd-domain/pom.xml b/example/example-app/example-app-cmd-domain/pom.xml
index 3147c576..9e3c5b7d 100644
--- a/example/example-app/example-app-cmd-domain/pom.xml
+++ b/example/example-app/example-app-cmd-domain/pom.xml
@@ -6,7 +6,7 @@
com.codingapi.springboot
example-app
- 3.4.7
+ 3.4.8
../pom.xml
diff --git a/example/example-app/example-app-cmd-meta/pom.xml b/example/example-app/example-app-cmd-meta/pom.xml
index 33dabf74..5d551572 100644
--- a/example/example-app/example-app-cmd-meta/pom.xml
+++ b/example/example-app/example-app-cmd-meta/pom.xml
@@ -6,7 +6,7 @@
com.codingapi.springboot
example-app
- 3.4.7
+ 3.4.8
../pom.xml
diff --git a/example/example-app/example-app-query/pom.xml b/example/example-app/example-app-query/pom.xml
index cc3cee5c..006f5b78 100644
--- a/example/example-app/example-app-query/pom.xml
+++ b/example/example-app/example-app-query/pom.xml
@@ -6,7 +6,7 @@
com.codingapi.springboot
example-app
- 3.4.7
+ 3.4.8
../pom.xml
diff --git a/example/example-app/pom.xml b/example/example-app/pom.xml
index 83502a5c..e6da8289 100644
--- a/example/example-app/pom.xml
+++ b/example/example-app/pom.xml
@@ -6,7 +6,7 @@
com.codingapi.springboot
springboot-example
- 3.4.7
+ 3.4.8
../pom.xml
pom
diff --git a/example/example-domain/example-domain-leave/pom.xml b/example/example-domain/example-domain-leave/pom.xml
index 4121e107..3688152c 100644
--- a/example/example-domain/example-domain-leave/pom.xml
+++ b/example/example-domain/example-domain-leave/pom.xml
@@ -6,7 +6,7 @@
com.codingapi.springboot
example-domain
- 3.4.7
+ 3.4.8
../pom.xml
diff --git a/example/example-domain/example-domain-user/pom.xml b/example/example-domain/example-domain-user/pom.xml
index 22601c0b..eca8ed5b 100644
--- a/example/example-domain/example-domain-user/pom.xml
+++ b/example/example-domain/example-domain-user/pom.xml
@@ -6,7 +6,7 @@
com.codingapi.springboot
example-domain
- 3.4.7
+ 3.4.8
../pom.xml
diff --git a/example/example-domain/pom.xml b/example/example-domain/pom.xml
index 9c373382..327d095c 100644
--- a/example/example-domain/pom.xml
+++ b/example/example-domain/pom.xml
@@ -5,7 +5,7 @@
com.codingapi.springboot
springboot-example
- 3.4.7
+ 3.4.8
../pom.xml
4.0.0
diff --git a/example/example-infra/example-infra-flow/pom.xml b/example/example-infra/example-infra-flow/pom.xml
index 4587e594..6e3c6d60 100644
--- a/example/example-infra/example-infra-flow/pom.xml
+++ b/example/example-infra/example-infra-flow/pom.xml
@@ -5,7 +5,7 @@
com.codingapi.springboot
example-infra
- 3.4.7
+ 3.4.8
../pom.xml
diff --git a/example/example-infra/example-infra-jpa/pom.xml b/example/example-infra/example-infra-jpa/pom.xml
index 226932e5..b50f360d 100644
--- a/example/example-infra/example-infra-jpa/pom.xml
+++ b/example/example-infra/example-infra-jpa/pom.xml
@@ -5,7 +5,7 @@
com.codingapi.springboot
example-infra
- 3.4.7
+ 3.4.8
../pom.xml
diff --git a/example/example-infra/example-infra-security/pom.xml b/example/example-infra/example-infra-security/pom.xml
index 847628dc..be841049 100644
--- a/example/example-infra/example-infra-security/pom.xml
+++ b/example/example-infra/example-infra-security/pom.xml
@@ -6,7 +6,7 @@
com.codingapi.springboot
example-infra
- 3.4.7
+ 3.4.8
../pom.xml
diff --git a/example/example-infra/pom.xml b/example/example-infra/pom.xml
index 7e37b278..ac4df273 100644
--- a/example/example-infra/pom.xml
+++ b/example/example-infra/pom.xml
@@ -6,7 +6,7 @@
com.codingapi.springboot
springboot-example
- 3.4.7
+ 3.4.8
../pom.xml
pom
diff --git a/example/example-interface/pom.xml b/example/example-interface/pom.xml
index 2312a697..4307fdb7 100644
--- a/example/example-interface/pom.xml
+++ b/example/example-interface/pom.xml
@@ -6,7 +6,7 @@
com.codingapi.springboot
springboot-example
- 3.4.7
+ 3.4.8
example-interface
diff --git a/example/example-server/pom.xml b/example/example-server/pom.xml
index 7089921e..d062bdd1 100644
--- a/example/example-server/pom.xml
+++ b/example/example-server/pom.xml
@@ -5,7 +5,7 @@
springboot-example
com.codingapi.springboot
- 3.4.7
+ 3.4.8
4.0.0
diff --git a/example/pom.xml b/example/pom.xml
index 7d4e3f4e..6624caad 100644
--- a/example/pom.xml
+++ b/example/pom.xml
@@ -19,7 +19,7 @@
springboot-example
- 3.4.7
+ 3.4.8
springboot-example
springboot-example project for Spring Boot
diff --git a/pom.xml b/pom.xml
index ee3df504..a96f1382 100644
--- a/pom.xml
+++ b/pom.xml
@@ -12,7 +12,7 @@
com.codingapi.springboot
springboot-parent
- 3.4.7
+ 3.4.8
https://github.com/codingapi/springboot-framewrok
springboot-parent
diff --git a/springboot-starter-data-authorization/pom.xml b/springboot-starter-data-authorization/pom.xml
index 08199fa8..24370a54 100644
--- a/springboot-starter-data-authorization/pom.xml
+++ b/springboot-starter-data-authorization/pom.xml
@@ -6,7 +6,7 @@
com.codingapi.springboot
springboot-parent
- 3.4.7
+ 3.4.8
springboot-starter-data-authorization
diff --git a/springboot-starter-data-fast/pom.xml b/springboot-starter-data-fast/pom.xml
index c49242de..8a90e5cb 100644
--- a/springboot-starter-data-fast/pom.xml
+++ b/springboot-starter-data-fast/pom.xml
@@ -5,7 +5,7 @@
springboot-parent
com.codingapi.springboot
- 3.4.7
+ 3.4.8
4.0.0
diff --git a/springboot-starter-flow/pom.xml b/springboot-starter-flow/pom.xml
index 6701f8d9..e5ff5853 100644
--- a/springboot-starter-flow/pom.xml
+++ b/springboot-starter-flow/pom.xml
@@ -6,7 +6,7 @@
springboot-parent
com.codingapi.springboot
- 3.4.7
+ 3.4.8
springboot-starter-flow
diff --git a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/FlowService.java b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/FlowService.java
index 450a1c76..ea49cb6f 100644
--- a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/FlowService.java
+++ b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/FlowService.java
@@ -57,11 +57,13 @@ public FlowService(FlowWorkRepository flowWorkRepository,
* @return 流程详情
*/
public FlowDetail detail(long recordId, String workCode, IFlowOperator currentOperator) {
+ if (recordId > 0) {
+ return flowDetailService.detail(recordId, currentOperator);
+ }
if (StringUtils.hasText(workCode)) {
return flowDetailService.detail(workCode, currentOperator);
- } else {
- return flowDetailService.detail(recordId, currentOperator);
}
+ return null;
}
/**
@@ -196,7 +198,7 @@ public FlowSubmitResult trySubmitFlow(long recordId, IFlowOperator currentOperat
* @return
*/
public FlowStepResult getFlowStep(long recordId, IBindData bindData, IFlowOperator currentOperator) {
- FlowStepService flowStepService = new FlowStepService(recordId,null, currentOperator, bindData, flowServiceRepositoryHolder);
+ FlowStepService flowStepService = new FlowStepService(recordId, null, currentOperator, bindData, flowServiceRepositoryHolder);
return flowStepService.getFlowStep();
}
@@ -208,7 +210,7 @@ public FlowStepResult getFlowStep(long recordId, IBindData bindData, IFlowOperat
* @return
*/
public FlowStepResult getFlowStep(String workCode, IBindData bindData, IFlowOperator currentOperator) {
- FlowStepService flowStepService = new FlowStepService(0,workCode, currentOperator, bindData, flowServiceRepositoryHolder);
+ FlowStepService flowStepService = new FlowStepService(0, workCode, currentOperator, bindData, flowServiceRepositoryHolder);
return flowStepService.getFlowStep();
}
@@ -243,10 +245,11 @@ public FlowResult submitFlow(long recordId, IFlowOperator currentOperator, IBind
/**
* 唤醒流程
- * @param processId 流程实例id
+ *
+ * @param processId 流程实例id
* @param currentOperator 当前操作者
*/
- public void notifyFlow(String processId,IFlowOperator currentOperator) {
+ public void notifyFlow(String processId, IFlowOperator currentOperator) {
FlowNotifyService flowNotifyService = new FlowNotifyService(processId, currentOperator, flowServiceRepositoryHolder);
flowNotifyService.notifyFlow();
}
diff --git a/springboot-starter-security/pom.xml b/springboot-starter-security/pom.xml
index ebb6838a..6ab487c5 100644
--- a/springboot-starter-security/pom.xml
+++ b/springboot-starter-security/pom.xml
@@ -6,7 +6,7 @@
springboot-parent
com.codingapi.springboot
- 3.4.7
+ 3.4.8
springboot-starter-security
diff --git a/springboot-starter/pom.xml b/springboot-starter/pom.xml
index 28fb3db1..23e4942e 100644
--- a/springboot-starter/pom.xml
+++ b/springboot-starter/pom.xml
@@ -5,7 +5,7 @@
com.codingapi.springboot
springboot-parent
- 3.4.7
+ 3.4.8
springboot-starter
diff --git a/springboot-starter/src/main/resources/banner.txt b/springboot-starter/src/main/resources/banner.txt
index 0a166f07..b132e8fd 100644
--- a/springboot-starter/src/main/resources/banner.txt
+++ b/springboot-starter/src/main/resources/banner.txt
@@ -1,4 +1,4 @@
------------------------------------------------------
-CodingApi SpringBoot-Starter 3.4.7
+CodingApi SpringBoot-Starter 3.4.8
springboot version (${spring-boot.version})
------------------------------------------------------
From a5ac8b34c09d2ca2632b3c27e175e6a6f50f1c63 Mon Sep 17 00:00:00 2001
From: lorne <1991wangliang@gmail.com>
Date: Fri, 4 Jul 2025 10:07:16 +0800
Subject: [PATCH 2/4] fix #121
---
.../springboot/flow/event/FlowApprovalEvent.java | 3 ++-
.../springboot/flow/service/FlowService.java | 4 ++--
.../flow/service/impl/FlowRecallService.java | 9 ++++++++-
.../flow/service/impl/FlowRemoveService.java | 13 ++++++++++++-
4 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/event/FlowApprovalEvent.java b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/event/FlowApprovalEvent.java
index d6b8f406..f9dbee72 100644
--- a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/event/FlowApprovalEvent.java
+++ b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/event/FlowApprovalEvent.java
@@ -36,7 +36,8 @@ public class FlowApprovalEvent implements ISyncEvent {
public static final int STATE_CIRCULATE = 9;
// 保存
public static final int STATE_SAVE = 10;
-
+ // 删除
+ public static final int STATE_DELETE = 11;
private final int state;
private final IFlowOperator operator;
diff --git a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/FlowService.java b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/FlowService.java
index ea49cb6f..dd2ccee8 100644
--- a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/FlowService.java
+++ b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/FlowService.java
@@ -41,8 +41,8 @@ public FlowService(FlowWorkRepository flowWorkRepository,
this.flowServiceRepositoryHolder = new FlowServiceRepositoryHolder(flowWorkRepository, flowRecordRepository, flowBindDataRepository, flowOperatorRepository, flowProcessRepository, flowBackupRepository);
this.flowDetailService = new FlowDetailService(flowWorkRepository, flowRecordRepository, flowBindDataRepository, flowOperatorRepository, flowProcessRepository);
this.flowCustomEventService = new FlowCustomEventService(flowWorkRepository, flowRecordRepository, flowProcessRepository);
- this.flowRecallService = new FlowRecallService(flowWorkRepository, flowRecordRepository, flowProcessRepository);
- this.flowRemoveService = new FlowRemoveService(flowWorkRepository, flowRecordRepository, flowProcessRepository);
+ this.flowRecallService = new FlowRecallService(flowWorkRepository, flowRecordRepository, flowProcessRepository,flowBindDataRepository);
+ this.flowRemoveService = new FlowRemoveService(flowWorkRepository, flowRecordRepository, flowProcessRepository,flowBindDataRepository);
this.flowSaveService = new FlowSaveService(flowWorkRepository, flowRecordRepository, flowBindDataRepository, flowProcessRepository);
this.flowTransferService = new FlowTransferService(flowWorkRepository, flowRecordRepository, flowBindDataRepository, flowProcessRepository);
this.flowPostponedService = new FlowPostponedService(flowWorkRepository, flowRecordRepository, flowProcessRepository);
diff --git a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/impl/FlowRecallService.java b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/impl/FlowRecallService.java
index ff630cd8..ff3d8aa6 100644
--- a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/impl/FlowRecallService.java
+++ b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/impl/FlowRecallService.java
@@ -1,5 +1,7 @@
package com.codingapi.springboot.flow.service.impl;
+import com.codingapi.springboot.flow.bind.BindDataSnapshot;
+import com.codingapi.springboot.flow.bind.IBindData;
import com.codingapi.springboot.flow.domain.FlowWork;
import com.codingapi.springboot.flow.event.FlowApprovalEvent;
import com.codingapi.springboot.flow.record.FlowRecord;
@@ -19,6 +21,7 @@ public class FlowRecallService {
private final FlowWorkRepository flowWorkRepository;
private final FlowRecordRepository flowRecordRepository;
private final FlowProcessRepository flowProcessRepository;
+ private final FlowBindDataRepository flowBindDataRepository;
/**
* 撤回流程
@@ -44,6 +47,9 @@ public void recall(long recordId, IFlowOperator currentOperator) {
// 下一流程的流程记录
List childrenRecords = flowRecordRepository.findFlowRecordByPreId(recordId);
+
+ BindDataSnapshot bindDataSnapshot = flowBindDataRepository.getBindDataSnapshotById(flowRecord.getSnapshotId());
+
// 下一流程均为办理且未读
// 如果是在开始节点撤销,则直接删除
@@ -67,7 +73,8 @@ public void recall(long recordId, IFlowOperator currentOperator) {
flowRecordRepository.delete(childrenRecords);
}
+ IBindData bindData = bindDataSnapshot.toBindData();
- EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_RECALL, flowRecord, currentOperator, flowWork, null), true);
+ EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_RECALL, flowRecord, currentOperator, flowWork, bindData), true);
}
}
diff --git a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/impl/FlowRemoveService.java b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/impl/FlowRemoveService.java
index 97a167e7..1041a74b 100644
--- a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/impl/FlowRemoveService.java
+++ b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/impl/FlowRemoveService.java
@@ -1,12 +1,18 @@
package com.codingapi.springboot.flow.service.impl;
+import com.codingapi.springboot.flow.bind.BindDataSnapshot;
+import com.codingapi.springboot.flow.bind.IBindData;
import com.codingapi.springboot.flow.domain.FlowNode;
+import com.codingapi.springboot.flow.domain.FlowWork;
+import com.codingapi.springboot.flow.event.FlowApprovalEvent;
import com.codingapi.springboot.flow.record.FlowRecord;
+import com.codingapi.springboot.flow.repository.FlowBindDataRepository;
import com.codingapi.springboot.flow.repository.FlowProcessRepository;
import com.codingapi.springboot.flow.repository.FlowRecordRepository;
import com.codingapi.springboot.flow.repository.FlowWorkRepository;
import com.codingapi.springboot.flow.service.FlowRecordVerifyService;
import com.codingapi.springboot.flow.user.IFlowOperator;
+import com.codingapi.springboot.framework.event.EventPusher;
import lombok.AllArgsConstructor;
import org.springframework.transaction.annotation.Transactional;
@@ -17,6 +23,7 @@ public class FlowRemoveService {
private final FlowWorkRepository flowWorkRepository;
private final FlowRecordRepository flowRecordRepository;
private final FlowProcessRepository flowProcessRepository;
+ private final FlowBindDataRepository flowBindDataRepository;
/**
* 删除流程
@@ -37,15 +44,19 @@ public void remove(long recordId, IFlowOperator currentOperator) {
flowRecordVerifyService.loadFlowNode();
flowRecordVerifyService.verifyFlowRecordNotFinish();
flowRecordVerifyService.verifyFlowRecordIsTodo();
+ FlowWork flowWork = flowRecordVerifyService.getFlowWork();
FlowNode flowNode = flowRecordVerifyService.getFlowNode();
FlowRecord flowRecord = flowRecordVerifyService.getFlowRecord();
if(!flowNode.isStartNode()){
throw new IllegalArgumentException("flow record not remove");
}
+ BindDataSnapshot bindDataSnapshot = flowBindDataRepository.getBindDataSnapshotById(flowRecord.getSnapshotId());
+ IBindData bindData = bindDataSnapshot.toBindData();
flowProcessRepository.deleteByProcessId(flowRecord.getProcessId());
-
flowRecordRepository.deleteByProcessId(flowRecord.getProcessId());
+
+ EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_DELETE, flowRecord, currentOperator, flowWork, bindData), true);
}
}
From c5818461283e091c1d51d46829df87f74651152a Mon Sep 17 00:00:00 2001
From: lorne <1991wangliang@gmail.com>
Date: Fri, 4 Jul 2025 12:09:24 +0800
Subject: [PATCH 3/4] fix #123
---
.../flow/convert/FlowProcessConvertor.java | 3 +-
.../infra/flow/entity/FlowProcessEntity.java | 5 +
.../flow/jpa/FlowProcessEntityRepository.java | 1 -
.../flow/jpa/FlowRecordEntityRepository.java | 38 ++--
.../repository/FlowProcessRepositoryImpl.java | 9 +
.../repository/FlowRecordRepositoryImpl.java | 5 +-
.../springboot/flow/em/FlowStatus.java | 6 +-
.../springboot/flow/em/FlowType.java | 6 +-
.../flow/event/FlowApprovalEvent.java | 16 ++
.../springboot/flow/record/FlowProcess.java | 13 ++
.../springboot/flow/record/FlowRecord.java | 12 +
.../repository/FlowProcessRepository.java | 3 +-
.../springboot/flow/service/FlowService.java | 31 ++-
.../flow/service/impl/FlowBackService.java | 100 +++++++++
.../flow/service/impl/FlowRecallService.java | 5 +-
.../flow/service/impl/FlowRemoveService.java | 14 +-
.../flow/service/impl/FlowVoidedService.java | 82 +++++++
.../repository/FlowProcessRepositoryImpl.java | 8 +
.../repository/FlowRecordRepositoryImpl.java | 107 ++++++---
.../springboot/flow/test/FlowBackTest.java | 207 ++++++++++++++++++
.../springboot/flow/test/FlowVoidedTest.java | 189 ++++++++++++++++
21 files changed, 800 insertions(+), 60 deletions(-)
create mode 100644 springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/impl/FlowBackService.java
create mode 100644 springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/impl/FlowVoidedService.java
create mode 100644 springboot-starter-flow/src/test/java/com/codingapi/springboot/flow/test/FlowBackTest.java
create mode 100644 springboot-starter-flow/src/test/java/com/codingapi/springboot/flow/test/FlowVoidedTest.java
diff --git a/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/convert/FlowProcessConvertor.java b/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/convert/FlowProcessConvertor.java
index 1131e08c..0df7a61f 100644
--- a/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/convert/FlowProcessConvertor.java
+++ b/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/convert/FlowProcessConvertor.java
@@ -10,7 +10,7 @@ public static FlowProcess convert(FlowProcessEntity entity){
return null;
}
return new FlowProcess(entity.getProcessId(),
- entity.getCreateTime(),entity.getBackupId(),entity.getCreateOperatorId());
+ entity.getCreateTime(),entity.getBackupId(),entity.getCreateOperatorId(), entity.getVoided());
}
@@ -23,6 +23,7 @@ public static FlowProcessEntity convert(FlowProcess flowProcess){
entity.setCreateTime(flowProcess.getCreateTime());
entity.setBackupId(flowProcess.getBackupId());
entity.setCreateOperatorId(flowProcess.getCreateOperatorId());
+ entity.setVoided(flowProcess.isVoided());
return entity;
}
}
diff --git a/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/entity/FlowProcessEntity.java b/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/entity/FlowProcessEntity.java
index a4117b01..865190f7 100644
--- a/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/entity/FlowProcessEntity.java
+++ b/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/entity/FlowProcessEntity.java
@@ -33,4 +33,9 @@ public class FlowProcessEntity {
*/
private Long createOperatorId;
+ /**
+ * 是否作废
+ */
+ private Boolean voided;
+
}
diff --git a/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/jpa/FlowProcessEntityRepository.java b/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/jpa/FlowProcessEntityRepository.java
index 6cfe1bb2..09969206 100644
--- a/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/jpa/FlowProcessEntityRepository.java
+++ b/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/jpa/FlowProcessEntityRepository.java
@@ -7,7 +7,6 @@ public interface FlowProcessEntityRepository extends FastRepository {
-
+ @Query(value = "select r from FlowRecordEntity r where r.flowType!='DELETE' and r.id = ?1")
FlowRecordEntity getFlowRecordEntityById(long id);
void deleteByProcessId(String processId);
-
+ @Query(value = "select r from FlowRecordEntity r where r.flowType!='DELETE' and r.preId = ?1")
List findFlowRecordEntityByPreId(long preId);
+ @Query(value = "select r from FlowRecordEntity r where r.flowType!='DELETE' and r.processId = ?1")
List findFlowRecordEntityByProcessId(String processId);
- @Query(value = "select r from FlowRecordEntity r where r.flowType = 'TODO' and r.flowStatus = 'RUNNING' and r.processId = ?1")
+ @Query(value = "select r from FlowRecordEntity r where r.flowType!='DELETE' and r.flowType = 'TODO' and r.flowStatus = 'RUNNING' and r.processId = ?1")
List findTodoFlowRecordByProcessId(String processId);
@Query(value = "select r from FlowRecordEntity r" +
" LEFT JOIN (select min(m.id) as id from FlowRecordEntity m where m.currentOperatorId = ?1 and m.flowType = 'TODO' and m.flowStatus = 'RUNNING' and m.mergeable = true ) debup " +
"on r.id = debup.id" +
- " where r.currentOperatorId = ?1 and r.flowType = 'TODO' and r.flowStatus = 'RUNNING'" +
+ " where r.flowType!='DELETE' and r.currentOperatorId = ?1 and r.flowType = 'TODO' and r.flowStatus = 'RUNNING'" +
" and (r.mergeable !=true or debup.id is NOT null ) order by r.id desc")
Page findTodoByOperatorId(long operatorId, PageRequest pageRequest);
- @Query(value = "select r from FlowRecordEntity r where r.currentOperatorId = ?1 and r.workCode = ?2 and r.nodeCode = ?3" +
+ @Query(value = "select r from FlowRecordEntity r where r.flowType!='DELETE'and r.currentOperatorId = ?1 and r.workCode = ?2 and r.nodeCode = ?3" +
" and r.mergeable = true and r.flowType = 'TODO' and r.flowStatus = 'RUNNING' order by r.id desc")
List findMergeFlowRecordById(long currentOperatorId,String workCode, String nodeCode);
- @Query(value = "select r from FlowRecordEntity r where r.currentOperatorId = ?1 and r.workCode = ?2 and r.flowType = 'TODO' and r.flowStatus = 'RUNNING' order by r.id desc")
+ @Query(value = "select r from FlowRecordEntity r where r.flowType!='DELETE'and r.currentOperatorId = ?1 and r.workCode = ?2 and r.flowType = 'TODO' and r.flowStatus = 'RUNNING' order by r.id desc")
Page findTodoByOperatorIdAndWorkCode(long operatorId, String workCode, PageRequest pageRequest);
- @Query(value = "select r from FlowRecordEntity r where r.currentOperatorId = ?1 and r.read = false and r.flowStatus = 'RUNNING' order by r.id desc")
+ @Query(value = "select r from FlowRecordEntity r where r.flowType!='DELETE'and r.currentOperatorId = ?1 and r.read = false and r.flowStatus = 'RUNNING' order by r.id desc")
Page findUnReadByOperatorId(long operatorId, PageRequest pageRequest);
- @Query(value = "select r from FlowRecordEntity r where r.currentOperatorId = ?1 and r.workCode = ?2 and r.read = false and r.flowStatus = 'RUNNING' order by r.id desc")
+ @Query(value = "select r from FlowRecordEntity r where r.flowType!='DELETE'and r.currentOperatorId = ?1 and r.workCode = ?2 and r.read = false and r.flowStatus = 'RUNNING' order by r.id desc")
Page findUnReadByOperatorIdAndWorkCode(long operatorId, String workCode, PageRequest pageRequest);
- @Query(value = "select d from FlowRecordEntity d where d.id in (select max(r.id) from FlowRecordEntity r where r.currentOperatorId = ?1 and r.flowType = 'DONE' group by r.processId ) order by d.id desc")
+ @Query(value = "select d from FlowRecordEntity d where d.flowType!='DELETE'and d.id in (select max(r.id) from FlowRecordEntity r where r.currentOperatorId = ?1 and r.flowType = 'DONE' group by r.processId ) order by d.id desc")
Page findDoneByOperatorId(long operatorId, PageRequest pageRequest);
- @Query(value = "select d from FlowRecordEntity d where d.id in (select max(r.id) from FlowRecordEntity r where r.currentOperatorId = ?1 and r.workCode = ?2 and r.flowType = 'DONE' group by r.processId) order by d.id desc")
+ @Query(value = "select d from FlowRecordEntity d where d.flowType!='DELETE'and d.id in (select max(r.id) from FlowRecordEntity r where r.currentOperatorId = ?1 and r.workCode = ?2 and r.flowType = 'DONE' group by r.processId) order by d.id desc")
Page findDoneByOperatorIdAndworkCode(long operatorId, String workCode, PageRequest pageRequest);
- @Query(value = "select d from FlowRecordEntity d where d.id in (select max(r.id) from FlowRecordEntity r where r.currentOperatorId = ?1 and r.preId = 0 and r.nodeCode = 'start' group by r.processId) order by d.id desc")
+ @Query(value = "select d from FlowRecordEntity d where d.flowType!='DELETE'and d.id in (select max(r.id) from FlowRecordEntity r where r.currentOperatorId = ?1 and r.preId = 0 and r.nodeCode = 'start' group by r.processId) order by d.id desc")
Page findInitiatedByOperatorId(long operatorId, PageRequest pageRequest);
- @Query(value = "select d from FlowRecordEntity d where d.id in (select max(r.id) from FlowRecordEntity r where r.currentOperatorId = ?1 group by r.processId) order by d.id desc")
+ @Query(value = "select d from FlowRecordEntity d where d.flowType!='DELETE' and d.id in (select max(r.id) from FlowRecordEntity r where r.currentOperatorId = ?1 group by r.processId) order by d.id desc")
Page findAllByOperatorId(long operatorId, PageRequest pageRequest);
- @Query(value = "select d from FlowRecordEntity d where d.id in (select max(r.id) from FlowRecordEntity r where r.currentOperatorId = ?1 and r.workCode = ?2 and r.preId = 0 and r.nodeCode = 'start' group by r.processId) order by d.id desc")
+ @Query(value = "select d from FlowRecordEntity d where d.flowType!='DELETE' and d.id in (select max(r.id) from FlowRecordEntity r where r.currentOperatorId = ?1 and r.workCode = ?2 and r.preId = 0 and r.nodeCode = 'start' group by r.processId) order by d.id desc")
Page findInitiatedByOperatorIdAndWorkCode(long operatorId, String workCode, PageRequest pageRequest);
- @Query(value = "select r from FlowRecordEntity r where r.currentOperatorId = ?1 and r.flowType = 'TODO' and r.flowStatus = 'RUNNING' and r.timeoutTime >0 and r.timeoutTime < ?2 order by r.id desc")
+ @Query(value = "select r from FlowRecordEntity r where r.flowType!='DELETE' and r.currentOperatorId = ?1 and r.flowType = 'TODO' and r.flowStatus = 'RUNNING' and r.timeoutTime >0 and r.timeoutTime < ?2 order by r.id desc")
Page findTimeoutTodoByOperatorId(long operatorId, long currentTime, PageRequest pageRequest);
- @Query(value = "select r from FlowRecordEntity r where r.currentOperatorId = ?1 and r.workCode = ?2 and r.flowType = 'TODO' and r.flowStatus = 'RUNNING' and r.timeoutTime >0 and r.timeoutTime < ?3 order by r.id desc")
+ @Query(value = "select r from FlowRecordEntity r where r.flowType!='DELETE' and r.currentOperatorId = ?1 and r.workCode = ?2 and r.flowType = 'TODO' and r.flowStatus = 'RUNNING' and r.timeoutTime >0 and r.timeoutTime < ?3 order by r.id desc")
Page findTimeoutTodoByOperatorIdAndWorkCode(long operatorId, String workCode, long currentTime, PageRequest pageRequest);
- @Query(value = "select r from FlowRecordEntity r where r.currentOperatorId = ?1 and r.flowType = 'TODO' and r.flowStatus = 'RUNNING' and r.postponedCount > 0 order by r.id desc")
+ @Query(value = "select r from FlowRecordEntity r where r.flowType!='DELETE' and r.currentOperatorId = ?1 and r.flowType = 'TODO' and r.flowStatus = 'RUNNING' and r.postponedCount > 0 order by r.id desc")
Page findPostponedTodoByOperatorId(long operatorId, PageRequest pageRequest);
- @Query(value = "select r from FlowRecordEntity r where r.currentOperatorId = ?1 and r.workCode =?2 and r.flowType = 'TODO' and r.flowStatus = 'RUNNING' and r.postponedCount > 0 order by r.id desc")
+ @Query(value = "select r from FlowRecordEntity r where r.flowType!='DELETE' and r.currentOperatorId = ?1 and r.workCode =?2 and r.flowType = 'TODO' and r.flowStatus = 'RUNNING' and r.postponedCount > 0 order by r.id desc")
Page findPostponedTodoByOperatorIdAndWorkCode(long operatorId, String workCode, PageRequest pageRequest);
-
- @Query(value = "select d from FlowRecordEntity d where d.id in (select max(r.id) from FlowRecordEntity r group by r.processId ) order by d.id desc")
+ @Query(value = "select d from FlowRecordEntity d where d.flowType!='DELETE' and d.id in (select max(r.id) from FlowRecordEntity r group by r.processId ) order by d.id desc")
Page findAllFlowRecords(PageRequest pageRequest);
}
diff --git a/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/repository/FlowProcessRepositoryImpl.java b/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/repository/FlowProcessRepositoryImpl.java
index 33f8b1b2..73d930d4 100644
--- a/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/repository/FlowProcessRepositoryImpl.java
+++ b/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/repository/FlowProcessRepositoryImpl.java
@@ -24,12 +24,21 @@ public void save(FlowProcess flowProcess) {
flowProcessEntityRepository.save( FlowProcessConvertor.convert(flowProcess));
}
+ @Override
+ public FlowProcess getFlowProcessByProcessId(String processId) {
+ return FlowProcessConvertor.convert(flowProcessEntityRepository.getFlowProcessEntityByProcessId(processId));
+ }
+
@Override
public FlowWork getFlowWorkByProcessId(String processId) {
FlowProcess flowProcess = FlowProcessConvertor.convert(flowProcessEntityRepository.getFlowProcessEntityByProcessId(processId));
if(flowProcess==null){
return null;
}
+ if(flowProcess.isVoided()){
+ return null;
+ }
+
FlowBackup flowBackup = flowBackupRepository.getFlowBackupById(flowProcess.getBackupId());
if (flowBackup != null) {
try {
diff --git a/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/repository/FlowRecordRepositoryImpl.java b/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/repository/FlowRecordRepositoryImpl.java
index 1c11c340..6adddab1 100644
--- a/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/repository/FlowRecordRepositoryImpl.java
+++ b/example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/repository/FlowRecordRepositoryImpl.java
@@ -40,7 +40,10 @@ public FlowRecord getFlowRecordById(long id) {
@Override
public List findFlowRecordByPreId(long preId) {
- return flowRecordEntityRepository.findFlowRecordEntityByPreId(preId).stream().map(item->FlowRecordConvertor.convert(item,flowOperatorRepository)).toList();
+ return flowRecordEntityRepository.findFlowRecordEntityByPreId(preId).stream()
+ .map(item->FlowRecordConvertor.convert(item,flowOperatorRepository))
+ .filter(flowRecord -> !flowRecord.isDelete())
+ .toList();
}
@Override
diff --git a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/em/FlowStatus.java b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/em/FlowStatus.java
index 7c4bceec..b762cc99 100644
--- a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/em/FlowStatus.java
+++ b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/em/FlowStatus.java
@@ -13,7 +13,11 @@ public enum FlowStatus {
/**
* 已完成
*/
- FINISH;
+ FINISH,
+ /**
+ * 已作废
+ */
+ VOIDED;
public static FlowStatus parser(String status) {
diff --git a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/em/FlowType.java b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/em/FlowType.java
index 5e36e57b..930eb03b 100644
--- a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/em/FlowType.java
+++ b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/em/FlowType.java
@@ -24,7 +24,11 @@ public enum FlowType {
/**
* 等待执行
*/
- WAITING;
+ WAITING,
+ /**
+ * 删除
+ */
+ DELETE;
public static FlowType parser(String type){
diff --git a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/event/FlowApprovalEvent.java b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/event/FlowApprovalEvent.java
index f9dbee72..64dccbbc 100644
--- a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/event/FlowApprovalEvent.java
+++ b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/event/FlowApprovalEvent.java
@@ -38,6 +38,10 @@ public class FlowApprovalEvent implements ISyncEvent {
public static final int STATE_SAVE = 10;
// 删除
public static final int STATE_DELETE = 11;
+ // 退回
+ public static final int STATE_BACK = 12;
+ // 作废
+ public static final int STATE_VOIDED = 13;
private final int state;
private final IFlowOperator operator;
@@ -109,4 +113,16 @@ public boolean isRecall() {
public boolean isFinish() {
return state == STATE_FINISH;
}
+
+ public boolean isDelete() {
+ return state == STATE_DELETE;
+ }
+
+ public boolean isVoided() {
+ return state == STATE_VOIDED;
+ }
+
+ public boolean isBack() {
+ return state == STATE_BACK;
+ }
}
diff --git a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/record/FlowProcess.java b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/record/FlowProcess.java
index b8a4f975..d678921e 100644
--- a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/record/FlowProcess.java
+++ b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/record/FlowProcess.java
@@ -32,11 +32,24 @@ public class FlowProcess {
*/
private long createOperatorId;
+ /**
+ * 是否作废
+ */
+ private boolean voided;
+
+ /**
+ * 作废流程
+ */
+ public void voided(){
+ this.voided = true;
+ }
+
public FlowProcess(long backupId, IFlowOperator createOperator) {
this.processId = RandomGenerator.generateUUID();
this.createTime = System.currentTimeMillis();
this.backupId = backupId;
this.createOperatorId = createOperator.getUserId();
+ this.voided = false;
}
}
diff --git a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/record/FlowRecord.java b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/record/FlowRecord.java
index d8f11670..b45970e8 100644
--- a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/record/FlowRecord.java
+++ b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/record/FlowRecord.java
@@ -393,6 +393,14 @@ public void recall() {
this.updateTime = System.currentTimeMillis();
}
+ /**
+ * 删除流程
+ */
+ public void delete() {
+ this.flowType = FlowType.DELETE;
+ this.updateTime = System.currentTimeMillis();
+ }
+
/**
* 复制流程记录
@@ -428,6 +436,9 @@ public FlowRecord copy() {
return record;
}
+ public boolean isDelete() {
+ return this.flowType == FlowType.DELETE;
+ }
/**
* 是否超时
@@ -460,4 +471,5 @@ public boolean isOverNode() {
public boolean isStartNode() {
return this.nodeCode.equals(FlowNode.CODE_START);
}
+
}
diff --git a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/repository/FlowProcessRepository.java b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/repository/FlowProcessRepository.java
index 293aeecf..d92e2b75 100644
--- a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/repository/FlowProcessRepository.java
+++ b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/repository/FlowProcessRepository.java
@@ -10,9 +10,10 @@ public interface FlowProcessRepository {
void save(FlowProcess flowProcess);
-
FlowWork getFlowWorkByProcessId(String processId);
+ FlowProcess getFlowProcessByProcessId(String processId);
+
void deleteByProcessId(String processId);
}
diff --git a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/FlowService.java b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/FlowService.java
index dd2ccee8..77980ce3 100644
--- a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/FlowService.java
+++ b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/FlowService.java
@@ -28,6 +28,8 @@ public class FlowService {
private final FlowTransferService flowTransferService;
private final FlowPostponedService flowPostponedService;
private final FlowUrgeService flowUrgeService;
+ private final FlowVoidedService flowVoidedService;
+ private final FlowBackService flowBackService;
private final FlowServiceRepositoryHolder flowServiceRepositoryHolder;
@@ -41,12 +43,14 @@ public FlowService(FlowWorkRepository flowWorkRepository,
this.flowServiceRepositoryHolder = new FlowServiceRepositoryHolder(flowWorkRepository, flowRecordRepository, flowBindDataRepository, flowOperatorRepository, flowProcessRepository, flowBackupRepository);
this.flowDetailService = new FlowDetailService(flowWorkRepository, flowRecordRepository, flowBindDataRepository, flowOperatorRepository, flowProcessRepository);
this.flowCustomEventService = new FlowCustomEventService(flowWorkRepository, flowRecordRepository, flowProcessRepository);
- this.flowRecallService = new FlowRecallService(flowWorkRepository, flowRecordRepository, flowProcessRepository,flowBindDataRepository);
- this.flowRemoveService = new FlowRemoveService(flowWorkRepository, flowRecordRepository, flowProcessRepository,flowBindDataRepository);
+ this.flowRecallService = new FlowRecallService(flowWorkRepository, flowRecordRepository, flowProcessRepository, flowBindDataRepository);
+ this.flowRemoveService = new FlowRemoveService(flowWorkRepository, flowRecordRepository, flowProcessRepository, flowBindDataRepository);
this.flowSaveService = new FlowSaveService(flowWorkRepository, flowRecordRepository, flowBindDataRepository, flowProcessRepository);
this.flowTransferService = new FlowTransferService(flowWorkRepository, flowRecordRepository, flowBindDataRepository, flowProcessRepository);
this.flowPostponedService = new FlowPostponedService(flowWorkRepository, flowRecordRepository, flowProcessRepository);
this.flowUrgeService = new FlowUrgeService(flowWorkRepository, flowRecordRepository, flowProcessRepository);
+ this.flowVoidedService = new FlowVoidedService(flowWorkRepository, flowRecordRepository, flowProcessRepository, flowBindDataRepository);
+ this.flowBackService = new FlowBackService(flowWorkRepository, flowRecordRepository, flowProcessRepository, flowBindDataRepository);
}
/**
@@ -289,4 +293,27 @@ public void remove(long recordId, IFlowOperator currentOperator) {
flowRemoveService.remove(recordId, currentOperator);
}
+
+ /**
+ * 作废流程
+ *
+ * @param processId 流程processId
+ * @param currentOperator 当前操作者
+ */
+ public void voided(String processId, IFlowOperator currentOperator) {
+ flowVoidedService.voided(processId, currentOperator);
+ }
+
+
+ /**
+ * 退回流程
+ *
+ * @param processId 流程processId
+ * @param backNodeCode 退回节点编码
+ * @param currentOperator 当前操作者
+ */
+ public void back(String processId, String backNodeCode, IFlowOperator currentOperator) {
+ flowBackService.back(processId, backNodeCode, currentOperator);
+ }
+
}
diff --git a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/impl/FlowBackService.java b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/impl/FlowBackService.java
new file mode 100644
index 00000000..2a659aec
--- /dev/null
+++ b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/impl/FlowBackService.java
@@ -0,0 +1,100 @@
+package com.codingapi.springboot.flow.service.impl;
+
+import com.codingapi.springboot.flow.bind.IBindData;
+import com.codingapi.springboot.flow.domain.FlowWork;
+import com.codingapi.springboot.flow.event.FlowApprovalEvent;
+import com.codingapi.springboot.flow.record.FlowProcess;
+import com.codingapi.springboot.flow.record.FlowRecord;
+import com.codingapi.springboot.flow.repository.FlowBindDataRepository;
+import com.codingapi.springboot.flow.repository.FlowProcessRepository;
+import com.codingapi.springboot.flow.repository.FlowRecordRepository;
+import com.codingapi.springboot.flow.repository.FlowWorkRepository;
+import com.codingapi.springboot.flow.user.IFlowOperator;
+import com.codingapi.springboot.framework.event.EventPusher;
+import lombok.AllArgsConstructor;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.Comparator;
+import java.util.List;
+
+/**
+ * 流程退回服务(流程管理员操作)
+ */
+@Transactional
+@AllArgsConstructor
+public class FlowBackService {
+
+ private final FlowWorkRepository flowWorkRepository;
+ private final FlowRecordRepository flowRecordRepository;
+ private final FlowProcessRepository flowProcessRepository;
+ private final FlowBindDataRepository flowBindDataRepository;
+
+
+ /**
+ * 退回流程
+ *
+ * @param processId 流程processId
+ * @param backNodeCode 退回节点编码
+ * @param currentOperator 当前操作者
+ */
+ public void back(String processId, String backNodeCode, IFlowOperator currentOperator) {
+ if (!currentOperator.isFlowManager()) {
+ throw new IllegalArgumentException("current operator not flow manager");
+ }
+
+ FlowProcess flowProcess = flowProcessRepository.getFlowProcessByProcessId(processId);
+ if (flowProcess.isVoided()) {
+ throw new IllegalArgumentException("flow process already voided");
+ }
+
+ List historyRecords = flowRecordRepository
+ .findFlowRecordByProcessId(processId)
+ .stream()
+ .sorted(Comparator.comparingLong(FlowRecord::getId))
+ .toList();
+
+ for (FlowRecord flowRecord : historyRecords) {
+ if (flowRecord.isFinish()) {
+ throw new IllegalArgumentException("flow record already finish");
+ }
+ }
+
+ if (historyRecords.isEmpty()) {
+ throw new IllegalArgumentException("flow record not found");
+ }
+
+ List historyNodeCodes = historyRecords.stream()
+ .map(FlowRecord::getNodeCode)
+ .distinct()
+ .toList();
+
+ if (!historyNodeCodes.contains(backNodeCode)) {
+ throw new IllegalArgumentException("flow node code not found");
+ }
+
+ FlowRecord beginRecord = historyRecords.get(0);
+ for (FlowRecord flowRecord : historyRecords) {
+ if(flowRecord.getNodeCode().equals(backNodeCode)){
+ beginRecord = flowRecord;
+ }
+ }
+
+ for (FlowRecord flowRecord : historyRecords) {
+ if(flowRecord.getId()> beginRecord.getId() ){
+ flowRecord.delete();
+ }else {
+ if(flowRecord.getNodeCode().equals(beginRecord.getNodeCode())){
+ flowRecord.recall();
+ }
+ }
+ }
+
+ flowRecordRepository.save(historyRecords);
+
+ FlowWork flowWork = flowWorkRepository.getFlowWorkByCode(beginRecord.getWorkCode());
+ IBindData bindData = flowBindDataRepository.getBindDataSnapshotById(beginRecord.getSnapshotId()).toBindData();
+
+ EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_BACK, beginRecord, currentOperator, flowWork, bindData), true);
+
+ }
+}
diff --git a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/impl/FlowRecallService.java b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/impl/FlowRecallService.java
index ff3d8aa6..fb04b619 100644
--- a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/impl/FlowRecallService.java
+++ b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/impl/FlowRecallService.java
@@ -71,7 +71,10 @@ public void recall(long recordId, IFlowOperator currentOperator) {
flowRecord.recall();
flowRecordRepository.update(flowRecord);
- flowRecordRepository.delete(childrenRecords);
+ for(FlowRecord childrenRecord : childrenRecords) {
+ childrenRecord.delete();
+ }
+ flowRecordRepository.save(childrenRecords);
}
IBindData bindData = bindDataSnapshot.toBindData();
diff --git a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/impl/FlowRemoveService.java b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/impl/FlowRemoveService.java
index 1041a74b..92a6a776 100644
--- a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/impl/FlowRemoveService.java
+++ b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/impl/FlowRemoveService.java
@@ -5,6 +5,7 @@
import com.codingapi.springboot.flow.domain.FlowNode;
import com.codingapi.springboot.flow.domain.FlowWork;
import com.codingapi.springboot.flow.event.FlowApprovalEvent;
+import com.codingapi.springboot.flow.record.FlowProcess;
import com.codingapi.springboot.flow.record.FlowRecord;
import com.codingapi.springboot.flow.repository.FlowBindDataRepository;
import com.codingapi.springboot.flow.repository.FlowProcessRepository;
@@ -16,6 +17,8 @@
import lombok.AllArgsConstructor;
import org.springframework.transaction.annotation.Transactional;
+import java.util.List;
+
@Transactional
@AllArgsConstructor
public class FlowRemoveService {
@@ -54,8 +57,15 @@ public void remove(long recordId, IFlowOperator currentOperator) {
BindDataSnapshot bindDataSnapshot = flowBindDataRepository.getBindDataSnapshotById(flowRecord.getSnapshotId());
IBindData bindData = bindDataSnapshot.toBindData();
- flowProcessRepository.deleteByProcessId(flowRecord.getProcessId());
- flowRecordRepository.deleteByProcessId(flowRecord.getProcessId());
+ FlowProcess flowProcess = flowProcessRepository.getFlowProcessByProcessId(flowRecord.getProcessId());
+ flowProcess.voided();
+ flowProcessRepository.save(flowProcess);
+
+ List historyRecords = flowRecordRepository.findFlowRecordByProcessId(flowRecord.getProcessId());
+ for (FlowRecord record : historyRecords) {
+ record.delete();
+ }
+ flowRecordRepository.save(historyRecords);
EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_DELETE, flowRecord, currentOperator, flowWork, bindData), true);
}
diff --git a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/impl/FlowVoidedService.java b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/impl/FlowVoidedService.java
new file mode 100644
index 00000000..059cff2d
--- /dev/null
+++ b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/impl/FlowVoidedService.java
@@ -0,0 +1,82 @@
+package com.codingapi.springboot.flow.service.impl;
+
+import com.codingapi.springboot.flow.bind.BindDataSnapshot;
+import com.codingapi.springboot.flow.bind.IBindData;
+import com.codingapi.springboot.flow.domain.FlowWork;
+import com.codingapi.springboot.flow.event.FlowApprovalEvent;
+import com.codingapi.springboot.flow.record.FlowProcess;
+import com.codingapi.springboot.flow.record.FlowRecord;
+import com.codingapi.springboot.flow.repository.FlowBindDataRepository;
+import com.codingapi.springboot.flow.repository.FlowProcessRepository;
+import com.codingapi.springboot.flow.repository.FlowRecordRepository;
+import com.codingapi.springboot.flow.repository.FlowWorkRepository;
+import com.codingapi.springboot.flow.user.IFlowOperator;
+import com.codingapi.springboot.framework.event.EventPusher;
+import lombok.AllArgsConstructor;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+
+/**
+ * 流程作废服务(流程管理员操作)
+ */
+@Transactional
+@AllArgsConstructor
+public class FlowVoidedService {
+
+ private final FlowWorkRepository flowWorkRepository;
+ private final FlowRecordRepository flowRecordRepository;
+ private final FlowProcessRepository flowProcessRepository;
+ private final FlowBindDataRepository flowBindDataRepository;
+
+
+ /**
+ * 作废流程
+ *
+ * @param processId 流程processId
+ * @param currentOperator 当前操作者
+ */
+ public void voided(String processId, IFlowOperator currentOperator) {
+ if (!currentOperator.isFlowManager()) {
+ throw new IllegalArgumentException("current operator not flow manager");
+ }
+
+ FlowProcess flowProcess = flowProcessRepository.getFlowProcessByProcessId(processId);
+ if(flowProcess.isVoided()){
+ throw new IllegalArgumentException("flow process already voided");
+ }
+ flowProcess.voided();
+ flowProcessRepository.save(flowProcess);
+
+ FlowRecord currentRecord = null;
+ List flowRecords = flowRecordRepository.findFlowRecordByProcessId(processId);
+ if (!flowRecords.isEmpty()) {
+ for (FlowRecord flowRecord : flowRecords) {
+ if (flowRecord.isFinish()) {
+ throw new IllegalArgumentException("flow record already finish");
+ }
+ flowRecord.delete();
+ if(currentRecord==null || flowRecord.getId()> currentRecord.getId()){
+ currentRecord = flowRecord;
+ }
+ }
+ }
+ flowRecordRepository.save(flowRecords);
+
+ FlowWork flowWork = null;
+
+ IBindData bindData = null;
+ if (currentRecord != null) {
+ // 删除流程绑定数据
+ BindDataSnapshot dataSnapshot = flowBindDataRepository.getBindDataSnapshotById(currentRecord.getSnapshotId());
+ if (dataSnapshot != null) {
+ bindData = dataSnapshot.toBindData();
+ }
+ flowWork = flowWorkRepository.getFlowWorkByCode(currentRecord.getWorkCode());
+ }
+
+ EventPusher.push(new FlowApprovalEvent(FlowApprovalEvent.STATE_VOIDED, currentRecord, currentOperator, flowWork, bindData), true);
+
+
+ }
+}
diff --git a/springboot-starter-flow/src/test/java/com/codingapi/springboot/flow/repository/FlowProcessRepositoryImpl.java b/springboot-starter-flow/src/test/java/com/codingapi/springboot/flow/repository/FlowProcessRepositoryImpl.java
index 6d5c1b5c..da73c580 100644
--- a/springboot-starter-flow/src/test/java/com/codingapi/springboot/flow/repository/FlowProcessRepositoryImpl.java
+++ b/springboot-starter-flow/src/test/java/com/codingapi/springboot/flow/repository/FlowProcessRepositoryImpl.java
@@ -24,6 +24,14 @@ public void save(FlowProcess flowProcess) {
}
}
+ @Override
+ public FlowProcess getFlowProcessByProcessId(String processId) {
+ return cache.stream()
+ .filter(flowProcess -> flowProcess.getProcessId().equals(processId))
+ .filter(flowProcess -> !flowProcess.isVoided())
+ .findFirst().orElse(null);
+ }
+
@Override
public FlowWork getFlowWorkByProcessId(String processId) {
FlowProcess process = cache.stream().filter(flowProcess -> flowProcess.getProcessId().equals(processId)).findFirst().orElse(null);
diff --git a/springboot-starter-flow/src/test/java/com/codingapi/springboot/flow/repository/FlowRecordRepositoryImpl.java b/springboot-starter-flow/src/test/java/com/codingapi/springboot/flow/repository/FlowRecordRepositoryImpl.java
index 9c7f66ea..2bec3ea1 100644
--- a/springboot-starter-flow/src/test/java/com/codingapi/springboot/flow/repository/FlowRecordRepositoryImpl.java
+++ b/springboot-starter-flow/src/test/java/com/codingapi/springboot/flow/repository/FlowRecordRepositoryImpl.java
@@ -25,7 +25,10 @@ public void save(List records) {
@Override
public FlowRecord getFlowRecordById(long id) {
- return cache.stream().filter(record -> record.getId() == id).findFirst().orElse(null);
+ return cache.stream()
+ .filter(record -> record.getId() == id)
+ .filter(record -> !record.isDelete())
+ .findFirst().orElse(null);
}
@@ -39,13 +42,16 @@ public void update(FlowRecord flowRecord) {
@Override
public List findFlowRecordByPreId(long preId) {
- return cache.stream().filter(record -> record.getPreId() == preId).toList();
+ return cache.stream().filter(record -> record.getPreId() == preId)
+ .filter(record -> !record.isDelete())
+ .toList();
}
@Override
public List findFlowRecordByProcessId(String processId) {
return cache.stream().filter(record -> record.getProcessId().equals(processId))
.sorted((o1, o2) -> (int) (o1.getCreateTime() - o2.getCreateTime()))
+ .filter(record -> !record.isDelete())
.toList();
}
@@ -57,106 +63,146 @@ public List findMergeFlowRecordById(String workCode, String nodeCode
&& record.getNodeCode().equals(nodeCode)
&& record.isMergeable()
)
+ .filter(record -> !record.isDelete())
.toList();
}
@Override
public List findTodoFlowRecordByProcessId(String processId) {
- return cache.stream().filter(record -> record.isTodo() && record.getProcessId().equals(processId)).toList();
+ return cache.stream().filter(record -> record.isTodo() && record.getProcessId().equals(processId))
+ .filter(record -> !record.isDelete())
+ .toList();
}
public Page findAll(PageRequest pageRequest) {
- return new PageImpl<>(cache);
+ return new PageImpl<>(cache.stream()
+ .filter(flowRecord -> !flowRecord.isDelete())
+ .toList());
}
@Override
public Page findDoneByOperatorId(long operatorId, PageRequest pageRequest) {
- List flowRecords = cache.stream().filter(record -> record.isDone() && record.getCurrentOperator().getUserId() == operatorId).toList();
+ List flowRecords = cache.stream()
+ .filter(record -> record.isDone() && record.getCurrentOperator().getUserId() == operatorId)
+ .filter(record -> !record.isDelete())
+ .toList();
return new PageImpl<>(flowRecords);
}
@Override
public Page findUnReadByOperatorId(long operatorId, PageRequest pageRequest) {
- List flowRecords = cache.stream().filter(record -> record.isUnRead() && record.getCurrentOperator().getUserId() == operatorId).toList();
+ List flowRecords = cache.stream()
+ .filter(record -> record.isUnRead() && record.getCurrentOperator().getUserId() == operatorId)
+ .filter(record -> !record.isDelete())
+ .toList();
return new PageImpl<>(flowRecords);
}
@Override
public Page findUnReadByOperatorId(long operatorId, String workCode, PageRequest pageRequest) {
- List flowRecords = cache.stream().filter(record -> record.isUnRead() && record.getWorkCode().equals(workCode) && record.getCurrentOperator().getUserId() == operatorId).toList();
+ List flowRecords = cache.stream()
+ .filter(record -> record.isUnRead() && record.getWorkCode().equals(workCode) && record.getCurrentOperator().getUserId() == operatorId)
+ .filter(record -> !record.isDelete())
+ .toList();
return new PageImpl<>(flowRecords);
}
@Override
public Page findDoneByOperatorId(long operatorId, String workCode, PageRequest pageRequest) {
- List flowRecords = cache.stream().filter(record -> record.isDone()
- && record.getCurrentOperator().getUserId() == operatorId
- && record.getWorkCode().equals(workCode)
- ).toList();
+ List flowRecords = cache.stream().
+ filter(record -> record.isDone()
+ && record.getCurrentOperator().getUserId() == operatorId
+ && record.getWorkCode().equals(workCode))
+ .filter(record -> !record.isDelete())
+ .toList();
return new PageImpl<>(flowRecords);
}
@Override
public Page findInitiatedByOperatorId(long operatorId, PageRequest pageRequest) {
- List flowRecords = cache.stream().filter(record -> record.isInitiated() && record.getCreateOperator().getUserId() == operatorId).toList();
+ List flowRecords = cache.stream()
+ .filter(record -> record.isInitiated() && record.getCreateOperator().getUserId() == operatorId)
+ .filter(record -> !record.isDelete())
+ .toList();
return new PageImpl<>(flowRecords);
}
@Override
public Page findInitiatedByOperatorId(long operatorId, String workCode, PageRequest pageRequest) {
- List flowRecords = cache.stream().filter(
- record -> record.isInitiated()
- && record.getCreateOperator().getUserId() == operatorId
- && record.getWorkCode().equals(workCode)
- ).toList();
+ List flowRecords = cache.stream()
+ .filter(
+ record -> record.isInitiated()
+ && record.getCreateOperator().getUserId() == operatorId
+ && record.getWorkCode().equals(workCode)
+ )
+ .filter(record -> !record.isDelete())
+ .toList();
return new PageImpl<>(flowRecords);
}
@Override
public Page findTodoByOperatorId(long operatorId, PageRequest pageRequest) {
- List flowRecords = cache.stream().filter(record -> record.isTodo() && record.getCurrentOperator().getUserId() == operatorId).toList();
+ List flowRecords = cache.stream()
+ .filter(record -> record.isTodo() && record.getCurrentOperator().getUserId() == operatorId)
+ .filter(record -> !record.isDelete())
+ .toList();
return new PageImpl<>(flowRecords);
}
@Override
public Page findTodoByOperatorId(long operatorId, String workCode, PageRequest pageRequest) {
- List flowRecords = cache.stream().filter(record -> record.isTodo() && record.getCurrentOperator().getUserId() == operatorId && record.getWorkCode().equals(workCode)).toList();
+ List flowRecords = cache.stream()
+ .filter(record -> record.isTodo() && record.getCurrentOperator().getUserId() == operatorId && record.getWorkCode().equals(workCode))
+ .filter(record -> !record.isDelete())
+ .toList();
return new PageImpl<>(flowRecords);
}
@Override
public Page findTimeoutTodoByOperatorId(long operatorId, PageRequest pageRequest) {
- List flowRecords = cache.stream().filter(record -> record.isTimeout() && record.isTodo() && record.getCurrentOperator().getUserId() == operatorId).toList();
+ List flowRecords = cache.stream()
+ .filter(record -> record.isTimeout() && record.isTodo() && record.getCurrentOperator().getUserId() == operatorId)
+ .filter(record -> !record.isDelete())
+ .toList();
return new PageImpl<>(flowRecords);
}
@Override
public Page findTimeoutTodoByOperatorId(long operatorId, String workCode, PageRequest pageRequest) {
- List flowRecords = cache.stream().filter(
- record -> record.isTimeout()
- && record.isTodo() && record.getCurrentOperator().getUserId() == operatorId
- && record.getWorkCode().equals(workCode)
- ).toList();
+ List flowRecords = cache.stream()
+ .filter(
+ record -> record.isTimeout()
+ && record.isTodo() && record.getCurrentOperator().getUserId() == operatorId
+ && record.getWorkCode().equals(workCode)
+ )
+ .filter(record -> !record.isDelete())
+ .toList();
return new PageImpl<>(flowRecords);
}
@Override
public Page findPostponedTodoByOperatorId(long operatorId, PageRequest pageRequest) {
- List flowRecords = cache.stream().filter(record -> record.isPostponed() && record.isTodo() && record.getCurrentOperator().getUserId() == operatorId).toList();
+ List flowRecords = cache.stream()
+ .filter(record -> record.isPostponed() && record.isTodo() && record.getCurrentOperator().getUserId() == operatorId)
+ .filter(record -> !record.isDelete())
+ .toList();
return new PageImpl<>(flowRecords);
}
@Override
public Page findPostponedTodoByOperatorId(long operatorId, String workCode, PageRequest pageRequest) {
- List flowRecords = cache.stream().filter(record -> record.isPostponed()
- && record.isTodo() && record.getCurrentOperator().getUserId() == operatorId
- && record.getWorkCode().equals(workCode)
- ).toList();
+ List flowRecords = cache.stream()
+ .filter(record -> record.isPostponed()
+ && record.isTodo() && record.getCurrentOperator().getUserId() == operatorId
+ && record.getWorkCode().equals(workCode)
+ )
+ .filter(record -> !record.isDelete())
+ .toList();
return new PageImpl<>(flowRecords);
}
@@ -164,6 +210,7 @@ public Page findPostponedTodoByOperatorId(long operatorId, String wo
public void finishFlowRecordByProcessId(String processId) {
cache.stream()
.filter(record -> record.getProcessId().equals(processId))
+ .filter(record -> !record.isDelete())
.forEach(FlowRecord::finish);
}
diff --git a/springboot-starter-flow/src/test/java/com/codingapi/springboot/flow/test/FlowBackTest.java b/springboot-starter-flow/src/test/java/com/codingapi/springboot/flow/test/FlowBackTest.java
new file mode 100644
index 00000000..022d7790
--- /dev/null
+++ b/springboot-starter-flow/src/test/java/com/codingapi/springboot/flow/test/FlowBackTest.java
@@ -0,0 +1,207 @@
+package com.codingapi.springboot.flow.test;
+
+import com.codingapi.springboot.flow.bind.BindDataSnapshot;
+import com.codingapi.springboot.flow.build.FlowWorkBuilder;
+import com.codingapi.springboot.flow.domain.FlowWork;
+import com.codingapi.springboot.flow.domain.Opinion;
+import com.codingapi.springboot.flow.em.ApprovalType;
+import com.codingapi.springboot.flow.flow.Leave;
+import com.codingapi.springboot.flow.matcher.OperatorMatcher;
+import com.codingapi.springboot.flow.record.FlowRecord;
+import com.codingapi.springboot.flow.repository.*;
+import com.codingapi.springboot.flow.service.FlowService;
+import com.codingapi.springboot.flow.user.User;
+import org.junit.jupiter.api.Test;
+import org.springframework.data.domain.PageRequest;
+
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+public class FlowBackTest {
+
+ private final UserRepository userRepository = new UserRepository();
+ private final FlowWorkRepository flowWorkRepository = new FlowWorkRepositoryImpl();
+ private final FlowRecordRepositoryImpl flowRecordRepository = new FlowRecordRepositoryImpl();
+ private final FlowBindDataRepositoryImpl flowBindDataRepository = new FlowBindDataRepositoryImpl();
+ private final LeaveRepository leaveRepository = new LeaveRepository();
+ private final FlowBackupRepository flowBackupRepository = new FlowBackupRepositoryImpl();
+ private final FlowProcessRepository flowProcessRepository = new FlowProcessRepositoryImpl(flowBackupRepository, userRepository);
+ private final FlowService flowService = new FlowService(flowWorkRepository, flowRecordRepository, flowBindDataRepository, userRepository, flowProcessRepository, flowBackupRepository);
+
+ /**
+ * 流程退回测试,结束的流程作废失败
+ */
+ @Test
+ void back1() {
+ PageRequest pageRequest = PageRequest.of(0, 1000);
+
+ User user = new User("张飞");
+ userRepository.save(user);
+
+ User dept = new User("刘备");
+ userRepository.save(dept);
+
+ User boss = new User("诸葛亮",true);
+ userRepository.save(boss);
+
+ FlowWork flowWork = FlowWorkBuilder.builder(user)
+ .title("请假流程")
+ .skipIfSameApprover(true)
+ .nodes()
+ .node("开始节点", "start", "default", ApprovalType.UN_SIGN, OperatorMatcher.anyOperatorMatcher())
+ .node("部门领导审批", "dept", "default", ApprovalType.UN_SIGN, OperatorMatcher.specifyOperatorMatcher(dept.getUserId()))
+ .node("总经理审批", "manager", "default", ApprovalType.UN_SIGN, OperatorMatcher.specifyOperatorMatcher(dept.getUserId()))
+ .node("结束节点", "over", "default", ApprovalType.UN_SIGN, OperatorMatcher.anyOperatorMatcher())
+ .relations()
+ .relation("部门领导审批", "start", "dept")
+ .relation("总经理审批", "dept", "manager")
+ .relation("结束节点", "manager", "over")
+ .build();
+
+ flowWorkRepository.save(flowWork);
+
+ String workCode = flowWork.getCode();
+
+ Leave leave = new Leave("我要出去看看");
+ leaveRepository.save(leave);
+
+ // 创建流程
+ flowService.startFlow(workCode, user, leave, "发起流程");
+
+ // 查看我的待办
+ List userTodos = flowRecordRepository.findTodoByOperatorId(user.getUserId(), pageRequest).getContent();
+ assertEquals(1, userTodos.size());
+
+ // 提交流程
+ FlowRecord userTodo = userTodos.get(0);
+ assertEquals(0, userTodo.getTimeoutTime());
+
+ flowService.submitFlow(userTodo.getId(), user, leave, Opinion.pass("同意"));
+
+ // 查看刘备经理的待办
+ List deptTodos = flowRecordRepository.findTodoByOperatorId(dept.getUserId(), pageRequest).getContent();
+ assertEquals(1, deptTodos.size());
+
+ // 提交委托dept部门经理的审批
+ FlowRecord deptTodo = deptTodos.get(0);
+ flowService.submitFlow(deptTodo.getId(), dept, leave, Opinion.pass("同意"));
+
+ assertThrows(IllegalArgumentException.class,()->{
+ // 退回流程
+ flowService.back(deptTodo.getProcessId(),"start",boss);
+ });
+
+ // 查看所有流程
+ List records = flowRecordRepository.findAll(pageRequest).getContent();
+ assertEquals(3, records.size());
+
+ userTodos = flowRecordRepository.findTodoByOperatorId(user.getUserId(), pageRequest).getContent();
+ assertEquals(0, userTodos.size());
+
+ records = flowRecordRepository.findAll(pageRequest).getContent();
+ assertEquals(3, records.size());
+ // 查看所有流程是否都已经结束
+ assertTrue(records.stream().allMatch(FlowRecord::isFinish));
+
+ List snapshots = flowBindDataRepository.findAll();
+ assertEquals(4, snapshots.size());
+
+ }
+
+
+ /**
+ * 流程退回测试,在结束节点前退回流程
+ */
+ @Test
+ void back2() {
+ PageRequest pageRequest = PageRequest.of(0, 1000);
+
+ User user = new User("张飞");
+ userRepository.save(user);
+
+ User dept = new User("刘备");
+ userRepository.save(dept);
+
+ User boss = new User("诸葛亮",true);
+ userRepository.save(boss);
+
+ FlowWork flowWork = FlowWorkBuilder.builder(user)
+ .title("请假流程")
+ .skipIfSameApprover(true)
+ .nodes()
+ .node("开始节点", "start", "default", ApprovalType.UN_SIGN, OperatorMatcher.anyOperatorMatcher())
+ .node("部门领导审批", "dept", "default", ApprovalType.UN_SIGN, OperatorMatcher.specifyOperatorMatcher(dept.getUserId()))
+ .node("总经理审批", "manager", "default", ApprovalType.UN_SIGN, OperatorMatcher.specifyOperatorMatcher(boss.getUserId()))
+ .node("结束节点", "over", "default", ApprovalType.UN_SIGN, OperatorMatcher.anyOperatorMatcher())
+ .relations()
+ .relation("部门领导审批", "start", "dept")
+ .relation("总经理审批", "dept", "manager")
+ .relation("结束节点", "manager", "over")
+ .build();
+
+ flowWorkRepository.save(flowWork);
+
+ String workCode = flowWork.getCode();
+
+ Leave leave = new Leave("我要出去看看");
+ leaveRepository.save(leave);
+
+ // 创建流程
+ flowService.startFlow(workCode, user, leave, "发起流程");
+
+ // 查看我的待办
+ List userTodos = flowRecordRepository.findTodoByOperatorId(user.getUserId(), pageRequest).getContent();
+ assertEquals(1, userTodos.size());
+
+ // 提交流程
+ FlowRecord userTodo = userTodos.get(0);
+ assertEquals(0, userTodo.getTimeoutTime());
+
+ flowService.submitFlow(userTodo.getId(), user, leave, Opinion.pass("同意"));
+
+ // 查看刘备经理的待办
+ List deptTodos = flowRecordRepository.findTodoByOperatorId(dept.getUserId(), pageRequest).getContent();
+ assertEquals(1, deptTodos.size());
+
+ // 提交委托dept部门经理的审批
+ FlowRecord deptTodo = deptTodos.get(0);
+ // 流程作废
+ flowService.back(deptTodo.getProcessId(),"start",boss);
+
+ // 查看所有流程
+ List records = flowRecordRepository.findAll(pageRequest).getContent();
+ assertEquals(1, records.size());
+
+ userTodos = flowRecordRepository.findTodoByOperatorId(user.getUserId(), pageRequest).getContent();
+ assertEquals(1, userTodos.size());
+
+ userTodo = userTodos.get(0);
+ assertEquals(0, userTodo.getTimeoutTime());
+
+ flowService.submitFlow(userTodo.getId(), user, leave, Opinion.pass("同意"));
+
+
+ deptTodos = flowRecordRepository.findTodoByOperatorId(dept.getUserId(), pageRequest).getContent();
+ assertEquals(1, deptTodos.size());
+
+ // 提交委托dept部门经理的审批
+ deptTodo = deptTodos.get(0);
+ flowService.submitFlow(deptTodo.getId(), dept, leave, Opinion.pass("同意"));
+
+ List bossTodos = flowRecordRepository.findTodoByOperatorId(boss.getUserId(), pageRequest).getContent();
+ assertEquals(1, bossTodos.size());
+
+ FlowRecord bossTodo = bossTodos.get(0);
+ flowService.submitFlow(bossTodo.getId(), boss, leave, Opinion.pass("同意"));
+
+ records = flowRecordRepository.findAll(pageRequest).getContent();
+ assertEquals(3, records.size());
+ // 查看所有流程是否都已经结束
+ assertTrue(records.stream().allMatch(FlowRecord::isFinish));
+
+ List snapshots = flowBindDataRepository.findAll();
+ assertEquals(5, snapshots.size());
+
+ }
+}
diff --git a/springboot-starter-flow/src/test/java/com/codingapi/springboot/flow/test/FlowVoidedTest.java b/springboot-starter-flow/src/test/java/com/codingapi/springboot/flow/test/FlowVoidedTest.java
new file mode 100644
index 00000000..83215ef0
--- /dev/null
+++ b/springboot-starter-flow/src/test/java/com/codingapi/springboot/flow/test/FlowVoidedTest.java
@@ -0,0 +1,189 @@
+package com.codingapi.springboot.flow.test;
+
+import com.codingapi.springboot.flow.bind.BindDataSnapshot;
+import com.codingapi.springboot.flow.build.FlowWorkBuilder;
+import com.codingapi.springboot.flow.domain.FlowWork;
+import com.codingapi.springboot.flow.domain.Opinion;
+import com.codingapi.springboot.flow.em.ApprovalType;
+import com.codingapi.springboot.flow.flow.Leave;
+import com.codingapi.springboot.flow.matcher.OperatorMatcher;
+import com.codingapi.springboot.flow.record.FlowRecord;
+import com.codingapi.springboot.flow.repository.*;
+import com.codingapi.springboot.flow.service.FlowService;
+import com.codingapi.springboot.flow.user.User;
+import org.junit.jupiter.api.Test;
+import org.springframework.data.domain.PageRequest;
+
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+public class FlowVoidedTest {
+
+ private final UserRepository userRepository = new UserRepository();
+ private final FlowWorkRepository flowWorkRepository = new FlowWorkRepositoryImpl();
+ private final FlowRecordRepositoryImpl flowRecordRepository = new FlowRecordRepositoryImpl();
+ private final FlowBindDataRepositoryImpl flowBindDataRepository = new FlowBindDataRepositoryImpl();
+ private final LeaveRepository leaveRepository = new LeaveRepository();
+ private final FlowBackupRepository flowBackupRepository = new FlowBackupRepositoryImpl();
+ private final FlowProcessRepository flowProcessRepository = new FlowProcessRepositoryImpl(flowBackupRepository, userRepository);
+ private final FlowService flowService = new FlowService(flowWorkRepository, flowRecordRepository, flowBindDataRepository, userRepository, flowProcessRepository, flowBackupRepository);
+
+
+ /**
+ * 流程作废测试,结束的流程作废失败
+ */
+ @Test
+ void voided1() {
+ PageRequest pageRequest = PageRequest.of(0, 1000);
+
+ User user = new User("张飞");
+ userRepository.save(user);
+
+ User dept = new User("刘备");
+ userRepository.save(dept);
+
+ User boss = new User("诸葛亮",true);
+ userRepository.save(boss);
+
+ FlowWork flowWork = FlowWorkBuilder.builder(user)
+ .title("请假流程")
+ .skipIfSameApprover(true)
+ .nodes()
+ .node("开始节点", "start", "default", ApprovalType.UN_SIGN, OperatorMatcher.anyOperatorMatcher())
+ .node("部门领导审批", "dept", "default", ApprovalType.UN_SIGN, OperatorMatcher.specifyOperatorMatcher(dept.getUserId()))
+ .node("总经理审批", "manager", "default", ApprovalType.UN_SIGN, OperatorMatcher.specifyOperatorMatcher(dept.getUserId()))
+ .node("结束节点", "over", "default", ApprovalType.UN_SIGN, OperatorMatcher.anyOperatorMatcher())
+ .relations()
+ .relation("部门领导审批", "start", "dept")
+ .relation("总经理审批", "dept", "manager")
+ .relation("结束节点", "manager", "over")
+ .build();
+
+ flowWorkRepository.save(flowWork);
+
+ String workCode = flowWork.getCode();
+
+ Leave leave = new Leave("我要出去看看");
+ leaveRepository.save(leave);
+
+ // 创建流程
+ flowService.startFlow(workCode, user, leave, "发起流程");
+
+ // 查看我的待办
+ List userTodos = flowRecordRepository.findTodoByOperatorId(user.getUserId(), pageRequest).getContent();
+ assertEquals(1, userTodos.size());
+
+ // 提交流程
+ FlowRecord userTodo = userTodos.get(0);
+ assertEquals(0, userTodo.getTimeoutTime());
+
+ flowService.submitFlow(userTodo.getId(), user, leave, Opinion.pass("同意"));
+
+ // 查看刘备经理的待办
+ List deptTodos = flowRecordRepository.findTodoByOperatorId(dept.getUserId(), pageRequest).getContent();
+ assertEquals(1, deptTodos.size());
+
+ // 提交委托dept部门经理的审批
+ FlowRecord deptTodo = deptTodos.get(0);
+ flowService.submitFlow(deptTodo.getId(), dept, leave, Opinion.pass("同意"));
+
+ assertThrows(IllegalArgumentException.class,()->{
+ // 作废流程
+ flowService.voided(deptTodo.getProcessId(),boss);
+ });
+
+ // 查看所有流程
+ List records = flowRecordRepository.findAll(pageRequest).getContent();
+ assertEquals(3, records.size());
+
+ userTodos = flowRecordRepository.findTodoByOperatorId(user.getUserId(), pageRequest).getContent();
+ assertEquals(0, userTodos.size());
+
+ records = flowRecordRepository.findAll(pageRequest).getContent();
+ assertEquals(3, records.size());
+ // 查看所有流程是否都已经结束
+ assertTrue(records.stream().allMatch(FlowRecord::isFinish));
+
+ List snapshots = flowBindDataRepository.findAll();
+ assertEquals(4, snapshots.size());
+
+ }
+
+
+ /**
+ * 流程作废测试,在结束节点前作废流程
+ */
+ @Test
+ void voided2() {
+ PageRequest pageRequest = PageRequest.of(0, 1000);
+
+ User user = new User("张飞");
+ userRepository.save(user);
+
+ User dept = new User("刘备");
+ userRepository.save(dept);
+
+ User boss = new User("诸葛亮",true);
+ userRepository.save(boss);
+
+ FlowWork flowWork = FlowWorkBuilder.builder(user)
+ .title("请假流程")
+ .skipIfSameApprover(true)
+ .nodes()
+ .node("开始节点", "start", "default", ApprovalType.UN_SIGN, OperatorMatcher.anyOperatorMatcher())
+ .node("部门领导审批", "dept", "default", ApprovalType.UN_SIGN, OperatorMatcher.specifyOperatorMatcher(dept.getUserId()))
+ .node("总经理审批", "manager", "default", ApprovalType.UN_SIGN, OperatorMatcher.specifyOperatorMatcher(dept.getUserId()))
+ .node("结束节点", "over", "default", ApprovalType.UN_SIGN, OperatorMatcher.anyOperatorMatcher())
+ .relations()
+ .relation("部门领导审批", "start", "dept")
+ .relation("总经理审批", "dept", "manager")
+ .relation("结束节点", "manager", "over")
+ .build();
+
+ flowWorkRepository.save(flowWork);
+
+ String workCode = flowWork.getCode();
+
+ Leave leave = new Leave("我要出去看看");
+ leaveRepository.save(leave);
+
+ // 创建流程
+ flowService.startFlow(workCode, user, leave, "发起流程");
+
+ // 查看我的待办
+ List userTodos = flowRecordRepository.findTodoByOperatorId(user.getUserId(), pageRequest).getContent();
+ assertEquals(1, userTodos.size());
+
+ // 提交流程
+ FlowRecord userTodo = userTodos.get(0);
+ assertEquals(0, userTodo.getTimeoutTime());
+
+ flowService.submitFlow(userTodo.getId(), user, leave, Opinion.pass("同意"));
+
+ // 查看刘备经理的待办
+ List deptTodos = flowRecordRepository.findTodoByOperatorId(dept.getUserId(), pageRequest).getContent();
+ assertEquals(1, deptTodos.size());
+
+ // 提交委托dept部门经理的审批
+ FlowRecord deptTodo = deptTodos.get(0);
+ // 流程作废
+ flowService.voided(deptTodo.getProcessId(),boss);
+
+ // 查看所有流程
+ List records = flowRecordRepository.findAll(pageRequest).getContent();
+ assertEquals(0, records.size());
+
+ userTodos = flowRecordRepository.findTodoByOperatorId(user.getUserId(), pageRequest).getContent();
+ assertEquals(0, userTodos.size());
+
+ records = flowRecordRepository.findAll(pageRequest).getContent();
+ assertEquals(0, records.size());
+ // 查看所有流程是否都已经结束
+ assertTrue(records.stream().allMatch(FlowRecord::isDelete));
+
+ List snapshots = flowBindDataRepository.findAll();
+ assertEquals(2, snapshots.size());
+
+ }
+}
From ff6620f98a2b3b0cb97987c1f45a70715f06d1a8 Mon Sep 17 00:00:00 2001
From: lorne <1991wangliang@gmail.com>
Date: Fri, 4 Jul 2025 15:40:22 +0800
Subject: [PATCH 4/4] fix #123
---
admin-ui/package.json | 6 ++---
admin-ui/src/api/flow.ts | 8 +++++++
admin-ui/src/components/flow/register.tsx | 16 +++++++++++++
.../example/app/cmd/meta/pojo/FlowCmd.java | 23 +++++++++++++++++++
.../cmd/meta/service/FlowRecordRouter.java | 10 ++++++++
.../api/meta/FlowRecordCmdController.java | 13 +++++++++++
mobile-ui/package.json | 6 ++---
mobile-ui/src/api/flow.ts | 10 ++++++++
mobile-ui/src/components/flow/register.tsx | 16 +++++++++++++
9 files changed, 102 insertions(+), 6 deletions(-)
diff --git a/admin-ui/package.json b/admin-ui/package.json
index cf375011..28838ebe 100644
--- a/admin-ui/package.json
+++ b/admin-ui/package.json
@@ -6,9 +6,9 @@
"@ant-design/icons": "^5.4.0",
"@ant-design/pro-components": "^2.8.7",
"@babel/standalone": "^7.25.6",
- "@codingapi/flow-pc": "^0.0.41",
- "@codingapi/form-pc": "^0.0.41",
- "@codingapi/ui-framework": "^0.0.41",
+ "@codingapi/flow-pc": "^0.0.42",
+ "@codingapi/form-pc": "^0.0.42",
+ "@codingapi/ui-framework": "^0.0.42",
"@dnd-kit/core": "^6.2.0",
"@dnd-kit/sortable": "^9.0.0",
"@handsontable/react-wrapper": "^15.0.0",
diff --git a/admin-ui/src/api/flow.ts b/admin-ui/src/api/flow.ts
index 8f7b34c7..6dd53846 100644
--- a/admin-ui/src/api/flow.ts
+++ b/admin-ui/src/api/flow.ts
@@ -87,6 +87,14 @@ export async function urge(body:any) {
return httpClient.post('/api/cmd/flowRecord/urge', body);
}
+export async function back(body:any) {
+ return httpClient.post('/api/cmd/flowRecord/back', body);
+}
+
+export async function voided(body:any) {
+ return httpClient.post('/api/cmd/flowRecord/voided', body);
+}
+
// 待办中心控制
diff --git a/admin-ui/src/components/flow/register.tsx b/admin-ui/src/components/flow/register.tsx
index a6afa6ca..bac76610 100644
--- a/admin-ui/src/components/flow/register.tsx
+++ b/admin-ui/src/components/flow/register.tsx
@@ -60,6 +60,22 @@ class DefaultFlowApiImpl implements FlowApi{
return flowApi.detail(null,workCode);
}
+ backFlow(body: any): Promise {
+ return flowApi.back(body);
+ }
+
+ voidedFlow(body: any): Promise {
+ return flowApi.voided(body);
+ }
+
+ getFlowStep(recordId?: number, workCode?: string): Promise {
+ const body = {
+ recordId,
+ workCode
+ }
+ return flowApi.getFlowStep(body);
+ }
+
}
FlowApiContent.getInstance().registerFlowApi(new DefaultFlowApiImpl());
diff --git a/example/example-app/example-app-cmd-meta/src/main/java/com/codingapi/example/app/cmd/meta/pojo/FlowCmd.java b/example/example-app/example-app-cmd-meta/src/main/java/com/codingapi/example/app/cmd/meta/pojo/FlowCmd.java
index 8ea1fcef..9c633c9c 100644
--- a/example/example-app/example-app-cmd-meta/src/main/java/com/codingapi/example/app/cmd/meta/pojo/FlowCmd.java
+++ b/example/example-app/example-app-cmd-meta/src/main/java/com/codingapi/example/app/cmd/meta/pojo/FlowCmd.java
@@ -213,6 +213,29 @@ public String getUserName() {
}
+ @Setter
+ @Getter
+ public static class BackFlow {
+
+ private String processId;
+ private String backNodeCode;
+
+ public String getUserName() {
+ return TokenContext.current().getUsername();
+ }
+ }
+
+ @Setter
+ @Getter
+ public static class VoidedFlow {
+
+ private String processId;
+
+ public String getUserName() {
+ return TokenContext.current().getUsername();
+ }
+ }
+
@Setter
@Getter
public static class PostponedFlow {
diff --git a/example/example-app/example-app-cmd-meta/src/main/java/com/codingapi/example/app/cmd/meta/service/FlowRecordRouter.java b/example/example-app/example-app-cmd-meta/src/main/java/com/codingapi/example/app/cmd/meta/service/FlowRecordRouter.java
index 512a7ad1..ef96d766 100644
--- a/example/example-app/example-app-cmd-meta/src/main/java/com/codingapi/example/app/cmd/meta/service/FlowRecordRouter.java
+++ b/example/example-app/example-app-cmd-meta/src/main/java/com/codingapi/example/app/cmd/meta/service/FlowRecordRouter.java
@@ -93,4 +93,14 @@ public void remove(FlowCmd.RemoveFlow request) {
IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName());
flowService.remove(request.getRecordId(), current);
}
+
+ public void back(FlowCmd.BackFlow request) {
+ IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName());
+ flowService.back(request.getProcessId(),request.getBackNodeCode(), current);
+ }
+
+ public void voided(FlowCmd.VoidedFlow request) {
+ IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName());
+ flowService.voided(request.getProcessId(), current);
+ }
}
diff --git a/example/example-interface/src/main/java/com/codingapi/example/api/meta/FlowRecordCmdController.java b/example/example-interface/src/main/java/com/codingapi/example/api/meta/FlowRecordCmdController.java
index ad992359..3a0ab7fe 100644
--- a/example/example-interface/src/main/java/com/codingapi/example/api/meta/FlowRecordCmdController.java
+++ b/example/example-interface/src/main/java/com/codingapi/example/api/meta/FlowRecordCmdController.java
@@ -84,4 +84,17 @@ public Response remove(@RequestBody FlowCmd.RemoveFlow request) {
return Response.buildSuccess();
}
+
+ @PostMapping("/back")
+ public Response back(@RequestBody FlowCmd.BackFlow request) {
+ flowRecordRouter.back(request);
+ return Response.buildSuccess();
+ }
+
+
+ @PostMapping("/voided")
+ public Response voided(@RequestBody FlowCmd.VoidedFlow request) {
+ flowRecordRouter.voided(request);
+ return Response.buildSuccess();
+ }
}
diff --git a/mobile-ui/package.json b/mobile-ui/package.json
index 92710816..6f3d9e98 100644
--- a/mobile-ui/package.json
+++ b/mobile-ui/package.json
@@ -4,9 +4,9 @@
"private": true,
"dependencies": {
"@babel/standalone": "^7.25.6",
- "@codingapi/flow-mobile": "^0.0.41",
- "@codingapi/form-mobile": "^0.0.41",
- "@codingapi/ui-framework": "^0.0.41",
+ "@codingapi/flow-mobile": "^0.0.42",
+ "@codingapi/form-mobile": "^0.0.42",
+ "@codingapi/ui-framework": "^0.0.42",
"@logicflow/core": "^2.0.10",
"@logicflow/extension": "^2.0.14",
"@reduxjs/toolkit": "^2.2.7",
diff --git a/mobile-ui/src/api/flow.ts b/mobile-ui/src/api/flow.ts
index bf84351c..ed727453 100644
--- a/mobile-ui/src/api/flow.ts
+++ b/mobile-ui/src/api/flow.ts
@@ -94,6 +94,16 @@ export async function urge(body:any) {
}
+export async function back(body:any) {
+ return httpClient.post('/api/cmd/flowRecord/back', body);
+}
+
+export async function voided(body:any) {
+ return httpClient.post('/api/cmd/flowRecord/voided', body);
+}
+
+
+
// 待办中心控制
export async function findAllByOperatorId( lastId?: string,
diff --git a/mobile-ui/src/components/flow/register.tsx b/mobile-ui/src/components/flow/register.tsx
index 88ec70cb..9531fef8 100644
--- a/mobile-ui/src/components/flow/register.tsx
+++ b/mobile-ui/src/components/flow/register.tsx
@@ -61,6 +61,22 @@ class DefaultFlowApiImpl implements FlowApi{
return flowApi.detail(null,workCode);
}
+ backFlow(body: any): Promise {
+ return flowApi.back(body);
+ }
+
+ voidedFlow(body: any): Promise {
+ return flowApi.voided(body);
+ }
+
+ getFlowStep(recordId?: number, workCode?: string): Promise {
+ const body = {
+ recordId,
+ workCode
+ }
+ return flowApi.getFlowStep(body);
+ }
+
}
FlowApiContent.getInstance().registerFlowApi(new DefaultFlowApiImpl());