Browse Source

流程查询下一节点审核人信息

user5 2 years ago
parent
commit
4d2e93cbfa

+ 9 - 0
jeeplus-plugins/jeeplus-flowable/src/main/java/com/jeeplus/flowable/mapper/FlowMapper.java

@@ -4,8 +4,11 @@
 package com.jeeplus.flowable.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.jeeplus.flowable.model.ActHiIdentitylink;
 import com.jeeplus.flowable.model.Flow;
 
+import java.util.List;
+
 /**
  * 审批Mapper接口
  *
@@ -16,4 +19,10 @@ public interface FlowMapper extends BaseMapper <Flow> {
 
     int updateProcInsIdByBusinessId(Flow act);
 
+    /**
+     * 根据流程id查询流程信息
+     * @param processInstanceId
+     * @return
+     */
+    List<ActHiIdentitylink> getActHiIdentitylinkList(String processInstanceId);
 }

+ 18 - 0
jeeplus-plugins/jeeplus-flowable/src/main/java/com/jeeplus/flowable/mapper/xml/FlowMapper.xml

@@ -11,4 +11,22 @@
 		WHERE id = #{businessId}
 	</update>
 
+	<select id="getActHiIdentitylinkList" resultType="com.jeeplus.flowable.model.ActHiIdentitylink">
+		select
+		  ID_ as "id",
+		  REV_ as "rev",
+		  GROUP_ID_ as "groupId",
+		  TYPE_ as "type",
+		  USER_ID_ as "userId",
+		  TASK_ID_ as "taskId",
+		  PROC_INST_ID_ as "procInstId",
+		  PROC_DEF_ID_ as "procDefId",
+		  SCOPE_ID_ as "scopeId",
+		  SCOPE_TYPE_ as "scopeType",
+		  SCOPE_DEFINITION_ID_ as "scopeDefinitionId"
+		from
+		  act_ru_identitylink
+		where PROC_INST_ID_= #{processInstanceId}
+	</select>
+
 </mapper>

+ 22 - 0
jeeplus-plugins/jeeplus-flowable/src/main/java/com/jeeplus/flowable/model/ActHiIdentitylink.java

@@ -0,0 +1,22 @@
+package com.jeeplus.flowable.model;
+
+import lombok.Data;
+
+/**
+ * @author: 徐滕
+ * @version: 2022-10-27 14:37
+ */
+@Data
+public class ActHiIdentitylink {
+    private String id;
+    private String rev;
+    private String groupId;
+    private String type;
+    private String userId;
+    private String taskId;
+    private String procInstId;
+    private String procDefId;
+    private String scopeId;
+    private String scopeType;
+    private String scopeDefinitionId;
+}

+ 2 - 0
jeeplus-plugins/jeeplus-flowable/src/main/java/com/jeeplus/flowable/model/Flow.java

@@ -68,6 +68,8 @@ public class Flow  {
 
 	private String formUrl;//流程表单地址
 
+	private String processInstanceId;//流程实例id
+
 
 	public Flow() {
 		super();

+ 125 - 2
jeeplus-plugins/jeeplus-flowable/src/main/java/com/jeeplus/flowable/service/FlowTaskService.java

@@ -11,6 +11,7 @@ import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.jeeplus.common.utils.Collections3;
 import com.jeeplus.flowable.constant.FlowableConstant;
+import com.jeeplus.flowable.model.ActHiIdentitylink;
 import com.jeeplus.flowable.vo.*;
 import com.jeeplus.flowable.common.cmd.BackUserTaskCmd;
 import com.jeeplus.flowable.model.Flow;
@@ -24,16 +25,22 @@ import com.jeeplus.sys.utils.StringUtils;
 import com.jeeplus.sys.utils.UserUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.flowable.bpmn.constants.BpmnXMLConstants;
-import org.flowable.bpmn.model.BpmnModel;
-import org.flowable.bpmn.model.FlowNode;
+import org.flowable.bpmn.model.*;
 import org.flowable.bpmn.model.Process;
+import org.flowable.common.engine.impl.de.odysseus.el.ExpressionFactoryImpl;
+import org.flowable.common.engine.impl.de.odysseus.el.util.SimpleContext;
+import org.flowable.common.engine.impl.javax.el.ExpressionFactory;
+import org.flowable.common.engine.impl.javax.el.ValueExpression;
 import org.flowable.editor.language.json.converter.util.CollectionUtils;
 import org.flowable.engine.*;
 import org.flowable.engine.history.HistoricActivityInstance;
 import org.flowable.engine.history.HistoricProcessInstance;
 import org.flowable.engine.history.HistoricProcessInstanceQuery;
+import org.flowable.engine.impl.persistence.entity.ExecutionEntityImpl;
+import org.flowable.engine.impl.util.CommandContextUtil;
 import org.flowable.engine.runtime.ActivityInstance;
 import org.flowable.engine.runtime.ProcessInstance;
+import org.flowable.identitylink.service.impl.persistence.entity.IdentityLinkEntity;
 import org.flowable.task.api.DelegationState;
 import org.flowable.task.api.Task;
 import org.flowable.task.api.TaskQuery;
@@ -392,6 +399,10 @@ public class FlowTaskService {
         // 启动流程
         ProcessInstance procIns = runtimeService.startProcessInstanceByKey (procDefKey, businessTable + ":" + businessId, vars);
 
+        //FlowNode currentTask = this.getNextTask(procIns.getProcessInstanceId());
+
+
+
         // 更新业务表流程实例ID
         Flow act = new Flow ();
         act.setBusinessTable (businessTable);// 业务表名
@@ -405,6 +416,118 @@ public class FlowTaskService {
 
 
     /**
+     * 获取当前节点信息
+     * @param processInstanceId
+     * @return
+     */
+    private FlowNode getCurrentTask(String processInstanceId){
+        //当前任务信息
+        Task task =taskService.createTaskQuery().processInstanceId(processInstanceId).active().singleResult();
+
+        if(task!=null) {
+            //获取流程发布Id信息
+            String definitionId = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult().getProcessDefinitionId();
+            //获取bpm对象
+            BpmnModel bpmnModel = SpringUtil.getBean (RepositoryService.class).getBpmnModel(definitionId);
+            //传节点定义key 获取当前节点
+            FlowNode flowNode = (FlowNode) bpmnModel.getFlowElement(task.getTaskDefinitionKey());
+            return flowNode;
+        }else{
+            return null;
+        }
+
+    }
+
+
+    /**
+     * 获取流程实例的下一个节点的信息 BPMN
+     * 流程实例id
+     * 在遇到网关、分支的时候可能出现问题
+     */
+    @Deprecated
+    private UserTask getNextTask(String processInstanceId) {
+        UserTask userTask=null;
+        //当前任务信息
+        Task task =taskService.createTaskQuery().processInstanceId(processInstanceId).active().singleResult();
+
+        if(task!=null) {
+            //获取流程发布Id信息
+            String definitionId = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult().getProcessDefinitionId();
+            //获取bpm对象
+            BpmnModel bpmnModel = SpringUtil.getBean (RepositoryService.class).getBpmnModel(definitionId);
+            //传节点定义key 获取当前节点
+            FlowNode flowNode = (FlowNode) bpmnModel.getFlowElement(task.getTaskDefinitionKey());
+            //输出连线
+            List<SequenceFlow> outgoingFlows = flowNode.getOutgoingFlows();
+            //遍历返回下一个节点信息
+            for (SequenceFlow outgoingFlow : outgoingFlows) {
+                //类型自己判断
+                FlowElement targetFlowElement = outgoingFlow.getTargetFlowElement();
+                //用户任务
+                if (targetFlowElement instanceof UserTask) {
+                    userTask = (UserTask) targetFlowElement;
+                    break;
+                }else if (targetFlowElement instanceof EndEvent) {
+                    return null;
+                }else{
+                    Map proInsMap=runtimeService.getVariables(processInstanceId);
+                    return setExclusiveGateway(targetFlowElement,proInsMap);
+                }
+            }
+            return userTask;
+        }else{
+            return null;
+        }
+    }
+
+
+    private UserTask setExclusiveGateway(FlowElement targetFlow, Map proInsMap) {
+
+        List<SequenceFlow> targetFlows = ((Gateway) targetFlow).getOutgoingFlows();
+        for (SequenceFlow sequenceFlow : targetFlows) {
+            try {
+                if(checkFormDataByRuleEl(sequenceFlow.getConditionExpression(),proInsMap)) {
+                    //目标节点信息
+                    FlowElement targetFlowElement = sequenceFlow.getTargetFlowElement();
+
+                    if (targetFlowElement instanceof UserTask) {
+                        return (UserTask) targetFlowElement;
+                    } else if (targetFlowElement instanceof EndEvent) {
+                        return null;
+                    } else if (targetFlowElement instanceof ServiceTask) {
+                        return (UserTask) targetFlowElement;//不一定对 按照UserTask 来
+                    } else if (targetFlowElement instanceof Gateway) {
+                        //递归寻找
+                        setExclusiveGateway(targetFlowElement,proInsMap);
+                    } else if (targetFlowElement instanceof SubProcess) {
+                        return null;//目前不管
+                    } else {
+                        return null;
+                    }
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+        return null;
+    }
+    private  Boolean checkFormDataByRuleEl(String el, Map<String, Object> formData) throws Exception {
+
+        ExpressionFactory factory = new ExpressionFactoryImpl();
+        SimpleContext context = new SimpleContext();
+        for (Object k : formData.keySet()) {
+            if (formData.get(k) != null) {
+                context.setVariable(k.toString(), factory.createValueExpression(formData.get(k), formData.get(k).getClass()));
+            }
+        }
+
+        ValueExpression e = factory.createValueExpression(context, el, Boolean.class);
+        return (Boolean) e.getValue(context);
+    }
+
+
+
+    /**
      * 删除任务
      *
      * @param taskId       任务ID