我的第一個activiti實例 (代碼方式) ctiviti入門列子一個簡單的activiti請假流程


轉:

activiti入門列子一個簡單的activiti請假流程

我的第一個activiti實例

整個項目的目錄結構:


pom.xml:

[html]  view plain  copy
 
  1. <project= =  
  2. => <modelVersion></modelVersion> <groupId></groupId> <artifactId></artifactId> <version></version> <packaging></packaging> <name></name> <url></url> <properties> <project.build.sourceEncoding></project.build.sourceEncoding> </properties> <dependencies>   
  3. <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency>   
  4. <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency>   
  5. <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency>   
  6. <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency>   
  7. <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency>   
  8. <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency>   
  9. <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency>   
  10. <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> <dependency> <groupId></groupId> <artifactId></artifactId> <version></version> </dependency> </dependencies> </project>  


activiti.cfg.xml:

 

[html]  view plain  copy
 
  1. <?xml= =?> <beans=  
  2. =  
  3. => <bean= => <property= = /> <property= = /> <property= = /> <property= = /> <property= = /> </bean> </beans>  

 

 

在 resource 下新建Activiti Diagram

可以通過這個地址安裝插件  《Activiti BPMN 2.0 designer - http://activiti.org/designer/update/ 》




將UserTask分別修改成入下圖所示



修改好ID 和 NAME然后在修改Main config中的Assignee,員工請假修改為張三,老板審批修改為老板



點擊Window--->Preferences--->Activiti--->Save Actions:將Create process definition image when saving the diagram勾選

然后保存bpmn文件的時候會自動幫你截圖

通過ProcessEngines.getDefaultProcessEngine獲取流程引擎

[java]  view plain  copy
 
  1. //通過activiti.cfg.xml獲取流程引擎  class"java">  

 

通過源碼可以看到  getDefaultProcessEngine方法會通過默認的activiti.cfg.xml文件名或者是activiti-context.xml文件名讀取xml文件

 

當獲取到的processEngine對象不為空時   就會在數據庫創建關於activiti的23張表

具體作用如下:

 

跟詳細的情況可以去下面這個地址了解:

http://www.cnblogs.com/llzgzljl/archive/2013/10/07/3356108.html

此時你可以在數據庫中看到act_ge_property表中插入了3條數據

將MyLeave.bpmn和MyLeave.png打包成myleave.zip文件(一定要是zip別壓縮成rar)

執行以下方法,發布請假流程:

[java]  view plain  copy
 
  1. /** 
  2.  * 發布流程 
  3.  * 發布流程后,流程文件會保存到數據庫中 
  4.  */ @Test publicvoid   
  5. this"myleave.zip" new   
  6. )  
  7. }  

查看數據庫  發布的流程文件信息會保存在下面的三張表中:

 

我們可以通過RepositoryService獲取詳細的流程定義信息

[java]  view plain  copy
 
  1. @Test publicvoid   
  2.   
  3. );  
  4.   
  5.   
  6. for +pd.getId()++pd.getName()++pd.getKey()++pd.getVersion()++pd.getResourceName()++pd.getDiagramResourceName());  
  7. }  

key 和 name 就是我們原先畫bpmn時候聲明的:

 

使用流程定義的Key發布一個請假流程:

[java]  view plain  copy
 
  1. /** 
  2.      * 發布流程 
  3.      */   
  4. publicvoid          * 啟動請假單流程  並獲取流程實例 
  5.          * 因為該請假單流程可以會啟動多個所以每啟動一個請假單流程都會在數據庫中插入一條新版本的流程數據 
  6.          * 通過key啟動的流程就是當前key下最新版本的流程 
  7.          *  
  8.          */ );  
  9. +processInstance.getId()++processInstance.getActivityId());  
  10.     }  

當流程發布后在  act_ru_task ,act_ru_execution, act_ru_identitylink 表中插入流程數據

接下來就可以通過用戶ID去查看該用戶的任務了

[java]  view plain  copy
 
  1. /** 
  2.  * 查看任務 
  3.  */ @Test publicvoid   
  4.   
  5. )  
  6. for +task.getId()++task.getName()++task.getAssignee()++task.getCreateTime());  
  7. }  

提出請假申請,啟動流程

[java]  view plain  copy
 
  1. @Test publicvoid   
  2. ;  
  3.   
  4. }  

查看數據庫變化 可以看到 表中的數據已經變成了老板審批相關數據

老板查看任務 ,並審批請假

[java]  view plain  copy
 
  1. /** 
  2.  * 查看任務 
  3.  */ @Test publicvoid   
  4.   
  5. )  
  6. for +task.getId()++task.getName()++task.getAssignee()++task.getCreateTime());  
  7. }  
[java]  view plain  copy
 
  1. @Test publicvoid   
  2. ;  
  3.   
  4. }  

流程完畢,可以再act_hi_actinst表中看到整個請假流程

 

整個流程的過程是  1.發布流程 --->2.啟動流程--->3.相關人查看任務完成並完成

數據都是存放在數據庫中

 


免責聲明!

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



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