activiti combat

database

  • 1. act_ge_ General data table, ge is the abbreviation of general
  • 2, act_hi_ historical data table, hi is the abbreviation of history, corresponding to the HistoryService interface
  • 3. act_id_ Identity data table, id is the abbreviation of identity, corresponding to the IdentityService interface
  • 4, act_re_ process storage table, re is the abbreviation of repository, corresponding to the RepositoryService interface, storing static data such as process deployment and process definition
  • 5, act_ru_ runtime data table, ru is the abbreviation of runtime, corresponding to the RuntimeService interface and TaskService interface, storing dynamic data such as process instances and user tasks

interface

Insert picture description here

ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

RuntimeService runtimeService = processEngine.getRuntimeService();
RepositoryService repositoryService = processEngine.getRepositoryService();
TaskService taskService = processEngine.getTaskService();
ManagementService managementService = processEngine.getManagementService();
IdentityService identityService = processEngine.getIdentityService();
HistoryService historyService = processEngine.getHistoryService();
FormService formService = processEngine.getFormService();
  • RepositoryService: Provides a series of management process deployment and process definition APIs.
  • RuntimeService: Manage and control process instances while the process is running.
  • TaskService: Manage process tasks, such as task reminders, task completion, and task creation.
  • IdentityService: Provides APIs for managing process role data. These role data include user groups, users, and the relationships between them.
  • ManagementService: Provides services for management and maintenance of process engines.
  • HistoryService: Operate on the historical data of the process, including querying and deleting these historical data.
  • FormService: Form service.

web process design tool

1. Deploy the process designer application activiti-app.war provided by Activiti to the Tomcat webapps directory.
2. Create a new MySql database. Modify the db.properties configuration file in the activiti-app \ WEB-INF \ classes \ META-INF \ activiti-app directory to use the MySql database (the H2 memory database is used by default, and the created model will be lost after restart)
3. Open the browser and enter http: // localhost: 8080 / activiti-explorer, use the user kermit and password kermit to log in
Insert picture description here
Insert picture description here
Insert picture description here

Design a leave process

Process creation and deployment The
Insert picture description here
Insert picture description here
process information is as follows:
Insert picture description here
Initiate the application, which is 1 day and 4 days respectively.
Insert picture description here
Convert system users to activiti users

	User user=identityService.newUser(*sysUser.getLoginName()*);
				user.setLastName(*sysUser.getUserName()*);
				user.setFirstName*(sysUser.getUserName()*);
				user.setEmail(*sysUser.getEmail()*);
				identityService.saveUser(user);

Insert picture description hereCreate a group (corresponding to the group in the leave process)

	Group  group = identityService.newGroup(*idGroup.getId()*);
		group.setName(*idGroup.getName()*);
		group.setType(*idGroup.getType()*);
		identityService.saveGroup(group);

Insert picture description here
User group binding
Insert picture description here
View task

	//查出当前登录用户所在的用户组
		List<Group> groups = identityService.createGroupQuery()
				.groupMember(String.valueOf(getLoginName())).list();
		List<String> groupNames = groups.stream()
				.map(group -> group.getId()).collect(Collectors.toList());
		  if (groups == null){
			return null;
		  }
//查询用户组的待审批请假流程列表
		List<Task> tasks = taskService.createTaskQuery()
				//指定任务
				//.processDefinitionKey(ActConstant.ProcessInstance_QingJia)
				.taskCandidateGroupIn(groupNames)
				.listPage(pageDomain.getPageNum() - 1, pageDomain.getPageSize());
  //获取下个节点 信息
		ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(newOaTask.getProcessInstanceId()).singleResult();
		if(pi==null){
			log.info("insertLeaveApply 流程 {} 结束" ,id);
		}else{
			Task nextTask = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
			log.info("insertLeaveApply 流程 {} 进行中 ,下个任务 {}",id,nextTask.getId());
		}

Insert picture description here

(Manager Approval)-User login for manager role [This task ID is the first time when it is approved, it is different from the above, please ignore]

//查询当前审批节点
        Task task = taskService.createTaskQuery().taskId(id).singleResult();
        if (ActConstant.ProcessResult_PASS.equals(auditResult)){  
           //通过
            //设置流程参数
            Map<String, Object> args = new HashMap<>();
            args.put("auditId", task.getId());
            //设置审批任务的执行人
            taskService.claim(task.getId(), getLoginName());
            //完成审批任务
            taskService.complete(task.getId(), args);
        }else{
          //  不通过
            runtimeService.deleteProcessInstance(task.getProcessInstanceId(), task.getId());
        }

Insert picture description here

After that, you can see the flow of the process ...
Insert picture description here
(Director's review)-User login of the role of the director The
Insert picture description here
process flows to hr
Insert picture description here
hr Login to view the task
Insert picture description here
Review a
Insert picture description here

Integrated springboot

package com.platform.config;

import org.activiti.engine.*;
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.activiti.engine.impl.history.HistoryLevel;
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 liuli
 * 7大接口
 * RepositoryService:提供一系列管理流程部署和流程定义的API。
 * RuntimeService:在流程运行时对流程实例进行管理与控制。
 * TaskService:对流程任务进行管理,例如任务提醒、任务完成和创建任务等。
 * IdentityService:提供对流程角色数据进行管理的API,这些角色数据包括用户组、用户及它们之间的关系。
 * ManagementService:提供对流程引擎进行管理和维护的服务。
 * HistoryService:对流程的历史数据进行操作,包括查询、删除这些历史数据。
 * FormService:表单服务。
 *
 * 1、act_ge_ 通用数据表,ge是general的缩写
 * 2、act_hi_ 历史数据表,hi是history的缩写,对应HistoryService接口
 * 3、act_id_ 身份数据表,id是identity的缩写,对应IdentityService接口
 * 4、act_re_ 流程存储表,re是repository的缩写,对应RepositoryService接口,存储流程部署和流程定义等静态数据
 * 5、act_ru_ 运行时数据表,ru是runtime的缩写,对应RuntimeService接口和TaskService接口,存储流程实例和用户任务等动态数据
 */
@Configuration
public class ActivitiConfig
{
    @Bean
    public ProcessEngineConfiguration processEngineConfiguration(DataSource dataSource, PlatformTransactionManager transactionManager)
    {
        SpringProcessEngineConfiguration processEngineConfiguration = new SpringProcessEngineConfiguration();
        processEngineConfiguration.setDataSource(dataSource);
        /**
         * false:false为默认值,设置为该值后,Activiti在启动时,会对比数据库表中保存的版本,如果没有表或者版本不匹配时,将在启动时抛出异常。
         * true:设置为该值后,Activiti会对数据库中所有的表进行更新,如果表不存在,则Activiti会自动创建。
         * create-drop:Activiti启动时,会执行数据库表的创建操作,在Activiti关闭时,执行数据库表的删除操作。
         * drop-create:Activiti启动时,执行数据库表的删除操作在Activiti关闭时,会执行数据库表的创建操作。
         */
        processEngineConfiguration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
        processEngineConfiguration.setDatabaseType("mysql");
        processEngineConfiguration.setTransactionManager(transactionManager);
        // 流程图字体
        processEngineConfiguration.setActivityFontName("宋体");
        processEngineConfiguration.setAnnotationFontName("宋体");
        processEngineConfiguration.setLabelFontName("宋体");
        /**
         * 保存历史数据级别设置为full最高级别,便于历史数据的追溯
         * none:不保存任何的历史数据,因此,在流程执行过程中,这是最高效的。
         * activity:级别高于none,保存流程实例与流程行为,其他数据不保存。
         * audit:除activity级别会保存的数据外,还会保存全部的流程任务及其属性。audit为history的默认值。
         * full:保存历史数据的最高级别,除了会保存audit级别的数据外,还会保存其他全部流程相关的细节数据,包括一些流程参数等。
         */
        //使用系统业务自定义的
        processEngineConfiguration.setHistoryLevel(HistoryLevel.NONE);
        // 用户验证表改成使用视图
        processEngineConfiguration.setDbIdentityUsed(false);

        return processEngineConfiguration;
    }

    @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();
    }
}

Time and space issues This value provides a rough idea and key business code, if you do n’t understand, please contact me to discuss

Reference materials:
http://www.mossle.com/docs/activiti/index.html#activitiExplorer
https://juejin.im/post/5a4064365188252b145b4560
https://www.jianshu.com/p/701056e672a4

Published 51 original articles · won praise 2 · Views 6374

Guess you like

Origin blog.csdn.net/wenwang3000/article/details/102859178