公众号:架构师与哈苏
关注公众号进入it交流群! 公众号:架构师与哈苏 不定时都会推送一些实用的干货。。。

pom.xml

 <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.activiti.dependencies</groupId>
                <artifactId>activiti-dependencies</artifactId>
                <version>7.1.0.M4</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
        </dependencies>
    </dependencyManagement>



    <dependencies>

        <!-- activiti -->
        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-spring-boot-starter</artifactId>
        </dependency>
        <!-- Activiti生成流程图 -->
        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-image-generator</artifactId>
        </dependency>
        <!--<dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-engine</artifactId>
        </dependency>-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
 </dependencies>

启动类上加上配置,不使用security

@SpringBootApplication(exclude = {
        org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class,
        org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration.class
})

安装idea插件

image.png

创建流程图 bpmn

在resources/processes 下
image.png

image.png

测试类

package com.meeno.inner.oa;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;
import com.meeno.inner.oa.extend.operaterecord.enums.OperateRecordTypeEnum;
import com.meeno.inner.oa.extend.project.workreport.service.WorkReportService;
import lombok.extern.java.Log;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.assertj.core.util.Lists;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@RunWith(SpringRunner.class)
@SpringBootTest
@Log
public class OaApplicationTests {
  

    @Autowired
    private RuntimeService runtimeService;
    @Autowired
    private TaskService taskService;

    @Test
    public void startProcesses(){
        //开启流程
        ProcessInstance leave = this.runtimeService.startProcessInstanceByKey("leave");
        // 查询当前任务
        Task currentTask = taskService.createTaskQuery().processInstanceId(leave.getId()).singleResult();
        //声明任务
        taskService.claim(currentTask.getId(), "wzq");
//        taskService.setAssignee();
        // 完成任务
        //携带的参数
        Map<String,Object> params = Maps.newHashMap();
        params.put("name","吴志奇好帅!");
        taskService.complete(currentTask.getId(), params);
        System.out.println("1");
    }

    @Test
    public void findProcessesList(){
        //        / 多此一举 taskList中包含了以下内容(用户的任务中包含了所在用户组的任务)
//        Group group = identityService.createGroupQuery().groupMember(userName).singleResult();
//        List<Task> list = taskService.createTaskQuery().taskCandidateGroup(group.getId()).list();
//        taskList.addAll(list);
        /*List<Task> taskList = taskService.createTaskQuery().taskCandidateUser(userName)
                .orderByTaskCreateTime().desc().list();*/
        List<Task> taskList = taskService.createTaskQuery().taskAssignee("wzq")
                .orderByTaskCreateTime().desc().list();
        for (Task task : taskList) {
            String assignee =  task.getAssignee();
            String instanceId = task.getProcessInstanceId();
            ProcessInstance instance = runtimeService.createProcessInstanceQuery().processInstanceId(instanceId).singleResult();
            String name = this.runtimeService.getVariable(instance.getId(), "name", String.class);
            System.out.println(name);
        }
        System.out.println("findProcessesList");

    }


/*    public void passAudit(String taskId,){

        taskService.claim(taskId, userName);
        taskService.complete(taskId, vars);
    }*/



}

问题1:VERSION_ 找不到

去数据库中act_re_deployment创建两个字段
image.png

VERSION_ int
PROJECT_RELEASE_VERSION_ varchar

问题2:bpmn中午乱码问题

image.png

添加配置 重启idea

-Dfile.encoding=UTF-8

image.png

问题3:idea插件创建的bpmn启动报错

image.png

把这个

xmlns=""

删除保存 在启动项目就可以了

gitee上的demo项目

https://gitee.com/wuzhiqi123/demo-activiti

posted on 2020-09-22 12:17  公众号/架构师与哈苏  阅读(916)  评论(0编辑  收藏  举报