Activity探究(下)

IDEA编写第一个Activity
首先 maven项目走起来,不懂的同学,翻翻IDEA如何创建maven项目
项目名为helloActiviti

先要下载一个插件
IDEA-File-Settirng-Plugins
找一个插件 actiBPM用于编辑Activity需要的流程图。流程图的概念

在这里插入图片描述
右键new 有BPMN File就说明插件安装完成
Pom.xml 如下:
Resources

<?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>

    <groupId>helloActiviti</groupId>
    <artifactId>helloActiviti</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-spring</artifactId>
            <version>5.18.0</version>
        </dependency>
        <!--JUnit测试-->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.7</version>
        </dependency>
        <!--activiti-->
        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-engine</artifactId>
            <version>5.18.0</version>
            <exclusions>
                <exclusion>
                    <artifactId>slf4j-api</artifactId>
                    <groupId>org.slf4j</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-beans</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>jackson-core-asl</artifactId>
                    <groupId>org.codehaus.jackson</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>commons-lang3</artifactId>
                    <groupId>org.apache.commons</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>commons-lang3</artifactId>
                    <groupId>org.apache.commons</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <!--MySQL 驱动包,如果是其他库的话需要换驱动包-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.47</version>
        </dependency>
    </dependencies>

</project>

引入相关包,日志,mysql还有单元测试,等等。
右键建立出一个新的BPMN文件,需要解释几个组件
在这里插入图片描述
Activiti.cfg.xml 配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
        <property name="jdbcDriver" value="com.mysql.jdbc.Driver"></property>
        <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/activity_test?useUnicode=true&amp;characterEncoding=utf8"></property>
        <property name="jdbcUsername" value="root"></property>
        <property name="jdbcPassword" value="root"></property>
        <property name="databaseSchemaUpdate" value="true"></property>
    </bean>


</beans>
/**
 * 根据配置文件activiti.cfg.xml创建ProcessEngine
 */
@Test
public void testCreateProcessEngineByCfgXml() {
    ProcessEngineConfiguration cfg = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
    ProcessEngine engine = cfg.buildProcessEngine();
}

接下来的逻辑参照1文中的生命流程。
从配置文件中加载内容。

/**
 * 发布流程
 * RepositoryService
 */
@Test
public void deployProcess() {
    RepositoryService repositoryService = processEngine.getRepositoryService();
    DeploymentBuilder builder = repositoryService.createDeployment();
    builder.addClasspathResource("test.bpmn");
    builder.deploy();
}

相当于将画好的流程发布。
Test.bpmn是啥就是,上面那个流程图将后缀改成xml如下:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:tns="http://www.activiti.org/testm1587367090204" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" expressionLanguage="http://www.w3.org/1999/XPath" id="m1587367090204" name="" targetNamespace="http://www.activiti.org/testm1587367090204" typeLanguage="http://www.w3.org/2001/XMLSchema">
  <process id="myProcess_1" isClosed="false" isExecutable="true" processType="None">
    <startEvent id="_2" name="StartEvent"/>
    <userTask activiti:exclusive="true" id="_3" name="UserTask"/>
    <endEvent id="_4" name="EndEvent"/>
    <sequenceFlow id="_5" sourceRef="_2" targetRef="_3"/>
    <userTask activiti:exclusive="true" id="_7" name="UserTask"/>
    <sequenceFlow id="_8" sourceRef="_3" targetRef="_7"/>
    <sequenceFlow id="_9" sourceRef="_7" targetRef="_4"/>
  </process>
  <bpmndi:BPMNDiagram documentation="background=#3C3F41;count=1;horizontalcount=1;orientation=0;width=842.4;height=1195.2;imageableWidth=832.4;imageableHeight=1185.2;imageableX=5.0;imageableY=5.0" id="Diagram-_1" name="New Diagram">
    <bpmndi:BPMNPlane bpmnElement="myProcess_1">
      <bpmndi:BPMNShape bpmnElement="_2" id="Shape-_2">
        <dc:Bounds height="32.0" width="32.0" x="185.0" y="10.0"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_3" id="Shape-_3">
        <dc:Bounds height="55.0" width="85.0" x="135.0" y="80.0"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_4" id="Shape-_4">
        <dc:Bounds height="32.0" width="32.0" x="185.0" y="325.0"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_7" id="Shape-_7">
        <dc:Bounds height="55.0" width="85.0" x="135.0" y="215.0"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="_5" id="BPMNEdge__5" sourceElement="_2" targetElement="_3">
        <di:waypoint x="201.0" y="42.0"/>
        <di:waypoint x="201.0" y="80.0"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_8" id="BPMNEdge__8" sourceElement="_3" targetElement="_7">
        <di:waypoint x="177.5" y="135.0"/>
        <di:waypoint x="177.5" y="215.0"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_9" id="BPMNEdge__9" sourceElement="_7" targetElement="_4">
        <di:waypoint x="201.0" y="270.0"/>
        <di:waypoint x="201.0" y="325.0"/>
        <bpmndi:BPMNLabel>
          <dc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

根据bpmn中的id启动流程

 /**
     * 启动流程
     * <p>
     * RuntimeService
     */
    @Test
    public void startProcess() {
        RuntimeService runtimeService = processEngine.getRuntimeService();
//可根据id、key、message启动流程
        runtimeService.startProcessInstanceByKey("myProcess_1");
    }
	
/**
 * 查看任务
 * TaskService
 */
@Test
public void queryTask() {
    TaskService taskService = processEngine.getTaskService(); //根据assignee(代理人)查询任务
    String assignee = "emp";
    List<Task> tasks = taskService.createTaskQuery().taskAssignee(assignee).list();
    int size = tasks.size();
    for (int i = 0; i < size; i++) {
        Task task = tasks.get(i);
    }
    for (Task task : tasks) {
        System.out.println("taskId:" + task.getId() + ",taskName:" + task.getName() + ",assignee:" + task.getAssignee() + ",createTime:" + task.getCreateTime());
    }
}

/**
 * 办理任务
 */
@Test
public void handleTask() {
    TaskService taskService = processEngine.getTaskService(); //根据上一步生成的taskId执行任务
    String taskId = "10006";
    taskService.complete(taskId);
}

具体过程在数据库中所产生的的表,这里就不细说了,根据1文中的结构,没做一步操作,自己去研究一下基本就摸得一清二楚了。接下来是业务系统的并入,为了让这个流程,不是为了流而流,是为了服务于业务本身。需要接入指定的权限系统流程才有意义。
还有一个变量的定义。在基于变量的使用的前提下,就可以动态指定执行人。基本就完成了基础的流程需求。鉴于公司需要jeesite 所以搞定activity的研究直接就转Jflow这真的是一个深坑。不过确实功能十分强大啊。国人的好东西。不多见。

随着Activity的深入合并
同时也研究了一下JFLOW 国内的开源代码
其实相对于Activity来说JFLOW。
相对于使用上来说Activity仅有后端,需要补足前端,跟踪,会签等功能。但是具备基本的流程。而且只有38个表。权限系统可以自由结合。和外部耦合低。
可是jflow就不是一个了 是一套,一整套。

在这里插入图片描述
这就是jflow的基础表。每当新建一个流程还会有两个表产生。虽然一切都很完善,如果需要在已经成型的系统上嵌入,需要重写所有权限系统有关的表的视图。也就是不管你用啥,你都要对着我的口。索性将权限系统和流程系统全关联,好处是,你可以更集中注意力于业务本身而非代码,坏处就是我相信那个系统放进去141+个表都不会很开心。当然如果是一个流程特别多的系统那么可能就不是141+ 可能是200+,设想一下1000+的概念。如果只是基础流程我推荐使用Activity如果流程不太正常,就是不太正常那种不太正常。比如写个论文作为流程的一部分等等。这种你理解之外的流程比较多,那就用jflow。如果系统里根本上来说就一两个流程,那就自己随便写个表。所以在使用谁上 要考虑清楚。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值