소스 검색

谁可以发起该流程

caixiaofeng 6 달 전
부모
커밋
5684db7c39

+ 16 - 0
flow-workflow/flow-workflow-entity/src/main/java/com/flow/entity/FlowModel.java

@@ -20,6 +20,7 @@ import org.flowable.common.engine.api.delegate.event.FlowableEventType;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.stream.Collectors;
 
 @EqualsAndHashCode(callSuper = true)
 @Data
@@ -43,6 +44,8 @@ public class FlowModel extends BaseEntity {
     @TableField(typeHandler = JacksonTypeHandler.class)
     private List<String> admin;
     @TableField(typeHandler = JacksonTypeHandler.class)
+    private List<Principal> starters;
+    @TableField(typeHandler = JacksonTypeHandler.class)
     private Settings settings;
 
     public BpmnModel toBpmnModel() {
@@ -77,6 +80,19 @@ public class FlowModel extends BaseEntity {
             adminElement.setElementText(String.join(",", this.getAdmin()));
         }
         process.addExtensionElement(adminElement);
+        // 设置谁可以发起流程
+        if (CollectionUtils.isNotEmpty(this.starters)) {
+            List<String> candidateStarterUsers = this.starters.stream()
+                    .filter(principal -> principal.getType() == PrincipalType.USER)
+                    .map(Principal::getId)
+                    .collect(Collectors.toList());
+            process.setCandidateStarterUsers(candidateStarterUsers);
+            List<String> candidateStarterRoles = this.starters.stream()
+                    .filter(principal -> principal.getType() == PrincipalType.ROLE)
+                    .map(Principal::getId)
+                    .collect(Collectors.toList());
+            process.setCandidateStarterGroups(candidateStarterRoles);
+        }
         // 设置流程
         bpmnModel.addProcess(process);
         // 自动布局

+ 9 - 0
flow-workflow/flow-workflow-entity/src/main/java/com/flow/entity/Principal.java

@@ -0,0 +1,9 @@
+package com.flow.entity;
+
+import lombok.Data;
+
+@Data
+public class Principal {
+    private PrincipalType type;
+    private String id;
+}

+ 5 - 0
flow-workflow/flow-workflow-entity/src/main/java/com/flow/entity/PrincipalType.java

@@ -0,0 +1,5 @@
+package com.flow.entity;
+
+public enum PrincipalType {
+    USER, ROLE, DEPARTMENT
+}