基于Jeecg-boot的flowable流程支持拒绝同意流程操作

更多功能看演示系统

gitee源代码地址

后端代码: https://gitee.com/nbacheng/nbcio-boot

前端代码:https://gitee.com/nbacheng/nbcio-vue.git

在线演示(包括H5) : http://122.227.135.243:9888

        因为看很多朋友需要这种同意拒绝的排它网关流程,所以这次先支持这种操作,但这个还不支持的第一个发起人后面的这种排它网关操作。

      1、增加下面一个接口,以便控制拒绝按钮是否可用

 
    @ApiOperation(value = "获取下一节点的通用同意拒绝排它网关")
    @PostMapping(value = "/nextApprovedEG")
    public Result nextApprovedEG(@RequestParam(name="taskId",required=true) String taskId) {
        return Result.OK(flowTaskService.getNextApprovedExclusiveGateway(taskId));
    }

2、FlowTaskVo增加下面的一个参数

    @ApiModelProperty("下一个网关是否是同意拒绝通用网关")
    private boolean approved; //网关条件是${approved}或${!approved}

3、IFlowTaskService增加下面方法

    /**
     * 获取下个节点信息,对排它网关的通用同意拒绝做特殊处理
     *  add by nbacheng
     *           
     * @param FlowTaskVo taskVo
     *           
     * @return
     */
    boolean getNextApprovedExclusiveGateway(String taskId);

4、FlowTaskServiceImpl增加下面方法

    /**
	 * 获取下个节点信息,目前只对排它网关的${approved}做特殊处理
	 *  add by nbacheng
	 *           
	 * @param FlowTaskVo taskVo
	 *           
	 * @return
	 */
    
	@Override
	public boolean getNextApprovedExclusiveGateway(String taskId) {
		//当前节点
        Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(task.getProcessDefinitionId()).singleResult();
        BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());
        String key = task.getTaskDefinitionKey();
        FlowElement flowElement = bpmnModel.getFlowElement(key);
        //获取Task的出线信息--可以拥有多个
        List<SequenceFlow> outGoingFlows = null;
        if (flowElement instanceof UserTask) {
            outGoingFlows = ((UserTask) flowElement).getOutgoingFlows();
        }
        //遍历返回下一个节点信息,只考虑后面排它网关是${approved}参数
        for (SequenceFlow outgoingFlow : outGoingFlows) {
            //类型自己判断(获取下个节点是网关还是节点)
            FlowElement targetFlowElement = outgoingFlow.getTargetFlowElement();
            //下个是节点
           if(targetFlowElement instanceof ExclusiveGateway){// 
        	   boolean existApproved =  GetExclusiveGatewayExpression(targetFlowElement);//对表达式里有${approved}做特殊处理,就是对同意或拒绝(类似通过或不通过)
        	   if(existApproved) {
        		   return true;
        	   }
        	   break;
            }
        }
		return false;
        
	}
	
	 /**
     * 获取排他网关分支名称、分支表达式是否存在${approved}
     * @param flowElement
     * @param 
     * add by nbacheng
     */
    private boolean GetExclusiveGatewayExpression(FlowElement flowElement) {
    	// 获取所有网关分支
        List<SequenceFlow> targetFlows=((ExclusiveGateway)flowElement).getOutgoingFlows();
        // 循环每个网关分支
        for(SequenceFlow sequenceFlow : targetFlows){
            // 获取下一个网关和节点数据
            FlowElement targetFlowElement=sequenceFlow.getTargetFlowElement();
            // 网关数据不为空
            if (StringUtils.isNotBlank(sequenceFlow.getConditionExpression())) {
                // 获取网关判断条件
            	String expression = sequenceFlow.getConditionExpression();
            	if(expression.contains("${approved}")) {
            		return true;
            	}
            }
        }    
    	return false;   	
    }

5、taskFormComplete修改如下:

 /**
     * 任务节点有表单的操作
     *
     * @param taskVo
     */
    private void taskFormComplete(FlowTaskVo taskVo) {
    	Map<String , Object> approved = new HashMap<String , Object>();
    	boolean existApprovedEG =  getNextApprovedExclusiveGateway(taskVo.getTaskId());//检测下个否是是判断同意拒绝网关,是要做特殊处理
    	
    	if(taskVo.getValues() !=null && taskVo.getValues().containsKey("taskformvalues")) {//有任务节点表单
    		@SuppressWarnings("unchecked")
			Map<String , Object> taskformvalues = (Map<String, Object>) taskVo.getValues().get("taskformvalues");
    		taskService.setVariableLocal(taskVo.getTaskId(), "taskformvalues", taskformvalues);
    		taskService.complete(taskVo.getTaskId(),taskformvalues);//保存taskformvalues到变量表里
    	}
    	else if (existApprovedEG) {//是${approved}拒绝同意网关
    		if (taskVo.isApproved()) {
    			approved.put("approved", true);
    		}
    		else {
    			approved.put("approved", false);
    		}
    		taskService.complete(taskVo.getTaskId(),approved);//保存approved到变量表里
    	}
    	else {
    		taskService.complete(taskVo.getTaskId());
    	}
    }

6、增加一个拒绝按钮

<el-button type="primary" @click="taskComplete">确 定</el-button>

7、增加一个按钮判断方法

//获取下一个通用拒绝同意排它网关
      getNextApprovedEG(taskId) {
        nextApprovedEG({taskId: taskId}).then(res => {
          if(res.success) {
            const data = res.result;
            console.log("getNextApprovedEG",data)
            this.bapproved = data;
          }
         
          
        });  
      },      

8、taskComplete(approved)增加一个变量,以区分是同意还是拒绝。
9、演示图片如下:

猜你喜欢

转载自blog.csdn.net/qq_40032778/article/details/131230393