springboot2.2
activiti6.0
activiti-modeler 5.22.0
注明:版本不一样会导致报错
效果图
代码分享:
链接:https://pan.baidu.com/s/1F1lmE4F6ykVY1UPl6NcRaQ
提取码:1234
pom文件
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com</groupId>
<artifactId>springboot_activiti</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot_activiti</name>
<description>Demo project for Spring Boot</description>
<properties>
<springboot.version>2.2.0.RELEASE</springboot.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<activiti.version>6.0.0</activiti.version>
</properties>
<dependencies>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-engine</artifactId>
<version>${activiti.version}</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring</artifactId>
<version>${activiti.version}</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<artifactId>spring-context</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>spring-jdbc</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>spring-tx</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>spring-orm</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>spring-beans</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>mybatis</artifactId>
<groupId>org.mybatis</groupId>
</exclusion>
<exclusion>
<artifactId>activation</artifactId>
<groupId>javax.activation</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-basic</artifactId>
<version>${activiti.version}</version>
</dependency>
<!-- Activiti 流程图 -->
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-common-rest</artifactId>
<version>${activiti.version}</version>
</dependency>
<!-- Activiti 在线设计 -->
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-modeler</artifactId>
<version>5.22.0</version>
<exclusions>
<exclusion>
<artifactId>spring-beans</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>spring-context</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>spring-core</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>spring-tx</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>spring-web</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>spring-security-config</artifactId>
<groupId>org.springframework.security</groupId>
</exclusion>
<exclusion>
<artifactId>spring-security-core</artifactId>
<groupId>org.springframework.security</groupId>
</exclusion>
<exclusion>
<artifactId>spring-security-crypto</artifactId>
<groupId>org.springframework.security</groupId>
</exclusion>
<exclusion>
<artifactId>spring-security-web</artifactId>
<groupId>org.springframework.security</groupId>
</exclusion>
<exclusion>
<artifactId>spring-webmvc</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<artifactId>activation</artifactId>
<groupId>javax.activation</groupId>
</exclusion>
<exclusion>
<artifactId>commons-io</artifactId>
<groupId>commons-io</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>${springboot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.10.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<port>8081</port>
<path>/activity</path>
<systemProperties>
<com.sun.management.jmxremote.port>4000</com.sun.management.jmxremote.port>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
页面代码介绍:
springboot静态文件处理
@Configuration public class WebConfig implements WebMvcConfigurer { @Override public void addResourceHandlers(ResourceHandlerRegistry registry){ registry.addResourceHandler("/html/**").addResourceLocations("classpath:/html/"); registry.addResourceHandler("/diagram-viewer/**").addResourceLocations("classpath:/html/"); registry.addResourceHandler("/editor-app/**").addResourceLocations("classpath:/html/"); registry.addResourceHandler("/js/**").addResourceLocations("classpath:/js/"); registry.addResourceHandler("/css/**").addResourceLocations("classpath:/css/"); } }
获取json数据的请求
@RestController public class Test01Controller { @RequestMapping("/editor/stencilset") public String test01(){ InputStream stream=this.getClass().getClassLoader().getResourceAsStream("stencilset.json"); try{ return IOUtils.toString(stream,"utf-8"); }catch (Exception e){ } return null; } }
在线设计流程新建model
@Controller @RequestMapping("model") public class ModelTest { @RequestMapping("create") public void createModel(HttpServletRequest request, HttpServletResponse response){ try{ String modelName = "modelName6"; String modelKey = "modelKey66"; String description = "modelKey666"; ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); RepositoryService repositoryService = processEngine.getRepositoryService(); ObjectMapper objectMapper = new ObjectMapper(); ObjectNode editorNode = objectMapper.createObjectNode(); editorNode.put("id", "canvas"); editorNode.put("resourceId", "canvas"); ObjectNode stencilSetNode = objectMapper.createObjectNode(); stencilSetNode.put("namespace", "http://b3mn.org/stencilset/bpmn2.0#"); editorNode.put("stencilset", stencilSetNode); Model modelData = repositoryService.newModel(); ObjectNode modelObjectNode = objectMapper.createObjectNode(); modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, modelName); modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1); modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, description); modelData.setMetaInfo(modelObjectNode.toString()); modelData.setName(modelName); modelData.setKey(modelKey); //保存模型 repositoryService.saveModel(modelData); repositoryService.addModelEditorSource(modelData.getId(), editorNode.toString().getBytes("utf-8")); response.sendRedirect(request.getContextPath() + "/html/modeler.html?modelId=" + modelData.getId()); }catch (Exception e){ } } }
画流程图保存请求
@RequestMapping("/model/{modelId}/save") @ResponseStatus(HttpStatus.OK) public void saveModel(@PathVariable String modelId, HttpServletRequest req, HttpServletResponse resp) { try { Model model = this.repositoryService.getModel(modelId); ObjectNode modelJson = (ObjectNode)this.objectMapper.readTree(model.getMetaInfo()); modelJson.put("name", req.getParameter("name")); modelJson.put("description",req.getParameter("description")); model.setMetaInfo(modelJson.toString()); model.setName(req.getParameter("name")); this.repositoryService.saveModel(model); this.repositoryService.addModelEditorSource(model.getId(), (req.getParameter("json_xml")).getBytes("utf-8")); InputStream svgStream = new ByteArrayInputStream((req.getParameter("svg_xml")).getBytes("utf-8")); TranscoderInput input = new TranscoderInput(svgStream); PNGTranscoder transcoder = new PNGTranscoder(); ByteArrayOutputStream outStream = new ByteArrayOutputStream(); TranscoderOutput output = new TranscoderOutput(outStream); transcoder.transcode(input, output); byte[] result = outStream.toByteArray(); System.out.println(new String(result,"utf-8")); this.repositoryService.addModelEditorSourceExtra(model.getId(), result); outStream.close(); } catch (Exception var11) { LOGGER.error("Error saving model", var11); throw new ActivitiException("Error saving model", var11); } }
流程图查看的请求
@RequestMapping( value = {"/model/{modelId}/json"}, method = {RequestMethod.GET}, produces = {"application/json"} ) public ObjectNode getEditorJson(@PathVariable String modelId) { ObjectNode modelNode = null; Model model = this.repositoryService.getModel(modelId); if (model != null) { try { if (StringUtils.isNotEmpty(model.getMetaInfo())) { modelNode = (ObjectNode)this.objectMapper.readTree(model.getMetaInfo()); } else { modelNode = this.objectMapper.createObjectNode(); modelNode.put("name", model.getName()); } modelNode.put("modelId", model.getId()); ObjectNode editorJsonNode = (ObjectNode)this.objectMapper.readTree(new String(this.repositoryService.getModelEditorSource(model.getId()), "utf-8")); modelNode.put("model", editorJsonNode); } catch (Exception var5) { LOGGER.error("Error creating model JSON", var5); throw new ActivitiException("Error creating model JSON", var5); } } return modelNode; }
流程图保存成功以后这张表会有数据
流程图部署以后会出现bomn结尾的文件,
部署流程的请求,根据modelId
@RequestMapping("/model/test02") public void test02(Object obj) throws Exception { Model modelData = repositoryService.getModel("40001"); ObjectNode modelNode = (ObjectNode) new ObjectMapper().readTree(repositoryService.getModelEditorSource(modelData.getId())); byte[] bpmnBytes = null; BpmnModel model = new BpmnJsonConverter().convertToBpmnModel(modelNode); bpmnBytes = new BpmnXMLConverter().convertToXML(model); String processName = modelData.getName() + ".bpmn"; Deployment deployment = repositoryService.createDeployment() .name(modelData.getName()).addString(processName, new String(bpmnBytes,"UTF-8")) .deploy(); }
根据这个表的key进行流程启动,指定审批人
随意写了一些demo。。。。
重点步骤 就是新建model,保存提交部署流程,启动流程指定审批人,审批提交