Java Activiti(1)---基础流程

来源:互联网 发布:b2b源码授权费用 编辑:程序博客网 时间:2024/06/05 08:49

一、从创建表到办理完成任务

public class LeaveActionTest {    private ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();    //1.1、创建表    public static void createTabelAuto(){        //创建对象        ProcessEngineConfiguration conf = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();        String driver = PropertiesUtil.getValue("jdbc_driver", "conf/jdbc.properties");        String url = PropertiesUtil.getValue("jdbc_url", "conf/jdbc.properties");        String username = PropertiesUtil.getValue("jdbc_username", "conf/jdbc.properties");        String password = PropertiesUtil.getValue("jdbc_password", "conf/jdbc.properties");        //设置数据库        conf.setJdbcDriver(driver);        conf.setJdbcUrl(url);        conf.setJdbcUsername(username);        conf.setJdbcPassword(password);        //自动建表        conf.setDatabaseSchemaUpdate("true");        //创建引擎        ProcessEngine processEngine = conf.buildProcessEngine();    }    //1.2、创建表,processEngineConfiguration为数据库实体bean    public static void createTabelByXML(){        //创建对象        String resource = "activiti-context2.xml";        String beanName = "processEngineConfiguration";        ProcessEngineConfiguration conf = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource(resource, beanName);        //创建引擎        ProcessEngine processEngine = conf.buildProcessEngine();    }    //2、部署流程定义    @Test    public void deployLeave() throws Exception {        DeploymentBuilder builder = processEngine.getRepositoryService().createDeployment();        builder.addClasspathResource("flow/leave.bpmn");        builder.addClasspathResource("flow/leave.png");        Deployment deploy = builder.deploy();        System.out.println("deploy.getId()==" + deploy.getId());    }    //3、获得流程定义的id    @Test    public void queryFinition() throws Exception {        ProcessDefinitionQuery query = processEngine.getRepositoryService().createProcessDefinitionQuery();        //添加过滤条件        query.processDefinitionKey("leaveFlow");        //添加排序        query.orderByProcessDefinitionVersion().desc();        //分页        query.listPage(0, 10);        List<ProcessDefinition> processDefinitions = query.list();        for (ProcessDefinition p : processDefinitions) {            System.out.println("p.getId()===" +p.getId());        }    }    @Test    public void querys() throws Exception {        List<ProcessDefinition> processDefinitions = processEngine.getRepositoryService().createProcessDefinitionQuery().list();        List<Deployment> deployments = processEngine.getRepositoryService().createDeploymentQuery().list();        List<ProcessInstance> processInstances = processEngine.getRuntimeService().createProcessInstanceQuery().list();        List<Task> tasks = processEngine.getTaskService().createTaskQuery().list();    }    //4、根据流程定义的id获得流程实例的id    @Test    public void getProcessInstance() throws Exception {        String processDefinitionId = "leaveFlow:1:4";        ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitionId);        System.out.println("processInstance.getId()===" + processInstance.getId());    }    //5、根据流程实例,查询任务列表  ,说明一个流程定义对应多个流程实例,一个流程实例对应多个任务列表    @Test    public void getProcessTask() throws Exception {        String processInstanceId = "5001";        //1        //String assignee = "tom";        //2        //String assignee = "jack";        //3        String assignee = "smith";        //任务列表        TaskQuery taskQuery = processEngine.getTaskService().createTaskQuery();        //查询tom的任务列表        taskQuery.taskAssignee(assignee);        List<Task> tasks = taskQuery.list();        for (Task task: tasks){            System.out.println(task.getId() + ":" + task.getName());        }    }    //6、办理任务,办理完成后,第三步就找不到tom的这个任务了,跑到下个jack的任务中了,5与6是相互重复的    @Test    public void dealProcessTask() throws Exception {        String taskId = "";        processEngine.getTaskService().complete(taskId);    }}

二、数据库配置

jdbc_driver=com.microsoft.sqlserver.jdbc.SQLServerDriverjdbc_url=jdbc:sqlserver://localhost:1433;DatabaseName=activitijdbc_username=sajdbc_password=sa

三、流程文件leave.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: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="m1505312057485" name="" targetNamespace="http://www.activiti.org/test" typeLanguage="http://www.w3.org/2001/XMLSchema">  <process id="leaveFlow" isClosed="false" isExecutable="true" name="leaveFlow" processType="None">    <startEvent id="startId" name="start"/>    <endEvent id="endId" name="end"/>    <userTask activiti:assignee="tom" activiti:async="false" activiti:exclusive="true" id="processSubmitId" name="提交请假申请"/>    <userTask activiti:assignee="jack" activiti:exclusive="true" id="processSupervisorId" name="项目经理审批"/>    <sequenceFlow id="_6" sourceRef="startId" targetRef="processSubmitId"/>    <sequenceFlow id="_7" sourceRef="processSubmitId" targetRef="processSupervisorId"/>    <userTask activiti:assignee="smith" activiti:exclusive="true" id="processManagerId" name="部门经理审批"/>    <sequenceFlow id="_10" sourceRef="processSupervisorId" targetRef="processManagerId"/>    <sequenceFlow id="_11" sourceRef="processManagerId" targetRef="endId"/>    <sequenceFlow sourceRef="startId" targetRef="processSubmitId" id="startId-processSubmitId"/>  </process>  <bpmndi:BPMNDiagram documentation="background=#FFFFFF;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="leaveFlow">      <bpmndi:BPMNShape bpmnElement="startId" id="Shape-startId">        <omgdc:Bounds height="32.0" width="32.0" x="390.0" y="115.0"/>        <bpmndi:BPMNLabel>          <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>        </bpmndi:BPMNLabel>      </bpmndi:BPMNShape>      <bpmndi:BPMNShape bpmnElement="endId" id="Shape-endId">        <omgdc:Bounds height="32.0" width="32.0" x="400.0" y="495.0"/>        <bpmndi:BPMNLabel>          <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>        </bpmndi:BPMNLabel>      </bpmndi:BPMNShape>      <bpmndi:BPMNShape bpmnElement="processSubmitId" id="Shape-processSubmitId">        <omgdc:Bounds height="55.0" width="85.0" x="370.0" y="215.0"/>        <bpmndi:BPMNLabel>          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>        </bpmndi:BPMNLabel>      </bpmndi:BPMNShape>      <bpmndi:BPMNShape bpmnElement="processSupervisorId" id="Shape-processSupervisorId">        <omgdc:Bounds height="55.0" width="85.0" x="365.0" y="305.0"/>        <bpmndi:BPMNLabel>          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>        </bpmndi:BPMNLabel>      </bpmndi:BPMNShape>      <bpmndi:BPMNShape bpmnElement="processManagerId" id="Shape-processManagerId">        <omgdc:Bounds height="55.0" width="85.0" x="370.0" y="405.0"/>        <bpmndi:BPMNLabel>          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>        </bpmndi:BPMNLabel>      </bpmndi:BPMNShape>      <bpmndi:BPMNEdge bpmnElement="_6" id="BPMNEdge__6" sourceElement="startId" targetElement="processSubmitId">        <omgdi:waypoint x="406.0" y="147.0"/>        <omgdi:waypoint x="406.0" y="215.0"/>        <bpmndi:BPMNLabel>          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>        </bpmndi:BPMNLabel>      </bpmndi:BPMNEdge>      <bpmndi:BPMNEdge bpmnElement="_7" id="BPMNEdge__7" sourceElement="processSubmitId" targetElement="processSupervisorId">        <omgdi:waypoint x="410.0" y="270.0"/>        <omgdi:waypoint x="410.0" y="305.0"/>        <bpmndi:BPMNLabel>          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>        </bpmndi:BPMNLabel>      </bpmndi:BPMNEdge>      <bpmndi:BPMNEdge bpmnElement="_11" id="BPMNEdge__11" sourceElement="processManagerId" targetElement="endId">        <omgdi:waypoint x="416.0" y="460.0"/>        <omgdi:waypoint x="416.0" y="495.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="processSupervisorId" targetElement="processManagerId">        <omgdi:waypoint x="410.0" y="360.0"/>        <omgdi:waypoint x="410.0" y="405.0"/>        <bpmndi:BPMNLabel>          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>        </bpmndi:BPMNLabel>      </bpmndi:BPMNEdge>      <bpmndi:BPMNEdge bpmnElement="startId-processSubmitId">        <omgdi:waypoint x="406.0" y="131.0"/>        <omgdi:waypoint x="412.5" y="242.5"/>      </bpmndi:BPMNEdge>    </bpmndi:BPMNPlane>  </bpmndi:BPMNDiagram></definitions>

—————————————————————————————————————————————————–

java架构师项目实战,高并发集群分布式,大数据高可用视频教程,共760G

下载地址:

https://item.taobao.com/item.htm?id=555888526201

01.高级架构师四十二个阶段高
02.Java高级系统培训架构课程148课时
03.Java高级互联网架构师课程
04.Java互联网架构Netty、Nio、Mina等-视频教程
05.Java高级架构设计2016整理-视频教程
06.架构师基础、高级片
07.Java架构师必修linux运维系列课程
08.Java高级系统培训架构课程116课时
+
hadoop系列教程,java设计模式与数据结构, Spring Cloud微服务, SpringBoot入门

—————————————————————————————————————————————————–

原创粉丝点击