activiti任務TASK


一、概要

  1. 設計TASK的表主要是:ACT_RU_TASK,ACT_HI_TASKINST(見參考-activiti表);
  2. 任務主要有:人工任務(usertask),服務任務(servicetask)等;
  3. 候選人/候選組(candidate):可以執行任務的一類人或者多個組,候選人/候選組中都可以去簽收任務,一旦某人簽收,就成為受理人,其他人就不能再簽收受理此任務;usertask流程圖中,candidate標示候選;候選人涉及的表ACT_RU_IDENTITYLINK;
  4. 受理人(assignee):有兩種情況,一種是候選人/組中有人簽收任務后成為受理人,另外一種是流程圖中直接指定受理人,但是可以指定一個動態受理人;受理人涉及的表ACT_RU_TASK;
  5. 持有人(owner):持有人設置主要是存入歷史表中,用於歷史任務的查詢,涉及的表ACT_HI_TASKINST;

二、任務操作

  1. 創建TASK任務與設置權限:可以使用代碼創建任務,但是實際操作中都是繪制流程圖。繪制TASK后,在屬性可以設置候選人和受理人,一般都是設置候選人,因為固定受理人不太符合程序變動;

          候選人設置了deptleader,該值將部署在表ACT_RU_IDENTITYLINK中,查看xml看見:    

//設置了候選組
 <userTask id="deptLeaderAudit" name="部門領導審批" activiti:candidateGroups="deptLeader">
 </userTask>

    完整的XML(無圖形位置信息)

<process id="leave" name="請假流程" isExecutable="true">
    <documentation>請假流程演示</documentation>
    <startEvent id="startevent1" name="Start" activiti:initiator="applyUserId"></startEvent>
    <userTask id="deptLeaderAudit" name="部門領導審批" activiti:candidateGroups="deptLeader"></userTask>
    <exclusiveGateway id="exclusivegateway5" name="Exclusive Gateway"></exclusiveGateway>
    <userTask id="modifyApply" name="調整申請" activiti:assignee="${applyUserId}">
      <extensionElements>
        <activiti:taskListener event="complete" delegateExpression="${afterModifyApplyContentProcessor}"></activiti:taskListener>
      </extensionElements>
    </userTask>
    <userTask id="hrAudit" name="人事審批" activiti:candidateGroups="hr"></userTask>
    <exclusiveGateway id="exclusivegateway6" name="Exclusive Gateway"></exclusiveGateway>
    <userTask id="reportBack" name="銷假" activiti:assignee="${applyUserId}">
      <extensionElements>
        <activiti:taskListener event="complete" delegateExpression="${reportBackEndProcessor}"></activiti:taskListener>
      </extensionElements>
    </userTask>
    <endEvent id="endevent1" name="End"></endEvent>
    <exclusiveGateway id="exclusivegateway7" name="Exclusive Gateway"></exclusiveGateway>
    <sequenceFlow id="flow2" sourceRef="startevent1" targetRef="deptLeaderAudit"></sequenceFlow>
    <sequenceFlow id="flow3" sourceRef="deptLeaderAudit" targetRef="exclusivegateway5"></sequenceFlow>
    <sequenceFlow id="flow4" name="不同意" sourceRef="exclusivegateway5" targetRef="modifyApply">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${!deptLeaderPass}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="flow5" name="同意" sourceRef="exclusivegateway5" targetRef="hrAudit">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${deptLeaderPass}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="flow6" sourceRef="hrAudit" targetRef="exclusivegateway6"></sequenceFlow>
    <sequenceFlow id="flow7" name="同意" sourceRef="exclusivegateway6" targetRef="reportBack">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${hrPass}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="flow8" sourceRef="reportBack" targetRef="endevent1"></sequenceFlow>
    <sequenceFlow id="flow9" name="不同意" sourceRef="exclusivegateway6" targetRef="modifyApply">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${!hrPass}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="flow10" name="重新申請" sourceRef="exclusivegateway7" targetRef="deptLeaderAudit">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${reApply}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="flow11" sourceRef="modifyApply" targetRef="exclusivegateway7"></sequenceFlow>
    <sequenceFlow id="flow12" name="結束流程" sourceRef="exclusivegateway7" targetRef="endevent1">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${!reApply}]]></conditionExpression>
    </sequenceFlow>
  </process>

         2.查詢候選任務

    //根據候選組ID查詢擁有任務
    List<Task> tasks = taskService.createTaskQuery().taskCandidateGroup(groupA.getId()).list();
    for (Task task : tasks){
    System.out.println(task.getName());
  }
//根據用戶ID查詢任務 tasks = taskService.createTaskQuery().taskCandidateUser(user.getId()).list(); for (Task task : tasks){
    System.out.println(task.getName());
  }
//調用taskCandidateGroupIn List<String> groupIds = new ArrayList<String>(); groupIds.add(groupA.getId()); groupIds.add(groupB.getId());
tasks
= taskService.createTaskQuery().taskCandidateGroupIn(groupIds).list(); for (Task task : tasks){
    System.out.println(task.getName());
  }
//查詢權限數據 List<IdentityLink> links = taskService.getIdentityLinksForTask(tasks.get(0).getId()); System.out.println("關系數據量: " + links.size());}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM