diff --git a/example/example-app/example-app-cmd-domain/pom.xml b/example/example-app/example-app-cmd-domain/pom.xml index 07bb2e9a..3147c576 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.6 + 3.4.7 ../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 ecc81780..33dabf74 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.6 + 3.4.7 ../pom.xml 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 89a1970d..8ea1fcef 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 @@ -32,6 +32,7 @@ public String getUserName() { @Getter public static class FlowStep{ private String workCode; + private long recordId; private JSONObject formData; @SneakyThrows @@ -43,6 +44,10 @@ public IBindData getBindData() { public String getUserName() { return TokenContext.current().getUsername(); } + + public boolean hasRecordId() { + return recordId > 0; + } } @Setter 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 9f9e1bff..512a7ad1 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 @@ -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); + } } diff --git a/example/example-app/example-app-query/pom.xml b/example/example-app/example-app-query/pom.xml index c761f347..cc3cee5c 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.6 + 3.4.7 ../pom.xml diff --git a/example/example-app/pom.xml b/example/example-app/pom.xml index 1c353ebf..83502a5c 100644 --- a/example/example-app/pom.xml +++ b/example/example-app/pom.xml @@ -6,7 +6,7 @@ com.codingapi.springboot springboot-example - 3.4.6 + 3.4.7 ../pom.xml pom diff --git a/example/example-domain/example-domain-leave/pom.xml b/example/example-domain/example-domain-leave/pom.xml index 9214092a..4121e107 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.6 + 3.4.7 ../pom.xml diff --git a/example/example-domain/example-domain-user/pom.xml b/example/example-domain/example-domain-user/pom.xml index 894b1260..22601c0b 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.6 + 3.4.7 ../pom.xml diff --git a/example/example-domain/pom.xml b/example/example-domain/pom.xml index f8084d74..9c373382 100644 --- a/example/example-domain/pom.xml +++ b/example/example-domain/pom.xml @@ -5,7 +5,7 @@ com.codingapi.springboot springboot-example - 3.4.6 + 3.4.7 ../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 6f0f6a09..4587e594 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.6 + 3.4.7 ../pom.xml diff --git a/example/example-infra/example-infra-jpa/pom.xml b/example/example-infra/example-infra-jpa/pom.xml index a214d9e0..226932e5 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.6 + 3.4.7 ../pom.xml diff --git a/example/example-infra/example-infra-security/pom.xml b/example/example-infra/example-infra-security/pom.xml index ff42e8d3..847628dc 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.6 + 3.4.7 ../pom.xml diff --git a/example/example-infra/pom.xml b/example/example-infra/pom.xml index a5d936ae..7e37b278 100644 --- a/example/example-infra/pom.xml +++ b/example/example-infra/pom.xml @@ -6,7 +6,7 @@ com.codingapi.springboot springboot-example - 3.4.6 + 3.4.7 ../pom.xml pom diff --git a/example/example-interface/pom.xml b/example/example-interface/pom.xml index 6de39b7a..2312a697 100644 --- a/example/example-interface/pom.xml +++ b/example/example-interface/pom.xml @@ -6,7 +6,7 @@ com.codingapi.springboot springboot-example - 3.4.6 + 3.4.7 example-interface diff --git a/example/example-server/pom.xml b/example/example-server/pom.xml index 385238a5..7089921e 100644 --- a/example/example-server/pom.xml +++ b/example/example-server/pom.xml @@ -5,7 +5,7 @@ springboot-example com.codingapi.springboot - 3.4.6 + 3.4.7 4.0.0 diff --git a/example/pom.xml b/example/pom.xml index eb885902..7d4e3f4e 100644 --- a/example/pom.xml +++ b/example/pom.xml @@ -19,7 +19,7 @@ springboot-example - 3.4.6 + 3.4.7 springboot-example springboot-example project for Spring Boot diff --git a/pom.xml b/pom.xml index 7c85d831..ee3df504 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ com.codingapi.springboot springboot-parent - 3.4.6 + 3.4.7 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 a073f702..08199fa8 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.6 + 3.4.7 springboot-starter-data-authorization diff --git a/springboot-starter-data-fast/pom.xml b/springboot-starter-data-fast/pom.xml index aff99c8e..c49242de 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.6 + 3.4.7 4.0.0 diff --git a/springboot-starter-flow/pom.xml b/springboot-starter-flow/pom.xml index 6df442b8..6701f8d9 100644 --- a/springboot-starter-flow/pom.xml +++ b/springboot-starter-flow/pom.xml @@ -6,7 +6,7 @@ springboot-parent com.codingapi.springboot - 3.4.6 + 3.4.7 springboot-starter-flow diff --git a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/pojo/FlowStepResult.java b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/pojo/FlowStepResult.java index 36d49c36..f2fec457 100644 --- a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/pojo/FlowStepResult.java +++ b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/pojo/FlowStepResult.java @@ -17,32 +17,34 @@ public FlowStepResult() { this.flowNodes = new ArrayList<>(); } - public void addFlowNode(FlowNode flowNode,List operators) { - this.flowNodes.add(new FlowStepNode(flowNode.getId(), flowNode.getCode(),flowNode.getName(),flowNode.getType(),operators)); + public void addFlowNode(FlowNode flowNode,boolean done,List 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 operators; - public FlowStepNode(String id, String code, String name, NodeType type,List operators) { + public FlowStepNode(String id, String code, String name, NodeType type,boolean done,List operators) { this.id = id; this.code = code; this.name = name; this.type = type; this.operators = operators; + this.done = done; } } } 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 55e89657..450a1c76 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 @@ -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(); + } + /** * 获取流程执行节点 * @@ -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(); } diff --git a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/impl/FlowStepService.java b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/impl/FlowStepService.java index cf65a8cc..7e0e62f7 100644 --- a/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/impl/FlowStepService.java +++ b/springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/service/impl/FlowStepService.java @@ -12,12 +12,16 @@ 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 flowRecords; private final IFlowOperator currentOperator; private final IBindData bindData; @@ -25,35 +29,59 @@ public class FlowStepService { 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 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 historyRecords = new ArrayList<>(); + String processId = "flow_" + RandomGenerator.generateUUID(); FlowOperatorRepository flowOperatorRepository = flowServiceRepositoryHolder.getFlowOperatorRepository(); FlowRecordRepository flowRecordRepository = flowServiceRepositoryHolder.getFlowRecordRepository(); - + List historyRecords = new ArrayList<>(); BindDataSnapshot snapshot = new BindDataSnapshot(bindData); flowNodeService = new FlowNodeService(flowOperatorRepository, flowRecordRepository, @@ -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; diff --git a/springboot-starter-flow/src/test/java/com/codingapi/springboot/flow/test/CirculateTest.java b/springboot-starter-flow/src/test/java/com/codingapi/springboot/flow/test/CirculateTest.java index 2e2b1880..de20dd3e 100644 --- a/springboot-starter-flow/src/test/java/com/codingapi/springboot/flow/test/CirculateTest.java +++ b/springboot-starter-flow/src/test/java/com/codingapi/springboot/flow/test/CirculateTest.java @@ -30,12 +30,12 @@ public class CirculateTest { 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); + private final FlowProcessRepository flowProcessRepository = new FlowProcessRepositoryImpl(flowBackupRepository, userRepository); + private final FlowService flowService = new FlowService(flowWorkRepository, flowRecordRepository, flowBindDataRepository, userRepository, flowProcessRepository, flowBackupRepository); @Test - void circulate(){ + void circulate() { PageRequest pageRequest = PageRequest.of(0, 1000); User lorne = new User("lorne"); @@ -80,7 +80,7 @@ void circulate(){ // 创建流程 flowService.startFlow(workCode, user, leave, "发起流程"); - FlowStepResult result = flowService.getFlowStep(workCode, leave, user); + FlowStepResult result = flowService.getFlowStep( workCode, leave, user); result.print(); @@ -92,7 +92,7 @@ void circulate(){ FlowRecord userTodo = userTodos.get(0); // 保存流程 leave.setTitle("我要出去看看~~"); - flowService.save(userTodo.getId(), user, leave,"暂存"); + flowService.save(userTodo.getId(), user, leave, "暂存"); // 查看流程详情 FlowDetail flowDetail = flowService.detail(userTodo.getId(), user); @@ -118,6 +118,9 @@ void circulate(){ FlowRecord bossTodo = bossTodos.get(0); flowService.submitFlow(bossTodo.getId(), boss, leave, Opinion.pass("同意")); + result = flowService.getFlowStep(bossTodo.getId(), leave, boss); + result.print(); + // 查看所有流程 List records = flowRecordRepository.findAll(pageRequest).getContent(); assertEquals(6, records.size()); diff --git a/springboot-starter-flow/src/test/java/com/codingapi/springboot/flow/test/FlowTest.java b/springboot-starter-flow/src/test/java/com/codingapi/springboot/flow/test/FlowTest.java index 2376123b..6860e06b 100644 --- a/springboot-starter-flow/src/test/java/com/codingapi/springboot/flow/test/FlowTest.java +++ b/springboot-starter-flow/src/test/java/com/codingapi/springboot/flow/test/FlowTest.java @@ -118,6 +118,9 @@ void entrustTest() { FlowRecord bossTodo = bossTodos.get(0); flowService.submitFlow(bossTodo.getId(), boss, leave, Opinion.pass("同意")); + result = flowService.getFlowStep(bossTodo.getId(), leave, user); + result.print(); + // 查看所有流程 List records = flowRecordRepository.findAll(pageRequest).getContent(); assertEquals(3, records.size()); diff --git a/springboot-starter-security/pom.xml b/springboot-starter-security/pom.xml index 968ffe96..ebb6838a 100644 --- a/springboot-starter-security/pom.xml +++ b/springboot-starter-security/pom.xml @@ -6,7 +6,7 @@ springboot-parent com.codingapi.springboot - 3.4.6 + 3.4.7 springboot-starter-security diff --git a/springboot-starter/pom.xml b/springboot-starter/pom.xml index f19f7c20..28fb3db1 100644 --- a/springboot-starter/pom.xml +++ b/springboot-starter/pom.xml @@ -5,7 +5,7 @@ com.codingapi.springboot springboot-parent - 3.4.6 + 3.4.7 springboot-starter diff --git a/springboot-starter/src/main/resources/banner.txt b/springboot-starter/src/main/resources/banner.txt index d95633e3..0a166f07 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.6 +CodingApi SpringBoot-Starter 3.4.7 springboot version (${spring-boot.version}) ------------------------------------------------------