content: package com.open.capacity.activiti.config;
  
  import com.fasterxml.jackson.databind.ObjectMapper;
  import org.activiti.engine.*;
  import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
  import org.activiti.spring.ProcessEngineFactoryBean;
  import org.activiti.spring.SpringProcessEngineConfiguration;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.transaction.PlatformTransactionManager;
  
  import javax.sql.DataSource;
  
  /**
   * @Author: [gitgeek]
   * @Date: [2018-05-14 20:21]
   * @Description: [ activiti工作流配置 ]
   * @Version: [1.0.0]
   * @Copy: [com.zzg]
   */
  @Configuration
  public class ActivitiConfig {
  
      /**
       * spring 集成 activiti
       */
      @Bean
      public ProcessEngineConfiguration processEngineConfiguration(DataSource dataSource, PlatformTransactionManager transactionManager) {
          SpringProcessEngineConfiguration processEngineConfiguration = new SpringProcessEngineConfiguration();
          processEngineConfiguration.setDataSource(dataSource);
          //表不存在创建表
          processEngineConfiguration.setDatabaseSchemaUpdate("true");
          //指定数据库
          processEngineConfiguration.setDatabaseType("mysql");
          processEngineConfiguration.setTransactionManager(transactionManager);
          //历史变量
          processEngineConfiguration.setHistory("full");
          //指定字体
          processEngineConfiguration.setActivityFontName("宋体");
          processEngineConfiguration.setAnnotationFontName("宋体");
          processEngineConfiguration.setLabelFontName("宋体");
  
          return processEngineConfiguration;
      }
  
      //流程引擎，与spring整合使用factoryBean
      @Bean
      public ProcessEngineFactoryBean processEngine(ProcessEngineConfiguration processEngineConfiguration) {
          ProcessEngineFactoryBean processEngineFactoryBean = new ProcessEngineFactoryBean();
          processEngineFactoryBean.setProcessEngineConfiguration((ProcessEngineConfigurationImpl) processEngineConfiguration);
          return processEngineFactoryBean;
      }
  
      @Bean
      public RepositoryService repositoryService(ProcessEngine processEngine) {
          return processEngine.getRepositoryService();
      }
  
      @Bean
      public RuntimeService runtimeService(ProcessEngine processEngine) {
          return processEngine.getRuntimeService();
      }
  
      @Bean
      public TaskService taskService(ProcessEngine processEngine) {
          return processEngine.getTaskService();
      }
  
      @Bean
      public HistoryService historyService(ProcessEngine processEngine) {
          return processEngine.getHistoryService();
      }
  
      @Bean
      public FormService formService(ProcessEngine processEngine) {
          return processEngine.getFormService();
      }
  
      @Bean
      public IdentityService identityService(ProcessEngine processEngine) {
          return processEngine.getIdentityService();
      }
  
      @Bean
      public ManagementService managementService(ProcessEngine processEngine) {
          return processEngine.getManagementService();
      }
  
      @Bean
      public DynamicBpmnService dynamicBpmnService(ProcessEngine processEngine) {
          return processEngine.getDynamicBpmnService();
      }
  
      @Bean
      public ObjectMapper objectMapper() {
          return new ObjectMapper();
      }
  }
  