基于jeecg-boot的flowable流程跳转功能实现

更多nbcio-boot功能请看演示系统

gitee源代码地址

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

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

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

      今天我们实现nbcio-boot的flowable的流程跳转功能。

一、前端实现

界面实现,就是点击跳转出来的窗口


    
      
        
          
        
        
        
          
        
        
          
        
      
      
        取 消
        确 定
      
    

  相关处理函数如下:

/** 跳转 */
      handleJump() {
        this.jumpOpen = true;
        this.jumpTitle = "跳转流程";
        this.jumpNodeLoading = true
        userTaskList({ taskId: this.taskForm.taskId }).then((res) => {
          this.jumpNodeLoading = false
          this.jumpNodeData = res.result
        })
      },
      jumpComplete() {
        if (this.selectedRows.length < 1) {
          this.$message.warning('请选择跳转节点')
          return
        }
        // 流程信息
        this.jumpForm.deployId = this.$route.query && this.$route.query.deployId;
        this.jumpForm.taskId = this.$route.query && this.$route.query.taskId;
        this.jumpForm.procInsId = this.$route.query && this.$route.query.procInsId;
        this.jumpForm.instanceId = this.$route.query && this.$route.query.procInsId;
        // 初始化表单
        this.jumpForm.procDefId = this.$route.query && this.$route.query.procDefId;
        this.jumpForm.businessKey = this.$route.query && this.$route.query.businessKey;
        this.jumpForm.category = this.$route.query && this.$route.query.category;
        this.jumpForm.dataId = this.$route.query && this.$route.query.businessKey;
        //节点类型
        this.jumpForm.nodeType = this.$route.query && this.$route.query.nodeType;
        //online表单id和数据id
        this.jumpForm.onlineId = this.$route.query && this.$route.query.onlineId;
        if (this.jumpForm.category === 'online') {
          this.jumpForm.onlineDataId = this.$route.query && this.$route.query.businessKey;
        }  
        //对formdesigner后续加签审批的时候需要用到
        this.jumpForm.values = this.taskForm.values;
        //目标选择的节点信息
        this.jumpForm.targetActId = this.selectedRows[0].id;
        this.jumpForm.targetActName = this.selectedRows[0].name;
        console.log("this.jumpForm=",this.jumpForm);
        jumpTask(this.jumpForm).then(res => {
          if (res.success) {
            this.$message.success('跳转成功')
            this.jumpOpen = false;
            this.goBack();
          } else {
            this.$message.error('跳转失败:' + res.message)
          }
        });
      },
      
      /**
       * 跳转节点列表选择
       */
      onSelectChange (selectedRowKeys, selectedRows) {
        this.selectedRowKeys = selectedRowKeys
        this.selectedRows = selectedRows
      },

二、后端代码实现

@Override
	@Transactional(rollbackFor = Exception.class)
	public void jumpTask(FlowTaskVo flowTaskVo) {
		//校验任务是否存在
		Task task = taskService.createTaskQuery().taskId(flowTaskVo.getTaskId()).singleResult();
        //当前节点id
        String currentActId = task.getTaskDefinitionKey();
        //获取流程实例id
        String processInstanceId = task.getProcessInstanceId();
        //当前活动节点名称(任务名称)
        String currentActName = task.getName();
        //获取当前操作人姓名
        SysUser loginuser = iFlowThirdService.getLoginUser();
        String name = loginuser.getRealname();
        String type = FlowComment.JUMP.getType();
        //添加跳转意见 name + "将任务跳转到【" + targetActName + "】,跳转原因:" + comment + ";";
        taskService.addComment(task.getId(), processInstanceId, type,"当前任务["+currentActName +"]由" + name + "跳转到[" + flowTaskVo.getTargetActName() + "],跳转原因:" + flowTaskVo.getComment());
        //执行跳转操作
        runtimeService.createChangeActivityStateBuilder()
                .processInstanceId(processInstanceId)
                .moveActivityIdTo(currentActId, flowTaskVo.getTargetActId()).changeState();
		
	}

	@Override
	public Result userTaskList(FlowTaskVo flowTaskVo) {
		List resultList = new ArrayList();
      
        // 当前任务 task
        Task task = taskService.createTaskQuery().taskId(flowTaskVo.getTaskId()).singleResult();
        // 获取流程定义信息
        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(task.getProcessDefinitionId()).singleResult();

        //根据流程定义获取deployment
        String deploymentId = processDefinition.getDeploymentId();
        Deployment deployment = repositoryService.createDeploymentQuery().deploymentId(deploymentId).singleResult();
        if (ObjectUtil.isEmpty(deployment)) {
            throw new FlowableException("流程还没布置");
        }

        //获取bpmnModel并转为modelNode
        BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());
        //获取主流程
        Process mainProcess = bpmnModel.getMainProcess();
        //获取用户任务节点类型,深入子流程
        mainProcess.findFlowElementsOfType(UserTask.class, true).forEach(userTask -> {
        	UserTaskVo userTaskResult = new UserTaskVo();
        	userTaskResult.setId(userTask.getId());
        	userTaskResult.setProcessDefinitionId(processDefinition.getId());
        	userTaskResult.setName(userTask.getName());
        	resultList.add(userTaskResult);
        });
        return Result.OK(resultList);
	}

三、效果图

基于jeecg-boot的flowable流程跳转功能实现_第1张图片

基于jeecg-boot的flowable流程跳转功能实现_第2张图片

 

 

你可能感兴趣的:(前端vue,java开发,nbcio-boot,java,vue,nbcio-boot)