当前位置:   article > 正文

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

ruoyi-flowable-plus 自定义自己表单

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

gitee源代码地址

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

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

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

1、启动流程修改如下:

  1. /**
  2. * 启动流程实例
  3. */
  4. private R startProcess(ProcessDefinition procDef, Map<String, Object> variables) {
  5. if (ObjectUtil.isNotNull(procDef) && procDef.isSuspended()) {
  6. throw new ServiceException("流程已被挂起,请先激活流程");
  7. }
  8. // 设置流程发起人Id到流程中,包括变量
  9. String userStr = TaskUtils.getUserName();
  10. SysUser sysUsr = sysUserService.selectUserByUserName(userStr);
  11. setFlowVariables(sysUsr,variables);
  12. Map<String, Object> variablesnew = variables;
  13. Map<String, Object> usermap = new HashMap<String, Object>();
  14. List<String> userlist = new ArrayList<String>();
  15. boolean bparallelGateway = false;
  16. boolean bapprovedEG = false;
  17. //业务数据id
  18. String dataId = variables.get("dataId").toString();
  19. if(StringUtils.isNotEmpty(dataId)) {//自定义业务表单
  20. //设置自定义表单dataid的数据
  21. WfMyBusiness flowmybusiness = wfMyBusinessServiceImpl.getByDataId(variables.get("dataId").toString());
  22. String serviceImplName = flowmybusiness.getServiceImplName();
  23. WfCallBackServiceI flowCallBackService = (WfCallBackServiceI) SpringContextUtils.getBean(serviceImplName);
  24. if (flowCallBackService!=null){
  25. Object businessDataById = flowCallBackService.getBusinessDataById(variables.get("dataId").toString());
  26. variables.put("formData",businessDataById);
  27. }
  28. }
  29. //获取下个节点信息
  30. getNextFlowInfo(procDef, variablesnew, usermap, variables, userlist);
  31. //取出两个特殊的变量
  32. if(variablesnew.containsKey("bparallelGateway")) {//并行网关
  33. bparallelGateway = (boolean) variablesnew.get("bparallelGateway");
  34. variablesnew.remove("bparallelGateway");
  35. }
  36. if(variablesnew.containsKey("bapprovedEG")) {//通用拒绝同意排它网关
  37. bapprovedEG = (boolean) variablesnew.get("bapprovedEG");
  38. variablesnew.remove("bapprovedEG");
  39. }
  40. // 发起流程实例
  41. ProcessInstance processInstance = runtimeService.startProcessInstanceById(procDef.getId(), variables);
  42. // 第一个用户任务为发起人,则自动完成任务
  43. //wfTaskService.startFirstTask(processInstance, variables);
  44. R<Void> result = setNextAssignee(processInstance, usermap, userlist, sysUsr, variables, bparallelGateway, bapprovedEG);
  45. if(StringUtils.isNotEmpty(dataId)) {//自定义业务表单
  46. // 流程发起后的自定义业务更新-需要考虑两种情况,第一个发起人审批或跳过
  47. List<Task> tasks = taskService.createTaskQuery().processInstanceId(processInstance.getProcessInstanceId()).active().list();
  48. /*======================todo 启动之后 回调以及关键数据保存======================*/
  49. //如果保存数据前未调用必调的FlowCommonService.initActBusiness方法,就会有问题
  50. LoginUser sysUser = commonService.getLoginUser();
  51. if(tasks!=null) {
  52. SysUser sysTaskUser = new SysUser();
  53. List <String> listUser = new ArrayList<String>();
  54. List <String> listId = new ArrayList<String>();
  55. List <String> listName = new ArrayList<String>();
  56. String taskUser = "";
  57. String taskid = "";
  58. String taskName = "";
  59. int taskPriority = 0;
  60. for(Task task : tasks) {
  61. if(task.getAssignee() != null) {
  62. sysTaskUser = commonService.getSysUserByUserName(task.getAssignee());
  63. listUser.add(sysTaskUser.getNickName());
  64. }
  65. listId.add(task.getId());
  66. listName.add(task.getName());
  67. taskPriority = task.getPriority();
  68. }
  69. taskUser = listUser.stream().map(String::valueOf).collect(Collectors.joining(","));
  70. taskid = listId.stream().map(String::valueOf).collect(Collectors.joining(","));
  71. taskName = listName.stream().map(String::valueOf).collect(Collectors.joining(","));
  72. WfMyBusiness business = wfMyBusinessServiceImpl.getByDataId(dataId);
  73. business.setProcessDefinitionId(procDef.getId());
  74. business.setProcessInstanceId(processInstance.getProcessInstanceId());
  75. business.setActStatus(ActStatus.doing);
  76. business.setProposer(sysUser.getUsername());
  77. business.setTaskId(taskid);
  78. business.setTaskName(taskName);
  79. business.setTaskNameId(taskid);
  80. business.setPriority(String.valueOf(taskPriority));
  81. business.setDoneUsers("");
  82. business.setTodoUsers(taskUser);
  83. wfMyBusinessService.updateById(business);
  84. //spring容器类名
  85. String serviceImplNameafter = business.getServiceImplName();
  86. WfCallBackServiceI flowCallBackServiceafter = (WfCallBackServiceI) SpringContextUtils.getBean(serviceImplNameafter);
  87. // 流程处理完后,进行回调业务层
  88. business.setValues(variables);
  89. if (flowCallBackServiceafter!=null)flowCallBackServiceafter.afterFlowHandle(business);
  90. }
  91. else {
  92. WfMyBusiness business = wfMyBusinessServiceImpl.getByDataId(dataId);
  93. business.setProcessDefinitionId(procDef.getId());
  94. business.setProcessInstanceId(processInstance.getProcessInstanceId());
  95. business.setActStatus(ActStatus.pass);
  96. business.setProposer(sysUser.getUsername());
  97. business.setTaskId("");
  98. business.setTaskName("");
  99. business.setTaskNameId("");
  100. business.setDoneUsers("");
  101. business.setTodoUsers("");
  102. wfMyBusinessService.updateById(business);
  103. //spring容器类名
  104. String serviceImplNameafter = business.getServiceImplName();
  105. WfCallBackServiceI flowCallBackServiceafter = (WfCallBackServiceI) SpringContextUtils.getBean(serviceImplNameafter);
  106. // 流程处理完后,进行回调业务层
  107. business.setValues(variables);
  108. if (flowCallBackServiceafter!=null)flowCallBackServiceafter.afterFlowHandle(business);
  109. }
  110. }
  111. return result;
  112. }

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

  1. /**
  2. * 获取历史流程表单信息
  3. */
  4. private List<FormConf> processFormList(BpmnModel bpmnModel, HistoricProcessInstance historicProcIns, String dataId) {
  5. List<FormConf> procFormList = new ArrayList<>();
  6. List<HistoricActivityInstance> activityInstanceList = historyService.createHistoricActivityInstanceQuery()
  7. .processInstanceId(historicProcIns.getId()).finished()
  8. .activityTypes(CollUtil.newHashSet(BpmnXMLConstants.ELEMENT_EVENT_START, BpmnXMLConstants.ELEMENT_TASK_USER))
  9. .orderByHistoricActivityInstanceStartTime().asc()
  10. .list();
  11. List<String> processFormKeys = new ArrayList<>();
  12. for (HistoricActivityInstance activityInstance : activityInstanceList) {
  13. // 获取当前节点流程元素信息
  14. FlowElement flowElement = ModelUtils.getFlowElementById(bpmnModel, activityInstance.getActivityId());
  15. // 获取当前节点表单Key
  16. String formKey = ModelUtils.getFormKey(flowElement);
  17. if (formKey == null) {
  18. continue;
  19. }
  20. boolean localScope = Convert.toBool(ModelUtils.getElementAttributeValue(flowElement, ProcessConstants.PROCESS_FORM_LOCAL_SCOPE), false);
  21. Map<String, Object> variables;
  22. if (localScope) {
  23. // 查询任务节点参数,并转换成Map
  24. variables = historyService.createHistoricVariableInstanceQuery()
  25. .processInstanceId(historicProcIns.getId())
  26. .taskId(activityInstance.getTaskId())
  27. .list()
  28. .stream()
  29. .collect(Collectors.toMap(HistoricVariableInstance::getVariableName, HistoricVariableInstance::getValue));
  30. } else {
  31. if (processFormKeys.contains(formKey)) {
  32. continue;
  33. }
  34. variables = historicProcIns.getProcessVariables();
  35. processFormKeys.add(formKey);
  36. }
  37. Map<String, Object> formvariables = new HashedMap<String, Object>();
  38. //遍历Map
  39. if(variables.containsKey("variables")) {
  40. formvariables = (Map<String, Object>)((Map<String, Object>) variables.get("variables")).get("formValue");
  41. }
  42. // 非节点表单此处查询结果可能有多条,只获取第一条信息
  43. List<WfDeployFormVo> formInfoList = deployFormMapper.selectVoList(new LambdaQueryWrapper<WfDeployForm>()
  44. .eq(WfDeployForm::getDeployId, historicProcIns.getDeploymentId())
  45. .eq(WfDeployForm::getFormKey, formKey)
  46. .eq(localScope, WfDeployForm::getNodeKey, flowElement.getId()));
  47. //@update by Brath:避免空集合导致的NULL空指针
  48. WfDeployFormVo formInfo = formInfoList.stream().findFirst().orElse(null);
  49. if (ObjectUtil.isNotNull(formInfo)) {
  50. // 旧数据 formInfo.getFormName() 为 null
  51. String formName = Optional.ofNullable(formInfo.getFormName()).orElse(StringUtils.EMPTY);
  52. String title = localScope ? formName.concat("(" + flowElement.getName() + ")") : formName;
  53. FormConf formConf = JsonUtils.parseObject(formInfo.getContent(), FormConf.class);
  54. if (null != formConf) {
  55. //ProcessFormUtils.fillFormData(formConf, variables);
  56. formConf.setTitle(title);
  57. formConf.setFormValues(formvariables);
  58. procFormList.add(formConf);
  59. }
  60. }
  61. }
  62. if(StringUtils.isNoneEmpty(dataId)) {
  63. WfMyBusiness business = wfMyBusinessServiceImpl.getByDataId(dataId);
  64. String serviceImplName = business.getServiceImplName();
  65. WfCallBackServiceI flowCallBackService = (WfCallBackServiceI) SpringContextUtils.getBean(serviceImplName);
  66. // 流程处理完后,进行回调业务层
  67. if (flowCallBackService!=null){
  68. Map<String, Object> customMap = new HashMap<String, Object>();
  69. FormConf formConf = new FormConf();
  70. Object businessDataById = flowCallBackService.getBusinessDataById(dataId);
  71. customMap.put("formData",businessDataById);
  72. customMap.put("routeName", business.getRouteName());
  73. formConf.setFormValues(customMap);
  74. procFormList.add(formConf);
  75. }
  76. }
  77. return procFormList;
  78. }

3、效果图如下:

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/码创造者/article/detail/852379
推荐阅读
相关标签
  

闽ICP备14008679号