Java Activiti(7)--任务办理

1、具体操作

package com.cloud.wyscha.action;

import com.cloud.wyscha.entity.User;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.DeploymentBuilder;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.activiti.engine.task.TaskQuery;
import org.junit.Test;

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

/**
 * 任务办理
 * Created by Administrator on 2017/9/18.
 */
//@RunWith(SpringJUnit4ClassRunner.class)
//@ContextConfiguration(locations = {"classpath*:/conf/applicationContext.xml","classpath*:/conf/applicationContext_springmvc.xml"})
public class ActivitiPersonalTaskTest {
    private ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();


    //1、部署流程定义
    @Test
    public void deployLeave() throws Exception {
        DeploymentBuilder builder = processEngine.getRepositoryService().createDeployment();
        builder.addClasspathResource("flow/grouptask.bpmn");
        builder.addClasspathResource("flow/grouptask.png");
        builder.name("报销流程部署");
        Deployment deploy = builder.deploy();
        System.out.println("deploy.getId()==" + deploy.getId());
    }


    //2.、动流程实例时,添加变量
    @Test
    public void startProcessInstanceByKey() throws Exception {
        String processDefinitionKey = "grouptask";
        Map<String, Object> variable = new HashMap<String, Object>();
        variable.put("amount", "300元");
        variable.put("reason", "出差");
        ProcessInstance processInstance = processEngine.getRuntimeService().startProcessInstanceByKey(processDefinitionKey, variable);
        System.out.println("processInstance.getId()===" + processInstance.getId());
        System.out.println("processInstance.getProcessDefinitionId()===" + processInstance.getProcessDefinitionId());
    }

    //3、提交申请,办理个人任务
    @Test
    public void dealPersonalTask() throws Exception {
        String taskId = "60011";
        Map<String, Object> variable = new HashMap<String, Object>();
        variable.put("amount2", "300元");
        variable.put("reason2", "出差");
        processEngine.getTaskService().complete(taskId, variable);
    }

    //3.1、财务审批,查询组合任务
    @Test
    public void queryGroupTask() throws Exception {
        //查询谁能办理
        String userId = "jack";
        TaskQuery taskQuery = processEngine.getTaskService().createTaskQuery();
        taskQuery.taskCandidateUser(userId);
        List<Task> list = taskQuery.list();
        if(list != null && list.size()>0){

        }
    }

    //3.2、拾取任务并办理
    @Test
    public void claimGroupTask() throws Exception {
        String taskId = "62504";
        String userId = "smith";
        processEngine.getTaskService().claim(taskId,userId);
        processEngine.getTaskService().complete(taskId);
    }


    //3.3、退回任务
    @Test
    public void backGroupTask() throws Exception {
        String taskId = "62504";
        processEngine.getTaskService().setAssignee(taskId,null);
    }
}

2、流程文件

<?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="grouptask" isClosed="false" isExecutable="true" name="grouptask" 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="submit application"/>
    <userTask activiti:assignee="jack" activiti:candidateUsers="jack,smtih" activiti:exclusive="true" id="processSupervisorId" name="finance approval"/>
    <sequenceFlow id="_6" sourceRef="startId" targetRef="processSubmitId"/>
    <sequenceFlow id="_7" sourceRef="processSubmitId" targetRef="processSupervisorId"/>
    <sequenceFlow id="startId-processSubmitId" sourceRef="startId" targetRef="processSubmitId"/>
    <sequenceFlow id="_2" sourceRef="processSupervisorId" targetRef="endId"/>
    <sequenceFlow sourceRef="endId" targetRef="endId" id="endId-endId"/>
  </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="grouptask">
      <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="397.0" y="420.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="56.0" width="115.0" x="354.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="110.0" x="356.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:BPMNEdge bpmnElement="startId-processSubmitId" id="BPMNEdge_startId-processSubmitId" 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="-1.0" width="-1.0" x="-1.0" y="-1.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_2" id="BPMNEdge__2" sourceElement="processSupervisorId" targetElement="endId">
        <omgdi:waypoint x="416.0" y="360.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="_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="endId-endId">
        <omgdi:waypoint x="413.0" y="436.0"/>
        <omgdi:waypoint x="413.0" y="436.0"/>
      </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入门

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lovoo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值