Bladeren bron

flowable代码调整

lizhenhao 2 jaren geleden
bovenliggende
commit
76166a616c

+ 40 - 0
jeeplus-modules/jeeplus-flowable/src/main/java/com/jeeplus/flowable/controller/FlowableProcessController.java

@@ -22,6 +22,8 @@ import javax.xml.stream.XMLStreamException;
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
+import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -243,4 +245,42 @@ public class FlowableProcessController {
         return ResponseEntity.ok ( "删除成功,流程实例ID=" + procInsIds );
     }
 
+    /**
+     * 流程定义列表
+     */
+    @GetMapping("getByName")
+    public ResponseEntity getByName( Page<Map> page,String name) {
+        /*
+         * 保存两个对象,一个是ProcessDefinition(流程定义),一个是Deployment(流程部署)
+         */
+        page = flowProcessService.processList(page, "");
+        List<Map> records = page.getRecords();
+        Map resultMap = new HashMap();
+        for (Map map : records) {
+            if(name.equals(map.get("name"))){
+                resultMap = map;
+            }
+        }
+        return ResponseEntity.ok ( resultMap );
+    }
+
+    /**
+     * 流程定义列表
+     */
+    @GetMapping("getById")
+    public ResponseEntity getById( Page<Map> page,String id) {
+        /*
+         * 保存两个对象,一个是ProcessDefinition(流程定义),一个是Deployment(流程部署)
+         */
+        page = flowProcessService.processList(page, "");
+        List<Map> records = page.getRecords();
+        Map resultMap = new HashMap();
+        for (Map map : records) {
+            if(id.equals(map.get("id"))){
+                resultMap = map;
+            }
+        }
+        return ResponseEntity.ok ( resultMap );
+    }
+
 }

+ 79 - 3
jeeplus-modules/jeeplus-flowable/src/main/java/com/jeeplus/flowable/controller/FlowableTaskController.java

@@ -3,12 +3,14 @@
  */
 package com.jeeplus.flowable.controller;
 
+import cn.hutool.extra.spring.SpringUtil;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.jeeplus.common.TokenProvider;
 import com.jeeplus.extension.domain.NodeSetting;
 import com.jeeplus.extension.service.NodeSettingService;
+import com.jeeplus.flowable.model.ActRuTaskInfo;
 import com.jeeplus.flowable.model.Flow;
 import com.jeeplus.flowable.model.TaskComment;
 import com.jeeplus.flowable.service.FlowTaskService;
@@ -19,8 +21,10 @@ import com.jeeplus.sys.feign.IUserApi;
 import com.jeeplus.sys.service.dto.UserDTO;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.ibatis.annotations.Param;
+import org.flowable.bpmn.model.Process;
 import org.flowable.common.engine.impl.identity.Authentication;
 import org.flowable.engine.HistoryService;
+import org.flowable.engine.RepositoryService;
 import org.flowable.engine.RuntimeService;
 import org.flowable.engine.TaskService;
 import org.flowable.engine.runtime.ProcessInstance;
@@ -149,13 +153,20 @@ public class FlowableTaskController {
      */
     @PostMapping("start")
     public ResponseEntity start(@RequestBody Flow flow) {
-        String procInsId = flowTaskService.startProcess ( flow.getProcDefKey ( ), flow.getBusinessTable ( ), flow.getBusinessId ( ), flow.getTitle ( ) );
+        String procInsId = flowTaskService.startProcess ( flow.getProcDefKey ( ), flow.getBusinessTable ( ), flow.getBusinessId ( ), flow.getTitle ( ), flow.getProcDefId() );
 
         //指定下一步处理人
         if ( StringUtils.isNotBlank ( flow.getAssignee ( ) ) ) {
             Task task = taskService.createTaskQuery ( ).processInstanceId ( procInsId ).active ( ).singleResult ( );
-            if ( task != null ) {
-                taskService.setAssignee ( task.getId ( ), flow.getAssignee ( ) );
+            if(task != null){
+                String[] split = flow.getAssignee().split(",");
+                if (split.length == 1) {
+                    taskService.setAssignee(task.getId(), flow.getAssignee ());
+                } else {
+                    for (String i : split) {
+                        taskService.addCandidateUser(task.getId(),i);
+                    }
+                }
             }
         }
         return ResponseEntity.ok ( procInsId );
@@ -386,5 +397,70 @@ public class FlowableTaskController {
         return flowTaskService.checkIsLastTask(procInsId);
     }
 
+    /**
+     * 获取流程表单
+     */
+    @GetMapping("getTaskDefInfo")
+    public ResponseEntity getTaskDefInfo(Flow flow) {
+        if(StringUtils.isNotBlank(flow.getTaskId()) && StringUtils.isBlank(flow.getTaskName()) && StringUtils.isBlank(flow.getTaskDefKey())){
+            ActRuTaskInfo taskInfoByTaskId = flowTaskService.getTaskInfoByTaskId(flow.getTaskId());
+            if(null != taskInfoByTaskId){
+                flow.setTaskId(taskInfoByTaskId.getId());
+                flow.setProcInsId(taskInfoByTaskId.getProcInstId());
+                flow.setTaskName(taskInfoByTaskId.getName());
+                flow.setTaskDefKey(taskInfoByTaskId.getTaskDefKey());
+            }
+            //当前任务信息
+            Task task =taskService.createTaskQuery().processInstanceId(flow.getProcInsId()).active().singleResult();
+            if(null != task){
+                if(StringUtils.isNotBlank(task.getProcessDefinitionId())){
+                    flow.setProcDefId(task.getProcessDefinitionId());
+                }
+                if(null != task.getProcessVariables ()){
+                    String title = (String) task.getProcessVariables().get("title");
+                    if(StringUtils.isNotBlank(title)){
+                        flow.setTitle(title);
+                    }else{
+                        flow.setTitle("");
+                    }
+                }
+            }
+
+            Process process = SpringUtil.getBean (RepositoryService.class).getBpmnModel (taskInfoByTaskId.getProcDefId ()).getMainProcess ();
+            if(null != process && StringUtils.isNotBlank(process.getId())){
+                flow.setProcDefKey(process.getId());
+            }
+        }
+        // 获取流程XML上的表单KEY
+        String formKey = flowTaskService.getFormKey(flow.getProcDefId(), flow.getTaskDefKey());
+
+        NodeSetting typeNode = nodeSettingService.queryByKey (flow.getProcDefKey(), flow.getTaskDefKey(), "formType");
+        NodeSetting ReadOnlyNode = nodeSettingService.queryByKey (flow.getProcDefKey(), flow.getTaskDefKey(), "formReadOnly");
+        String formType = "1";
+        boolean formReadOnly = false;
+        if(typeNode != null){
+            formType = typeNode.getValue ();
+            formReadOnly = "true".equals(ReadOnlyNode.getValue ());
+        }else{
+            if(StringUtils.isBlank(formKey)){
+                formType = "1";
+            }else if(formKey.indexOf("/")>=0){
+                formType = "2";
+            }
+        }
+
+        // 获取流程实例对象
+        if (flow.getProcInsId() != null) {
+            if (flowTaskService.getProcIns(flow.getProcInsId()) != null) {
+                flow.setProcIns(flowTaskService.getProcIns(flow.getProcInsId()));
+            } else {
+                flow.setFinishedProcIns(flowTaskService.getFinishedProcIns(flow.getProcInsId()));
+            }
+        }
 
+        flow.setFormUrl(formKey);
+        flow.setFormReadOnly(formReadOnly);
+        flow.setFormType(formType);
+        return ResponseEntity.ok (flow);
+    }
 }

+ 8 - 0
jeeplus-modules/jeeplus-flowable/src/main/java/com/jeeplus/flowable/mapper/FlowMapper.java

@@ -4,6 +4,7 @@
 package com.jeeplus.flowable.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.jeeplus.flowable.model.ActRuTaskInfo;
 import com.jeeplus.flowable.model.Flow;
 
 /**
@@ -16,4 +17,11 @@ public interface FlowMapper extends BaseMapper <Flow> {
 
     int updateProcInsIdByBusinessId(Flow act);
 
+    /**
+     * 根据流程id查询流程信息
+     * @param taskId
+     * @return
+     */
+    ActRuTaskInfo getTaskInfoByTaskId(String taskId);
+
 }

+ 41 - 0
jeeplus-modules/jeeplus-flowable/src/main/java/com/jeeplus/flowable/mapper/xml/FlowMapper.xml

@@ -5,7 +5,48 @@
     <update id="updateProcInsIdByBusinessId">
         UPDATE ${businessTable}
         SET proc_ins_id = #{procInsId}
+        <if test="procDefId != null and procDefId != ''">
+            ,process_definition_id = #{procDefId}
+        </if>
         WHERE id = #{businessId}
     </update>
 
+    <select id="getTaskInfoByTaskId" resultType="com.jeeplus.flowable.model.ActRuTaskInfo">
+		select
+		  ID_ as "id",
+		  REV_ as "rev",
+		  EXECUTION_ID_ as "executionId",
+		  PROC_INST_ID_ as "procInstId",
+		  PROC_DEF_ID_ as "procDefId",
+		  TASK_DEF_ID_ as "taskDefId",
+		  SCOPE_ID_ as "scopeId",
+		  SUB_SCOPE_ID_ as "subScopeId",
+		  SCOPE_TYPE_ as "scopeType",
+		  SCOPE_DEFINITION_ID_ as "scopeDefinitionId",
+		  NAME_ as "name",
+		  PARENT_TASK_ID_ as "parentTaskId",
+		  DESCRIPTION_ as "description",
+		  TASK_DEF_KEY_ as "taskDefKey",
+		  OWNER_ as "owner",
+		  ASSIGNEE_ as "assignee",
+		  DELEGATION_ as "delegation",
+		  PRIORITY_ as "priority",
+		  CREATE_TIME_ as "createTime",
+		  DUE_DATE_ as "dueDate",
+		  CATEGORY_ as "category",
+		  SUSPENSION_STATE_ as "suspensionState",
+		  TENANT_ID_ as "tenantId",
+		  FORM_KEY_ as "formKey",
+		  CLAIM_TIME_ as "claimTime",
+		  IS_COUNT_ENABLED_ as "isCountEnabled",
+		  VAR_COUNT_ as "varCount",
+		  ID_LINK_COUNT_ as "idLinkCount",
+		  SUB_TASK_COUNT_  as "subTaskCount"
+		from
+		  act_ru_task
+		where ID_= #{taskId}
+		order by CREATE_TIME_ desc
+		limit 1
+	</select>
+
 </mapper>

+ 43 - 0
jeeplus-modules/jeeplus-flowable/src/main/java/com/jeeplus/flowable/model/ActRuTaskInfo.java

@@ -0,0 +1,43 @@
+package com.jeeplus.flowable.model;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * act_ru_task 表数据
+ */
+@Data
+public class ActRuTaskInfo implements Serializable {
+
+    private String id;
+    private Integer rev;
+    private String executionId;
+    private String procInstId;
+    private String procDefId;
+    private String taskDefId;
+    private String scopeId;
+    private String subScopeId;
+    private String scopeType;
+    private String scopeDefinitionId;
+    private String name;
+    private String parentTaskId;
+    private String description;
+    private String taskDefKey;
+    private String owner;
+    private String assignee;
+    private String delegation;
+    private Integer priority;
+    private Date createTime;
+    private Date dueDate;
+    private String category;
+    private Integer suspensionState;
+    private String tenantId;
+    private String formKey;
+    private Date claimTime;
+    private Integer isCountEnabled;
+    private Integer varCount;
+    private Integer idLinkCount;
+    private Integer subTaskCount;
+}

+ 45 - 0
jeeplus-modules/jeeplus-flowable/src/main/java/com/jeeplus/flowable/service/FlowProcessService.java

@@ -19,6 +19,7 @@ import com.jeeplus.flowable.vo.TaskVo;
 import com.jeeplus.sys.feign.ITenantApi;
 import com.jeeplus.sys.feign.IUserApi;
 import com.jeeplus.sys.service.dto.UserDTO;
+import com.jeeplus.sys.utils.UserUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.FilenameUtils;
@@ -633,5 +634,49 @@ public class FlowProcessService {
 
         }
     }
+    /**
+     * 驳回流程实例信息调整
+     *
+     * @param procInsId    流程实例ID
+     * @param processStatus    流程状态
+     */
+    @Transactional(readOnly = false)
+    public void rejectProcessInstanceById(String procInsId, ProcessStatus processStatus, String comment) {
+        ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(procInsId).singleResult();
+        if (processInstance != null) {
+            Task currentTask = taskService.createTaskQuery ().processInstanceId (procInsId).list ().get (0);
+            //1、添加审批记录
+            TaskComment taskComment = new TaskComment ();
+            if(processStatus == ProcessStatus.AGREE){
+                taskComment.setType ( ActionType.AGREE.getType ());
+                taskComment.setStatus (ActionType.AGREE.getStatus ());
+                taskComment.setMessage (comment);
+            }else if(processStatus == ProcessStatus.REVOKE){
+                taskComment.setType ( ActionType.REVOKE.getType ());
+                taskComment.setStatus (ActionType.REVOKE.getStatus ());
+                taskComment.setMessage (comment);
+            }else if(processStatus == ProcessStatus.STOP){
+                taskComment.setType (ActionType.STOP.getType ());
+                taskComment.setStatus (ActionType.STOP.getStatus ());
+                taskComment.setMessage (comment);
+            }else if(processStatus == ProcessStatus.REJECT){
+                taskComment.setType (ActionType.REJECT.getType ());
+                taskComment.setStatus (ActionType.REJECT.getStatus ());
+                taskComment.setMessage (comment);
+            }else if(processStatus == ProcessStatus.DELETED){
+                taskComment.setType (ActionType.DELETED.getType ());
+                taskComment.setStatus (ActionType.DELETED.getStatus ());
+                taskComment.setMessage (comment);
+            }
+
+
+
+            taskService.addComment (currentTask.getId (),procInsId, taskComment.getCommentType (), taskComment.getFullMessage ());
+            if(StrUtil.isBlank (currentTask.getAssignee ()))  { // 未签收任务
+                taskService.claim (currentTask.getId (), UserUtils.getCurrentUserDTO ().getId ());
+            }
+        }
+    }
+
 
 }

+ 28 - 3
jeeplus-modules/jeeplus-flowable/src/main/java/com/jeeplus/flowable/service/FlowTaskService.java

@@ -13,6 +13,7 @@ import com.jeeplus.common.utils.Collections3;
 import com.jeeplus.flowable.common.cmd.BackUserTaskCmd;
 import com.jeeplus.flowable.constant.FlowableConstant;
 import com.jeeplus.flowable.mapper.FlowMapper;
+import com.jeeplus.flowable.model.ActRuTaskInfo;
 import com.jeeplus.flowable.model.Flow;
 import com.jeeplus.flowable.model.TaskComment;
 import com.jeeplus.flowable.service.converter.json.FlowModelService;
@@ -355,9 +356,9 @@ public class FlowTaskService {
      * @param title         流程标题,显示在待办任务标题
      * @return 流程实例ID
      */
-    public String startProcess(String procDefKey, String businessTable, String businessId, String title) {
+    public String startProcess(String procDefKey, String businessTable, String businessId, String title, String procDefId) {
         Map <String, Object> vars = Maps.newHashMap ( );
-        return startProcess ( procDefKey, businessTable, businessId, title, vars );
+        return startProcess ( procDefKey, businessTable, businessId, title, vars , procDefId);
     }
 
     /**
@@ -371,7 +372,7 @@ public class FlowTaskService {
      * @return 流程实例ID
      */
     @SuppressWarnings("unused")
-    public String startProcess(String procDefKey, String businessTable, String businessId, String title, Map <String, Object> vars) {
+    public String startProcess(String procDefKey, String businessTable, String businessId, String title, Map <String, Object> vars, String procDefId) {
         //String userId = UserUtils.getUser().getLoginName();//ObjectUtils.toString(UserUtils.getUser().getId())
         // 设置流程变量
         if ( vars == null ) {
@@ -401,6 +402,7 @@ public class FlowTaskService {
         act.setBusinessTable ( businessTable );// 业务表名
         act.setBusinessId ( businessId );  // 业务表ID
         act.setProcInsId ( procIns.getId ( ) );
+        act.setProcDefId(procDefId);
         act.setVars ( vars );
         flowMapper.updateProcInsIdByBusinessId ( act );
         return act.getProcInsId ( );
@@ -451,6 +453,20 @@ public class FlowTaskService {
 
 
         Task task = taskService.createTaskQuery ( ).taskId ( flow.getTaskId ( ) ).singleResult ( );
+
+        Object agree = vars.get("agree");
+        Boolean flagAgree = null;
+        if(null != agree && StringUtils.isNotBlank(String.valueOf(agree))){
+            flagAgree = (Boolean) agree;
+        }
+        if(null != flagAgree){
+            if(flagAgree){
+                flowProcessService.rejectProcessInstanceById (task.getProcessInstanceId (), ProcessStatus.AGREE, flow.getComment ().getMessage ());
+            }else{
+                flowProcessService.rejectProcessInstanceById (task.getProcessInstanceId (), ProcessStatus.REJECT, flow.getComment ().getMessage ());
+            }
+        }
+
         // owner不为空说明可能存在委托任务
         if ( StrUtil.isNotBlank ( task.getOwner ( ) ) ) {
             DelegationState delegationState = task.getDelegationState ( );
@@ -914,4 +930,13 @@ public class FlowTaskService {
         }
     }
 
+    /**
+     * 根据taskId查询流程信息
+     * @param taskId
+     * @return
+     */
+    public ActRuTaskInfo getTaskInfoByTaskId(String taskId){
+        return flowMapper.getTaskInfoByTaskId(taskId);
+    }
+
 }