基于若依的ruoyi-nbcio流程管理系统修复自定义业务表单的收回功能

news/2024/7/10 1:10:34 标签: vue, java, ruoyi-nbcio, flowable

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

gitee源代码地址

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

演示地址:RuoYi-Nbcio后台管理系统

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

gitee源代码地址

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

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

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

       这个功能在已办任务里,就是用户可以通过已办任务,而且最好是发起人可以进行任务的收回,收回后可以重新进行业务流程提交。

     具体的代码如下,同时在自定义业务提交的时候做一个判断,符合这种情况可以进行提交:

java">@Override
	@Transactional(rollbackFor = Exception.class)
	public R recallProcess(WfTaskBo bo) {
		// 当前任务 listtask
    	List<Task>  listtask = taskService.createTaskQuery().processInstanceId(bo.getProcInsId()).active().list();
        if (listtask == null || listtask.size()==0) {
            throw new FlowableException("流程未启动或已执行完成,无法收回");
        }
        
    	if (taskService.createTaskQuery().taskId(listtask.get(0).getId()).singleResult().isSuspended()) {
            throw new FlowableException("任务处于挂起状态");
        }
    	
    	List<Task> procInsId = taskService.createNativeTaskQuery().sql("select * from ACT_HI_TASKINST where PROC_INST_ID_ = #{procInsId} ORDER BY START_TIME_ desc").parameter("procInsId", bo.getProcInsId()).list();
        
        String processInstanceId = listtask.get(0).getProcessInstanceId();

        //  获取所有历史任务(按创建时间升序)
        List<HistoricTaskInstance> hisTaskList = historyService.createHistoricTaskInstanceQuery()
        .processInstanceId(processInstanceId).orderByTaskCreateTime()
        .asc()
        .list();
        if (CollectionUtil.isEmpty(hisTaskList) || hisTaskList.size() < 2) {
            log.error("当前流程 【{}】 审批节点 【{}】正在初始节点无法收回", processInstanceId, listtask.get(0).getName());
            throw new FlowableException(String.format("当前流程 【%s】 审批节点【%s】正在初始节点无法收回", processInstanceId, listtask.get(0).getName()));
        }

        //  第一个任务
        HistoricTaskInstance startTask = hisTaskList.get(0);
        //若操作用户不是发起人,不能收回
        if(!StringUtils.equalsAnyIgnoreCase(LoginHelper.getUsername(), startTask.getAssignee())) {
        	throw new FlowableException("操作用户不是发起人,不能收回");
        }
        //  当前任务
        HistoricTaskInstance currentTask = hisTaskList.get(hisTaskList.size() - 1);

        BpmnModel bpmnModel = repositoryService.getBpmnModel(listtask.get(0).getProcessDefinitionId());

        //  获取第一个活动节点
        FlowNode startFlowNode = (FlowNode) bpmnModel.getMainProcess().getFlowElement(startTask.getTaskDefinitionKey());
        //  获取当前活动节点
        FlowNode currentFlowNode = (FlowNode) bpmnModel.getMainProcess().getFlowElement(currentTask.getTaskDefinitionKey());

        //  临时保存当前活动的原始方向
        List<SequenceFlow> originalSequenceFlowList = new ArrayList<>(currentFlowNode.getOutgoingFlows());
        //  清理活动方向
        currentFlowNode.getOutgoingFlows().clear();

        //  建立新方向
        SequenceFlow newSequenceFlow = new SequenceFlow();
        newSequenceFlow.setId("newSequenceFlowId");
        newSequenceFlow.setSourceFlowElement(currentFlowNode);
        newSequenceFlow.setTargetFlowElement(startFlowNode);
        List<SequenceFlow> newSequenceFlowList = new ArrayList<>();
        newSequenceFlowList.add(newSequenceFlow);
        //  当前节点指向新的方向
        currentFlowNode.setOutgoingFlows(newSequenceFlowList);

        //  完成当前任务
        for(Task task : listtask) {
		    taskService.addComment(task.getId(), listtask.get(0).getProcessInstanceId(),FlowComment.RECALL.getType(), "发起人收回");
		    taskService.setAssignee(task.getId(), startTask.getAssignee());
		    taskService.complete(task.getId());
        }
        

        //  重新查询当前任务
        Task nextTask = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();
        if (ObjectUtil.isNotNull(nextTask)) {
            taskService.setAssignee(nextTask.getId(), startTask.getAssignee());
            //taskService.complete(nextTask.getId());;//跳过流程发起节点
        }
        //自定义业务处理id
        String dataId = bo.getDataId();
        if(StringUtils.isNotEmpty(dataId)) {
        	WfMyBusiness business = wfMyBusinessService.getByDataId(dataId);
        	//更新删除自定义业务任务关联表与流程历史表,以便可以重新发起流程。
        	if (business != null) {
        		business.setActStatus(ActStatus.recall);
        		business.setTodoUsers("");
        		business.setDoneUsers("");
        		business.setProposer("");
        		business.setTaskName("");
        		business.setTaskId("");
        		business.setTaskNameId("");
            	wfMyBusinessService.updateById(business);
            }	
        }
        
        // 删除运行和历史的节点信息 
        this.deleteActivity(procInsId.get(1).getTaskDefinitionKey(), bo.getProcInsId(), dataId);
        //  恢复原始方向
        currentFlowNode.setOutgoingFlows(originalSequenceFlowList);
        
		return R.ok("发起人收回成功");
	}
java">try {
	        LambdaQueryWrapper<WfMyBusiness> wfMyBusinessLambdaQueryWrapper = new LambdaQueryWrapper<>();
	        wfMyBusinessLambdaQueryWrapper.eq(WfMyBusiness::getDataId, dataId);
	        WfMyBusiness business = wfMyBusinessService.getOne(wfMyBusinessLambdaQueryWrapper);
	        if (business==null || (business != null && business.getActStatus().equals(ActStatus.stop)) 
	        		           || (business != null && business.getActStatus().equals(ActStatus.recall))){
	        	if(processDefinition==null) {
	        		return R.fail("自定义表单也没关联流程定义表,流程没定义关联自定义表单"+wfCustomForm.getId());
	        	}
	        	boolean binit = wfCommonService.initActBusiness(wfCustomForm.getBusinessName(), dataId, serviceName, 
	        	processDefinition.getKey(), processDefinition.getId(), wfCustomForm.getRouteName());
	        	if(!binit) {
	        		return R.fail("自定义表单也没关联流程定义表,流程没定义关联自定义表单"+wfCustomForm.getId());
	        	}
	        	WfMyBusiness businessnew = wfMyBusinessService.getOne(wfMyBusinessLambdaQueryWrapper);
	           //流程实例关联初始化结束
	            if (StrUtil.isNotBlank(businessnew.getProcessDefinitionId())){
	              return this.startProcessByDefId(businessnew.getProcessDefinitionId(),variables);
	            }
	            return this.startProcessByDefKey(businessnew.getProcessDefinitionKey(),variables);
	        }
	        else {
	        	 return R.fail("已经存在这个dataid实例,不要重复申请:"+dataId);
	        }
		} catch (Exception e) {
	            e.printStackTrace();
	            throw new RuntimeException();
	    } 	


http://www.niftyadmin.cn/n/5333041.html

相关文章

Spring06

一、SpirngMvc的基本概念 Spring MVC 是 Spring 提供的一个基于 MVC 设计模式的轻量级 Web 开发框架&#xff0c;本质上相当于 Servlet。 MVC&#xff08;Model View Controller&#xff09;&#xff0c;一种用于设计创建Web应用程序的开发模式 Model&#xff08;模型&#xff…

238.【2023年华为OD机试真题(C卷)】火星文计算(模拟-JavaPythonC++JS实现)

🚀点击这里可直接跳转到本专栏,可查阅顶置最新的华为OD机试宝典~ 本专栏所有题目均包含优质解题思路,高质量解题代码(Java&Python&C++&JS分别实现),详细代码讲解,助你深入学习,深度掌握! 文章目录 一. 题目-火星文计算二.解题思路三.题解代码Python题解代…

修改iview的表格table展开的默认icon和样式

修改前 修改后 修改内容 .title_label_list .ivu-icon-ios-add{font-size: 26px;color: #888888; } .title_label_list .ivu-icon-ios-add:hover{color: #11AAAA; } .title_label_list .ivu-icon-ios-add:before {content: "\F341"; } .title_label_list .ivu-icon-…

Baumer工业相机堡盟工业相机如何通过NEOAPI SDK使用相机日志跟踪功能(C++)

Baumer工业相机堡盟工业相机如何通过NEOAPI SDK使用相机日志跟踪功能&#xff08;C&#xff09; Baumer工业相机Baumer工业相机NEOAPI SDK和短曝光功能的技术背景Baumer工业相机通过NEOAPI SDK使用相机日志跟踪功能1.引用合适的类文件2.通过NEOAPI SDK使用相机日志跟踪功能3.通…

Golang leetcode151 翻转字符串中的单词 双指针 常规+进阶

翻转字符串中的单词 leetcode151 常规做法 双指针 func reverseWords(s string) string { WordList : []string{} left : 0 L : len(s) //fmt.Println(L)for i, i2 : range s {//去除重复的空格if i > 0 && s[i-1] && i2 {leftcontinue}//不为空格时…

Android Google 开机向导定制 setup wizard

Android 开机向导定制 采用 rro_overlays 机制来定制开机向导&#xff0c;定制文件如下&#xff1a; GmsSampleIntegrationOverlay$ tree . ├── Android.bp ├── AndroidManifest.xml └── res └── raw ├── wizard_script_common_flow.xml ├── wizard_script…

【Python3】【力扣题】392. 判断子序列

【力扣题】题目描述&#xff1a; 【Python3】代码&#xff1a; 1、解题思路&#xff1a;遍历字符串s&#xff0c;使用一个列表依次记录在字符串t中的位置&#xff0c;若没有该字母则返回False&#xff0c;若索引号小于上一个字母的索引号&#xff0c;返回False。否则返回True。…

centos7 arm服务器编译升级安装动态库libstdc++.so.6,解决GLIBC和CXXABI版本低的问题

前言 由于centos7内置的libstdc.so.6版本太低&#xff0c;导致安装第三方包的时候&#xff0c;会报“CXXABI_1.3.8”不存在等问题。 自带的打印如下&#xff1a; strings /usr/lib64/libstdc.so.6 | grep GLIBC strings /usr/lib64/libstdc.so.6 | grep CXXABI 如图 升级 注…