NutzCN Logo
问答 reassignmenthandler里面,我如何指定委派对象?
发布于 172天前 作者 qq_f3f924f5 94 次浏览 复制 上一个帖子 下一个帖子
标签: fireflow

reassignmenthandler里面,我如何指定委派对象?

2 回复
/**
 * 工作交接
 * @param originalOwnerId
 * @param acceptUserId
 * @return
 */
@At
@Ok("jsp:/template/system/workflow/ReassignAllWorks.jsp")
public Map<String,Object> handover(@Param("originalOwnerId") String originalOwnerId ,
       @Param("acceptUserId") String acceptUserId,
       @Param("workItemId") String[] workItemIds
       ){
    final org.fireflow.engine.modules.ousystem.User currentUser = WorkflowUtil
         .getCurrentWorkflowUser();
    final WorkflowSession fireSession = WorkflowSessionFactory
         .createWorkflowSession(fireflowRuntimeContext, currentUser); 

    WorkflowStatement fireStatement = fireSession.createWorkflowStatement();

    WorkflowQuery<WorkItem> workItemQuery = fireSession.createWorkflowQuery(WorkItem.class);
    /*
    workItemQuery.add(Restrictions.eq(WorkItemProperty.OWNER_ID, originalOwnerId));
    workItemQuery.add(Restrictions.lt(WorkItemProperty.STATE, WorkItemState.DELIMITER));
    workItemQuery.addOrder(Order.desc(WorkItemProperty.CREATED_TIME));
    List<WorkItem> aliveWorkItems = workItemQuery.list();
    */

    OUSystemConnector ouConnector = fireflowRuntimeContext
         .getDefaultEngineModule(OUSystemConnector.class);


    final org.fireflow.engine.modules.ousystem.User nextUser = ouConnector
         .findUserById(acceptUserId);
    List<org.fireflow.engine.modules.ousystem.User> nextOwnerList = new ArrayList<org.fireflow.engine.modules.ousystem.User>();
    nextOwnerList.add(nextUser);

// if (aliveWorkItems!=null && aliveWorkItems.size()>0){
// for (WorkItem wi : aliveWorkItems){
if (workItemIds!=null && workItemIds.length>0){
for (String workItemId : workItemIds){
ReassignmentHandler reassignHandler = new ReassignmentHandler();
reassignHandler.setPotentialOwners(nextOwnerList);
reassignHandler.setParentWorkItemId(workItemId);

         WorkItem wi = workItemQuery.get(workItemId);
         if (wi==null) continue;
         try {
          if (wi.getState()==WorkItemState.INITIALIZED){
              fireStatement.claimWorkItem(wi.getId());
          }
          fireStatement.reassignWorkItemTo(wi.getId(), reassignHandler, null, null, "工作交接");
         } catch (InvalidOperationException e) {
          log.error("工作交接发生错误", e);
         }
       }
    }

    //Fire workflow没有缺省的工作交接接口,此处暂时直接修改表T_FF_RT_PROCESS_INSTANCE
    dao().update("T_FF_RT_PROCESS_INSTANCE",Chain.make("creator_id",nextUser.getId())
         .add("creator_name",nextUser.getName()).add("creator_dept_id", nextUser.getDeptId())
         .add("creator_dept_name", nextUser.getDeptName())
         ,
         Cnd.where("creator_id","=",originalOwnerId)
         .and("state","<",ProcessInstanceState.DELIMITER.getValue()));


    Map<String,Object> result = gotoReassignAllWorks(originalOwnerId);

    return result;


}
/*
 * 工作委派他人
 */
@At
@Ok("json")
public Map<String, Object> reassignWorkItemTo(
       @Param("workItemId") String workItemId,
       @Param("nextOwnerId") String nextOwnerId, @Param("note") String note,String needClaimWorkItem) {
    Map<String, Object> result = new HashMap<String, Object>();
    final org.fireflow.engine.modules.ousystem.User currentUser = WorkflowUtil
         .getCurrentWorkflowUser();
    final WorkflowSession fireSession = WorkflowSessionFactory
         .createWorkflowSession(fireflowRuntimeContext, currentUser);
    final WorkflowStatement statement = fireSession
         .createWorkflowStatement();
    try {
       OUSystemConnector ouConnector = fireflowRuntimeContext
          .getDefaultEngineModule(OUSystemConnector.class);

       if ("1".equals(needClaimWorkItem)){
         statement.claimWorkItem(workItemId);
       }

       final org.fireflow.engine.modules.ousystem.User nextUser = ouConnector
          .findUserById(nextOwnerId);
       List<org.fireflow.engine.modules.ousystem.User> nextOwnerList = new ArrayList<org.fireflow.engine.modules.ousystem.User>();
       nextOwnerList.add(nextUser);



       ReassignmentHandler reassignHandler = new ReassignmentHandler();
       reassignHandler.setPotentialOwners(nextOwnerList);
       reassignHandler.setParentWorkItemId(workItemId);

       statement.reassignWorkItemTo(workItemId, reassignHandler, null,
          null, note);

       result.put(MainModule.JTABLE_RESULT_KEY,
          MainModule.JTABLE_RESULT_VALUE_OK);
    } catch (InvalidOperationException e) {
       result.put(MainModule.JTABLE_RESULT_KEY,
          MainModule.JTABLE_RESULT_VALUE_OK);
       result.put(MainModule.JTABLE_MESSAGE_KEY, "委派失败。" + e.getMessage());
    }

    return result;
}
添加回复
请先登陆
回到顶部