莊周夢蝶

          生活、程序、未來
             :: 首頁 ::  ::  :: 聚合  :: 管理

          用osworkflow寫一個請假例子

          Posted on 2007-03-02 16:07 dennis 閱讀(12311) 評論(26)  編輯  收藏 所屬分類: java工作流
          update:這個例子是不當的,更合適的例子請自己上javaeye上搜索個帖子。源碼俺早就丟了,請不要再發郵件給我,謝謝。  
              osworkflow擴展非常容易,跟我們的應用結合起來使用也很容易。假設一個請假流程:員工請假,需要經過部門經理和人力資源部經理兩人共同審批,只有當兩人都許可時才通過,任一人駁回就失效,也就是一個and split和and Join流程,并且我們附加一個要求,當發送請假請求、許可和駁回這幾個操作時都將發送一條消息給相應的用戶。
              流程定義文件如下:
          <?xml version="1.0" encoding="UTF-8" ?>
          <!DOCTYPE workflow PUBLIC "-//OpenSymphony Group//DTD OSWorkflow 2.7//EN" 
          "http://www.opensymphony.com/osworkflow/workflow_2_7.dtd"
          >
          <workflow>
              
          <initial-actions>
                  
          <action id="0" name="開始">
                      
          <pre-functions>
                          
          <function type="class">
                              
          <arg name="class.name">
                                  com.opensymphony.workflow.util.Caller
                              
          </arg>
                          
          </function>
                      
          </pre-functions>
                      
          <results>
                          
          <unconditional-result old-status="Finished"
                              status
          ="Underway" step="1" owner="${caller}" />
                      
          </results>
                  
          </action>
              
          </initial-actions>

              
          <steps>
                  
          <step id="1" name="填假單">
                      
          <external-permissions>
                          
          <permission name="permA">
                              
          <restrict-to>
                                  
          <conditions type="AND">
                                      
          <condition type="class"><!--流程處于Underway狀態(流程已經啟動)-->
                                          
          <arg name="class.name">
                                              com.opensymphony.workflow.util.StatusCondition
                                          
          </arg>
                                          
          <arg name="status">Underway</arg>
                                      
          </condition>
                                      
          <condition type="class">
                                          
          <arg name="class.name">
                                              com.opensymphony.workflow.util.AllowOwnerOnlyCondition
                                          
          </arg>
                                      
          </condition>
                                  
          </conditions>
                              
          </restrict-to>
                          
          </permission>
                      
          </external-permissions>
                      
          <actions>
                          
          <action id="1" name="送出">
                              
          <restrict-to>
                                  
          <conditions type="AND">
                                      
          <condition type="class"><!--流程處于Underway狀態(流程已經啟動)-->
                                          
          <arg name="class.name">
                                              com.opensymphony.workflow.util.StatusCondition
                                          
          </arg>
                                          
          <arg name="status">Underway</arg>
                                      
          </condition>
                                      
          <condition type="class">
                                          
          <arg name="class.name">
                                              com.opensymphony.workflow.util.AllowOwnerOnlyCondition
                                          
          </arg>
                                      
          </condition>
                                  
          </conditions>
                              
          </restrict-to>
                              
          <pre-functions>
                                  
          <function type="class">
                                      
          <arg name="class.name">
                                          com.opensymphony.workflow.util.Caller
                                      
          </arg>
                                  
          </function>

                              
          </pre-functions>
                              
          <results>
                                  
          <unconditional-result old-status="Finished"
                                      split
          ="1" status="Queued">
                                      
          <post-functions>
                                          
          <function type="class">
                                              
          <arg name="class.name">
                                                  net.rubyeye.leavesys.service.workflow.SendRemindInfFunction
                                              
          </arg>
                                              
          <arg name="groupName">
                                                  AND (GROUPNAME='dept_manager' or
                                                  GROUPNAME='comp_manager')
                                              
          </arg>
                                              
          <arg name="content">
                                                  you have leavemsg to
                                                  check!please check it!
                                              
          </arg>
                                          
          </function>
                                      
          </post-functions>
                                  
          </unconditional-result>
                              
          </results>
                          
          </action>
                      
          </actions>
                  
          </step>
                  
          <step id="2" name="部門經理批假單">
                      
          <actions>
                          
          <action id="2" name="準許">
                              
          <restrict-to>
                                  
          <conditions>
                                      
          <condition type="class">
                                          
          <arg name="class.name">
                                              com.opensymphony.workflow.util.OSUserGroupCondition
                                          
          </arg>
                                          
          <arg name="group">dept_manager</arg>
                                      
          </condition>
                                  
          </conditions>
                              
          </restrict-to>
                              
          <pre-functions>
                                  
          <function type="class">
                                      
          <arg name="class.name">
                                          com.opensymphony.workflow.util.Caller
                                      
          </arg>
                                  
          </function>
                                  
          <function type="beanshell">
                                      
          <arg name="script">
                                          propertySet.setString("action1",
                                          "success");
                                      
          </arg>
                                  
          </function>
                              
          </pre-functions>
                              
          <results>
                                  
          <unconditional-result old-status="Finished"
                                      status
          ="Queued" join="1" owner="${caller}" />
                              
          </results>
                          
          </action>

                          
          <action id="3" name="駁回">
                              
          <restrict-to>
                                  
          <conditions>
                                      
          <condition type="class">
                                          
          <arg name="class.name">
                                              com.opensymphony.workflow.util.OSUserGroupCondition
                                          
          </arg>
                                          
          <arg name="group">dept_manager</arg>
                                      
          </condition>
                                  
          </conditions>
                              
          </restrict-to>
                              
          <pre-functions>
                                  
          <function type="class">
                                      
          <arg name="class.name">
                                          com.opensymphony.workflow.util.Caller
                                      
          </arg>
                                  
          </function>
                                  
          <function type="beanshell">
                                      
          <arg name="script">
                                          propertySet.setString("action1",
                                          "fail");
                                      
          </arg>
                                  
          </function>
                              
          </pre-functions>
                              
          <results>
                                  
          <unconditional-result old-status="Finished"
                                      status
          ="Queued" join="2" owner="${caller}" />
                              
          </results>
                          
          </action>
                      
          </actions>
                  
          </step>

                  
          <step id="3" name="公司經理批假單">
                      
          <actions>
                          
          <action id="4" name="準許">
                              
          <restrict-to>
                                  
          <conditions>
                                      
          <condition type="class">
                                          
          <arg name="class.name">
                                              com.opensymphony.workflow.util.OSUserGroupCondition
                                          
          </arg>
                                          
          <arg name="group">comp_manager</arg>
                                      
          </condition>
                                  
          </conditions>
                              
          </restrict-to>
                              
          <pre-functions>
                                  
          <function type="class">
                                      
          <arg name="class.name">
                                          com.opensymphony.workflow.util.Caller
                                      
          </arg>
                                  
          </function>
                                  
          <function type="beanshell">
                                      
          <arg name="script">
                                          propertySet.setString("action2",
                                          "success");
                                      
          </arg>
                                  
          </function>
                              
          </pre-functions>
                              
          <results>
                                  
          <unconditional-result old-status="Finished"
                                      status
          ="Queued" join="1" owner="${caller}" />
                              
          </results>
                          
          </action>

                          
          <action id="5" name="駁回">
                              
          <restrict-to>
                                  
          <conditions>
                                      
          <condition type="class">
                                          
          <arg name="class.name">
                                              com.opensymphony.workflow.util.OSUserGroupCondition
                                          
          </arg>
                                          
          <arg name="group">dept_manager</arg>
                                      
          </condition>
                                  
          </conditions>
                              
          </restrict-to>
                              
          <pre-functions>
                                  
          <function type="class">
                                      
          <arg name="class.name">
                                          com.opensymphony.workflow.util.Caller
                                      
          </arg>
                                  
          </function>
                                  
          <function type="beanshell">
                                      
          <arg name="script">
                                          propertySet.setString("action2",
                                          "fail");
                                      
          </arg>
                                  
          </function>
                              
          </pre-functions>
                              
          <results>
                                  
          <unconditional-result old-status="Finished"
                                      status
          ="Queued" join="2" owner="${caller}" />
                              
          </results>
                          
          </action>
                      
          </actions>
                  
          </step>

                  
          <step id="4" name="停止" />
              
          </steps>
              
          <splits>
                  
          <split id="1">
                      
          <unconditional-result old-status="Finished" status="Queued"
                          step
          ="2" />
                      
          <unconditional-result old-status="Finished" status="Queued"
                          step
          ="3" />
                  
          </split>
              
          </splits>
              
          <joins>
                  
          <join id="1">
                      
          <conditions type="AND">
                          
          <condition type="beanshell">
                              
          <arg name="script">
                                  
          <![CDATA[
               "Finished".equals(jn.getStep(2).getStatus()) &&
                  "Finished".equals(jn.getStep(3).getStatus())&&"success".equals(propertySet.getString("action1"))&&
                  "success".equals(propertySet.getString("action2"))
                
          ]]>
                              
          </arg>
                          
          </condition>
                      
          </conditions>
                      
          <unconditional-result old-status="Finished" status="Queued"
                          step
          ="4"/>
                  
          </join>

                  
          <join id="2">
                      
          <conditions type="OR">
                          
          <condition type="beanshell">
                              
          <arg name="script">
                                  
          <![CDATA[
               "Finished".equals(jn.getStep(2).getStatus()) &&"fail".equals(propertySet.getString("action1"))
                
          ]]>
                              
          </arg>
                          
          </condition>
                          
          <condition type="beanshell">
                              
          <arg name="script">
                                  
          <![CDATA[
              
                  "Finished".equals(jn.getStep(3).getStatus())&&"fail".equals(propertySet.getString("action2"))
                
          ]]>
                              
          </arg>
                          
          </condition>
                      
          </conditions>
                      
          <unconditional-result old-status="Finished" step="4"
                          status
          ="Queued">
                          
          <post-functions>
                              
          <function type="class">
                                  
          <arg name="class.name">
                                      net.rubyeye.leavesys.service.workflow.SendRemindInfFunction
                                  
          </arg>
                                  
          <arg name="groupName">
                                      AND GROUPNAME='employee' 
                                  
          </arg>
                                  
          <arg name="content">
                                      you leveamsg is fail!!!
                                  
          </arg>
                              
          </function>
                          
          </post-functions>
                      
          </unconditional-result>
                  
          </join>
              
          </joins>
          </workflow>

          請注意,我們在許可或者通過的時候propertySet.setString("action2",......),propertySet.setString("action3",......),然后在join點判斷,如果兩個都是success,流程結束;如果一個是fail,就發送一個消息給員工。

          發送消息的function像這樣:
          package net.rubyeye.leavesys.service.workflow;

          import java.sql.SQLException;
          import java.util.Map;

          import net.rubyeye.leavesys.domain.RemindInf;
          import net.rubyeye.leavesys.service.ManagerFactory;

          import com.opensymphony.module.propertyset.PropertySet;
          import com.opensymphony.workflow.FunctionProvider;
          import com.opensymphony.workflow.WorkflowException;

          public class SendRemindInfFunction implements FunctionProvider {

              
          public void execute(Map transientVars, Map args, PropertySet ps)
                      
          throws WorkflowException {
                  String groupName 
          = (String) args.get("groupName");
                  String content 
          = (String) args.get("content");
                  RemindInf remindInf 
          = new RemindInf();
                  remindInf.setContent(content);
                  
          try {
                      ManagerFactory.getRemindService().addRemindInfByGroupName(
                              groupName, remindInf);
                  } 
          catch (SQLException e) {
                      e.printStackTrace();
                  } 
          catch (Exception ex) {
                      ex.printStackTrace();
                  }
              }

          }

          得到兩個參數groupName和content(消息內容),調用業務對象發送消息。

          完整代碼下載在《LeaveSystem》

          代碼用到了自己過去寫的一個MVC框架和持久層,對此有興趣的參考這三篇文章:
          《設計自己的MVC框架》
          《設計模式之事務處理》
          《使用Annotation設計持久層》

          如果僅僅是想了解osworkflow的應用,建議您跑下流程,讀讀相關幾個業務類(LeaveServiceImpl.java,SendRemindInfFunction.java,service包下)即可。解壓縮后的文件可以直接導入myeclipse工程,部署在tomcat下,數據庫用的是oracle。跑起來以后可以用3個用戶登錄,test是雇員組,dennis是部門經理組,jordan是公司經理,都不需要密碼。寫的比較簡單,只是實驗性質,見諒。

          我認為使用osworkflow,只要了解了它的表結構和主要原理,根據你的業務需要結合幾張主要表(os_wfentry,os_currentstep,os_historystep等)合理設計數據庫和業務流程,可以省去過去為每個業務流程對象創建的一大堆flag(標志,目前的流程狀態)的累贅,充分利用工作流的威力。比如為部門經理和人力資源部經理顯示不同的需要審批的假單列表,只要結合os_historystep表進行聯合查詢,部門經理的應該是執行了未執行acion2,step在3的;而人力資源部經理得到的同樣是step在3,action未執行3的。

          手癢癢,很想把去年為一家公司寫的績效考核系統改寫一下,當時設計的一個contract對象擁有7,8個flag來標志合約狀態(直接上級審核,人力資源評價,KPI評價等),搞的非常混亂,而且流程寫死在代碼里,如果以后要改變考核流程,只有重新寫過一套。不過那家公司是國有企業,每年的固定的預算費用一定要花掉,反正大家一起賺國家的錢嘛。


          評論

          # re: 用osworkflow寫一個請假例子  回復  更多評論   

          2007-03-02 17:38 by BeanSoft
          氣氛有點冷清...

          # re: 用osworkflow寫一個請假例子[未登錄]  回復  更多評論   

          2007-03-02 18:11 by test
          沒有運行代碼下載啊?

          # re: 用osworkflow寫一個請假例子(提供代碼下載)  回復  更多評論   

          2007-03-02 18:54 by dennis
          @test
          放上去了,因為用到過去自己寫一些基礎框架,怕誤導人,一開始沒敢放上去,下載地址
          http://www.aygfsteel.com/Files/killme2008/LeaveSystem.rar

          # re: 用osworkflow寫一個請假例子(提供代碼下載)  回復  更多評論   

          2007-03-05 14:21 by kk
          請問下您的這個例子如何配置運行,我部署在tomcat下好象運行不了。
          我的郵箱BreatheTakingBeauty@hotmail.com

          # re: 用osworkflow寫一個請假例子(提供代碼下載)  回復  更多評論   

          2007-03-05 21:23 by hello
          最近公司 在 osworkflow & jbpm 間做 選擇,
          我研究 osworkflow ,看到 你 的 例子 ,不錯 ,贊一個 ,
          可代碼 不能 下 嗎??

          可否發 給 本人,謝謝

          truthyd@126.com

          # re: 用osworkflow寫一個請假例子(提供代碼下載)  回復  更多評論   

          2007-03-06 08:46 by dennis
          @hello
          我對osworkflow也在學習階段,這幾天看了下代碼,這個例子還是寫的太差,特別是沒有用到osworkflow的狀態查詢功能,而是直接結合表來查詢數據庫,導致代碼寫死了。沒什么參考價值,準備改改

          # re: 用osworkflow寫一個請假例子(提供代碼下載)  回復  更多評論   

          2007-03-06 10:11 by allan
          你好,你的那個例子似乎不能下,能不能發給我一份?
          地址:allan0410@qq.com
          也交個朋友,我現在急需一個像你的這個例子,對于初學osworkflow的幫助很大。。。

          # re: 用osworkflow寫一個請假例子(提供代碼下載)  回復  更多評論   

          2007-03-06 10:15 by allan
          在線等待。。。!~

          # re: 用osworkflow寫一個請假例子  回復  更多評論   

          2007-03-06 11:26 by dennis
          @allan
          又放上去了,例子寫的確實不好,有空修改下,最好的方式還是調用osworkflow的查詢API來進行狀態查詢,而非我現在做的直接查詢數據庫。倒有點后悔放上去了,希望沒誤導人

          # re: 用osworkflow寫一個請假例子(提供代碼下載)  回復  更多評論   

          2007-03-06 15:11 by allan
          怎么用eclipse3.2打開包錯啊?。。。
          似乎沒包

          # re: 用osworkflow寫一個請假例子(提供代碼下載)  回復  更多評論   

          2007-03-06 15:17 by allan
          能不能告訴我你那個工程要導入那些包??

          # re: 用osworkflow寫一個請假例子  回復  更多評論   

          2007-03-06 16:24 by allan
          跪求myutil.jar包,樓主能不能將源碼發給我。。。
          感激泣零

          # re: 用osworkflow寫一個請假例子  回復  更多評論   

          2007-03-06 16:29 by dennis
          @allan
          myutll.jar在WEB-INF/lib下,其他的就是需要osworflow的支持包,請自行下載

          # re: 用osworkflow寫一個請假例子  回復  更多評論   

          2007-03-07 13:21 by dennis
          那里需要重寫ConnectionManager,你所需要做的只是配置數據源而已,我不是在db_setup目錄下方了一個leave.xml,修改下里面的數據庫名配置,拷貝到tomcat安裝目錄下的\conf\Catalina\localhost就可以了

          # re: 用osworkflow寫一個請假例子  回復  更多評論   

          2007-03-07 14:19 by allan
          昏,問題解決了。。。
          原來是要拷到tomcat-common-lib下面
          這種連接方式太依賴服務器了。。。

          # re: 用osworkflow寫一個請假例子  回復  更多評論   

          2007-03-07 15:16 by dennis
          @allan
          哎,本來就是個例子,你指望他干什么呢?我本來就不想把代碼放上來的。請別再刷評論了,謝謝

          # re: 用osworkflow寫一個請假例子  回復  更多評論   

          2007-03-14 10:30 by zyg
          hi,你那個例子連接失效,能不能發郵件給我一個,萬分感謝

          我的郵箱地址 yg_zhangyg@tecamo.com

          # re: 用osworkflow寫一個請假例子  回復  更多評論   

          2007-03-22 15:01 by hiya
          代碼下不了。是否已經刪了。
          我的郵箱:chf@tsinghua.org.cn
          有BaseJDBCProvider.java文件嗎,發一個,謝謝先。

          我連不上數據源
          Could not look up DataSource錯。

          請教!!!!
          急!!!!

          # re: 用osworkflow寫一個請假例子  回復  更多評論   

          2007-03-27 10:34 by aa
          代碼下不了。是否已經刪了。
          我的郵箱:zzzyqqq@163.com
          有BaseJDBCProvider.java文件嗎,發一個,謝謝先。

          # re: 用osworkflow寫一個請假例子[未登錄]  回復  更多評論   

          2007-04-05 23:45 by Jeff
          代碼下不了? 我的郵箱是wji@ryerson.ca 請發一份好嗎?

          # re: 用osworkflow寫一個請假例子  回復  更多評論   

          2007-04-13 15:40 by yangrong
          能把你的例子給我發一份嗎?
          yangrongqiang@163.com,謝謝。

          # re: 用osworkflow寫一個請假例子  回復  更多評論   

          2007-04-15 11:04 by dennis
          @yangrong
          sorry,這個代碼我已經刪除了,我覺的寫的很爛,那時對osworkflow的理解還停留在初步了解,代碼不能見人的。請搜索CSDN java版上一個帖子,我記的有一個別人寫的例子非常不錯。

          # re: 用osworkflow寫一個請假例子  回復  更多評論   

          2007-04-20 16:17 by G_G
          房主不厚道
          :(

          # re: 用osworkflow寫一個請假例子  回復  更多評論   

          2007-06-12 17:17 by yuzhongren
          那位有原碼的能不能發給我一份阿,謝謝了zfjwzh@163.com

          # re: 用osworkflow寫一個請假例子  回復  更多評論   

          2007-06-13 13:54 by zhangying
          你好
          能給我發一份嗎>我的郵箱zhangy@sict.ac.cn
          非常感謝

          # re: 用osworkflow寫一個請假例子  回復  更多評論   

          2007-07-03 14:13 by e
          你好 。
          給我也發一份。
          guzhuopiao@hotmail.com
          主站蜘蛛池模板: 沁水县| 昔阳县| 宜州市| 竹北市| 葵青区| 津南区| 峨眉山市| 鲁甸县| 温州市| 宣汉县| 香港 | 河北区| 胶州市| 梁平县| 临夏县| 神池县| 杭锦后旗| 钟山县| 东兴市| 新邵县| 元氏县| 盖州市| 奎屯市| 会理县| 鱼台县| 徐水县| 彰武县| 金昌市| 龙川县| 淮阳县| 亳州市| 南宫市| 刚察县| 荆门市| 武川县| 荔浦县| 类乌齐县| 崇仁县| 武功县| 山东| 勃利县|