工作流activity

idea集成activity插件后画出审批流的bpmn文件

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/testm1510735932336" id="m1510735932336" name="">
  <process id="leave" isExecutable="true" isClosed="false" processType="None">
    <startEvent id="_2" name="StartEvent"></startEvent>
    <endEvent id="_3" name="EndEvent"></endEvent>
    <userTask id="approve" name="经理审批" activiti:assignee="${approve}"></userTask>
    <exclusiveGateway id="_5" name="ExclusiveGateway"></exclusiveGateway>
    <sequenceFlow id="_6" sourceRef="approve" targetRef="_5"></sequenceFlow>
    <sequenceFlow id="_7" name="通过" sourceRef="_5" targetRef="_3">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${pass}]]></conditionExpression>
    </sequenceFlow>
    <userTask id="application" name="提交申请" activiti:assignee="${apply}"></userTask>
    <sequenceFlow id="_9" sourceRef="_2" targetRef="application"></sequenceFlow>
    <sequenceFlow id="_10" sourceRef="application" targetRef="approve"></sequenceFlow>
    <userTask id="modify" name="修改申请" activiti:assignee="${apply}"></userTask>
    <sequenceFlow id="_12" name="不通过" sourceRef="_5" targetRef="modify">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${!pass}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="_13" sourceRef="modify" targetRef="approve"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_leave">
    <bpmndi:BPMNPlane bpmnElement="leave" id="BPMNPlane_leave">
      <bpmndi:BPMNShape bpmnElement="_2" id="BPMNShape__2">
        <omgdc:Bounds height="35.0" width="35.0" x="15.0" y="60.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_3" id="BPMNShape__3">
        <omgdc:Bounds height="35.0" width="35.0" x="630.0" y="63.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="approve" id="BPMNShape_approve">
        <omgdc:Bounds height="55.0" width="85.0" x="315.0" y="50.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_5" id="BPMNShape__5">
        <omgdc:Bounds height="40.0" width="40.0" x="505.0" y="60.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="application" id="BPMNShape_application">
        <omgdc:Bounds height="55.0" width="85.0" x="135.0" y="50.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="modify" id="BPMNShape_modify">
        <omgdc:Bounds height="55.0" width="85.0" x="315.0" y="150.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="_6" id="BPMNEdge__6">
        <omgdi:waypoint x="400.0" y="77.0"></omgdi:waypoint>
        <omgdi:waypoint x="505.0" y="80.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_7" id="BPMNEdge__7">
        <omgdi:waypoint x="545.0" y="80.0"></omgdi:waypoint>
        <omgdi:waypoint x="630.0" y="80.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_9" id="BPMNEdge__9">
        <omgdi:waypoint x="50.0" y="77.0"></omgdi:waypoint>
        <omgdi:waypoint x="135.0" y="77.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_10" id="BPMNEdge__10">
        <omgdi:waypoint x="220.0" y="77.0"></omgdi:waypoint>
        <omgdi:waypoint x="315.0" y="77.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_12" id="BPMNEdge__12">
        <omgdi:waypoint x="525.0" y="100.0"></omgdi:waypoint>
        <omgdi:waypoint x="525.0" y="177.0"></omgdi:waypoint>
        <omgdi:waypoint x="400.0" y="177.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_13" id="BPMNEdge__13">
        <omgdi:waypoint x="357.0" y="150.0"></omgdi:waypoint>
        <omgdi:waypoint x="357.0" y="105.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

引入依赖,选择需要的依赖

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>giveup</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>giveup</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</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-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-spring-boot-starter-basic</artifactId>
            <version>6.0.0</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.2</version>
        </dependency>

        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.8</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>compile</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

编写demo

package com.example.giveup.service.serviceImpl;

import com.example.giveup.service.ActivityConsumerService;
import org.activiti.engine.*;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;


@Service
public class ActivityConsumerServiceImpl implements ActivityConsumerService {

    @Autowired
    private RuntimeService runtimeService;

    @Autowired
    private TaskService taskService;

    @Autowired
    private RepositoryService repositoryService;


    @Override
    public boolean startActivityDemo() {
        System.out.println("method startActivityDemo begin....");
        //给占位符赋值
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("apply","zhangsan");
        map.put("approve","lisi");
        //流程启动
        ExecutionEntity pi1 = (ExecutionEntity) runtimeService.startProcessInstanceByKey("leave",map);
        //获取当前流程id
        String processId = pi1.getId();
        //获取当前任务id
        String taskId = taskService.createTaskQuery().processInstanceId(processId).singleResult().getId();
        //完成第一步申请,它会自动传递任务到下一层
        taskService.complete(taskId);

        //传递任务到这一层
        String taskId2 = taskService.createTaskQuery().processInstanceId(processId).singleResult().getId();
        //驳回申请
        map.put("pass", false);
        //完成任务,如果有下一层,则继续传递
        taskService.complete(taskId2,map);
        System.out.println("method startActivityDemo end....");
        return false;
    }
}

能用到的就这么多。。。有机会再去看看工作流里面角色相关的东西

 

posted @ 2019-07-09 19:16  Vtria丶  阅读(697)  评论(0编辑  收藏  举报