关注JEECG发展历程 关注最新动态和版本, 记录JEECG成长点滴 更新日志 - 技术支持 - 招聘英才

JEECG最新版本下载 JEECG智能开发平台 - 显著提高开发效率 常见问题 - 入门视频 - 参与开源团队

商务QQ: 69893005、418799587 商务热线(5*8小时): 010-64808099 官方邮箱: jeecgos@163.com

查看: 11151|回复: 0

activiti动态创建路径

[复制链接]
发表于 2014-8-24 18:29:44 | 显示全部楼层 |阅读模式

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package cn.gdyes.wf.workflow.manager.impl;

import cn.gdyes.wf.workflow.manager.IGeneralRejectManager;
import java.util.ArrayList;
import java.util.List;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.impl.RepositoryServiceImpl;
import org.activiti.engine.impl.persistence.entity.ExecutionEntity;
import org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity;
import org.activiti.engine.impl.persistence.entity.TaskEntity;
import org.activiti.engine.impl.pvm.PvmTransition;
import org.activiti.engine.impl.pvm.process.ActivityImpl;
import org.activiti.engine.impl.pvm.process.TransitionImpl;
import org.springframework.beans.factory.annotation.Autowired;

/**
*
* @author Administrator
*/
public class GeneralRejectManagerImpl implements IGeneralRejectManager {

    @Autowired   
    private TaskService taskService;
    @Autowired   
    private RuntimeService runtimeService;
    @Autowired   
    private RepositoryService repositoryService;

    private List<ActivityImpl> activitiList = new ArrayList();
   
    //根据ActivitiId获取Acitiviti
    public ActivityImpl findActivityImpl(List<ActivityImpl> activitiList, String activitiId) {

        for (ActivityImpl activityImpl : activitiList) {
            String id = activityImpl.getId();
            if (id.equals(activitiId)) {
                return activityImpl;
            }
        }
        return null;
    }

    public List<ActivityImpl> findEndActivityImpls(List<ActivityImpl> activitiList) {
        List<ActivityImpl> activityImpls = new ArrayList<ActivityImpl>();
        for (ActivityImpl activityImpl : activitiList) {
            List<PvmTransition> pvmTransitionList = activityImpl.getOutgoingTransitions();
            if (pvmTransitionList.isEmpty()) {
                activityImpls.add(activityImpl);
            }
        }
        return activityImpls;
    }
   
    //通用流程否决接口
    public void rejectAndEnd(String taskId) {
        
        TaskEntity taskEntity = (TaskEntity) taskService.createTaskQuery().taskId(taskId).singleResult();
        
        ProcessDefinitionEntity def = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(taskEntity.getProcessDefinitionId());
        
        
        ExecutionEntity executionEntity = (ExecutionEntity) runtimeService.createExecutionQuery().executionId(taskEntity.getExecutionId()).singleResult();//执行实例

        String activitiId = executionEntity.getActivityId();//当前实例的执行到哪个节点
        activitiList = def.getActivities();//获得当前任务的所有节点
        
        ActivityImpl activeActivity = findActivityImpl(activitiList, activitiId);
        ActivityImpl endActivity = findEndActivityImpls(activitiList).get(0);


        List<PvmTransition> pvmTransitionList = activeActivity.getOutgoingTransitions();//获取当前节点的所以出口(这个方法做的不好,应该返回List<TransitionImpl>才对的,这样就不用下面的强转换了,我想以后版本会改了这点)
        for (PvmTransition pvmTransition : pvmTransitionList) {
            TransitionImpl transitionImpl = (TransitionImpl) pvmTransition;//强转为TransitionImpl
            transitionImpl.setDestination(endActivity);
        }
        
        taskService.complete(taskId);
    }

}


您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表