11package com .codingapi .flow .service ;
22
3+ import com .codingapi .flow .exception .FlowExecutionException ;
34import com .codingapi .flow .repository .WorkflowRepository ;
45import com .codingapi .flow .repository .WorkflowRuntimeRepository ;
56import com .codingapi .flow .repository .WorkflowVersionRepository ;
@@ -29,7 +30,7 @@ public void saveWorkflowVersion(WorkflowVersion currentVersion, boolean creatabl
2930 if (versionList != null ) {
3031
3132 if (!creatable ) {
32- versionList .stream ().filter (WorkflowVersion ::isCurrent ).findFirst ().ifPresent (current ->{
33+ versionList .stream ().filter (WorkflowVersion ::isCurrent ).findFirst ().ifPresent (current -> {
3334 currentVersion .setId (current .getId ());
3435 currentVersion .setVersionName (current .getVersionName ());
3536 });
@@ -57,18 +58,26 @@ public Workflow getWorkflow(String workId) {
5758 return workflowRepository .get (workId );
5859 }
5960
61+ public void deleteVersion (long versionId ) {
62+ WorkflowVersion version = workflowVersionRepository .get (versionId );
63+ if (version != null && version .isCurrent ()) {
64+ throw FlowExecutionException .removeWorkflowError ();
65+ }
66+ workflowVersionRepository .delete (versionId );
67+ }
68+
6069
6170 public void changeVersion (long versionId ) {
6271 WorkflowVersion currentVersion = workflowVersionRepository .get (versionId );
6372 List <WorkflowVersion > versionList = workflowVersionRepository .findVersion (currentVersion .getWorkId ());
6473 if (versionList != null ) {
65- for (WorkflowVersion version : versionList ){
66- if (currentVersion .getId () == version .getId ()){
67- version .enableVersion ();
68- } else {
69- version .disableVersion ();
70- }
71- }
74+ for (WorkflowVersion version : versionList ) {
75+ if (currentVersion .getId () == version .getId ()) {
76+ version .enableVersion ();
77+ } else {
78+ version .disableVersion ();
79+ }
80+ }
7281 }
7382 workflowVersionRepository .saveAll (versionList );
7483 workflowRepository .save (currentVersion .toWorkflow ());
@@ -90,7 +99,7 @@ public void delete(String workId) {
9099
91100 public void saveWorkflow (Workflow workflow ) {
92101 WorkflowVersion workflowVersion = new WorkflowVersion (workflow );
93- this .saveWorkflowVersion (workflowVersion ,false );
102+ this .saveWorkflowVersion (workflowVersion , false );
94103 }
95104
96105 public void saveWorkflowRuntime (WorkflowRuntime workflowRuntime ) {
0 commit comments