Skip to content

fix #119 #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 30, 2025
Merged
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
2 changes: 1 addition & 1 deletion example/example-app/example-app-cmd-domain/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>example-app</artifactId>
<version>3.4.6</version>
<version>3.4.7</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion example/example-app/example-app-cmd-meta/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>example-app</artifactId>
<version>3.4.6</version>
<version>3.4.7</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public String getUserName() {
@Getter
public static class FlowStep{
private String workCode;
private long recordId;
private JSONObject formData;

@SneakyThrows
Expand All @@ -43,6 +44,10 @@ public IBindData getBindData() {
public String getUserName() {
return TokenContext.current().getUsername();
}

public boolean hasRecordId() {
return recordId > 0;
}
}

@Setter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ public FlowResult startFlow(FlowCmd.StartFlow request) {

public FlowStepResult getFlowStep(FlowCmd.FlowStep request) {
IFlowOperator current = flowUserRepository.getUserByUsername(request.getUserName());
return flowService.getFlowStep(request.getWorkCode(), request.getBindData(), current);
if(request.hasRecordId()) {
return flowService.getFlowStep(request.getRecordId(), request.getBindData(), current);
}else {
return flowService.getFlowStep(request.getWorkCode(), request.getBindData(), current);
}
}


Expand Down
2 changes: 1 addition & 1 deletion example/example-app/example-app-query/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>example-app</artifactId>
<version>3.4.6</version>
<version>3.4.7</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion example/example-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-example</artifactId>
<version>3.4.6</version>
<version>3.4.7</version>
<relativePath>../pom.xml</relativePath>
</parent>
<packaging>pom</packaging>
Expand Down
2 changes: 1 addition & 1 deletion example/example-domain/example-domain-leave/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>example-domain</artifactId>
<version>3.4.6</version>
<version>3.4.7</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion example/example-domain/example-domain-user/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>example-domain</artifactId>
<version>3.4.6</version>
<version>3.4.7</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion example/example-domain/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-example</artifactId>
<version>3.4.6</version>
<version>3.4.7</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion example/example-infra/example-infra-flow/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>example-infra</artifactId>
<version>3.4.6</version>
<version>3.4.7</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion example/example-infra/example-infra-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>example-infra</artifactId>
<version>3.4.6</version>
<version>3.4.7</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion example/example-infra/example-infra-security/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>example-infra</artifactId>
<version>3.4.6</version>
<version>3.4.7</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion example/example-infra/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-example</artifactId>
<version>3.4.6</version>
<version>3.4.7</version>
<relativePath>../pom.xml</relativePath>
</parent>
<packaging>pom</packaging>
Expand Down
2 changes: 1 addition & 1 deletion example/example-interface/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-example</artifactId>
<version>3.4.6</version>
<version>3.4.7</version>
</parent>

<artifactId>example-interface</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion example/example-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>springboot-example</artifactId>
<groupId>com.codingapi.springboot</groupId>
<version>3.4.6</version>
<version>3.4.7</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</parent>

<artifactId>springboot-example</artifactId>
<version>3.4.6</version>
<version>3.4.7</version>

<name>springboot-example</name>
<description>springboot-example project for Spring Boot</description>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-parent</artifactId>
<version>3.4.6</version>
<version>3.4.7</version>

<url>https://github.com/codingapi/springboot-framewrok</url>
<name>springboot-parent</name>
Expand Down
2 changes: 1 addition & 1 deletion springboot-starter-data-authorization/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.codingapi.springboot</groupId>
<artifactId>springboot-parent</artifactId>
<version>3.4.6</version>
<version>3.4.7</version>
</parent>

<artifactId>springboot-starter-data-authorization</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion springboot-starter-data-fast/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>springboot-parent</artifactId>
<groupId>com.codingapi.springboot</groupId>
<version>3.4.6</version>
<version>3.4.7</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion springboot-starter-flow/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>springboot-parent</artifactId>
<groupId>com.codingapi.springboot</groupId>
<version>3.4.6</version>
<version>3.4.7</version>
</parent>

<name>springboot-starter-flow</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,34 @@ public FlowStepResult() {
this.flowNodes = new ArrayList<>();
}

public void addFlowNode(FlowNode flowNode,List<? extends IFlowOperator> operators) {
this.flowNodes.add(new FlowStepNode(flowNode.getId(), flowNode.getCode(),flowNode.getName(),flowNode.getType(),operators));
public void addFlowNode(FlowNode flowNode,boolean done,List<? extends IFlowOperator> operators) {
this.flowNodes.add(new FlowStepNode(flowNode.getId(), flowNode.getCode(),flowNode.getName(),flowNode.getType(),done,operators));
}


public void print(){
System.out.println("FlowStepResult:==========================>");
for (FlowStepNode flowNode : flowNodes) {
System.out.println("flowNode = " + flowNode.getName());
System.out.println("flowNode = " + flowNode.getName()+",done = " + flowNode.isDone() + ",type = " + flowNode.getType()+" operators = " + flowNode.getOperators().stream().map(IFlowOperator::getUserId).toList());
}
}


@Getter
public static class FlowStepNode{
private final String id;
private final String code;
private final String name;
private final NodeType type;
private final boolean done;
private final List<? extends IFlowOperator> operators;

public FlowStepNode(String id, String code, String name, NodeType type,List<? extends IFlowOperator> operators) {
public FlowStepNode(String id, String code, String name, NodeType type,boolean done,List<? extends IFlowOperator> operators) {
this.id = id;
this.code = code;
this.name = name;
this.type = type;
this.operators = operators;
this.done = done;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,18 @@ public FlowSubmitResult trySubmitFlow(long recordId, IFlowOperator currentOperat
return flowTrySubmitService.trySubmitFlow(recordId);
}

/**
* 获取流程执行节点
*
* @param recordId
* @param currentOperator
* @return
*/
public FlowStepResult getFlowStep(long recordId, IBindData bindData, IFlowOperator currentOperator) {
FlowStepService flowStepService = new FlowStepService(recordId,null, currentOperator, bindData, flowServiceRepositoryHolder);
return flowStepService.getFlowStep();
}

/**
* 获取流程执行节点
*
Expand All @@ -196,7 +208,7 @@ public FlowSubmitResult trySubmitFlow(long recordId, IFlowOperator currentOperat
* @return
*/
public FlowStepResult getFlowStep(String workCode, IBindData bindData, IFlowOperator currentOperator) {
FlowStepService flowStepService = new FlowStepService(workCode, currentOperator, bindData, flowServiceRepositoryHolder);
FlowStepService flowStepService = new FlowStepService(0,workCode, currentOperator, bindData, flowServiceRepositoryHolder);
return flowStepService.getFlowStep();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,76 @@
import com.codingapi.springboot.flow.service.FlowNodeService;
import com.codingapi.springboot.flow.service.FlowServiceRepositoryHolder;
import com.codingapi.springboot.flow.user.IFlowOperator;
import com.codingapi.springboot.framework.utils.RandomGenerator;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class FlowStepService {
private final FlowWork flowWork;
private final long recordId;
private final List<FlowRecord> flowRecords;

private final IFlowOperator currentOperator;
private final IBindData bindData;
private final FlowServiceRepositoryHolder flowServiceRepositoryHolder;

private FlowNodeService flowNodeService;
private FlowNode flowNode;
private FlowRecord currentFlowRecord;

public FlowStepService(String workCode, IFlowOperator currentOperator, IBindData bindData, FlowServiceRepositoryHolder flowServiceRepositoryHolder) {
public FlowStepService(long recordId,String workCode, IFlowOperator currentOperator, IBindData bindData, FlowServiceRepositoryHolder flowServiceRepositoryHolder) {
this.recordId = recordId;
this.currentOperator = currentOperator;
this.bindData = bindData;
this.flowServiceRepositoryHolder = flowServiceRepositoryHolder;
this.flowWork = flowServiceRepositoryHolder.getFlowWorkRepository().getFlowWorkByCode(workCode);
if(this.recordId>0) {
this.currentFlowRecord = flowServiceRepositoryHolder.getFlowRecordRepository().getFlowRecordById(recordId);
this.flowRecords = flowServiceRepositoryHolder.getFlowRecordRepository().findFlowRecordByProcessId(currentFlowRecord.getProcessId()).stream().sorted(Comparator.comparingLong(FlowRecord::getId)).toList();
this.flowWork = flowServiceRepositoryHolder.getFlowWorkRepository().getFlowWorkByCode(currentFlowRecord.getWorkCode());
}else {
this.currentFlowRecord = null;
this.flowRecords = new ArrayList<>();
this.flowWork = flowServiceRepositoryHolder.getFlowWorkRepository().getFlowWorkByCode(workCode);
}
}


public FlowStepResult getFlowStep() {
FlowStepResult flowStepResult = new FlowStepResult();
// 获取开始节点
FlowNode start = flowWork.getStartNode();
if (start == null) {
throw new IllegalArgumentException("start node not found");
}

this.flowNode = start;
// 设置开始流程的上一个流程id
long preId = 0;
if(currentFlowRecord==null) {
// 获取开始节点
FlowNode start = flowWork.getStartNode();
if (start == null) {
throw new IllegalArgumentException("start node not found");
}
preId = 0;
this.flowNode = start;
}else {
for(FlowRecord flowRecord : flowRecords) {
FlowNode flowNode = this.flowWork.getNodeByCode(flowRecord.getNodeCode());
List<IFlowOperator> operators = new ArrayList<>();
if(flowRecord.getCurrentOperator()!=null) {
operators.add(flowRecord.getCurrentOperator());
}
boolean isDone =flowRecord.isDone() || flowRecord.getOpinion().isCirculate();
flowStepResult.addFlowNode(flowNode,isDone, operators);
}
FlowRecord lastRecord = this.flowRecords.get(this.flowRecords.size()-1);
this.flowNode = this.flowWork.getNodeByCode(lastRecord.getNodeCode());
preId = lastRecord.getId();
}

// 创建流程id
String processId = "flow_" + System.currentTimeMillis();

List<FlowRecord> historyRecords = new ArrayList<>();
String processId = "flow_" + RandomGenerator.generateUUID();

FlowOperatorRepository flowOperatorRepository = flowServiceRepositoryHolder.getFlowOperatorRepository();
FlowRecordRepository flowRecordRepository = flowServiceRepositoryHolder.getFlowRecordRepository();

List<FlowRecord> historyRecords = new ArrayList<>();
BindDataSnapshot snapshot = new BindDataSnapshot(bindData);
flowNodeService = new FlowNodeService(flowOperatorRepository,
flowRecordRepository,
Expand All @@ -67,16 +95,19 @@ public FlowStepResult getFlowStep() {
processId,
preId);

flowNodeService.setNextNode(start);
flowNodeService.setNextNode(this.flowNode);

this.flowNode = start;
flowStepResult.addFlowNode(this.flowNode, this.flowNodeService.loadNextNodeOperators());
if(currentFlowRecord==null) {
flowStepResult.addFlowNode(this.flowNode, false, this.flowNodeService.loadNextNodeOperators());
}

do {
flowNodeService.loadNextPassNode(this.flowNode);
this.flowNode = flowNodeService.getNextNode();

flowStepResult.addFlowNode(this.flowNode, this.flowNodeService.loadNextNodeOperators());
boolean isFinish = currentFlowRecord != null && currentFlowRecord.isFinish();

flowStepResult.addFlowNode(this.flowNode,isFinish, this.flowNodeService.loadNextNodeOperators());
} while (!flowNode.isOverNode());

return flowStepResult;
Expand Down
Loading