Activiti 初级入门项目

刚刚使用了activity做了一个项目,第一次就腆着脸给写出来吧!!!

审批流肯定要创建流程图,再编辑器上装bpm插件  

 

 

 

 

 装完就可以使用了

 

 要创建在resources/processes/新建个文件夹叫processes 不然会报错:

Caused by: java.io.FileNotFoundException: class path resource [processes/] cannot be resolved to URL because it does not exist
    at org.springframework.core.io.ClassPathResource.getURL(ClassPathResource.java:195)
    at org.springframework.core.io.support.PathMatchingResourcePatternResolver.findPathMatchingResources(PathMatchingResourcePatternResolver.java:495)
    at org.springframework.core.io.support.PathMatchingResourcePatternResolver.getResources(PathMatchingResourcePatternResolver.java:296)
    at org.springframework.context.support.AbstractApplicationContext.getResources(AbstractApplicationContext.java:1305)
    at org.springframework.context.support.GenericApplicationContext.getResources(GenericApplicationContext.java:238)
    at org.activiti.spring.boot.AbstractProcessEngineConfiguration.discoverProcessDefinitionResources(AbstractProcessEngineConfiguration.java:80)
    at org.activiti.spring.boot.AbstractProcessEngineAutoConfiguration.baseSpringProcessEngineConfiguration(AbstractProcessEngineAutoConfiguration.java:75)
    at org.activiti.spring.boot.DataSourceProcessEngineAutoConfiguration$DataSourceProcessEngineConfiguration.springProcessEngineConfiguration(DataSourceProcessEngineAutoConfiguration.java:57)
    at org.activiti.spring.boot.DataSourceProcessEngineAutoConfiguration$DataSourceProcessEngineConfiguration$$EnhancerBySpringCGLIB$$baa326a5.CGLIB$springProcessEngineConfiguration$1(<generated>)
    at org.activiti.spring.boot.DataSourceProcessEngineAutoConfiguration$DataSourceProcessEngineConfiguration$$EnhancerBySpringCGLIB$$baa326a5$$FastClassBySpringCGLIB$$cc2270af.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:361)
    at org.activiti.spring.boot.DataSourceProcessEngineAutoConfiguration$DataSourceProcessEngineConfiguration$$EnhancerBySpringCGLIB$$baa326a5.springProcessEngineConfiguration(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
    ... 86 common frames omitted

Caused by: java.io.FileNotFoundException: class path resource [processes/] cannot be resolved to URL because it does not exist 不存在这个文件夹

解决方法2在配置文件中配置:

在application.properties文件加配置

# spring-activiti

# 自动部署验证设置:true-开启(默认)、false-关闭

spring.activiti.check-process-definitions=false

 

 如上流程图就是这么简单 但是这文件可以用文本方式打开代码如下:

<?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:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" xmlns:tns="http://www.activiti.org/test" 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="m1587032668414" name="" targetNamespace="http://www.activiti.org/test" typeLanguage="http://www.w3.org/2001/XMLSchema">
  <process id="apply" isClosed="false" isExecutable="true" name="创建申请" processType="None">
    <startEvent id="_2" name="StartEvent">
      <extensionElements>
        <activiti:executionListener class="com.cmbchina.ccd.itpm.listener.SubmitListener" event="start"/>
      </extensionElements>
    </startEvent>
    <userTask activiti:assignee="${zgsp}" activiti:exclusive="true" id="_7" name="主管审批"/>
    <exclusiveGateway gatewayDirection="Unspecified" id="_9" name="ExclusiveGateway"/>
    <sequenceFlow id="_10" sourceRef="_7" targetRef="_9"/>
    <userTask activiti:assignee="${assignee}" activiti:exclusive="true" id="_11" name="项目管理员审批">
      <multiInstanceLoopCharacteristics activiti:collection="${pmoList}" activiti:elementVariable="assignee" isSequential="false">
        <completionCondition><![CDATA[${nrOfCompletedInstances/nrOfInstances > 0}]]></completionCondition>
      </multiInstanceLoopCharacteristics>
    </userTask>
    <sequenceFlow id="_12" name="通过" sourceRef="_9" targetRef="_11">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${condition==1}]]></conditionExpression>
    </sequenceFlow>
    <userTask activiti:assignee="${xmszgsp}" activiti:exclusive="true" id="_13" name="项目室主管审批"/>
    <exclusiveGateway gatewayDirection="Unspecified" id="_14" name="ExclusiveGateway"/>
    <sequenceFlow id="_16" name="通过" sourceRef="_14" targetRef="_13">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${condition==1}]]></conditionExpression>
    </sequenceFlow>
    <endEvent id="_17" name="EndEvent"/>
    <sequenceFlow id="_22" sourceRef="_2" targetRef="_7"/>
    <sequenceFlow id="_23" sourceRef="_11" targetRef="_14"/>
    <sequenceFlow id="_24" sourceRef="_13" targetRef="_17"/>
    <sequenceFlow id="_25" name="不通过" sourceRef="_14" targetRef="_17">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${condition==0}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="_26" name="不通过" sourceRef="_9" targetRef="_17">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${condition==0}]]></conditionExpression>
    </sequenceFlow>
  </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="apply">
      <bpmndi:BPMNShape bpmnElement="_2" id="Shape-_2">
        <omgdc:Bounds height="32.0" width="32.0" x="45.0" y="35.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_7" id="Shape-_7">
        <omgdc:Bounds height="55.0" width="85.0" x="215.0" y="25.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_9" id="Shape-_9" isMarkerVisible="false">
        <omgdc:Bounds height="32.0" width="32.0" x="430.0" y="30.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_11" id="Shape-_11">
        <omgdc:Bounds height="55.0" width="85.0" x="620.0" y="20.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_13" id="Shape-_13">
        <omgdc:Bounds height="55.0" width="85.0" x="405.0" y="295.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_14" id="Shape-_14" isMarkerVisible="false">
        <omgdc:Bounds height="32.0" width="32.0" x="635.0" y="190.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_17" id="Shape-_17">
        <omgdc:Bounds height="32.0" width="32.0" x="430.0" y="190.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="_24" id="BPMNEdge__24" sourceElement="_13" targetElement="_17">
        <omgdi:waypoint x="446.0" y="295.0"/>
        <omgdi:waypoint x="446.0" y="222.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_12" id="BPMNEdge__12" sourceElement="_9" targetElement="_11">
        <omgdi:waypoint x="461.0" y="45.0"/>
        <omgdi:waypoint x="545.0" y="45.0"/>
        <omgdi:waypoint x="620.0" y="45.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="6.0" width="4.0" x="0.0" y="-2.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_23" id="BPMNEdge__23" sourceElement="_11" targetElement="_14">
        <omgdi:waypoint x="650.0" y="75.0"/>
        <omgdi:waypoint x="650.0" y="130.0"/>
        <omgdi:waypoint x="650.0" y="191.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_26" id="BPMNEdge__26" sourceElement="_9" targetElement="_17">
        <omgdi:waypoint x="445.0" y="61.0"/>
        <omgdi:waypoint x="445.0" y="126.0"/>
        <omgdi:waypoint x="445.0" y="190.0312805773287"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="-1.0" width="0.0" x="0.0" y="10.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_25" id="BPMNEdge__25" sourceElement="_14" targetElement="_17">
        <omgdi:waypoint x="636.0" y="205.0"/>
        <omgdi:waypoint x="529.0" y="205.0"/>
        <omgdi:waypoint x="461.9687194226713" y="205.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_16" id="BPMNEdge__16" sourceElement="_14" targetElement="_13">
        <omgdi:waypoint x="650.0" y="221.0"/>
        <omgdi:waypoint x="650.0" y="313.0"/>
        <omgdi:waypoint x="490.0" y="313.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_22" id="BPMNEdge__22" sourceElement="_2" targetElement="_7">
        <omgdi:waypoint x="76.96871942267131" y="50.0"/>
        <omgdi:waypoint x="133.0" y="50.0"/>
        <omgdi:waypoint x="215.0" y="50.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_10" id="BPMNEdge__10" sourceElement="_7" targetElement="_9">
        <omgdi:waypoint x="300.0" y="45.0"/>
        <omgdi:waypoint x="360.0" y="45.0"/>
        <omgdi:waypoint x="431.0" y="45.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

这这里面有牵涉到多个项目管理员审批 一个人通过就是通过了 这属于多实例的一种,当时处理起来我有点不知道怎么处理 所以搜寻了很多的资料 (这可能是我不知道怎么搜索所以花费了不少时间)

最终就用了一句话

<![CDATA[${nrOfCompletedInstances/nrOfInstances > 0}]]>
这里的nrOfCompletedInstances 相当于处理人数nrOfInstances:需要处理的人数
我的需求是只要有一人处理就行 那就商大于0就OK 要是都需要处理 那就是 商恒等于0 哈哈原来这么简单
我这个应该只是工作流中的九牛一毛 里面有很多学问。有机会多多和博友交流
嘻嘻
posted @ 2020-05-06 11:29  BlackCatFish  阅读(345)  评论(0编辑  收藏  举报