前言
activiti是目前比拟风行的工作流框架,然而activiti学起来还是吃力,还是有点难度的,如何整合在线编辑器,如何和业务表单绑定,如何和零碎权限绑定,这些问题都是要思考到的,不是说纯正的把activiti整合到零碎中就完事了。现在国内比拟风行的是前后端拆散模式,之前都是前后端放一个工程外面,接口格调很乱,并且不好保护,前后端开发不是很不便。目前前端都做成了工程化的模式,比方国产的Vue,国外的React等等。为了顺应潮流,我就做了一套springboot-vue-activiti的疾速开发小脚手架,对于大型项目来说还是不太适宜,毕竟来说,一个人的开发能力无限,然而对于中小微型我的项目,并且带有审批业务的我的项目来说,那几乎就是一个福音了。
一、成果展现
1.模型设计器
2.流程节点设置
审批人员能够依据角色、部门、部门负责人、间接抉择人员等。
3.审批进度查问
二、操作过程
1.引入activiti依赖
<!-- Activiti 启动器 --> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-spring-boot-starter-basic</artifactId> <version>${activiti.version}</version> <exclusions> <exclusion> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> </exclusion> </exclusions> </dependency> <!-- Activiti 流程图 --> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-diagram-rest</artifactId> <version>${activiti.version}</version> </dependency> <!-- Activiti 在线设计 --> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-modeler</artifactId> <version>${activiti.version}</version> </dependency>
2.编辑器代码及汉化
3.application.yml配置
activiti: check-process-definitions: false #启用作业执行器 async-executor-activate: false #启用异步执行器 job-executor-activate: false
4.数据库表
三、业务表单和零碎权限绑定
1.思路
1.新建一张流程定义扩大表(用来存储流程部署的根本信息、关联业务表名、前端路由信息、业务表单类型等),流程部署完后往流程定义扩大表插入部署根本信息,而后编辑已公布的流程,往扩大表中插入本流程的分类,关联表单信息。
2.对于自定义节点设置,次要是用来定义每个节点由哪个角色,或者具体哪个人来审批。建设一张节点扩大表(存储节点流转信息,指定人ID、角色ID,等)。
2.局部代码
// 获取模型 Model modelData = repositoryService.getModel(id); byte[] bytes = repositoryService.getModelEditorSource(modelData.getId()); if (bytes == null) { return Result.error("模型数据为空,请先胜利设计流程并保留"); } try { JsonNode modelNode = new ObjectMapper().readTree(bytes); BpmnModel model = new BpmnJsonConverter().convertToBpmnModel(modelNode); if(model.getProcesses().size()==0){ return Result.error("模型不符要求,请至多设计一条主线流程"); } byte[] bpmnBytes = new BpmnXMLConverter().convertToXML(model); // 部署公布模型流程 String processName = modelData.getName() + ".bpmn20.xml"; Deployment deployment = repositoryService.createDeployment() .name(modelData.getName()) .addString(processName, new String(bpmnBytes, "UTF-8")) .deploy(); String metaInfo = modelData.getMetaInfo(); JSONObject metaInfoMap = JSON.parseObject(metaInfo); // 设置流程分类,保留扩大流程至数据库 List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).list(); for (ProcessDefinition pd : list) { ActZprocess actZprocess = new ActZprocess(); actZprocess.setId(pd.getId()); actZprocess.setName(modelData.getName()); actZprocess.setProcessKey(modelData.getKey()); actZprocess.setDeploymentId(deployment.getId()); actZprocess.setDescription(metaInfoMap.getString(ModelDataJsonConstants.MODEL_DESCRIPTION)); actZprocess.setVersion(pd.getVersion()); actZprocess.setDiagramName(pd.getDiagramResourceName()); actZprocessService.setAllOldByProcessKey(modelData.getKey()); actZprocess.setLatest(true); actZprocessService.save(actZprocess); } }catch (Exception e){ String err = e.toString(); log.error(e.getMessage(),e); if (err.indexOf("NCName")>-1){ return Result.error("部署失败:流程设计中的流程名称不能为空,不能为数字以及特殊字符结尾!"); } if (err.indexOf("PRIMARY")>-1){ return Result.error("部署失败:该模型已公布,key惟一!"); } return Result.error("部署失败!"); } return Result.ok("部署胜利");
/*获取高亮实时流程图*/ @RequestMapping(value = "/getHighlightImg/{id}", method = RequestMethod.GET) public void getHighlightImg(@PathVariable String id, HttpServletResponse response){ InputStream inputStream = null; ProcessInstance pi = null; String picName = ""; // 查问历史 HistoricProcessInstance hpi = historyService.createHistoricProcessInstanceQuery().processInstanceId(id).singleResult(); if (hpi.getEndTime() != null) { // 曾经完结流程获取原图 ProcessDefinition pd = repositoryService.createProcessDefinitionQuery().processDefinitionId(hpi.getProcessDefinitionId()).singleResult(); picName = pd.getDiagramResourceName(); inputStream = repositoryService.getResourceAsStream(pd.getDeploymentId(), pd.getDiagramResourceName()); } else { pi = runtimeService.createProcessInstanceQuery().processInstanceId(id).singleResult(); BpmnModel bpmnModel = repositoryService.getBpmnModel(pi.getProcessDefinitionId()); List<String> highLightedActivities = new ArrayList<String>(); // 高亮工作节点 List<Task> tasks = taskService.createTaskQuery().processInstanceId(id).list(); for (Task task : tasks) { highLightedActivities.add(task.getTaskDefinitionKey()); } List<String> highLightedFlows = new ArrayList<String>(); ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator(); //"宋体" inputStream = diagramGenerator.generateDiagram(bpmnModel, "png", highLightedActivities, highLightedFlows, "宋体", "宋体", "宋体",null, 1.0); picName = pi.getName()+".png"; } try { response.setContentType("application/octet-stream;charset=UTF-8"); response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(picName, "UTF-8")); byte[] b = new byte[1024]; int len = -1; while ((len = inputStream.read(b, 0, 1024)) != -1) { response.getOutputStream().write(b, 0, len); } response.flushBuffer(); } catch (IOException e) { log.error(e.toString()); throw new JeecgBootException("读取流程图片失败"); } }
总结
下面只是展现了局部代码和局部效果图,对于一个失常的审批流转业务来说,提交审批,申请人撤销,从新申请,审批人驳回,委托别人审批,会签,流程挂起,流程实时跟踪,并行网关,排他网关,监听,待办,已办音讯告诉等都是必须要的,我这就不一一展示了,如有须要,能够+q:2500564056。