当前位置: 首页 > news >正文

基于RuoYi-Flowable-Plus的若依ruoyi-nbcio支持自定义业务表单流程(三)

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

gitee源代码地址

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

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

相应的后端也要做一些调整

1、启动流程修改如下:

/*** 启动流程实例*/private R startProcess(ProcessDefinition procDef, Map<String, Object> variables) {if (ObjectUtil.isNotNull(procDef) && procDef.isSuspended()) {throw new ServiceException("流程已被挂起,请先激活流程");}   // 设置流程发起人Id到流程中,包括变量String userStr = TaskUtils.getUserName();SysUser sysUsr = sysUserService.selectUserByUserName(userStr);setFlowVariables(sysUsr,variables);	Map<String, Object> variablesnew = variables;Map<String, Object> usermap = new HashMap<String, Object>();List<String> userlist = new ArrayList<String>();boolean bparallelGateway = false;boolean bapprovedEG = false;//业务数据idString dataId = variables.get("dataId").toString();if(StringUtils.isNotEmpty(dataId)) {//自定义业务表单//设置自定义表单dataid的数据 WfMyBusiness flowmybusiness = wfMyBusinessServiceImpl.getByDataId(variables.get("dataId").toString());String serviceImplName = flowmybusiness.getServiceImplName();WfCallBackServiceI flowCallBackService = (WfCallBackServiceI) SpringContextUtils.getBean(serviceImplName);if (flowCallBackService!=null){Object businessDataById = flowCallBackService.getBusinessDataById(variables.get("dataId").toString());variables.put("formData",businessDataById);}}//获取下个节点信息getNextFlowInfo(procDef, variablesnew, usermap, variables, userlist);//取出两个特殊的变量if(variablesnew.containsKey("bparallelGateway")) {//并行网关bparallelGateway = (boolean) variablesnew.get("bparallelGateway");variablesnew.remove("bparallelGateway");}if(variablesnew.containsKey("bapprovedEG")) {//通用拒绝同意排它网关bapprovedEG = (boolean) variablesnew.get("bapprovedEG");variablesnew.remove("bapprovedEG");}// 发起流程实例ProcessInstance processInstance = runtimeService.startProcessInstanceById(procDef.getId(), variables);// 第一个用户任务为发起人,则自动完成任务//wfTaskService.startFirstTask(processInstance, variables);R<Void> result = setNextAssignee(processInstance, usermap, userlist, sysUsr, variables, bparallelGateway, bapprovedEG);	if(StringUtils.isNotEmpty(dataId)) {//自定义业务表单// 流程发起后的自定义业务更新-需要考虑两种情况,第一个发起人审批或跳过List<Task> tasks = taskService.createTaskQuery().processInstanceId(processInstance.getProcessInstanceId()).active().list();/*======================todo 启动之后  回调以及关键数据保存======================*///如果保存数据前未调用必调的FlowCommonService.initActBusiness方法,就会有问题LoginUser sysUser = commonService.getLoginUser();if(tasks!=null) {SysUser sysTaskUser = new SysUser();List <String> listUser = new ArrayList<String>();List <String> listId = new ArrayList<String>();List <String> listName = new ArrayList<String>();String taskUser = "";String taskid = "";String taskName = "";int taskPriority = 0;for(Task task : tasks) {if(task.getAssignee() != null) {sysTaskUser = commonService.getSysUserByUserName(task.getAssignee());listUser.add(sysTaskUser.getNickName());}listId.add(task.getId());listName.add(task.getName());taskPriority = task.getPriority();}taskUser = listUser.stream().map(String::valueOf).collect(Collectors.joining(","));taskid = listId.stream().map(String::valueOf).collect(Collectors.joining(","));taskName = listName.stream().map(String::valueOf).collect(Collectors.joining(","));WfMyBusiness business = wfMyBusinessServiceImpl.getByDataId(dataId);business.setProcessDefinitionId(procDef.getId());business.setProcessInstanceId(processInstance.getProcessInstanceId());business.setActStatus(ActStatus.doing);business.setProposer(sysUser.getUsername());business.setTaskId(taskid);business.setTaskName(taskName);business.setTaskNameId(taskid);business.setPriority(String.valueOf(taskPriority));business.setDoneUsers("");business.setTodoUsers(taskUser);wfMyBusinessService.updateById(business);//spring容器类名String serviceImplNameafter = business.getServiceImplName();WfCallBackServiceI flowCallBackServiceafter = (WfCallBackServiceI) SpringContextUtils.getBean(serviceImplNameafter);// 流程处理完后,进行回调业务层business.setValues(variables);if (flowCallBackServiceafter!=null)flowCallBackServiceafter.afterFlowHandle(business);}else {WfMyBusiness business = wfMyBusinessServiceImpl.getByDataId(dataId);business.setProcessDefinitionId(procDef.getId());business.setProcessInstanceId(processInstance.getProcessInstanceId());business.setActStatus(ActStatus.pass);business.setProposer(sysUser.getUsername());business.setTaskId("");business.setTaskName("");business.setTaskNameId("");business.setDoneUsers("");business.setTodoUsers("");wfMyBusinessService.updateById(business);//spring容器类名String serviceImplNameafter = business.getServiceImplName();WfCallBackServiceI flowCallBackServiceafter = (WfCallBackServiceI) SpringContextUtils.getBean(serviceImplNameafter);// 流程处理完后,进行回调业务层business.setValues(variables);if (flowCallBackServiceafter!=null)flowCallBackServiceafter.afterFlowHandle(business);}}return result;	}

2、获取表单列表修改如下:

/*** 获取历史流程表单信息*/private List<FormConf> processFormList(BpmnModel bpmnModel, HistoricProcessInstance historicProcIns, String dataId) {List<FormConf> procFormList = new ArrayList<>();List<HistoricActivityInstance> activityInstanceList = historyService.createHistoricActivityInstanceQuery().processInstanceId(historicProcIns.getId()).finished().activityTypes(CollUtil.newHashSet(BpmnXMLConstants.ELEMENT_EVENT_START, BpmnXMLConstants.ELEMENT_TASK_USER)).orderByHistoricActivityInstanceStartTime().asc().list();List<String> processFormKeys = new ArrayList<>();for (HistoricActivityInstance activityInstance : activityInstanceList) {// 获取当前节点流程元素信息FlowElement flowElement = ModelUtils.getFlowElementById(bpmnModel, activityInstance.getActivityId());// 获取当前节点表单KeyString formKey = ModelUtils.getFormKey(flowElement);if (formKey == null) {continue;}boolean localScope = Convert.toBool(ModelUtils.getElementAttributeValue(flowElement, ProcessConstants.PROCESS_FORM_LOCAL_SCOPE), false);Map<String, Object> variables;if (localScope) {// 查询任务节点参数,并转换成Mapvariables = historyService.createHistoricVariableInstanceQuery().processInstanceId(historicProcIns.getId()).taskId(activityInstance.getTaskId()).list().stream().collect(Collectors.toMap(HistoricVariableInstance::getVariableName, HistoricVariableInstance::getValue));} else {if (processFormKeys.contains(formKey)) {continue;}variables = historicProcIns.getProcessVariables();processFormKeys.add(formKey);}  Map<String, Object> formvariables = new HashedMap<String, Object>();//遍历Mapif(variables.containsKey("variables")) {formvariables = (Map<String, Object>)((Map<String, Object>) variables.get("variables")).get("formValue");}// 非节点表单此处查询结果可能有多条,只获取第一条信息List<WfDeployFormVo> formInfoList = deployFormMapper.selectVoList(new LambdaQueryWrapper<WfDeployForm>().eq(WfDeployForm::getDeployId, historicProcIns.getDeploymentId()).eq(WfDeployForm::getFormKey, formKey).eq(localScope, WfDeployForm::getNodeKey, flowElement.getId()));//@update by Brath:避免空集合导致的NULL空指针WfDeployFormVo formInfo = formInfoList.stream().findFirst().orElse(null);if (ObjectUtil.isNotNull(formInfo)) {// 旧数据 formInfo.getFormName() 为 nullString formName = Optional.ofNullable(formInfo.getFormName()).orElse(StringUtils.EMPTY);String title = localScope ? formName.concat("(" + flowElement.getName() + ")") : formName;FormConf formConf = JsonUtils.parseObject(formInfo.getContent(), FormConf.class);if (null != formConf) {//ProcessFormUtils.fillFormData(formConf, variables);formConf.setTitle(title);formConf.setFormValues(formvariables);procFormList.add(formConf);}}}if(StringUtils.isNoneEmpty(dataId)) {WfMyBusiness business = wfMyBusinessServiceImpl.getByDataId(dataId);String serviceImplName = business.getServiceImplName();WfCallBackServiceI flowCallBackService = (WfCallBackServiceI) SpringContextUtils.getBean(serviceImplName);// 流程处理完后,进行回调业务层if (flowCallBackService!=null){Map<String, Object> customMap = new HashMap<String, Object>();FormConf formConf = new FormConf();Object businessDataById = flowCallBackService.getBusinessDataById(dataId);customMap.put("formData",businessDataById);customMap.put("routeName", business.getRouteName());formConf.setFormValues(customMap);procFormList.add(formConf);}}return procFormList;}

3、效果图如下:

http://www.lryc.cn/news/195338.html

相关文章:

  • Spring-事务源码解析2
  • 基于ssm008医院门诊挂号系统+jsp【附PPT|开题|任务书|万字文档(LW)和搭建文档】
  • 【Linux常用命令11】Linux文件与权限详解
  • BAT026:删除当前目录指定文件夹以外的文件夹
  • Python浏览器自动化
  • 基于tornado BELLE 搭建本地的web 服务
  • 信息系统漏洞与风险管理制度
  • Hadoop3教程(十七):MapReduce之ReduceJoin案例分析
  • BAT026:删除当前目录及子目录下的空文件夹
  • nodejs+vue网课学习平台
  • Can Language Models Make Fun? A Case Study in Chinese Comical Crosstalk
  • 阿里云云服务器实例使用教学
  • promisify 是 Node.js 标准库 util 模块中的一个函数
  • ArcGIS在VUE框架中的构建思想
  • 【Overload游戏引擎细节分析】视图投影矩阵计算与摄像机
  • 什么是云原生?零基础学云原生难吗?
  • Ubuntu18.04下载安装基于使用QT的pcl1.13+vtk8.2,以及卸载
  • 7 使用Docker容器管理的tomcat容器中的项目连接mysql数据库
  • 双节前把我的网站重构了一遍
  • 基于 nodejs+vue网上考勤系统
  • 以数智化指标管理,驱动光伏能源行业的市场推进
  • lv8 嵌入式开发-网络编程开发 18 广播与组播的实现
  • 前端面试题个人笔记(后面继续更新完善)
  • 软件设计之工厂方法模式
  • 【Linux】shell运行原理及权限
  • OA系统和ERP系统有什么区别?
  • c语言之strcat函数使用和实现
  • Halo-Theme-Hao文档:如何设置导航栏?
  • 【Java学习之道】Java网络编程API介绍
  • [论文笔记]SimCSE