http://topmanopensource.iteye.com/blog/1315341
******************************************************
根据activiti官方提供的 编写
1.财务部门填写月财务报告
2.股东审核月财务审计报告
流程图:
流程配置:
- <?xml version="1.0" encoding="UTF-8"?>
- <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">
- <process id="financialReport" name="Monthly financial report reminder process">
- <startEvent id="startevent1" name="月财务报告审核开始"></startEvent>
- <!-- 采用用户组为accountancy编写财务报告 -->
- <userTask id="usertask1" name="财务编写月财务报告" activiti:candidateGroups="accountancy"></userTask>
- <userTask id="usertask2" name="股东审核月财务审计报告" activiti:candidateGroups="management"></userTask>
- <endEvent id="endevent1" name="月财务报告审核结束"></endEvent>
- <sequenceFlow id="flow1" name="" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
- <sequenceFlow id="flow2" name="" sourceRef="usertask1" targetRef="usertask2"></sequenceFlow>
- <sequenceFlow id="flow3" name="" sourceRef="usertask2" targetRef="endevent1"></sequenceFlow>
- </process>
- <bpmndi:BPMNDiagram id="BPMNDiagram_financialReport">
- <bpmndi:BPMNPlane bpmnElement="financialReport" id="BPMNPlane_financialReport">
- <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
- <omgdc:Bounds height="35" width="35" x="30" y="200"></omgdc:Bounds>
- </bpmndi:BPMNShape>
- <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
- <omgdc:Bounds height="55" width="105" x="125" y="190"></omgdc:Bounds>
- </bpmndi:BPMNShape>
- <bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
- <omgdc:Bounds height="55" width="105" x="290" y="190"></omgdc:Bounds>
- </bpmndi:BPMNShape>
- <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
- <omgdc:Bounds height="35" width="35" x="455" y="200"></omgdc:Bounds>
- </bpmndi:BPMNShape>
- <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
- <omgdi:waypoint x="65" y="217"></omgdi:waypoint>
- <omgdi:waypoint x="125" y="217"></omgdi:waypoint>
- </bpmndi:BPMNEdge>
- <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
- <omgdi:waypoint x="230" y="217"></omgdi:waypoint>
- <omgdi:waypoint x="290" y="217"></omgdi:waypoint>
- </bpmndi:BPMNEdge>
- <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
- <omgdi:waypoint x="395" y="217"></omgdi:waypoint>
- <omgdi:waypoint x="455" y="217"></omgdi:waypoint>
- </bpmndi:BPMNEdge>
- </bpmndi:BPMNPlane>
- </bpmndi:BPMNDiagram>
- </definitions>
编码如下:
- package com.easyway.spring.activiti;
- import java.util.List;
- import org.activiti.engine.HistoryService;
- import org.activiti.engine.ProcessEngine;
- import org.activiti.engine.ProcessEngineConfiguration;
- import org.activiti.engine.RepositoryService;
- import org.activiti.engine.RuntimeService;
- import org.activiti.engine.TaskService;
- import org.activiti.engine.history.HistoricProcessInstance;
- import org.activiti.engine.task.Task;
- /**
- * 根据activiti官方提供的 编写
- * 1.财务部门填写月财务报告
- * 2.股东审核月财务审计报告
- *
- *
- * activiti提供的财务报告审核
- * <!-- 采用用户组为accountancy编写财务报告 -->
- * <userTask id="usertask1" name="财务编写月财务报告" activiti:candidateGroups="accountancy"></userTask>
- * <!-- 采用用户组为management编写财务报告 -->
- * <userTask id="usertask2" name="股东审核月财务审计报告" activiti:candidateGroups="management"></userTask>
- *
- * 备注:
- * 默认的两个用户:
- * <pre>
- * 用户名 密码 用户组
- Table 2.1. The demo users
- UserId Password Security roles
- kermit kermit admin
- gonzo gonzo manager
- fozzie fozzie user
- * </pre>
- *
- * @author longgangbai
- *
- * 2011-12-18 下午04:08:46
- */
- public class CustomFinancialReportActiviti {
- public static void main(String[] args) {
- // Create Activiti process engine
- //创建一个流程引擎对象
- // ProcessEngine processEngine = ProcessEngineConfiguration
- // .createStandaloneProcessEngineConfiguration()
- // .buildProcessEngine();
- //创建一个流程引擎对象(为了便于多册测试,修改 name="databaseSchemaUpdate" value="create-drop" 默认为ture)
- ProcessEngine processEngine=ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml").buildProcessEngine();
- // Get Activiti services
- //获取流程相关的服务
- RepositoryService repositoryService = processEngine.getRepositoryService();
- RuntimeService runtimeService = processEngine.getRuntimeService();
- // Deploy the process definition
- //部署相关的流程配置
- repositoryService.createDeployment()
- .addClasspathResource("diagrams/financialReport.bpmn20.xml")
- .deploy();
- // Start a process instance
- //获取流程实例
- String procId = runtimeService.startProcessInstanceByKey("financialReport").getId();
- // Get the first task
- TaskService taskService = processEngine.getTaskService();
- //获取accountancy组可能要操作的任务
- List<Task> tasks = taskService.createTaskQuery().taskCandidateGroup("accountancy").list();
- for (Task task : tasks) {
- System.out.println("Following task is available for accountancy group: " + task.getName());
- //设置fozzie代办 claim it
- taskService.claim(task.getId(), "fozzie");
- }
- // Verify Fozzie can now retrieve the task
- //审核fozzie当前的获取的任务数量
- tasks = taskService.createTaskQuery().taskAssignee("fozzie").list();
- for (Task task : tasks) {
- System.out.println("Task for fozzie: " + task.getName());
- // Complete the task
- //设置forzze完毕
- taskService.complete(task.getId());
- }
- System.out.println("Number of tasks for fozzie: "
- + taskService.createTaskQuery().taskAssignee("fozzie").count());
- // Retrieve and claim the second task
- //管理者审核报告并让kermit代办
- tasks = taskService.createTaskQuery().taskCandidateGroup("management").list();
- for (Task task : tasks) {
- System.out.println("Following task is available for accountancy group: " + task.getName());
- taskService.claim(task.getId(), "kermit");
- }
- // Completing the second task ends the process
- //完成报告
- for (Task task : tasks) {
- taskService.complete(task.getId());
- }
- // verify that the process is actually finished
- //查询流程实例完成事件
- HistoryService historyService = processEngine.getHistoryService();
- HistoricProcessInstance historicProcessInstance =
- historyService.createHistoricProcessInstanceQuery().processInstanceId(procId).singleResult();
- System.out.println("Process instance end time: " + historicProcessInstance.getEndTime());
- }
- }
运行结果如下:
- 信息: ProcessEngine default created
- 2011-12-18 17:06:00 org.activiti.engine.impl.jobexecutor.JobAcquisitionThread run
- 信息: JobAcquisitionThread starting to acquire jobs
- 2011-12-18 17:06:00 org.activiti.engine.impl.bpmn.deployer.BpmnDeployer deploy
- 信息: Processing resource diagrams/financialReport.bpmn20.xml
- 2011-12-18 17:06:01 org.activiti.engine.impl.bpmn.parser.BpmnParse parseDefinitionsAttributes
- 信息: XMLSchema currently not supported as typeLanguage
- 2011-12-18 17:06:01 org.activiti.engine.impl.bpmn.parser.BpmnParse parseDefinitionsAttributes
- 信息: XPath currently not supported as expressionLanguage
- Following task is available for accountancy group:<span style="color: #ff0000;"> 财务编写月财务报告</span>
- <span style="color: #ff0000;">Task for fozzie: 财务编写月财务报告</span>
- <span style="color: #ff0000;">Number of tasks for fozzie: 0</span>
- <span style="color: #ff0000;">Following task is available for accountancy group: 股东审核月财务审计报告</span>
- <span style="color: #ff0000;">Process instance end time: Sun Dec 18 17:06:01 CST 2011
- </span>