`

充分利用 OSWorkflow 的 function

阅读更多

转自:http://www.blogjava.net/rosen/archive/2005/08/12/9888.html

 

  使用 OSWorkflow 已经有段时间了,现在看来实际需求不是请假条流程原型这么简单。
   
    有这样的需求:OA 系统中的公文审批共有六个 step,采用单点(不牵涉 split 和 join)逐级审核方式,不同角色登陆时,由同一页面处理,为了便于收发文统计,必须知道下一个接收人是哪个。
   
    由于在触发当前 action 的同时就要设置好下一接收者,遂需要引进新的协作表。当 action 时要调用另外的 save 方法,而这一过程当然不能在表现层进行。最开始的做法是用一个辅助 service 来取出每个 action 的下一接收者,如下:

  public List getLeader(int type,int companyId) {
  switch (type) {
   case 1:
    return docSendDao.getThisFaculty(companyId);
   case 2:
    return docSendDao.getOffice();
   case 3:
    return docSendDao.getSecGroup();
   case 4:
    return docSendDao.getOfficeLead();
   case 5:
    return docSendDao.getSecFaculty();
   default :
    return new ArrayList();
  }
 }

    这种做法在开发的前期还觉得不错,随着需求的进一步详细,发现当新增、修改流程时,也许我们要在这个 service 中满山遍野的找寻到底代码在哪里。更糟糕的是产品提交用户后,用户不会花费这么大的耐心让你这样维护。在经过短暂的思考后,决定利用 OSWorkflow 的 FunctionProvider 接口和 script 做文章。
   
    一个比较成熟的想法是(如各位有更好的方案不妨交流):每个流程都可能面临修改,那就把流程的每个 action 要做的事抽取出来,这样修改起来相对独立,比如要把下一默认接收者改成其他人;另一个目的是快速响应用户对新流程的需求,在提出需求后,生成相应的流程文 件及每个 action 要做的事,提交到服务器,重启就可以用了,而不是在已有代码基础上新增。这里的“每个 action 要做的事”就是 OSWorkflow 的 FunctionProvider 接口,实现这个接口,就可以为所欲为了。
   
    代码片断如下:

 流程定义
    <step id="1" name="科领导审批">
      <actions>
        <action id="2" name="批准" view="批准">
          <results>
            <unconditional-result id="2" old-status="Finished" status="Queued" step="2" owner="${stepOwner}">
           <pre-functions>
           //向 FacultyLea 类说明当前调用者
    <function type="beanshell">
     <arg name="script">
                        String caller = context.getCaller();
                        transientVars.put("caller", caller);
                    </arg>
    </function>
                     //FunctionProvider 实现类
                     //向协作表中写入当前调用者和下一默认接收者
             <function name="set.caller" type="class">
               <arg name="class.name">***.*****.util.FacultyLea</arg>               </function>
           </pre-functions>
        </unconditional-result>
          </results>
        </action>
        <action id="3" name="拒绝" view="拒绝">
          <results>
            <unconditional-result id="3" old-status="Finished" status="Finished" step="7"/>
          </results>
        </action>
      </actions>
    </step>

FacultyLea

public class FacultyLea implements FunctionProvider{
 
 ReadProperty readProperty = ReadProperty.getInstance();
 ApplicationContext ctx=new
 FileSystemXmlApplicationContext(System.getProperty("user.dir")+"/web/WEB-INF/classes/applicationContext.xml");
 
 private SendDao sendDao = (SendDao) ctx.getBean("sendDao");
 private DocService docService = (DocService) ctx.getBean("docService");
 
 public void execute(Map transientVars, Map args, PropertySet ps) throws WorkflowException {
  long l=((HibernateCurrentStep)((Collection)transientVars.get("currentSteps")).toArray()[0]).getEntryId();
 Doc md=docService.findDocByWrokFlowId(l+"");
 String caller=(String)transientVars.get("caller");
  
 //设置下一步的接收者
 Timestamp date = new Timestamp(System.currentTimeMillis());
 String query = "some hql here";
 List leaders = docSendDao.find(query);
        for(int i=0;i<leaders.size();i++){
            Send send = new Send();
            send.setSendUser(new UserLogin(new Integer(caller)));
            send.setDoc(md);
            ......
            sendDao.save(send);
        }
  
 //设置该步骤处理者
  transientVars.put("stepOwner", caller);
 }
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics