当前位置:   article > 正文

Flowable工作流详细使用介绍+配置详解_org.flowable

org.flowable

flowbale工作流各个表和字段的介绍:https://www.cnblogs.com/phyger/p/14067201.html

运行官方demo:https://blog.csdn.net/u013972652/article/details/109990809

flowable使用流程:

1.首先画流程图,给流程图绑定流程变量;

2.部署流程图,产生流程定义.

3.开启流程实例

流程部署之后:act_re_deployment记录数+1;act_re_procdef记录数+1;

act_ru_actinst:运行中的节点信息表,开启流程实例后,生成流程实例id,把模型的各个节点往里边插入值.

ac_ru_identitylink开启流程实例后,该流程实例的所有的参与人放到此表中.

act_ru_variable 开启一个流程实例后,往里边插入运行中变量的id,根据流程实例查询出开启流程实例put进去的变量,随着流程的递进增加或减少,流程完毕,流程实例下变量清空,进入到了历史表中.

act_ru_execution 每一个用户节点都是一个执行的实例.但是数据根流程实例.随着流程的递进,流程完毕,进入到历史表中

act_ru_task 开启流程实例后,当前要处理的人物存储在这个表中.随着节点的递进,流程实例下的记录不断改变

 

act_hi_varinst存放所有的历史变量

act_hi_taskinst存放所有的用户任务

act_hi_procinst存放单个流程实例

act_hi_comment存放用户操作的信息,包括审批信息,附言信息等.

act_hi_actinst存放所有的节点信息

流程图绑定变量#{deptManager} 跳过表达式${deptManager==''}

下边是配置代码:flowable的maven子模块

  1. 若依后台框架整合flowable的配置
  2. flowable的maven包下的config配置
  3. @Configuration
  4. @ComponentScan(value={"org.flowable.ui.modeler.rest.app"},excludeFilters={
  5. @ComponentScan.Filter(type=FilterType.ASSIGNABLE_TYPE,value=DatabaseConfiguration.class),
  6. @ComponentScan.Filter(type=FilterType.ASSIGNABLE_TYPE,value=StencilSetResource.class),
  7. @ComponentScan.Filter(type=FilterType.ASSIGNABLE_TYPE,value=EditorUsersResource.class),
  8. @ComponentScan.Filter(type=FilterType.ASSIGNABLE_TYPE,value=EditorGroupsResource.class),
  9. })
  10. @EnableAsync
  11. public class AppDispatcherServletConfiguration implements WebMvcRegistrations{
  12. private static final LOGGER = LoggerFactory.getLogger(AppDispatcherServletConfiguration.class);
  13. @Bean
  14. public SessionLocaleResolver localeResolver(){
  15. return new SessionLocaleResolver();
  16. }
  17. @Bean
  18. public LocaleChangeInterceptor LocaleChangeInterceptor(){
  19. LOGGER.debug("Configution localeChangeInterceptor");
  20. LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();
  21. localeChangeInterceptor.setParamName("language");
  22. return localeChangeInterceptor;
  23. }
  24. @SuppressWarnings("deprecation")
  25. @Override
  26. public RequestMappingHandlerMapping getRequestMappingHandlerMapping(){
  27. RequestMappingHandlerMapping requestMappingHandlerMapping = new RequestMappingHandlerMapping();
  28. requestMappingHandlerMapping.setUseSuffixPatternMatch(false);
  29. requestMappingHandlerMapping.setRemoveSemicolonContext(false);
  30. Object [] interceptors = {localeChangeInterceptor()};
  31. requestMappingHandlerMapping.setInterceptros(interceptors);
  32. return requestMappingHandlerMapping;
  33. }
  34. }
  35. @Configuration
  36. @EnableConfigurationProperities({FlowableModelerAppProperties.class})
  37. @ComponentScan(basePackages={
  38. "org.flowable.ui.modeler.repository",
  39. "org.flowable.ui.modeler.service",
  40. "org.flowable.ui.common.service",
  41. "org.flowable.ui.common.repository",
  42. "org.flowable.ui.comon.tenant"
  43. },execludeFilters={
  44. @ComponentScan.Filter(type=FilterType.ASSIGNABLE_TYPE,value=RemoteIdmService.class)
  45. })
  46. public class ApplicationConfiguration{
  47. @SuppressWarnings({"rawtypes","unchecked"})
  48. @Bean
  49. public ServletRegistrationBean apiServlet(ApplicationContext applicationContext){
  50. AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
  51. AnnotationConfigWebApplicationContext.setParent(applicationContext);
  52. AnnotationConfigWebApplicationContext.register(ApiDispatcherServletConfiguration.class);
  53. DispatcherServlet servlet = new DispatcherServlet(dispatcherServletConfiguration)
  54. ServletRegistrationBean registrationBean = new ServletRegistrationBean(servlet,"/api/*");
  55. registrationBean.setName("Flowable IDM App API Servlet");
  56. registrationBean.setLoadOnStartup(1);
  57. registrationBean.setAsyncSupoorted(true);
  58. return registrationBean;
  59. }
  60. @Bean
  61. public HttpFirewall allowUrlEncodedSlashHttpFirewall(){
  62. StricHttpFirewall firewall = new StrictHttpFirewall();
  63. firewall.setAllowUrlEncodeSlash(true);
  64. return firewall;
  65. }
  66. }
  67. @Configutation
  68. public class DatabaseLiquiAutoConfiguration{
  69. private static final Logger LOGGER = LoggerFactory.getLogger(DatabaseLiquiAutoConfigutation.class);
  70. protect static fianl String LIQUIBASE_CHANGELOG_PREFIX = "ACT_DE_";
  71. @Bean
  72. public Liquibase liquibase(DataSource dataSource){
  73. LOGGER.info("configuring Liquibase");
  74. Liquibase liquibase = null;
  75. try{
  76. DatabaseConnection connection = new JdbcConnection(dataSource.getConnection());
  77. Databse database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(connection);
  78. database.setDatabaseChangeLogTableName(LIQUIBASE_CHANGELOG_PREFIX+database.getDatabaseChangeLogTableName());
  79. database.setDatabaseChangeLogLockTableName(LIQUIBASE_CHANGELOG_PREFIX=database.getDatabaseChangeLogLockTableName());
  80. liquibase = new Liquibase("META_INF/liquibase/flowable0modeler-app-db-changelog.xml",new ClassLoaderResourceAccessor(),database);
  81. liquibase.updata("flowable");
  82. return liquibase;
  83. }catch(Exception e){
  84. throw new InternalServerErrorException("Error creating liquibase database",e)
  85. }finally{
  86. closeDatabase(liquibase);
  87. }
  88. }
  89. public void closeDatabase(Liquibase liquibase){
  90. if(liquibase!=null){
  91. Database database = liquibase.getDatabase();
  92. if(database!=null){
  93. try{
  94. database.close();
  95. }catch(DatabaseException e){
  96. LOGGER.warn("Error closing database",e);
  97. }
  98. }
  99. }
  100. }
  101. }
  102. @Api
  103. @RestController
  104. @RequestMapping("/app")
  105. public class FlowableStencilSetResource{
  106. private static final Logger LOGGER = LoggerFactory.getLogger(FlowableStencilSetResource.class);
  107. @Autowired
  108. protected ObjectMapper objectMapper;
  109. @ApiOperation("获取bpmn sets文件")
  110. @RequestMapping(value="rest/stencli-sets/editor",method=RequestMethod.GET,produces="application/json")
  111. public JsonNode getStencilSetForEditor(){
  112. try{
  113. InputStream is = this.getClass().getClassLoader().getReourceAsStream("stencilset/stencilset_bpmn.json");
  114. JsonNode stencilNode = objectMapper.readTree(is);
  115. return stencilNode;
  116. }catch(Exception e){
  117. LOGGER.error("Error reading bpmn stencil set json",e);
  118. throw new InternalServerErrorException("Error reading bpmn stencli set json");
  119. }
  120. }
  121. @ApiOperation(value="获取cmmn sets文件")
  122. @RequestMapping(value="/rest/stencil-sets/cmmneditor",method=RequestMethod.GET,produces="application/json")
  123. public JsonNode getCmmnStencilSetForEditor(){
  124. try{
  125. JsonNode stencilNode = objectMapper.readTree(this.getClass.getClassLoader().getResourceAsStream("stencilset/stencilset_cmmn.json"));
  126. return stencilNode;
  127. }catch(Exception e){
  128. LOGGER.error("Error reading bpmn stencli set json",e);
  129. throw new InternalSeverErrorException("Error reading bpmn stencil set json")
  130. }
  131. }
  132. }
  133. //流程引擎配置文件
  134. @Configuration
  135. public class ProcessEngineConfig{
  136. private Logger logger = LoggerFactory.getLogger(ProcessEngineConfig.class);
  137. @Bean
  138. public SpringProcessEngineConfiguration springProcessEngineConfiuration(DataSourceTransactionManager datasourceTransactionManager,DataSource dataSource){
  139. SpringProcessEngineConfiguration.springProcessEngineConfiguration = new SpringProcessEngineConfiguration();
  140. springProcessEngineConfiguration.setDataSource(dataSource);
  141. springProcessEngineConfiguration.setTransactionManager(datasourceTransactionManager);
  142. springProcessEngineConfiguration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEME_UPDATE_TRUE);
  143. springProcessEngineConfiguration.setAsyncExcutorActivate(true);
  144. springProcessEngineConfiguration.setActivityFontName();
  145. springProcessEngineConfiguration.setLabelFontName();
  146. springProcessEngineConfiguration.setAnnotationFontName();
  147. return springProcessEngineConfiguration;
  148. }
  149. }
  150. FlowableController.java
  151. @Api(tags="flowable测试接口")
  152. @RestController
  153. @RequestMapping("/flowable")
  154. public class FlowableController{
  155. @Autowired
  156. private IdentityService identityService;
  157. @Autowired
  158. private RepositoryService repositoryService;
  159. @Autowired
  160. private RuntimeService runtimeService;
  161. @Autowired
  162. private TaskService taskService;
  163. @Autowired
  164. private ProcessEngine processEngine;
  165. @ApiOperation("新建用户")
  166. @GetMaping("/user/createUser",produces={"application/json"})
  167. public User createUser(String name,String firstName,String lastName){
  168. User user = identityService.newUser(name);
  169. user.setFirstName(firstName);
  170. user.setLastName(lastName);
  171. user.setEmail("123@qq.com");
  172. user.setPassword("123456");
  173. identityService.saveUser(user);
  174. return user; //org.flowable.idm.api.User;
  175. }
  176. @ApiOperation("获取用户的任务")
  177. @GetMapping("value=/getTasks/{userId}",produces={"application/json"})
  178. public List<Title> getTasks(@PathVariable String userId){
  179. return taskService.createTaskQuery().taskAssignee(userId).orderByTaskCreateTime().desc().list();
  180. }
  181. @ApiOperation("审批不通过")
  182. @PostMapping("value=/faile/{taskId}")
  183. public String faile(@PathVariable String taskId){
  184. Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
  185. if(task == null){
  186. return "流程不存在";
  187. }
  188. HashMap<String,Object> map = new HashMap<>();
  189. map.put("approved",false);
  190. taskService.complete(taskId,map);
  191. return "审批不通过";
  192. }
  193. @ApiOperation("获取流程图")
  194. @PostMapping(value="processDiagram")
  195. public void getProcessDiagram(HttpServletResponse response,String processId) throws IOException{
  196. ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(processId).singleResult();
  197. //流程走完的不显示图
  198. if(pi==null){
  199. return;
  200. }
  201. Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
  202. String instanceId = task.getProcessInstanceId();
  203. List<Execution> executions = runtimeService.createExecutionQuery().processInstanceId(instanceId).list();
  204. List<String> activityIds = new ArrayList<>();
  205. List<String> flows = new ArrayList<>();
  206. for(Execution exe:executions){
  207. List<String> ids = runtimeService.getActiveActivityIds(exe.getId());
  208. activityIds.addAll(ids);
  209. }
  210. //获取流程图
  211. BpmnModel bpmnModel = repositoryService.getBpmnModel(pi.getProcessDefinitionId());
  212. ProcessEngineConfiguration engconf = processEngine.getprocessEngineConfiguration();
  213. ProcesDiagramGenerator diagramGenerator = engconf.getProcessDiagramGenerator();
  214. InputStream in = diagramGeneratro.generateDiagram(bpmnMode,"png",activityIds,flows,engconf.getActivityFontName(),engconf.getLabelFontName(),engconf.getAnnotaionFontName(),
  215. engconf.getClassLoader(),1.0,true);
  216. OutputStream out = null;
  217. byte[] buf = new byte[1024];
  218. int length = 0;
  219. try{
  220. out = response.getOutputStream();
  221. while((length=in.read(buf))!=-1){
  222. out.write(buf,0,length);
  223. }
  224. }finally{
  225. if(in!=null){
  226. in.close();
  227. }
  228. if(out!=null){
  229. out.close();
  230. }
  231. }
  232. }
  233. }
  234. ModelController.java
  235. @Api(tags="流程管理模块")
  236. @RestController
  237. @RequestMapping("/modelmanager")
  238. public class ModelController{
  239. private static final Logger LOGGER = LoggerFactory.getLogger(ModelController.class);
  240. @Autowired
  241. private IFlowableModelService flowableModelService;
  242. @Autowired
  243. private ModelService modelService;
  244. @Autowired
  245. private ProcessEngine processEngine;
  246. @Autowired
  247. private AddFlwProcessModelService addFlwProcessModelService;
  248. @Autowired
  249. private TokenService tokenService;
  250. @ApiOperation("获取模型列表")
  251. @GetMapping("/list-model")
  252. public ReturnVo<List<ChildModel>> listModel(){
  253. ReturnVo<List<ChildModel>> returnVo = new ReturnVo<>(ReturnCode.SUCCESS,"OK");
  254. List<AbstractModel> datas = modelService.getModelByModelType(Abstract.MODEL_TYPE_BPMN);
  255. ..........
  256. .........
  257. ........
  258. }
  259. }

 

 

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号