关闭

工作流Activiti的学习总结(十二) activiti官方十分钟快速学习

133人阅读 评论(0) 收藏 举报

  根据activiti官方提供的 编写 
      1.财务部门填写月财务报告
      2.股东审核月财务审计报告

 

流程图:

 

 

流程配置:

 

Xml代码  收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://activiti.org/bpmn20">  
  3.   <process id="financialReport" name="Monthly financial report reminder process">  
  4.     <startEvent id="startevent1" name="月财务报告审核开始"></startEvent>  
  5.     <!-- 采用用户组为accountancy编写财务报告  -->  
  6.     <userTask id="usertask1" name="财务编写月财务报告" activiti:candidateGroups="accountancy"></userTask>  
  7.     <userTask id="usertask2" name="股东审核月财务审计报告" activiti:candidateGroups="management"></userTask>  
  8.     <endEvent id="endevent1" name="月财务报告审核结束"></endEvent>  
  9.     <sequenceFlow id="flow1" name="" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>  
  10.     <sequenceFlow id="flow2" name="" sourceRef="usertask1" targetRef="usertask2"></sequenceFlow>  
  11.     <sequenceFlow id="flow3" name="" sourceRef="usertask2" targetRef="endevent1"></sequenceFlow>  
  12.   </process>  
  13.   <bpmndi:BPMNDiagram id="BPMNDiagram_financialReport">  
  14.     <bpmndi:BPMNPlane bpmnElement="financialReport" id="BPMNPlane_financialReport">  
  15.       <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">  
  16.         <omgdc:Bounds height="35" width="35" x="30" y="200"></omgdc:Bounds>  
  17.       </bpmndi:BPMNShape>  
  18.       <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">  
  19.         <omgdc:Bounds height="55" width="105" x="125" y="190"></omgdc:Bounds>  
  20.       </bpmndi:BPMNShape>  
  21.       <bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">  
  22.         <omgdc:Bounds height="55" width="105" x="290" y="190"></omgdc:Bounds>  
  23.       </bpmndi:BPMNShape>  
  24.       <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">  
  25.         <omgdc:Bounds height="35" width="35" x="455" y="200"></omgdc:Bounds>  
  26.       </bpmndi:BPMNShape>  
  27.       <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">  
  28.         <omgdi:waypoint x="65" y="217"></omgdi:waypoint>  
  29.         <omgdi:waypoint x="125" y="217"></omgdi:waypoint>  
  30.       </bpmndi:BPMNEdge>  
  31.       <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">  
  32.         <omgdi:waypoint x="230" y="217"></omgdi:waypoint>  
  33.         <omgdi:waypoint x="290" y="217"></omgdi:waypoint>  
  34.       </bpmndi:BPMNEdge>  
  35.       <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">  
  36.         <omgdi:waypoint x="395" y="217"></omgdi:waypoint>  
  37.         <omgdi:waypoint x="455" y="217"></omgdi:waypoint>  
  38.       </bpmndi:BPMNEdge>  
  39.     </bpmndi:BPMNPlane>  
  40.   </bpmndi:BPMNDiagram>  
  41. </definitions>  

 

编码如下:

Java代码  收藏代码
  1. package com.easyway.spring.activiti;  
  2.   
  3. import java.util.List;  
  4.   
  5. import org.activiti.engine.HistoryService;  
  6. import org.activiti.engine.ProcessEngine;  
  7. import org.activiti.engine.ProcessEngineConfiguration;  
  8. import org.activiti.engine.RepositoryService;  
  9. import org.activiti.engine.RuntimeService;  
  10. import org.activiti.engine.TaskService;  
  11. import org.activiti.engine.history.HistoricProcessInstance;  
  12. import org.activiti.engine.task.Task;  
  13. /** 
  14.  * 根据activiti官方提供的 编写  
  15.  *     1.财务部门填写月财务报告 
  16.  *     2.股东审核月财务审计报告 
  17.  *      
  18.  *      
  19.  * activiti提供的财务报告审核 
  20.  * <!-- 采用用户组为accountancy编写财务报告  --> 
  21.  *   <userTask id="usertask1" name="财务编写月财务报告" activiti:candidateGroups="accountancy"></userTask> 
  22.  * <!-- 采用用户组为management编写财务报告  --> 
  23.  *   <userTask id="usertask2" name="股东审核月财务审计报告" activiti:candidateGroups="management"></userTask> 
  24.  *  
  25.  * 备注: 
  26.  *    默认的两个用户: 
  27.  *    <pre> 
  28.  *       用户名   密码         用户组  
  29.         Table 2.1. The demo users 
  30.         UserId Password Security roles  
  31.         kermit kermit admin  
  32.         gonzo gonzo manager  
  33.         fozzie fozzie user  
  34.  *    </pre> 
  35.  *  
  36.  * @author longgangbai 
  37.  *  
  38.  * 2011-12-18  下午04:08:46 
  39.  */  
  40. public class CustomFinancialReportActiviti {  
  41.       
  42.         public static void main(String[] args) {  
  43.             // Create Activiti process engine   
  44.             //创建一个流程引擎对象  
  45. //          ProcessEngine processEngine = ProcessEngineConfiguration   
  46. //            .createStandaloneProcessEngineConfiguration()   
  47. //            .buildProcessEngine();   
  48.               
  49.           //创建一个流程引擎对象(为了便于多册测试,修改 name="databaseSchemaUpdate" value="create-drop"  默认为ture)  
  50.             ProcessEngine processEngine=ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml").buildProcessEngine();  
  51.               
  52.                
  53.             // Get Activiti services   
  54.             //获取流程相关的服务  
  55.             RepositoryService repositoryService = processEngine.getRepositoryService();   
  56.             RuntimeService runtimeService = processEngine.getRuntimeService();   
  57.                
  58.             // Deploy the process definition   
  59.             //部署相关的流程配置  
  60.             repositoryService.createDeployment()   
  61.               .addClasspathResource("diagrams/financialReport.bpmn20.xml")   
  62.               .deploy();   
  63.                
  64.             // Start a process instance   
  65.             //获取流程实例  
  66.             String procId = runtimeService.startProcessInstanceByKey("financialReport").getId();   
  67.                
  68.             // Get the first task   
  69.             TaskService taskService = processEngine.getTaskService();   
  70.             //获取accountancy组可能要操作的任务  
  71.             List<Task> tasks = taskService.createTaskQuery().taskCandidateGroup("accountancy").list();   
  72.             for (Task task : tasks) {   
  73.               System.out.println("Following task is available for accountancy group: " + task.getName());   
  74.                  
  75.               //设置fozzie代办 claim it   
  76.               taskService.claim(task.getId(), "fozzie");   
  77.             }   
  78.                
  79.             // Verify Fozzie can now retrieve the task   
  80.             //审核fozzie当前的获取的任务数量  
  81.             tasks = taskService.createTaskQuery().taskAssignee("fozzie").list();   
  82.             for (Task task : tasks) {   
  83.               System.out.println("Task for fozzie: " + task.getName());   
  84.                  
  85.               // Complete the task   
  86.               //设置forzze完毕  
  87.               taskService.complete(task.getId());   
  88.             }   
  89.                
  90.             System.out.println("Number of tasks for fozzie: "    
  91.                     + taskService.createTaskQuery().taskAssignee("fozzie").count());   
  92.                
  93.             // Retrieve and claim the second task   
  94.             //管理者审核报告并让kermit代办  
  95.             tasks = taskService.createTaskQuery().taskCandidateGroup("management").list();   
  96.             for (Task task : tasks) {   
  97.               System.out.println("Following task is available for accountancy group: " + task.getName());   
  98.               taskService.claim(task.getId(), "kermit");   
  99.             }   
  100.               
  101.             // Completing the second task ends the process   
  102.             //完成报告  
  103.             for (Task task : tasks) {   
  104.               taskService.complete(task.getId());   
  105.             }   
  106.                
  107.             // verify that the process is actually finished   
  108.             //查询流程实例完成事件  
  109.             HistoryService historyService = processEngine.getHistoryService();   
  110.             HistoricProcessInstance historicProcessInstance =    
  111.               historyService.createHistoricProcessInstanceQuery().processInstanceId(procId).singleResult();   
  112.             System.out.println("Process instance end time: " + historicProcessInstance.getEndTime());   
  113.           }   
  114.            
  115.         }  

 

 

运行结果如下:

Java代码  收藏代码
  1. 信息: ProcessEngine default created  
  2. 2011-12-18 17:06:00 org.activiti.engine.impl.jobexecutor.JobAcquisitionThread run  
  3. 信息: JobAcquisitionThread starting to acquire jobs  
  4. 2011-12-18 17:06:00 org.activiti.engine.impl.bpmn.deployer.BpmnDeployer deploy  
  5. 信息: Processing resource diagrams/financialReport.bpmn20.xml  
  6. 2011-12-18 17:06:01 org.activiti.engine.impl.bpmn.parser.BpmnParse parseDefinitionsAttributes  
  7. 信息: XMLSchema currently not supported as typeLanguage  
  8. 2011-12-18 17:06:01 org.activiti.engine.impl.bpmn.parser.BpmnParse parseDefinitionsAttributes  
  9. 信息: XPath currently not supported as expressionLanguage  
  10. Following task is available for accountancy group:<span style="color: #ff0000;"> 财务编写月财务报告</span>  
  11. <span style="color: #ff0000;">Task for fozzie: 财务编写月财务报告</span>  
  12. <span style="color: #ff0000;">Number of tasks for fozzie: 0</span>  
  13. <span style="color: #ff0000;">Following task is available for accountancy group: 股东审核月财务审计报告</span>  
  14. <span style="color: #ff0000;">Process instance end time: Sun Dec 18 17:06:01 CST 2011  
  15. </span>  
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:24448次
    • 积分:730
    • 等级:
    • 排名:千里之外
    • 原创:38篇
    • 转载:75篇
    • 译文:0篇
    • 评论:0条
    文章分类