工作流(workflow)

package com.byd.mes.plugins.workFlow;

import java.util.List;

import java.util.Map;

import com.byd.mes.bussiness.bo.main.OperationBO;
import com.byd.mes.bussiness.bo.main.ResourceBO;
import com.byd.mes.bussiness.bo.main.RouterBO;
import com.byd.mes.bussiness.bo.siteoperation.sfc.SfcInfoBO;
import com.byd.mes.bussiness.bo.system.UserBO;
import com.bydwf.vo.NodeVo;

public interface BydWorkFlowService{

	public interface Event{
		void execute(SfcInfoBO sfc,RouterBO routerBo,OperationBO operation,ResourceBO resource,NodeVo nodeVo,UserBO userBo,WFContext wfContext);
	}
	
	public class WFContext{
		private BydWorkFlowService s;
		
		public WFContext(BydWorkFlowService s){
			this.s = s;
		}
		public NodeVo getFirstNode(RouterBO routerBo){
			return this.s.getFirstNode(routerBo);
		}
		public List<NodeVo> getAllNodes(RouterBO router){
			return this.s.getAllNodes(router);
		}
		public List<NodeVo> getNextNodes(SfcInfoBO sfcInfoBo,String paramNodeId,Map contextproperties){
			return this.s.getNextNodes(sfcInfoBo, paramNodeId, contextproperties);
		}
		public List<NodeVo> getNextNodes(RouterBO routerBo,String paramNodeId){
			return this.s.getNextNodes(routerBo, paramNodeId);
		}
		public NodeVo getNodeById(RouterBO routerBo,String nodeId){
			return this.s.getNodeById(routerBo, nodeId);
		}
		public RouterBO getPreviousRouter(SfcInfoBO sfcInfoBo){
			return this.s.getPreviousRouter(sfcInfoBo);
		}
		public boolean isFirstOperation (OperationBO operation,RouterBO routerBo){
			return this.s.isFirstOperation(operation, routerBo);
		}
		public boolean isNodeOperation(OperationBO operation,NodeVo nodeVo){
			return this.s.isNodeOperation(operation, nodeVo);
		}
		public boolean isCurOperation(SfcInfoBO sfcInfoBo,OperationBO operationBo){
			return this.s.isCurOperation(sfcInfoBo, operationBo);
		}
	} 
	
	/**
	 * 发起工作流,生成工序步骤信息
	 * @param parameter
	 * @return
	 */
	void load(SfcInfoBO sfcInfoBo,RouterBO routerBo,UserBO userBo,String beforeLoadClass,String afterLoadClass,Map map);
	
	/**
	 * 将SFC状态由排队改为活动,如果传入的工艺路线是特殊工艺路线,如果之前没有走过,则发起工作流,生成工序步骤信息,
	 * 如果走过,则清空之前的工序步骤信息,然后到首工序活动
	 * @param sfcInfoBo
	 * @param routerBo
	 * @param sfcOperationBO
	 */
	void start(SfcInfoBO sfcInfoBo,OperationBO operationBO,ResourceBO resourceBo,RouterBO routerBo,UserBO userBo,String beforeStartClass,String afterStartClass,Map map);
	
	/**
	 * 跳到到下一节点
	 * @param sfcInfoBo
	 * @param fromNodeId
	 * @param toNodeId
	 * @return
	 */
	void approve(SfcInfoBO sfcInfoBo,RouterBO routerBo,String toNodeId,UserBO userBo,String beforeApproveClass,String afterApproveClass,Map map);
		
	/**
	 * 获取第一个节点
	 * @param sfcInfoBo
	 * @return
	 */
	@Deprecated
	NodeVo getFirstNode(RouterBO routerBo);	

	/**
	 * 获取所有节点
	 * @param RouterBO
	 * @return List<NodeVo>
	 */
	List<NodeVo> getAllNodes(RouterBO router);
	
	/**
	 * 获取下一下节点集
	 * @param sfcInfoBo
	 * @return
	 */
	List<NodeVo> getNextNodes(SfcInfoBO sfcInfoBo,String paramNodeId,Map contextproperties);
	
	/**
	 * 获取下一下节点集
	 * @param sfcInfoBo
	 * @return
	 */
	List<NodeVo> getNextNodes(RouterBO routerBo,String paramNodeId);

	/**
	 * 获取节点流程定义信息
	 * @param routerBo
	 * @param nodeId
	 * @return
	 */
	NodeVo getNodeById(RouterBO routerBo,String nodeId);
	/**
	 * 获取上一步工艺路线
	 * @param sfcInfoBo
	 * @return
	 */
	RouterBO getPreviousRouter(SfcInfoBO sfcInfoBo);
	
	/**
	 * 校验工序是否是工艺路线的首工序
	 * @param operation
	 * @param routerBo
	 * @return
	 */
	boolean isFirstOperation (OperationBO operation,RouterBO routerBo);
	
	/**
	 * 校验工序是否是步骤的工序
	 * @param operation
	 * @param nodeVo
	 * @return
	 */
	boolean isNodeOperation(OperationBO operation,NodeVo nodeVo);
	
	/**
	 * 校验工序是否是SFC当前所在工序
	 * @param sfcInfoBo
	 * @param operationBo
	 * @return
	 */
	boolean isCurOperation(SfcInfoBO sfcInfoBo,OperationBO operationBo);
}
/**
 * *CreateTime:2010-12-2 下午04:35:17
 *Description:MES功能点已工作流对接接口默认实现类
*/
package com.byd.mes.plugins.workFlow.impl;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.byd.mes.bussiness.bo.main.OperationBO;
import com.byd.mes.bussiness.bo.main.ResourceBO;
import com.byd.mes.bussiness.bo.main.RouterBO;
import com.byd.mes.bussiness.bo.main.StatusBO;
import com.byd.mes.bussiness.bo.siteoperation.podmanager.ActivityInfoBO;
import com.byd.mes.bussiness.bo.siteoperation.sfc.SfcInfoBO;
import com.byd.mes.bussiness.bo.siteoperation.sfc.SfcOperationBO;
import com.byd.mes.bussiness.bo.siteoperation.sfc.SfcRouterBO;
import com.byd.mes.bussiness.bo.system.UserBO;
import com.byd.mes.bussiness.service.ServiceException;
import com.byd.mes.bussiness.service.activity.ExecuteActivityService;
import com.byd.mes.bussiness.service.main.OperationService;
import com.byd.mes.bussiness.service.main.ResourceService;
import com.byd.mes.bussiness.service.main.RouterService;
import com.byd.mes.bussiness.service.main.StatusService;
import com.byd.mes.bussiness.service.siteoperation.podmanager.ActivityInfoService;
import com.byd.mes.bussiness.service.siteoperation.sfc.SfcInfoService;
import com.byd.mes.bussiness.service.siteoperation.sfc.SfcOperationService;
import com.byd.mes.bussiness.service.siteoperation.sfc.SfcRouterService;
import com.byd.mes.plugins.workFlow.BydWorkFlowService;
import com.byd.mes.util.BeanFactory;
import com.bydwf.util.MesWfutil;
import com.bydwf.vo.NodeVo;
import com.ibatis.sqlmap.client.SqlMapClient;

public class BydWorkFlowServiceImpl implements BydWorkFlowService{
	private static final Log log = LogFactory.getLog(BydWorkFlowServiceImpl.class);
	private SfcInfoService sfcInfoService;
	private StatusService statusService;
	private SfcOperationService sfcOperationService;
	private SfcRouterService sfcRouterService;
	private RouterService routerService;
	private OperationService operationService;
	private SqlMapClient sqlMapClient;
	private ResourceService resourceService;
	private ExecuteActivityService executeActivityService;
	private ActivityInfoService activityInfoService;
	
	static private final String EVENT_BEFORE_LOAD = "BEFORE_LOAD";
	static private final String EVENT_AFTER_LOAD = "AFTER_LOAD";
	static private final String EVENT_BEFORE_APPROVE = "BEFORE_APPROVE";
	static private final String EVENT_AFTER_APPROVE = "AFTER_APPROVE";
	static private final String EVENT_BEFORE_START = "BEFORE_START";
	static private final String EVENT_AFTER_START = "AFTER_START";
	private Map<String,String[]> listener;
		
	@Override
	public void start(SfcInfoBO sfcInfoBo,OperationBO operationBO,ResourceBO resourceBo,RouterBO routerBo,UserBO userBo,String beforeStartClass,String afterStartClass,Map map) {
	    Date curDate = new Date();
	    //校验SfcInfo是否为空
	    if(sfcInfoBo == null){
	    	throw new ServiceException("2001","调用MES工作流方法[START]时,传入的SfcInfoBO对象为空!");
	    }
	    if(StringUtils.isEmpty(sfcInfoBo.getId())){
	    	throw new ServiceException("2002","调用MES工作流方法[START]时,传入的SfcInfoBO对象的ID属性值为空!");
	    }
	    
	    //校验OperationBO是否为空
	    if(operationBO == null){
	    	throw new ServiceException("2003","调用MES工作流方法[START]时,传入的OperationBO对象为空!");
	    }
	    if(StringUtils.isEmpty(operationBO.getId())){
	    	throw new ServiceException("2004","调用MES工作流方法[START]时,传入的OperationBO对象的ID属性值为空!");
	    }
	    
	    //校验ResourceBO是否为空
	    if(resourceBo == null){
	    	throw new ServiceException("2005","调用MES工作流方法[START]时,传入的ResourceBO对象为空!");
	    }
	    if(StringUtils.isEmpty(resourceBo.getId())){
	    	throw new ServiceException("2006","调用MES工作流方法[START]时,传入的ResourceBO对象的ID属性值为空!");
	    }
	    
	    //校验RouterBO是否为空
	    if(routerBo == null){
	    	throw new ServiceException("2005","调用MES工作流方法[START]时,传入的RouterBO对象为空!");
	    }
	    if(StringUtils.isEmpty(routerBo.getId())){
	    	throw new ServiceException("2006","调用MES工作流方法[START]时,传入的RouterBO对象的ID属性值为空!");
	    }
	    
	    //校验UserBO是否为空
	    if(userBo == null){
	    	throw new ServiceException("2007","调用MES工作流方法[START]时,传入的UserBO对象为空!");
	    }
	    if(StringUtils.isEmpty(userBo.getId())){
	    	throw new ServiceException("2008","调用MES工作流方法[START]时,传入的UserBO对象的ID属性值为空!");
	    }
	    
	    
		//查询Sfc基本信息
		try{
			sfcInfoBo = sfcInfoService.findByPk(sfcInfoBo.getId());	
		}catch(Exception ex){
			throw new ServiceException("2100","执行MES工作流方法[START]时,根据SFC ID["+sfcInfoBo.getId()+"]查询SFC 基本信息失败!",ex);
		}		
		if(sfcInfoBo == null){
			throw new ServiceException("2101","执行MES工作流方法[START]时,SFC无效!");
		}
		
		//查询工艺路线信息
		try{
			routerBo = routerService.findByPk(routerBo.getId());
		}catch(Exception ex){
			throw new ServiceException("2103","SFC["+sfcInfoBo.getSfcNo()+"]在开始之前根据工艺路线 ID["+routerBo.getId()+"]查询工艺路线基本信息失败!",ex);
		}		
		if(routerBo == null){
			throw new ServiceException("2104","执行MES工作流方法[START]时,工艺路线无效!");
		}
		
		//查询资源
		try{
			resourceBo = resourceService.findByPk(resourceBo.getId());
		}catch(Exception ex){
			throw new ServiceException("2105","SFC["+sfcInfoBo.getSfcNo()+"]在开始之前根据资源 ID["+resourceBo.getId()+"]查询资源基本信息失败!",ex);
		}		
		if(resourceBo == null){
			throw new ServiceException("2106","执行MES工作流方法[START]时,资源(ResourceBO)无效!");
		}
		
		//查询工序
		try{
			operationBO=this.operationService.findByPk(operationBO.getId());
		}catch(Exception ex){
			throw new ServiceException("2107","SFC["+sfcInfoBo.getSfcNo()+"]在开始之前根据 工序ID["+operationBO.getId()+"]查询 工序基本信息失败!",ex);
		}		
		if(operationBO == null){
			throw new ServiceException("2108","执行MES工作流方法[START]时,工序无效!");
		}
						
		//查询SFC"活动"状态对象
		StatusBO statusActiveBo=statusService.findByUK(BeanFactory.getSystemParamters().get("mes.siteoperation.sfc.status"),
				BeanFactory.getSystemParamters().get("mes.siteoperation.sfc.status.active"));
		//查询SFC工序步骤"活动"状态对象
		StatusBO  operationActiveStatus=statusService.findByUK(BeanFactory.getSystemParamters().get("mes.siteoperation.operationstatus"),
				BeanFactory.getSystemParamters().get("mes.siteoperation.operationstatus.active"));
		
		MesWfutil mesWfUtil =null;
		NodeVo firstNode=null;
		List<NodeVo> allNodes=null;
		
		//获取工艺路线上的所有节点
		try{
			mesWfUtil = new MesWfutil(sqlMapClient);
			allNodes = mesWfUtil.getAllNodes(routerBo.getNo(), routerBo.getVersion());		
		}catch(Exception ex){
			throw new ServiceException("3003","调用工作流方法[getAllNodes]根据工艺路线["+routerBo.getNo()+"]["+routerBo.getVersion()+"]查询工艺路线所有工序步骤失败!",ex);
		}		
		if(allNodes == null || allNodes.size() <= 0){
			throw new ServiceException("3004","工艺路线["+routerBo.getNo()+"]["+routerBo.getVersion()+"]没有工序步骤!");
		}
		
		//获取工艺路线上的第一个节点
		try{
			firstNode =this.getFirstNode(routerBo);
		}catch(Exception ex){
			throw new ServiceException("3002","调用工作流方法[getFirsetNode]根据工艺路线["+routerBo.getNo()+"]["+routerBo.getVersion()+"]查询工艺路线第一个工序步骤失败!",ex);
		}
		if(firstNode == null){
			throw new ServiceException("3005","工艺路线["+routerBo.getNo()+"]["+routerBo.getVersion()+"]没有首工序步骤!");
		}
		
		//BeforeLoad:执行二次开发接口业务处理类
		log.debug(">>>>>>>>>>>>>>>>>>>>>>Execute Before Start Listener ");
		this.executeEvent(this.EVENT_BEFORE_START, sfcInfoBo, routerBo, operationBO, resourceBo, null, userBo);
		
		
		//A:校验SFC当前是否在传入的工艺路线上,是则校验SFC当前排队工序是否是传入的工序,是则将排队改为活动
		if(sfcInfoBo.getSfcRouter()!= null && 
				StringUtils.isNotEmpty(sfcInfoBo.getSfcRouter().getId()) && 
				sfcInfoBo.getRouter().getId().equals(routerBo.getId())){
			
			//校验SFC当前是否是排队状态
			if(this.sfcInfoService.isQuence(sfcInfoBo)){				
				//查询SFC当前工艺路线信息(SfcRouterBO)
				SfcRouterBO  sfcRouterBO= null;
				try {
					sfcRouterBO=this.sfcRouterService.findByUk(sfcInfoBo.getSite().getId(), sfcInfoBo.getId(), routerBo.getId());				
				} catch (Exception ex) {
					throw new ServiceException("2118","根据SFC["+sfcInfoBo.getSfcNo()+"]工艺路线["+routerBo.getNo()+"]["+routerBo.getVersion()+"]查询SFC工艺路线(SfcRouterBO)信息失败!",ex);
				}
				
				//A1:如果是步骤组:如果步骤类型是"SIMULTANEITY",则将开始变为活动,如果是"RANDOM",则将当前传入的工序步骤变为活动,将步骤中的其他步骤清空
				if( sfcRouterBO != null && 
					StringUtils.isNotEmpty(sfcRouterBO.getNodeGroup())){
					NodeVo nodeGroup = null;
					//查询步骤组代表节点信息
					try{
						nodeGroup = mesWfUtil.getNodeById(routerBo.getNo(),routerBo.getVersion(), sfcRouterBO.getNodeGroup());
					}catch(Exception ex){
						throw new ServiceException("3001","调用工作流方法[getNodeById]根据工艺路线["+routerBo.getNo()+"]["+routerBo.getVersion()+"]工序步骤ID["+sfcRouterBO.getNodeGroup()+"]查询工序步骤基本信息失败!",ex);
					}
					if(nodeGroup == null){
						throw new ServiceException("3006","在工艺路线["+routerBo.getNo()+"]["+routerBo.getVersion()+"]上没有找到工序步骤["+sfcRouterBO.getNodeGroup()+"]!");
					}
					
					//查询步骤组中的所有工序步骤
					List<SfcOperationBO> sfcOperations = null;
					SfcOperationBO sfcOperationBo = new SfcOperationBO();
					sfcOperationBo.setSite(sfcRouterBO.getSite());
					sfcOperationBo.setSfcRouter(sfcRouterBO);
					sfcOperationBo.setStepGroup(sfcRouterBO.getNodeGroup());
					try {						
						sfcOperations = sfcOperationService.find(sfcOperationBo );
					} catch (Exception ex) {
						throw new ServiceException("2310","查询SFC["+sfcInfoBo.getSfcNo()+"]在工艺路线RouterBo["+routerBo.getNo()+"]["+routerBo.getVersion()+"]上的工序步骤信息失败!",ex);
					}
					if(sfcOperations == null || sfcOperations.size() <= 0 ){
						throw new ServiceException("2318","SFC["+sfcInfoBo.getSfcNo()+"]在工艺路线RouterBo["+routerBo.getNo()+"]["+routerBo.getVersion()+"]上的步骤组["+sfcRouterBO.getNodeGroup()+"]中的步骤信息为空!");
					}
					
					//校验SFC是否是在步骤组上排队
					boolean isInNodeGroup = false;
					for(SfcOperationBO sob : sfcOperations){
						if(StringUtils.equals(operationBO.getId(), sob.getOperation().getId())){
							isInNodeGroup = true;
						}
					}
					if(!isInNodeGroup){
						throw new ServiceException("2319","SFC["+sfcInfoBo.getSfcNo()+"]不在工序["+operationBO.getNo()+"]上排队,它在步骤组["+nodeGroup.getNodeId()+"]上排队");
					}
					
					for(SfcOperationBO sob : sfcOperations){
						//如果传入工序在步骤组中,则将传入工序的步骤状态改为活动
						if(StringUtils.equals(operationBO.getId(), sob.getOperation().getId())){
							//更改SFC(SfcInfoBO)相关信息
							sfcInfoBo.setOriginalStatus(sfcInfoBo.getStatus());
							sfcInfoBo.setStatus(statusActiveBo);					
							sfcInfoBo.setOperationStepStatus(operationActiveStatus);
							sfcInfoBo.setLastHandleUser(userBo);
							sfcInfoBo.setLastHandleTime(curDate);
							sfcInfoBo.setCurrentResource(resourceBo);
							 
							sfcInfoBo.setOperation(operationBO);
							sfcInfoBo.setSfcOperation(sob);
							try {
								this.sfcInfoService.update(sfcInfoBo);
							} catch (Exception ex) {
								throw new ServiceException("2110","更新SFC["+sfcInfoBo.getSfcNo()+"]基本信息(SfcInfoBO)信息失败!",ex);
							}
							
							//更新SfcRouter信息
							try {
								sfcRouterBO.setLastSfcOperationStep(sob);
								this.sfcRouterService.update(sfcRouterBO);
							} catch (Exception ex) {
								throw new ServiceException("4004","更新SFC["+sfcInfoBo.getSfcNo()+"]的SFC工艺路线(SfcRouterBO)["+sfcRouterBO.getId()+"]中的当前工序步骤失败!",ex);
							}
							
							//更新SfcOperation信息
							try {
								sob.setStatus(operationActiveStatus);
								sob.setTriggerUser(userBo);
								sob.setActiveDate(curDate);
								sob.setActiveNum(sob.getActiveNum()+1);
								this.sfcOperationService.update(sob);						
							} catch (Exception ex) {
								throw new ServiceException("2112","更新SFC["+sfcInfoBo.getSfcNo()+"]SFC工序步骤(sfcOperationBO)信息失败!",ex);
							}
						}else{							
							//“RANDOM” 步骤组,任意步骤组,如果在一个步骤上开始了,则必须清空步骤组中的其他步骤的状态
							if(StringUtils.equals("RANDOM", nodeGroup.getNodeGroupType())){
								try {
									StatusBO  operationDoneStatus=statusService.findByUK(BeanFactory.getSystemParamters().get("mes.siteoperation.operationstatus"),
											BeanFactory.getSystemParamters().get("mes.siteoperation.operationstatus.complete"));
									if(sob.getStatus() != null && 
											StringUtils.isNotEmpty(sob.getStatus().getId()) && 
											!StringUtils.equals(sob.getStatus().getId(), operationDoneStatus.getId())){
										sob.setSfcQty(0);
										sob.setStatus(null);
										sob.setActiveDate(curDate);
										sob.setTriggerUser(userBo);
										sob.setPreviousOperation(null);
										this.sfcOperationService.update(sob);
									}															
								} catch (Exception ex) {
									throw new ServiceException("2112","更新SFC["+sfcInfoBo.getSfcNo()+"]SFC工序步骤(sfcOperationBO)信息失败!",ex);
								}
							}
						}
					}
				}else{//A2:不是步骤组
					//校验SFC当前所在工序是否是传入的工序
					if(sfcInfoBo.getOperation().equals(operationBO)){
						//更改SFC(SfcInfoBO)相关信息
						sfcInfoBo.setOriginalStatus(sfcInfoBo.getStatus());
						sfcInfoBo.setStatus(statusActiveBo);					
						sfcInfoBo.setOperationStepStatus(operationActiveStatus);
						sfcInfoBo.setLastHandleUser(userBo);
						sfcInfoBo.setLastHandleTime(curDate);
						sfcInfoBo.setCurrentResource(resourceBo);
						try {
							this.sfcInfoService.update(sfcInfoBo);
						} catch (Exception ex) {
							throw new ServiceException("2110","更新SFC["+sfcInfoBo.getSfcNo()+"]基本信息(SfcInfoBO)信息失败!",ex);
						}
						
						//更改SFC SFC工序步骤(SfcOperationBO)相关信息
						SfcOperationBO sfcOperationBO = null;
						try{
							sfcOperationBO=sfcOperationService.findByPk(sfcInfoBo.getSfcOperation().getId());
						}catch(Exception ex){
							throw new ServiceException("2111","SFC["+sfcInfoBo.getSfcNo()+"]在开始之前根据 SFC当前工序步骤ID["+sfcInfoBo.getSfcOperation().getId()+"]查询 SFC工序步骤(sfcOperationBO)信息失败!",ex);
						}
						sfcOperationBO.setStatus(operationActiveStatus);
						sfcOperationBO.setTriggerUser(userBo);
						sfcOperationBO.setActiveDate(curDate);
						sfcOperationBO.setActiveNum(sfcOperationBO.getActiveNum()+1);
						try {
							this.sfcOperationService.update(sfcOperationBO);						
						} catch (Exception ex) {
							throw new ServiceException("2112","更新SFC["+sfcInfoBo.getSfcNo()+"]SFC工序步骤(sfcOperationBO)信息失败!",ex);
						}
					}else{
						throw new ServiceException("2113","SFC["+sfcInfoBo.getSfcNo()+"]不在工序["+operationBO.getNo()+"]上排队,它在工序["+sfcInfoBo.getOperation().getNo()+"]上排队");
					}
				}
			}else{
				StatusBO Status=this.statusService.findByPk(sfcInfoBo.getStatus().getId());
				throw new ServiceException("2114","SFC["+sfcInfoBo.getSfcNo()+"]不在工序["+operationBO.getNo()+"]上排队,它在工序["+sfcInfoBo.getOperation().getNo()+"]"+Status.getNo() );
			}
		}else{
			//B:SFC当前不在传入的工艺路线上,校验传入工序是否是传入工艺路线的首工序,是则校验传入工艺路线之前有没有走过,没有走过,则生成工序步骤信息,走过,则清空之前的工艺路线信息,重新再走;						
			if(isNodeOperation(operationBO,firstNode) ){
				SfcRouterBO  sfcRouterBO= null;
				try {
					sfcRouterBO=this.sfcRouterService.findByUk(sfcInfoBo.getSite().getId(), sfcInfoBo.getId(), routerBo.getId());				
				} catch (Exception ex) {
					throw new ServiceException("2115","根据SFC["+sfcInfoBo.getSfcNo()+"]工艺路线["+routerBo.getNo()+"]["+routerBo.getVersion()+"]查询SFC工艺路线(SfcRouterBO)信息失败!",ex);
				}
				//B1:传入工艺路线之前走过
				if(sfcRouterBO!=null){
					 //清空SFC工序步骤信息					
					 List<SfcOperationBO> sfcOperations = null;
					 SfcOperationBO sfcOperation = new SfcOperationBO();
					 sfcOperation.setSite(sfcRouterBO.getSite());
					 sfcOperation.setSfcRouter(sfcRouterBO);
					 try {						
						sfcOperations = sfcOperationService.find(sfcOperation );
					 } catch (Exception ex) {
						throw new ServiceException("2310","查询SFC["+sfcInfoBo.getSfcNo()+"]在工艺路线RouterBo["+routerBo.getNo()+"]["+routerBo.getVersion()+"]上的工序步骤信息失败!",ex);
					 }
					 for(SfcOperationBO sob:sfcOperations){
						 sfcInfoBo = clearSfcOperationInfo(sfcInfoBo,sob,userBo,firstNode,operationActiveStatus,curDate,operationBO);				 
					 }
					 
					 //Update SfcRouter
					 sfcRouterBO.setPreviousRouter(sfcInfoBo.getSfcRouter());
					 sfcRouterBO.setLastSfcOperationStep(sfcInfoBo.getSfcOperation());
					 if(StringUtils.equals("NODEGROUP", firstNode.getExNodeType())){
						 sfcRouterBO.setNodeGroup(firstNode.getNodeId());
					 }
					 try {
							this.sfcRouterService.update(sfcRouterBO);
						} catch (Exception ex) {
							throw new ServiceException("2116","更新SFC["+sfcInfoBo.getSfcNo()+"]SFC工艺路线(SfcRouterBO)["+routerBo.getNo()+"]["+routerBo.getVersion()+"]中的当前工序步骤失败!",ex);
					 }
					 
					 //update SfcInfo
					 sfcInfoBo.setOriginalStatus(sfcInfoBo.getStatus());
					 sfcInfoBo.setStatus(statusActiveBo);
					 sfcInfoBo.setOperationStepStatus(operationActiveStatus);
					 sfcInfoBo.setSfcRouter(sfcRouterBO);					 					 
					 sfcInfoBo.setRouter(routerBo);
					 sfcInfoBo.setOperation(operationBO);
					 sfcInfoBo.setLastHandleUser(userBo);
					 sfcInfoBo.setLastHandleTime(curDate);
					 sfcInfoBo.setCurrentResource(resourceBo);
					 try {
						 this.sfcInfoService.update(sfcInfoBo);
					 } catch (Exception ex) {
						 throw new ServiceException("2117","更新SFC["+sfcInfoBo.getSfcNo()+"]基本信息(SfcInfoBO)信息失败!",ex);
					 }				 
					 
				//B2:传入工艺路线之前没走过
				}else{
					//生成SFC工艺路线信息(SfcRouter), 更改它的上一工艺路线
					createSfcRouterOperationInfo( sfcInfoBo,  routerBo,  userBo , allNodes,statusActiveBo,operationActiveStatus,firstNode,operationBO,curDate,resourceBo);
				}
			}else{
				throw new ServiceException("2122","工序["+operationBO.getNo()+"]不是工艺路线["+routerBo.getNo()+"]["+routerBo.getVersion()+"]的首工序,不能开始!");
			}
		}
		
		//AfterLoad:执行二次开发接口业务处理类
		log.debug(">>>>>>>>>>>>>>>>>>>>>>Execute After Start Listener");
		this.executeEvent(this.EVENT_AFTER_START, sfcInfoBo, routerBo, operationBO, resourceBo, null, userBo);
	}
	
	@Override
	public void load(SfcInfoBO sfcInfoBo,RouterBO routerBo,UserBO userBo,String beforeLoadClass,String afterLoadClass,Map mapParam){
		Date curDate = new Date();
		// TODO Auto-generated method stub	
		//校验SfcInfo是否为空
	    if(sfcInfoBo == null){
	    	throw new ServiceException("2009","调用MES工作流方法[LOAD]时,传入的SfcInfoBO对象为空!");
	    }
	    if(StringUtils.isEmpty(sfcInfoBo.getId())){
	    	throw new ServiceException("2010","调用MES工作流方法[LOAD]时,传入的SfcInfoBO对象的ID属性值为空!");
	    }
	    	    
	    //校验RouterBO是否为空
	    if(routerBo == null){
	    	throw new ServiceException("2011","调用MES工作流方法[LOAD]时,传入的RouterBO对象为空!");
	    }
	    if(StringUtils.isEmpty(routerBo.getId())){
	    	throw new ServiceException("2012","调用MES工作流方法[LOAD]时,传入的RouterBO对象的ID属性值为空!");
	    }
	    
	    //校验UserBO是否为空
	    if(userBo == null){
	    	throw new ServiceException("2013","调用MES工作流方法[LOAD]时,传入的UserBO对象为空!");
	    }
	    if(StringUtils.isEmpty(userBo.getId())){
	    	throw new ServiceException("2014","调用MES工作流方法[LOAD]时,传入的UserBO对象的ID属性值为空!");
	    }		
		
		//根据SFC ID查询SFC(SfcInfoBO)基本信息
		try{
			sfcInfoBo = sfcInfoService.findByPk(sfcInfoBo.getId());	
		}catch(Exception ex){
			throw new ServiceException("2200","生成SFC工序步骤之前根据SFC ID["+sfcInfoBo.getId()+"]查询SFC 基本信息失败!",ex);
		}		
		if(sfcInfoBo == null){
			throw new ServiceException("2201","SFC为空,不能生成工序步骤!");
		}
		//根据ROUTER ID查询ROUTER 基本信息
		try{
			routerBo = routerService.findByPk(routerBo.getId());
		}catch(Exception ex){
			throw new ServiceException("2203","SFC["+sfcInfoBo.getSfcNo()+"]在生成工序步骤之前根据工艺路线 ID["+routerBo.getId()+"]查询工艺路线基本信息失败!",ex);
		}		
		if(routerBo == null){
			throw new ServiceException("2204","工艺路线为空,不能生成工序步骤!");
		}
		
		//查询SFC"排队"状态对象
		StatusBO statusBo=statusService.findByUK(BeanFactory.getSystemParamters().get("mes.siteoperation.sfc.status"),
				BeanFactory.getSystemParamters().get("mes.siteoperation.sfc.status.queue"));
		//查询SFC工序步骤"排队"状态对象
		StatusBO  operationStepStatus=statusService.findByUK(BeanFactory.getSystemParamters().get("mes.siteoperation.operationstatus"),
				BeanFactory.getSystemParamters().get("mes.siteoperation.operationstatus.queue"));
		
		MesWfutil mesWfUtil =null;
		//生成工序步骤信息
		//获取工艺路线上的所有节点
		List<NodeVo> allNodes = null;
		NodeVo firstNode = null;
		OperationBO firstOperation = null;
		try{
			mesWfUtil = new MesWfutil(sqlMapClient);
			allNodes = mesWfUtil.getAllNodes(routerBo.getNo(), routerBo.getVersion());
		}catch(Exception ex){
			throw new ServiceException("3003","调用工作流方法[getAllNodes]根据工艺路线["+routerBo.getNo()+"]["+routerBo.getVersion()+"]查询工艺路线所有工序步骤失败!",ex);
		}
		//获取工艺路线的第一个节点
		try{				
			firstNode = mesWfUtil.getFirstNode(routerBo.getNo(), routerBo.getVersion());
		}catch(Exception ex){
			throw new ServiceException("3002","调用工作流方法[getFirsetNode]根据工艺路线["+routerBo.getNo()+"]["+routerBo.getVersion()+"]查询工艺路线第一个工序步骤失败!",ex);
		}
	    
		//如果第一节点的类型是"OPERATION",则获取其工序
		if(StringUtils.equals("OPERATION", firstNode.getExNodeType())){
			//获取工艺路线的第一个工序
			try{
				firstOperation = operationService.findByPk(firstNode.getOperationId());
			}catch(Exception ex){
				throw new ServiceException("2206","根据工序 ID["+firstNode.getOperationId()+"]查询工序基本信息失败!",ex);
			}
		}	
		
		//BeforeLoad:执行二次开发接口业务处理类
		log.debug(">>>>>>>>>>>>>>>>>>>>>>Execute Before Load Listener ");
		this.executeEvent(this.EVENT_BEFORE_LOAD, sfcInfoBo, routerBo, firstOperation, null, firstNode, userBo);
		
		if(allNodes != null && allNodes.size()>0){
			createSfcRouterOperationInfo( sfcInfoBo,  routerBo,  userBo , allNodes,statusBo,operationStepStatus,firstNode,firstOperation,curDate,sfcInfoBo.getCurrentResource());
		}else{
			throw new ServiceException("2207","工艺路线["+routerBo.getNo()+"]["+routerBo.getVersion()+"]中没有工序步骤,不能开始!");
		}
		
		//AfterLoad:执行二次开发接口业务处理类
		log.debug(">>>>>>>>>>>>>>>>>>>>>>Execute After Load Listener ");
		this.executeEvent(this.EVENT_AFTER_LOAD, sfcInfoBo, routerBo, firstOperation, null, firstNode, userBo);
	}
	
	@Override
	public void approve(SfcInfoBO sfcInfoBo,RouterBO toRouter,String toNodeId,UserBO userBo,String beforeApproveClass,String afterApproveClass,Map map) {
		Date curDate = new Date();
		// TODO Auto-generated method stub
		//校验SfcInfo是否为空
	    if(sfcInfoBo == null){
	    	throw new ServiceException("2015","调用MES工作流方法[APPROVE]时,传入的SFC对象为空!");
	    }
	    if(StringUtils.isEmpty(sfcInfoBo.getId())){
	    	throw new ServiceException("2016","调用MES工作流方法[APPROVE]时,传入的SfcInfoBO对象ID为空!");
	    }
	    
	    //校验RouterBO是否为空
	    if(toRouter == null){
	    	throw new ServiceException("2017","调用MES工作流方法[APPROVE]时,传入的RouterBO对象为空!");
	    }
	    if(StringUtils.isEmpty(toRouter.getId())){
	    	throw new ServiceException("2018","调用MES工作流方法[APPROVE]时,传入的RouterBO对象的ID属性值为空!");
	    }
	    
	    //校验UserBO是否为空
	    if(userBo == null){
	    	throw new ServiceException("2019","调用MES工作流方法[APPROVE]时,传入的UserBO对象为空!");
	    }
	    if(StringUtils.isEmpty(userBo.getId())){
	    	throw new ServiceException("2020","调用MES工作流方法[APPROVE]时,传入的UserBO对象的ID属性值为空!");
	    }
		
		//校验toNodeId是否为空值
		if(StringUtils.isEmpty(toNodeId)){
			throw new ServiceException("2300","调用MES工作流方法[APPROVE]时,传入的下一步骤ID为空值!");
		}
				
		//查询SFC基本信息
		try{
			sfcInfoBo = sfcInfoService.findByPk(sfcInfoBo.getId());	
		}catch(Exception ex){
			throw new ServiceException("2301","执行MES工作流方法[APPROVE]时,根据SFC ID["+sfcInfoBo.getId()+"]查询SFC基本信息失败!",ex);
		}
		
		try{
			toRouter = routerService.findByPk(toRouter.getId());
		}catch(Exception ex){
			throw new ServiceException("2303","执行MES工作流APPROVE时根据工艺路线 ID["+toRouter.getId()+"]查询工艺路线基本信息失败!",ex);
		}
		
		MesWfutil mesWfUtil =null;
		List<NodeVo> toRouterAllNodes=null;		
		NodeVo toNode = null;
	
		//获取即将跳转到的节点基本信息
		try{
			mesWfUtil = new MesWfutil(sqlMapClient);
			toNode = mesWfUtil.getNodeById(toRouter.getNo(),toRouter.getVersion(), toNodeId);
		}catch(Exception ex){
			throw new ServiceException("3001","调用工作流方法[getNodeById]根据工艺路线["+sfcInfoBo.getRouter().getNo()+"]["+sfcInfoBo.getRouter().getVersion()+"]工序步骤ID["+toNodeId+"]查询工序步骤基本信息失败!",ex);
		}
		if(toNode == null){
			throw new ServiceException("2324","即将跳转到的步骤["+toNodeId+"]不在即将跳转到的工艺路线上["+toRouter.getNo()+"]["+toRouter.getVersion()+"]!");
		}		
			
		//获取工艺路线上的所有节点
		try{
			toRouterAllNodes = mesWfUtil.getAllNodes(toRouter.getNo(),toRouter.getVersion());		
		}catch(Exception ex){
			throw new ServiceException("3003","调用工作流方法[getAllNodes]根据工艺路线["+toRouter.getNo()+"]["+toRouter.getVersion()+"]查询工艺路线所有工序步骤失败!",ex);
		}
			
		//BeforeApprove:执行二次开发接口业务处理类
		log.debug(">>>>>>>>>>>>>>>>>>>>>>Execute Before Approve Listener ");
		this.executeEvent(this.EVENT_BEFORE_APPROVE, sfcInfoBo, toRouter, null, null, toNode, userBo);
		
		//O:公共操作=>>将当前工序步骤状态改为完成
		//查询SFC“排队”状态对象
		StatusBO statusQueueBo=statusService.findByUK(BeanFactory.getSystemParamters().get("mes.siteoperation.sfc.status"),
				BeanFactory.getSystemParamters().get("mes.siteoperation.sfc.status.queue"));
		//查询SFC工序步骤"排队"状态对象
		StatusBO operationQueueBoStatus=statusService.findByUK(BeanFactory.getSystemParamters().get("mes.siteoperation.operationstatus"),
				BeanFactory.getSystemParamters().get("mes.siteoperation.operationstatus.queue"));
		//查询工序步骤“完成”状态对象
		StatusBO  operationDoneStatus=statusService.findByUK(BeanFactory.getSystemParamters().get("mes.siteoperation.operationstatus"),
				BeanFactory.getSystemParamters().get("mes.siteoperation.operationstatus.complete"));		
		
		SfcRouterBO curSfcRouterBo = null;	
		SfcOperationBO curSfcOperationBo = null;			
        //查询SFC当前工艺路线信息
		try{
			curSfcRouterBo = sfcRouterService.findByPk(sfcInfoBo.getSfcRouter().getId());
		}catch(Exception ex){
			throw new ServiceException("2305","SFC["+sfcInfoBo.getSfcNo()+"]执行Complete时根据SfcRouter ID["+sfcInfoBo.getSfcRouter().getId()+"]查询SFC工艺路线信息失败!",ex);
		}	
		//判断是否是步骤组
		if(curSfcRouterBo.getLastSfcOperationStep()==null||curSfcRouterBo.getLastSfcOperationStep().getId()==null||StringUtils.isEmpty(curSfcRouterBo.getLastSfcOperationStep().getId()) ){
			throw new ServiceException("2306","SFC["+sfcInfoBo.getSfcNo()+"]在工艺路线["+toRouter.getNo()+"]["+toRouter.getVersion()+"]步骤组["+curSfcRouterBo.getNodeGroup()+"]排队,不能跳转!");
		}
		//查询当前工序步骤信息
		try{
			curSfcOperationBo = sfcOperationService.findByPk(curSfcRouterBo.getLastSfcOperationStep().getId());
		}catch(Exception ex){
			throw new ServiceException("2306","SFC["+sfcInfoBo.getSfcNo()+"]执行Complete时根据SfcOperation ID["+curSfcRouterBo.getLastSfcOperationStep().getId()+"]查询SFC工序步骤信息失败!",ex);
		}		
		curSfcOperationBo.setActiveDate(curDate);
		curSfcOperationBo.setTriggerUser(userBo);
		curSfcOperationBo.setStatus(operationDoneStatus);
		curSfcOperationBo.setThroughNum(curSfcOperationBo.getThroughNum()+1 );
		//更新当前工序步骤状态为完成
		try {						
			 sfcOperationService.update(curSfcOperationBo);
		} catch (Exception ex) {
			throw new ServiceException("2307","更新SFC["+sfcInfoBo.getSfcNo()+"]的SFC工序步骤(SfcOperationBO)["+curSfcOperationBo.getId()+"]信息失败!",ex);
		}		
				
		//A.判断节点类型是否是工序,是则跳转到下一节点
		if(StringUtils.equals("OPERATION", toNode.getExNodeType())){
			//查询传入进来的工艺路线的SfcRouterBO
			SfcRouterBO toSfcRouterBo = null;			
			OperationBO toOperation = null;
			try{
				toSfcRouterBo = sfcRouterService.findByUk(sfcInfoBo.getSite().getId(), sfcInfoBo.getId(), toRouter.getId());
			}catch(Exception ex){
				throw new ServiceException("2308","根据SFC["+sfcInfoBo.getSfcNo()+"]工艺路线["+toRouter.getNo()+"]["+toRouter.getVersion()+"]查询SFC工艺路线信息(SfcRouterBO)失败!",ex);
			}
			//获取即将跳转到的工序基本信息
			try{			
				toOperation = operationService.findByPk(toNode.getOperationId());
			}catch(Exception ex){
				throw new ServiceException("2310","根据工序ID["+toNode.getOperationId()+"]查询工序信息失败!",ex);
			}
			//如果工艺路线之前没有走过,并且传入的节点是传入工艺路线的首节点,则发起工作流程,生成步骤信息;否则抛出异常
			if(toSfcRouterBo == null){
				//throw new ServiceException("2309","SFC["+sfcInfoBo.getSfcNo()+"]没有走过工艺路线["+routerBo.getNo()+"]["+routerBo.getVersion()+"],不能跳转!");				
				NodeVo toRouterFirstNode = null;
				try{
					toRouterFirstNode = mesWfUtil.getFirstNode(toRouter.getNo(),toRouter.getVersion());
				}catch(Exception ex){
					throw new ServiceException("3002","调用工作流方法[getFirsetNode]根据工艺路线["+toRouter.getNo()+"]["+toRouter.getVersion()+"]查询工艺路线第一个工序步骤失败!",ex);
				}
				if(StringUtils.equals(toRouterFirstNode.getNodeId(), toNode.getNodeId())){
					this.createSfcRouterOperationInfo(sfcInfoBo, toRouter, userBo, toRouterAllNodes,statusQueueBo , operationQueueBoStatus,toNode,toOperation,curDate,sfcInfoBo.getCurrentResource());					
				}else{
					throw new ServiceException("2309","SFC["+sfcInfoBo.getSfcNo()+"]没有走过工艺路线["+toRouter.getNo()+"]["+toRouter.getVersion()+"],步骤["+toNode.getNodeId()+"]不是工艺路线["+toRouter.getNo()+"]["+toRouter.getVersion()+"]的首步骤,不能跳转!");				
				}				
			}else{
				//如果工艺路线之前走过,则直接跳转指定的节点上
				List<SfcOperationBO> sfcOperationBOs=null;
				SfcOperationBO sfcOperationBO= new SfcOperationBO();
				sfcOperationBO.setSfcRouter(toSfcRouterBo);
				sfcOperationBO.setSite(sfcInfoBo.getSite());
				//获取传入工艺路线的所有工序步骤信息
				try {						
					sfcOperationBOs = sfcOperationService.find(sfcOperationBO );
				} catch (Exception ex) {
					throw new ServiceException("2310","查询SFC["+sfcInfoBo.getSfcNo()+"]在工艺路线RouterBo["+toRouter.getNo()+"]["+toRouter.getVersion()+"]上的工序步骤信息失败!",ex);
				}
				//查找需要调整的工序步骤
				for (SfcOperationBO bean : sfcOperationBOs) {
					if(StringUtils.equals(bean.getStepId(), toNodeId)){
						bean.setStatus(operationQueueBoStatus);
						bean.setSfcQty(sfcInfoBo.getQty());
						bean.setActiveDate(curDate);
						bean.setTriggerUser(userBo);
						bean.setPreviousOperation(curSfcOperationBo);
						bean.setQueueNum(bean.getQueueNum()+1);
						//如果即将跳去的节点是SFC当前所在的节点,则将循环次数加1
						if(StringUtils.equals(bean.getId(), curSfcOperationBo.getId())){
							bean.setLoopNum(bean.getLoopNum() + 1);
						}						
						try {						
							 sfcOperationService.update(bean);
						} catch (Exception ex) {
							throw new ServiceException("2311","更新SFC["+sfcInfoBo.getSfcNo()+"]的SFC工序步骤(SfcOperationBO)["+bean.getId()+"]信息失败!",ex);
						}
						//判断传入的工艺路线是否与当前工艺路线相同
						if(!toRouter.equals(sfcInfoBo.getRouter())){
							toSfcRouterBo.setPreviousRouter(sfcInfoBo.getSfcRouter());
						}
						toSfcRouterBo.setLastSfcOperationStep(bean);
						if(StringUtils.isEmpty(bean.getStepGroup())){
							toSfcRouterBo.setNodeGroup(null);
							sfcInfoBo.setStepGroup(null);
						}						
						try {
							this.sfcRouterService.update(toSfcRouterBo);
						} catch (Exception ex) {
							throw new ServiceException("2312","更新SFC["+sfcInfoBo.getSfcNo()+"]的SFC工艺路线(SfcRouterBO)["+curSfcRouterBo.getId()+"]中的当前工序步骤失败!",ex);
						}
						
						sfcInfoBo.setOriginalStatus(sfcInfoBo.getStatus());					
						sfcInfoBo.setStatus(statusQueueBo );
						sfcInfoBo.setOperationStepStatus(operationQueueBoStatus);
						sfcInfoBo.setRouter(toRouter);
						sfcInfoBo.setOperation(toOperation);
						sfcInfoBo.setSfcRouter(toSfcRouterBo);
						sfcInfoBo.setSfcOperation(bean);					
						sfcInfoBo.setLastHandleTime(curDate);
						sfcInfoBo.setLastHandleUser(userBo);
						sfcInfoBo.setStepId(toNodeId );
						try {
							 this.sfcInfoService.update(sfcInfoBo);
						} catch (Exception ex) {
							 throw new ServiceException("2313","更新SFC["+sfcInfoBo.getSfcNo()+"]基本信息(SfcInfoBO)信息失败!",ex);
						}
					}else{
						//将循环次数清零
						if(StringUtils.equals(bean.getId(), curSfcOperationBo.getId()) && curSfcOperationBo.getLoopNum() > 0){
							bean.setLoopNum(0);
							try {						
								 sfcOperationService.update(bean);
							} catch (Exception ex) {
								throw new ServiceException("2323","将SFC["+sfcInfoBo.getSfcNo()+"]的SFC工序步骤(SfcOperationBO)["+bean.getId()+"]的循环次数清零失败!",ex);
							}
						}
					}
				}
			}
		}
							
		//B.判断节点的类型是处置功能HANDFUNCTION,是则执行节点上的处置功能
		if(StringUtils.equals("HANDFUNCTION", toNode.getExNodeType())){
		   //获取处置功能功能点,执行处置功能
			ActivityInfoBO activityBo = new ActivityInfoBO(toNode.getHandFunction());
			try{
				activityBo = activityInfoService.findByPk(toNode.getHandFunction());
			}catch(Exception ex){
				throw new ServiceException("2322","根据功能点ID["+toNode.getHandFunction()+"]查询功能点信息失败!",ex);
			}
			try{				
				executeActivityService.executeSingle(sfcInfoBo.getSite(),sfcInfoBo, sfcInfoBo.getOperation(),
						sfcInfoBo.getCurrentResource(), activityBo, userBo, null);
			}catch(Exception ex){
				throw new ServiceException("2314","执行Complete时执行下一工序步骤上设置的处置功能上配置的活动["+activityBo.getActivityNo()+"]失败!",ex);
			}				   	
		}	
		
		//C.判断节点类型是否是子工艺路线,是则判断该子工艺路线之前有没有走过,有则清空之前的工序步骤信息,然后到子工艺路线的首工序排队,没有生成子工艺路线步骤信息
		if(StringUtils.equals("CHILDROUTER", toNode.getExNodeType())){
			//抓取子工艺路线
			NodeVo toChildRouterFirstNode=null;
			List<NodeVo> toChildAllNodes = null;
			RouterBO toChildRouter = null;	
			OperationBO toChildOperation = null;
			//查询子工艺路线
			try{
				toChildRouter = routerService.findByPk(toNode.getChildRouterId());
			}catch(Exception ex){
				throw new ServiceException("2315","执行Complete之前根据子工艺路线 ID["+toNode.getOperationId()+"]查询子工艺路线基本信息失败!",ex);
			}
			//查询子工艺路线上的所有节点
			try{
				toChildAllNodes = mesWfUtil.getAllNodes(toChildRouter.getNo(),toChildRouter.getVersion());		
			}catch(Exception ex){
				throw new ServiceException("3003","调用工作流方法[getAllNodes]根据工艺路线["+toRouter.getNo()+"]["+toRouter.getVersion()+"]查询工艺路线所有工序步骤失败!",ex);
			}
			//查询子工艺路线第一个步骤
			try{				
				toChildRouterFirstNode = mesWfUtil.getFirstNode(toChildRouter.getNo(), toChildRouter.getVersion());
			}catch(Exception ex){
				throw new ServiceException("2316","调用工作流方法[getFirsetNode]根据工艺路线["+toChildRouter.getNo()+"]["+toChildRouter.getVersion()+"]查询工艺路线第一个工序步骤失败!",ex);
			}
			//查询子工艺路线首工序
			if(StringUtils.equals("NODEGROUP", toChildRouterFirstNode.getExNodeType())){
				try{
					toChildOperation = operationService.findByPk(toChildRouterFirstNode.getOperationId());
				}catch(Exception ex){
					throw new ServiceException("2317","根据工序 ID["+toNode.getOperationId()+"]查询工序基本信息失败!",ex);
				}
			}
			
			//查询SFC 子工艺路线步骤信息(SfcRouter),校验传入工艺路线之前走过
			SfcRouterBO  sfcRouterBO= null;
			try {
				sfcRouterBO=this.sfcRouterService.findByUk(sfcInfoBo.getSite().getId(), sfcInfoBo.getId(), toChildRouter.getId());				
			} catch (Exception ex) {
				throw new ServiceException("2318","根据SFC["+sfcInfoBo.getSfcNo()+"]工艺路线["+toRouter.getNo()+"]["+toRouter.getVersion()+"]查询SFC工艺路线(SfcRouterBO)信息是否存在失败!",ex);
			}			
			if(sfcRouterBO!=null){
				 //清空SFC工序步骤信息
				 List<SfcOperationBO> sfcOperations = null;
				 try{
					 SfcOperationBO sfcOperation = new SfcOperationBO();
					 sfcOperation.setSite(sfcRouterBO.getSite());
					 sfcOperation.setSfcRouter(sfcRouterBO);
					 try {						
						sfcOperations = sfcOperationService.find(sfcOperation );
					 } catch (Exception ex) {
						throw new ServiceException("2310","查询SFC["+sfcInfoBo.getSfcNo()+"]在工艺路线RouterBo["+toChildRouter.getNo()+"]["+toChildRouter.getVersion()+"]上的工序步骤信息失败!",ex);
					 }
				 }catch(Exception ex){
					 
				 }
				 for(SfcOperationBO sob:sfcOperations){
					 sfcInfoBo =clearSfcOperationInfo(sfcInfoBo,sob,userBo,toChildRouterFirstNode,operationQueueBoStatus,curDate,toChildOperation);				 
				 }
				 
				 //Update SfcRouter
				 sfcRouterBO.setPreviousRouter(sfcInfoBo.getSfcRouter());
				 sfcRouterBO.setLastSfcOperationStep(sfcInfoBo.getSfcOperation());
				 try {	
					this.sfcRouterService.update(sfcRouterBO);
				} catch (Exception ex) {
					throw new ServiceException("2319","更新SFC["+sfcInfoBo.getSfcNo()+"]工艺路线(SfcRouterBO)工艺路线["+toRouter.getNo()+"]["+toRouter.getVersion()+"]的信息中的当前工序步骤失败!",ex);
				 }
				 
				 //update SfcInfo
				 sfcInfoBo.setOriginalStatus(sfcInfoBo.getStatus());
				 sfcInfoBo.setStatus(statusQueueBo);
				 sfcInfoBo.setOperationStepStatus(operationQueueBoStatus);
				 sfcInfoBo.setRouter(toChildRouter);
				 sfcInfoBo.setOperation(toChildOperation);
				 sfcInfoBo.setSfcRouter(sfcRouterBO);
				 sfcInfoBo.setLastHandleUser(userBo);
				 sfcInfoBo.setLastHandleTime(curDate);
				 try {
					 this.sfcInfoService.update(sfcInfoBo);
				 } catch (Exception ex) {
					 throw new ServiceException("2320","更新SFC["+sfcInfoBo.getSfcNo()+"]基本信息(SfcInfoBO)信息失败!",ex);
				 }
			//传入工艺路线之前没走过
			}else{
				this.createSfcRouterOperationInfo(sfcInfoBo, toChildRouter, userBo, toChildAllNodes,statusQueueBo , operationQueueBoStatus,toChildRouterFirstNode,toChildOperation,curDate,sfcInfoBo.getCurrentResource());
			}
		}		
		
		//D.判断节点类型是否是步骤组
		if(StringUtils.equals("NODEGROUP", toNode.getExNodeType())){
			//查询传入进来的工艺路线的SfcRouterBO
			SfcRouterBO toSfcRouterBo = null;			
			OperationBO toOperation = null;
			try{
				toSfcRouterBo = sfcRouterService.findByUk(sfcInfoBo.getSite().getId(), sfcInfoBo.getId(), toRouter.getId());
			}catch(Exception ex){
				throw new ServiceException("2308","根据SFC["+sfcInfoBo.getSfcNo()+"]工艺路线["+toRouter.getNo()+"]["+toRouter.getVersion()+"]查询SFC工艺路线信息(SfcRouterBO)失败!",ex);
			}
			
			//如果工艺路线之前没有走过,并且传入的节点是传入工艺路线的首节点,则发起工作流程,生成步骤信息;否则抛出异常
			if(toSfcRouterBo == null){								
				NodeVo toRouterFirstNode = null;
				try{
					toRouterFirstNode = mesWfUtil.getFirstNode(toRouter.getNo(),toRouter.getVersion());
				}catch(Exception ex){
					throw new ServiceException("3002","调用工作流方法[getFirsetNode]根据工艺路线["+toRouter.getNo()+"]["+toRouter.getVersion()+"]查询工艺路线第一个工序步骤失败!",ex);
				}
				if(StringUtils.equals(toRouterFirstNode.getNodeId(), toNode.getNodeId())){
					this.createSfcRouterOperationInfo(sfcInfoBo, toRouter, userBo, toRouterAllNodes,statusQueueBo , operationQueueBoStatus,toNode,toOperation,curDate,sfcInfoBo.getCurrentResource());					
				}else{
					throw new ServiceException("2309","SFC["+sfcInfoBo.getSfcNo()+"]没有走过工艺路线["+toRouter.getNo()+"]["+toRouter.getVersion()+"],步骤["+toNode.getNodeId()+"]不是工艺路线["+toRouter.getNo()+"]["+toRouter.getVersion()+"]的首步骤,不能跳转!");				
				}				
			}else{
				//如果之前走过,则直接跳转过去
				List<SfcOperationBO> sfcOperationBOs=null;
				SfcOperationBO sfcOperationBO= new SfcOperationBO();
				sfcOperationBO.setSfcRouter(toSfcRouterBo);
				sfcOperationBO.setSite(sfcInfoBo.getSite());
				sfcOperationBO.setStepGroup(toNode.getNodeId());
				//获取传入步骤组中的所有工序步骤信息
				try {						
					sfcOperationBOs = sfcOperationService.find(sfcOperationBO );
				} catch (Exception ex) {
					throw new ServiceException("2310","查询SFC["+sfcInfoBo.getSfcNo()+"]在工艺路线RouterBo["+toRouter.getNo()+"]["+toRouter.getVersion()+"]上的工序步骤信息失败!",ex);
				}
				//Update SfcOperationBO
				for (SfcOperationBO bean : sfcOperationBOs) {
					 
					bean.setStatus(operationQueueBoStatus);
					bean.setSfcQty(sfcInfoBo.getQty());
					bean.setActiveDate(curDate);
					bean.setTriggerUser(userBo);
					bean.setPreviousOperation(curSfcOperationBo);
					bean.setQueueNum(bean.getQueueNum()+1);
					try {						
						 sfcOperationService.update(bean);
					} catch (Exception ex) {
						throw new ServiceException("2311","更新SFC["+sfcInfoBo.getSfcNo()+"]的SFC工序步骤(SfcOperationBO)["+bean.getId()+"]信息失败!",ex);
					}
				}
				//Update SfcRouterBO
				//判断传入的工艺路线是否与当前工艺路线相同
				if(!toRouter.equals(sfcInfoBo.getRouter())){
					toSfcRouterBo.setPreviousRouter(sfcInfoBo.getSfcRouter());
				}
				toSfcRouterBo.setLastSfcOperationStep(null);
				toSfcRouterBo.setNodeGroup(toNode.getNodeId());				
				 try {
					this.sfcRouterService.update(toSfcRouterBo);
				} catch (Exception ex) {
					throw new ServiceException("2312","更新SFC["+sfcInfoBo.getSfcNo()+"]的SFC工艺路线(SfcRouterBO)["+curSfcRouterBo.getId()+"]中的当前工序步骤失败!",ex);
				}
				//Update SfcInfoBO
				sfcInfoBo.setOriginalStatus(sfcInfoBo.getStatus());					
				sfcInfoBo.setStatus(statusQueueBo );
				sfcInfoBo.setOperationStepStatus(operationQueueBoStatus);
				sfcInfoBo.setRouter(toRouter);
				sfcInfoBo.setOperation(toOperation);
				sfcInfoBo.setSfcRouter(toSfcRouterBo);
				sfcInfoBo.setSfcOperation(null);					
				sfcInfoBo.setLastHandleTime(curDate);
				sfcInfoBo.setLastHandleUser(userBo);
				sfcInfoBo.setStepGroup(toNode.getNodeId());
				sfcInfoBo.setStepId(toNode.getNodeId());
				try {
					 this.sfcInfoService.update(sfcInfoBo);
				} catch (Exception ex) {
					 throw new ServiceException("2313","更新SFC["+sfcInfoBo.getSfcNo()+"]基本信息(SfcInfoBO)信息失败!",ex);
				}
			}
		}
		
		//AfterApprove:执行二次开发接口业务处理类
		log.debug(">>>>>>>>>>>>>>>>>>>>>>Execute After Approve Listener ");
		this.executeEvent(this.EVENT_AFTER_APPROVE, sfcInfoBo, toRouter, null, null, toNode, userBo);
	}
		
	@Override
	public NodeVo getFirstNode(RouterBO routerBo){
		// TODO Auto-generated method stub
		//校验RouterBO是否为空
	    if(routerBo == null){
	    	throw new ServiceException("2021","调用MES工作流getFirstNode时,传入的RouterBO为空!");
	    }
	    if(StringUtils.isEmpty(routerBo.getId())){
	    	throw new ServiceException("2022","调用MES工作流getFirstNode时,传入的RouterBO对象ID为空!");
	    }
	    
		try{
			routerBo = routerService.findByPk(routerBo.getId());
		}catch(Exception ex){
			throw new ServiceException("2050","获取工艺路线首工序时根据ROUTER ID["+routerBo.getId()+"]查询工艺路线基本信息异常!",ex);
		}
		MesWfutil mesWfUtil =null;
		NodeVo nv = null;
		try{
			mesWfUtil = new MesWfutil(sqlMapClient);
			nv = mesWfUtil.getFirstNode(routerBo.getNo(), routerBo.getVersion());
		}catch(Exception ex){
			throw new ServiceException("3002","调用工作流方法[getFirsetNode]根据工艺路线["+routerBo.getNo()+"]["+routerBo.getVersion()+"]查询工艺路线第一个工序步骤失败!",ex);
		}
		return nv;
	}
		
	@Override
	public List<NodeVo> getAllNodes(RouterBO router) {
		// TODO Auto-generated method stub
		//校验RouterBO是否为空
	    if(router == null){
	    	throw new ServiceException("2023","调用MES工作流getAllNodes时,传入的RouterBO为空!");
	    }
	    if(StringUtils.isEmpty(router.getId())){
	    	throw new ServiceException("2024","调用MES工作流getAllNodes时,传入的RouterBO对象ID为空!");
	    }
		try{
			router = routerService.findByPk(router.getId());
		}catch(Exception ex){
			throw new ServiceException("2050","获取工艺路线所有工序步骤时根据ROUTER ID["+router.getId()+"]查询工艺路线基本信息异常!",ex);
		}
		MesWfutil mesWfUtil =null;
		List<NodeVo> nv = null;
		try{
			mesWfUtil = new MesWfutil(sqlMapClient);
			nv = mesWfUtil.getAllNodes(router.getNo(), router.getVersion());
		}catch(Exception ex){
			throw new ServiceException("3003","调用工作流方法[getAllNodes]根据工艺路线["+router.getNo()+"]["+router.getVersion()+"]查询工艺路线所有工序步骤失败!",ex);
		}
		return nv;
	}
	@Override
	public List<NodeVo> getNextNodes(RouterBO routerBo, String paramNodeId) {
		MesWfutil mesWfUtil =null;
		List<NodeVo> canToNodes = null;
		mesWfUtil = new MesWfutil(sqlMapClient);
		try {
			canToNodes = mesWfUtil.getNextNodes(routerBo.getNo(), routerBo.getVersion(),paramNodeId);
		} catch (SQLException ex) {
			throw new ServiceException("3004","调用工作流方法[getNextNodes]根据工艺路线["+routerBo.getNo()+"]["+routerBo.getVersion()+"]工序步骤ID["+paramNodeId+"]获取一下工序步骤集失败!",ex);
		}

		return canToNodes;
	}
	@Override
	public List<NodeVo> getNextNodes(SfcInfoBO sfcInfoBo,String paramNodeId,Map contextproperties) {
		// TODO Auto-generated method stub
		//校验SfcInfoBO是否为空
	    if(sfcInfoBo == null){
	    	throw new ServiceException("2025","调用MES工作流getNextNodes时,传入的SfcInfoBO为空!");
	    }
	    if(StringUtils.isEmpty(sfcInfoBo.getId())){
	    	throw new ServiceException("2026","调用MES工作流getNextNodes时,传入的SfcInfoBO对象ID为空!");
	    }
	    
	    //校验paramNodeId是否为空
	    if(paramNodeId == null){
	    	throw new ServiceException("2027","调用MES工作流getNextNodes时,传入的步骤ID为空!");
	    }
	    if(StringUtils.isEmpty(sfcInfoBo.getId())){
	    	throw new ServiceException("2028","调用MES工作流getNextNodes时,传入的步骤ID为空!");
	    }
		
		//查询SFC基本信息
		try{
			sfcInfoBo = sfcInfoService.findByPk(sfcInfoBo.getId());	
		}catch(Exception ex){
			throw new ServiceException("2011","获取下一工序步骤时根据SFC ID["+sfcInfoBo.getId()+"]查询SFC基本信息(SfcInfoBO)失败!",ex);
		}
				
		SfcRouterBO curSfcRouterBo = null;		
		//查询SFC当前工艺路线(SfcRouterBO)信息
		try{
			curSfcRouterBo = sfcRouterService.findByPk(sfcInfoBo.getSfcRouter().getId());
		}catch(Exception ex){
			throw new ServiceException("2012","获取SFC["+sfcInfoBo.getSfcNo()+"]下一工序步骤时根据SfcRouter ID["+sfcInfoBo.getSfcRouter().getId()+"]查询SFC当前工艺路线信息(SfcRouterBO)失败!",ex);
		}
		
		MesWfutil mesWfUtil =null;
		List<NodeVo> returnNodes = new ArrayList<NodeVo>();
		List<NodeVo> canToNodes = null;		
		NodeVo curNode = null;
		NodeVo paramNode = null;
		Object excuteJsResult = null;
				
		//获取传入的节点信息
		try{		
			mesWfUtil = new MesWfutil(sqlMapClient);
			paramNode = mesWfUtil.getNodeById(sfcInfoBo.getRouter().getNo(), sfcInfoBo.getRouter().getVersion(), paramNodeId);
		}catch(Exception ex){
			throw new ServiceException("3001","调用工作流方法[getNodeById]根据工艺路线["+sfcInfoBo.getRouter().getNo()+"]["+sfcInfoBo.getRouter().getVersion()+"]工序步骤ID["+paramNodeId+"]查询工序步骤基本信息失败!",ex);
		}
		if(paramNode == null){
			throw new ServiceException("2014","在工艺路线["+sfcInfoBo.getRouter().getNo()+"]["+sfcInfoBo.getRouter().getVersion()+"]中没有找到工序步骤["+paramNodeId+"]!");
		}
				
		//A:传入节点是返回步骤RETURN,则计算原来工艺路线上可以去的节点
		if(StringUtils.equals(paramNode.getExNodeType(), "RETURN") ){
		   //获取SFC当前工艺路线的上一工艺路线,如果没有则抛出异常,如果有则计算上一工艺路线上可以Return的工序	
		    if(curSfcRouterBo.getPreviousRouter() == null){
				throw new ServiceException("2014","SFC["+sfcInfoBo.getSfcNo()+"]所走的工艺路线只有["+sfcInfoBo.getRouter().getNo()+"]["+sfcInfoBo.getRouter().getVersion()+"]一条,不能执行返回步骤!");				   
			}
			   
		    if(StringUtils.isEmpty(curSfcRouterBo.getPreviousRouter().getId())){
				throw new ServiceException("2015","SFC["+sfcInfoBo.getSfcNo()+"]所走的工艺路线只有["+sfcInfoBo.getRouter().getNo()+"]["+sfcInfoBo.getRouter().getVersion()+"]一条,不能执行返回步骤!");				   
			}
			   
		    SfcRouterBO preSfcRouterBo = null;
		    SfcOperationBO preSfcOperationBo = null;
		    RouterBO preRouterBo = null;
			   
		    //获取SFC原工艺路线(SfcRouterBO)的信息
			try{
			   preSfcRouterBo = sfcRouterService.findByPk(curSfcRouterBo.getPreviousRouter().getId());
			}catch(Exception ex){							
			   throw new ServiceException("2016","获取SFC["+sfcInfoBo.getSfcNo()+"]下一工序步骤时根据SfcRouter ID["+curSfcRouterBo.getPreviousRouter().getId()+"]查询SFC原工艺路线基本信息失败!",ex);
			}
			   
			//获取SFC原工艺路线上的最后工序步骤(SfcOperationBO)信息
			try{
			   preSfcOperationBo = sfcOperationService.findByPk(preSfcRouterBo.getLastSfcOperationStep().getId());
			}catch(Exception ex){
			   throw new ServiceException("2017","获取SFC["+sfcInfoBo.getSfcNo()+"]下一工序步骤时根据SfcOperation ID["+preSfcRouterBo.getLastSfcOperationStep().getId()+"]查询SFC原工序步骤基本信息失败!",ex);
			}
				
			//获取原工艺路线的基本信息
			try{
			   preRouterBo = routerService.findByPk(preSfcRouterBo.getRouter().getId());
			}catch(Exception ex){
			   throw new ServiceException("2018","获取SFC["+sfcInfoBo.getSfcNo()+"]下一工序步骤时根据工艺路线 ID["+preSfcRouterBo.getRouter().getId()+"]查询工艺路线基本信息失败!",ex);
			}
			   
			//获取SFC原工艺路线上的最后工序步骤的节点信息
			NodeVo preNodeVo = null;
			try{							
				preNodeVo = mesWfUtil.getNodeById(preRouterBo.getNo(), preRouterBo.getVersion(), preSfcOperationBo.getStepId());
			}catch(Exception ex){
				throw new ServiceException("3001","调用工作流方法[getNodeById]根据工艺路线["+preRouterBo.getNo()+"]["+preRouterBo.getVersion()+"]工序步骤ID["+preSfcOperationBo.getStepId()+"]查询工序步骤基本信息失败!",ex);
			}
			   
		    //B1:ReturnAny:获取原工艺路线的所有节点
			if(StringUtils.equals("ReturnAny", paramNode.getReturnFunction())){					
				List<NodeVo> preAllNodes = null;
				try{							
					preAllNodes = mesWfUtil.getAllNodes(preRouterBo.getNo(), preRouterBo.getVersion());
				}catch(Exception ex){
					throw new ServiceException("3003","调用工作流方法[getAllNodes]根据工艺路线["+preRouterBo.getNo()+"]["+preRouterBo.getVersion()+"]查询工艺路线所有工序步骤失败!",ex);
				}
					
				if(preAllNodes != null && preAllNodes.size()>0 ){
					for(int i=0;i<preAllNodes.size();i++){
						if(preAllNodes.get(i).getExNodeType().equals("START") ||
								preAllNodes.get(i).getExNodeType().equals("END")||
								preAllNodes.get(i).getExNodeType().equals("NODEGROUP")||
								preAllNodes.get(i).getExNodeType().equals("RETURN")
								){
							preAllNodes.remove(i);
						}
					}
					returnNodes = preAllNodes;
				}				
				return returnNodes;
			 }
			   
			 //B2:ReturnBack:获取原工艺路线的原节点
			 if(StringUtils.equals("ReturnBack", paramNode.getReturnFunction())){	
			     returnNodes.add(preNodeVo);
				 return returnNodes;
			 }
			   
			 //B3:ReturnNext:获取原工艺路线的原节点的下一个节点集
			 if(StringUtils.equals("ReturnNext", paramNode.getReturnFunction())){	
				 List<NodeVo> preNextNodes = null;
				 try{
				   preNextNodes = mesWfUtil.getNextNodes(preRouterBo.getNo(), preRouterBo.getVersion(), preNodeVo.getNodeId());
				 }catch(Exception ex){
					throw new ServiceException("3004","调用工作流方法[getNextNodes]根据工艺路线["+preRouterBo.getNo()+"]["+preRouterBo.getVersion()+"]工序步骤ID["+preNodeVo.getNodeId()+"]获取一下工序步骤失败!",ex);
				 }
				 returnNodes = preNextNodes;
				 return returnNodes;
			  }
			   
			  //B4:ReturnPrevious:获取原工艺路线的原节点的上一个节点
			  if(StringUtils.equals("ReturnPrevious", paramNode.getReturnFunction())){	
				   if(preSfcOperationBo.getPreviousOperation() == null){
					   throw new ServiceException("2017","SFC["+sfcInfoBo.getSfcNo()+"]原工艺路线["+preRouterBo.getNo()+"]["+preRouterBo.getVersion()+"]的原工序步骤没有上一工序,不能执行ReturnPrevious!");
				   }
				   
				   if(StringUtils.isEmpty(preSfcOperationBo.getPreviousOperation().getId())){
					   throw new ServiceException("2018","SFC["+sfcInfoBo.getSfcNo()+"]原工艺路线["+preRouterBo.getNo()+"]["+preRouterBo.getVersion()+"]的原工序步骤没有上一工序,不能执行ReturnPrevious!");
				   }
				   
				   SfcOperationBO prePreviousSfcOperation = null;
				   //获取SFC原工艺路线上的最后工序步骤信息的上一工序步骤  
				   try{
					   prePreviousSfcOperation = sfcOperationService.findByPk(preSfcOperationBo.getPreviousOperation().getId());
				   }catch(Exception ex){
						throw new ServiceException("2019","根据SfcOperation ID["+preSfcRouterBo.getLastSfcOperationStep().getId()+"]查询SFC["+sfcInfoBo.getSfcNo()+"]工序步骤基本信息失败!",ex);
				   }
				   
				   NodeVo prePreviousNodeVo = null;
				   try{							
						preNodeVo = mesWfUtil.getNodeById(preRouterBo.getNo(), preRouterBo.getVersion(), prePreviousSfcOperation.getStepId());
				   }catch(Exception ex){
						throw new ServiceException("3001","调用工作流方法[getNodeById]根据工艺路线["+preRouterBo.getNo()+"]["+preRouterBo.getVersion()+"]工序步骤ID["+prePreviousSfcOperation.getStepId()+"]查询工序步骤基本信息失败!",ex);
				   }
				   
				   if(prePreviousNodeVo != null){
					   returnNodes.add(prePreviousNodeVo);
				   } 				   
				   return returnNodes;
			  }	
		}
		
		//B:不是返回步骤		
		//执行JS脚本,如果返回值为空值或"-1",则让用户选择去哪个工序
		if(StringUtils.isNotEmpty(paramNode.getExecutionRules())){
			excuteJsResult = this.excuteJS(paramNode.getExecutionRules(), "getNextNode", contextproperties);			
		}
		
		//如果执行JS后返回-2,则抛出异常
		if(excuteJsResult != null && excuteJsResult.equals("-2")){
			throw new ServiceException("2020","JS语法错误,请检查节点["+paramNode.getNodeId()+"]上设置的执行规则JS脚本!");
		}
		
		//如果执行JS后返回一个节点号,则将返回的节点返回
		if(excuteJsResult != null && !excuteJsResult.equals("-1")){
			//获取执行JS脚本后返回的节点信息
			NodeVo nv = null;
			try{
				nv = mesWfUtil.getNodeById(sfcInfoBo.getRouter().getNo(), sfcInfoBo.getRouter().getVersion(), excuteJsResult.toString().trim());
			}catch(Exception ex){
				throw new ServiceException("3001","调用工作流方法[getNodeById]根据工艺路线["+sfcInfoBo.getRouter().getNo()+"]["+sfcInfoBo.getRouter().getVersion()+"]工序步骤["+excuteJsResult.toString()+"]查询节点基本信息失败!",ex);
			}
			
			if(nv == null ){
				throw new ServiceException("3010","在工艺路线["+sfcInfoBo.getRouter().getNo()+"]["+sfcInfoBo.getRouter().getVersion()+"]中没有找到工序步骤["+excuteJsResult.toString()+"],请检查工序步骤["+curNode.getNodeId()+"]上设置的执行规则JS脚本!");
			}	
			
		    returnNodes.add(nv);			
		    return returnNodes;
		}
		
		//没有JS 或是 执行JS返回-1,则获取所有可以去的工序步骤
		try{
			canToNodes = mesWfUtil.getNextNodes(sfcInfoBo.getRouter().getNo(), sfcInfoBo.getRouter().getVersion(), paramNode.getNodeId());
			returnNodes.addAll(canToNodes);
		}catch(Exception ex){
			throw new ServiceException("3004","调用工作流方法[getNextNodes]根据工艺路线["+sfcInfoBo.getRouter().getNo()+"]["+sfcInfoBo.getRouter().getVersion()+"]工序步骤ID["+paramNode.getNodeId()+"]获取一下工序步骤集失败!",ex);
		}
		
		//如果传入节点是步骤组
		if( paramNode.getNodeId().indexOf(".")>0 ){
			String nodeGroupId = paramNode.getNodeId().subSequence(0, paramNode.getNodeId().indexOf(".")).toString();
			List<SfcOperationBO> sfcOperations = null;
			SfcOperationBO sfcOperationBo = new SfcOperationBO();
			sfcOperationBo.setSite(curSfcRouterBo.getSite());
			sfcOperationBo.setSfcRouter(curSfcRouterBo);
			sfcOperationBo.setStepGroup(nodeGroupId);
			try {						
				sfcOperations = sfcOperationService.find(sfcOperationBo );
			} catch (Exception ex) {
				throw new ServiceException("2310","查询SFC["+sfcInfoBo.getSfcNo()+"]在工艺路线RouterBo["+sfcInfoBo.getRouter().getNo()+"]["+sfcInfoBo.getRouter().getVersion()+"]上的工序步骤信息失败!",ex);
			}
			//查询工序步骤“完成”状态对象
			StatusBO  operationDoneStatus=statusService.findByUK(BeanFactory.getSystemParamters().get("mes.siteoperation.operationstatus"),
					BeanFactory.getSystemParamters().get("mes.siteoperation.operationstatus.complete"));
			int doneNodesInNodeGroup = 0;
			for(SfcOperationBO sob : sfcOperations){
				if(StringUtils.equals(sob.getStatus().getId(), operationDoneStatus.getId())){
					doneNodesInNodeGroup = doneNodesInNodeGroup + 1;
				}
			}
			//查询步骤组节点信息
			NodeVo nodeGroup = null;
			try{					
				nodeGroup = mesWfUtil.getNodeById(sfcInfoBo.getRouter().getNo(), sfcInfoBo.getRouter().getVersion(), nodeGroupId);
			}catch(Exception ex){
				throw new ServiceException("3001","调用工作流方法[getNodeById]根据工艺路线["+sfcInfoBo.getRouter().getNo()+"]["+sfcInfoBo.getRouter().getVersion()+"]工序步骤ID["+nodeGroupId+"]查询工序步骤信息失败!",ex);
			}
			
			if(nodeGroup.getMustExeNum() != null && doneNodesInNodeGroup >= nodeGroup.getMustExeNum().intValue()){
				try{				
					canToNodes = mesWfUtil.getNextNodes(sfcInfoBo.getRouter().getNo(), sfcInfoBo.getRouter().getVersion(),nodeGroupId);
					returnNodes.addAll(canToNodes);
				}catch(Exception ex){
					throw new ServiceException("3004","调用工作流方法[getNextNodes]根据工艺路线["+sfcInfoBo.getRouter().getNo()+"]["+sfcInfoBo.getRouter().getVersion()+"]工序步骤ID["+nodeGroupId+"]获取一下工序步骤集失败!",ex);
				}
			}
		}			
		
		return returnNodes;
	}
	
	@Override
	public NodeVo getNodeById(RouterBO routerBo, String nodeId) {
		// TODO Auto-generated method stub
		if(routerBo == null){
			throw new ServiceException("2029","获取节点基本信息时传入的工艺路线对象为空!");
		}
		if(StringUtils.isEmpty(routerBo.getId())){
			throw new ServiceException("2030","获取节点基本信息时传入的工艺路线ID为空值!");
		}
		if(StringUtils.isEmpty(nodeId)){
			throw new ServiceException("2031","获取节点基本信息时传入的节点ID为空值!");
		}
		try{
			routerBo = routerService.findByPk(routerBo.getId());
		}catch(Exception ex){
			throw new ServiceException("2064","获取节点基本信息时根据工艺路线ID["+routerBo.getId()+"]查询工艺路线基本信息失败!",ex);
		}
		
		MesWfutil mesWfUtil =null;
		NodeVo nv = null;
		try{
			mesWfUtil = new MesWfutil(sqlMapClient);
			nv = mesWfUtil.getNodeById(routerBo.getNo(), routerBo.getVersion(), nodeId);
		}catch(Exception ex){			
			throw new ServiceException("3001","调用工作流方法[getNodeById]根据工艺路线["+routerBo.getNo()+"]["+routerBo.getVersion()+"]工序步骤ID["+nodeId+"]查询工序步骤基本信息失败!",ex);
		}
		return nv;
	}
	
	/**
	 * JS脚本执行方法
	 * @param jsfun
	 * @param funname
	 * @param contextproperties
	 * @return
	 */
	public Object excuteJS(String jsfun,String funname,Map contextproperties){
		if(contextproperties == null){
			contextproperties = new HashMap();
			contextproperties.put("NCCODE",null);
			contextproperties.put("LOOPCOUNT",null);
		}
		
		if(contextproperties.get("NCCODE") != null && StringUtils.isEmpty(contextproperties.get("NCCODE").toString())){
			contextproperties.put("NCCODE",null);
		}
		
		if(contextproperties.get("LOOPCOUNT") != null &&  StringUtils.isEmpty(contextproperties.get("LOOPCOUNT").toString())){
			contextproperties.put("LOOPCOUNT",null);
		}
		
		String beforeJsFun = " function getNextNode(param){try{var NCCODE = param.get(\"NCCODE\");var LOOPCOUNT = param.get(\"LOOPCOUNT\"); ";
		String afterJsFun  = " return \"-1\";}catch(ex){return \"-2\";}return \"-1\";}";
		
		jsfun = beforeJsFun + jsfun + afterJsFun ;
		
		//初始化返回对象
		Object returnObject = null;
		//获取脚本引擎
        ScriptEngineManager sem = new ScriptEngineManager();
        ScriptEngine se = null;
        se = sem.getEngineByExtension("js");   
        try {
            se.eval(jsfun);
            if (se instanceof Invocable) {
                Invocable invoke = (Invocable) se;
                //执行指定的JS方法
                returnObject = invoke.invokeFunction(funname,contextproperties);
            }
        } catch (NoSuchMethodException ex) {
        	throw new ServiceException("4000","执行JS脚本失败!",ex); 
        } catch (ScriptException ex) {
        	throw new ServiceException("4001","执行JS脚本失败!",ex); 
        }
        //返回
		return returnObject;
	}
	
	@Override
	public RouterBO getPreviousRouter(SfcInfoBO sfcInfoBo) {
		RouterBO routerBo=null;
		SfcRouterBO sfcRouterBo=null ,PreviousRouter=null;
		//校验SFC是否为空
		if(sfcInfoBo == null){
	    	throw new ServiceException("2032","调用MES工作流getPreviousRouter时,传入的SfcInfoBO为空!");
	    }
	    if(StringUtils.isEmpty(sfcInfoBo.getId())){
	    	throw new ServiceException("2033","调用MES工作流getPreviousRouter时,传入的SfcInfoBO对象ID为空!");
	    }
		
		//获取sfc基本信息
		try{
			sfcInfoBo = sfcInfoService.findByPk(sfcInfoBo.getId());	
		}catch(Exception ex){
			throw new ServiceException("2500","根据SFC ID["+sfcInfoBo.getId()+"]查询SFC 基本信息失败!",ex);
		}		
		if(sfcInfoBo == null){
			throw new ServiceException("2501","SfcInfoBO对象为空,不能开始!");
		} 
		if(StringUtils.isNotEmpty(sfcInfoBo.getSfcRouter().getId())){
			try{
				//获取当前sfc工艺路线
				sfcRouterBo = this.sfcRouterService.findByPk(sfcInfoBo.getSfcRouter().getId());
			}catch(Exception ex){
				throw new ServiceException("2502","根据SFC["+sfcInfoBo.getSfcNo()+"]工艺路线["+sfcInfoBo.getSfcRouter().getId()+"]查询SFC 工艺路线信息失败!",ex);
			}
			if(sfcRouterBo!=null&&StringUtils.isNotEmpty(sfcRouterBo.getPreviousRouter().getId())){
				try{
					//获取上一步sfc工艺路线
					PreviousRouter = this.sfcRouterService.findByPk(sfcRouterBo.getPreviousRouter().getId());
					if(PreviousRouter!=null &&  PreviousRouter.getRouter()!=null){
						routerBo=PreviousRouter.getRouter();
					}
				}catch(Exception ex){
					throw new ServiceException("2503","根据SFC["+sfcInfoBo.getSfcNo()+"]上一步工艺路线["+PreviousRouter.getId()+"]查询SFC工艺路线信息失败!",ex);
				}
			}			
		}
		return routerBo;
	} 
	
	
	//清除sfc工序步骤信息
	private SfcInfoBO clearSfcOperationInfo(SfcInfoBO sfcInfoBo,SfcOperationBO sfcOperation,UserBO userBo,NodeVo firstNode,StatusBO status,Date curDate,OperationBO operation){		
		
		//查询SFC工序步骤"排队"状态对象
		StatusBO  operationStepQueueStatus=statusService.findByUK(BeanFactory.getSystemParamters().get("mes.siteoperation.operationstatus"),
				BeanFactory.getSystemParamters().get("mes.siteoperation.operationstatus.queue"));
		
		 sfcOperation.setSfcQty(0);
		 sfcOperation.setStatus(null);
		 sfcOperation.setActiveDate(curDate);
		 sfcOperation.setTriggerUser(userBo);
		 sfcOperation.setPreviousOperation(null);	
		 
		 if(StringUtils.equals("NODEGROUP", firstNode.getExNodeType())){
			 if(StringUtils.equals(sfcOperation.getStepGroup(), firstNode.getNodeId())){
				 sfcOperation.setSfcQty(sfcInfoBo.getQty());
				 sfcOperation.setStatus(status);
				 sfcOperation.setPreviousOperation(sfcInfoBo.getSfcOperation());
				 
				 sfcInfoBo.setStepGroup(sfcOperation.getStepGroup());
				 if( operation!= null && 
					 StringUtils.isNotEmpty(operation.getId()) && 
					 operation.getId() != null &&
					 StringUtils.equals(operation.getId(), sfcOperation.getOperation().getId())){
					 	 sfcInfoBo.setOperation(operation);
					     sfcInfoBo.setSfcOperation(sfcOperation);	
					     sfcInfoBo.setStepId(sfcOperation.getStepId() );
					     if(StringUtils.equals(operationStepQueueStatus.getId(), status.getId())){
					    	 sfcOperation.setActiveNum(sfcOperation.getActiveNum()+1);
					     }else{
					    	 sfcOperation.setQueueNum(sfcOperation.getQueueNum()+1);
					     }
				 }else{
					 sfcOperation.setStatus(operationStepQueueStatus);
					 sfcOperation.setQueueNum(sfcOperation.getQueueNum()+1);
				 }				 
			 }
		 }else{
			 if(sfcOperation.getStepId().equals(firstNode.getNodeId())){
				 sfcOperation.setSfcQty(sfcInfoBo.getQty());
				 sfcOperation.setStatus(status);
				 sfcOperation.setPreviousOperation(sfcInfoBo.getSfcOperation());				 
				 sfcInfoBo.setSfcOperation(sfcOperation);
				 sfcInfoBo.setStepGroup(null);
				 sfcInfoBo.setStepId(firstNode.getNodeId() );
				 if(StringUtils.equals(operationStepQueueStatus.getId(), status.getId())){
			    	 sfcOperation.setActiveNum(sfcOperation.getActiveNum()+1);
			     }else{
			    	 sfcOperation.setQueueNum(sfcOperation.getQueueNum()+1);
			     }
			 }
		 }
		 
		 try {
				this.sfcOperationService.update(sfcOperation);
			} catch (Exception ex) {
				throw new ServiceException("4001","更新SFC["+sfcInfoBo.getSfcNo()+"]工序步骤工艺路线["+sfcInfoBo.getRouter().getNo()+"]["+sfcInfoBo.getRouter().getVersion()+"]步骤["+sfcOperation.getStepId()+"]信息失败!",ex);
		 }		
		 return sfcInfoBo;
	}
	
	
	//创建sfc工艺路线以及工序步骤相关信息
	private void createSfcRouterOperationInfo(SfcInfoBO sfcInfoBo,RouterBO routerBo,UserBO userBo ,List<NodeVo> allNodes,StatusBO statusBO,StatusBO operationStatusBO,NodeVo firstNode,OperationBO firstOperation,Date curDate,ResourceBO resource){
		   if(!( StringUtils.equals("OPERATION",firstNode.getExNodeType()) || 
				 StringUtils.equals("NODEGROUP",firstNode.getExNodeType()) )
				 ){
			  throw new ServiceException("4006","工艺路线["+routerBo.getNo()+"]["+routerBo.getVersion()+"]首工序步骤不能是‘"+firstNode.getExNodeType()+"’类型!");
		   }
		   
		   //查询SFC工序步骤"排队"状态对象
		   StatusBO  operationStepQueueStatus=statusService.findByUK(BeanFactory.getSystemParamters().get("mes.siteoperation.operationstatus"),
					BeanFactory.getSystemParamters().get("mes.siteoperation.operationstatus.queue"));
		   
		    //创建SfcRouterBO实例并对属性赋值	
			SfcRouterBO sfcRouterBo = new SfcRouterBO();
			sfcRouterBo.setSite(sfcInfoBo.getSite());
			sfcRouterBo.setSfc(sfcInfoBo);
			sfcRouterBo.setRouter(routerBo);
			sfcRouterBo.setPreviousRouter(sfcInfoBo.getSfcRouter());
			sfcRouterBo.setCreateUser(userBo);
			sfcRouterBo.setCreateDate(curDate);
			
			try {
				sfcRouterBo.setId(this.sfcRouterService.save(sfcRouterBo));
			} catch (Exception ex) {
				throw new ServiceException("4002","保存SFC["+sfcInfoBo.getSfcNo()+"]工艺路线SfcRouterBO["+sfcRouterBo.getId()+"]信息失败!",ex);
			}	
			
			for(int i=0;i<allNodes.size();i++){
				//普通工序
				if(StringUtils.equals("OPERATION", allNodes.get(i).getExNodeType().trim()) ){
					SfcOperationBO sob = new SfcOperationBO();
					sob.setSite(sfcRouterBo.getSite());
					sob.setSfcRouter(sfcRouterBo);
					sob.setOperation(operationService.findByPk(allNodes.get(i).getOperationId()));
					sob.setStepId(allNodes.get(i).getNodeId());
					sob.setSfcQty(0);
					sob.setThroughNum(0);
					sob.setActiveNum(0);
					sob.setQueueNum(0);
					sob.setLoopNum(0);
					sob.setActiveDate(curDate);
					sob.setTriggerUser(userBo);
					if(allNodes.get(i).getNodeId().equals(firstNode.getNodeId())){
						sob.setSfcQty(sfcInfoBo.getQty());
						sob.setStatus(operationStatusBO);	
						sob.setPreviousOperation(sfcInfoBo.getSfcOperation());
						if(!StringUtils.equals(operationStepQueueStatus.getId(), operationStatusBO.getId())){								
							sob.setStatus(operationStatusBO);	
							sob.setActiveNum(1);
						}else{
							sob.setStatus(operationStepQueueStatus);
							sob.setQueueNum(1);
						}		
					}	
					try {						
						sob.setId(this.sfcOperationService.save(sob));
						if(allNodes.get(i).getNodeId().equals(firstNode.getNodeId())){
							sfcRouterBo.setLastSfcOperationStep(sob);
						}
					} catch (Exception ex) {
						throw new ServiceException("4003","生成SFC["+sfcInfoBo.getSfcNo()+"]的工序步骤信息(sfcOperationBO)["+sob.getId()+"]信息失败!",ex);
					}
				}
				//步骤组
				if(StringUtils.equals("NODEGROUP", allNodes.get(i).getExNodeType().trim()) ){
					List<NodeVo> groupNodes = allNodes.get(i).getGroupList();
					for(int j=0;j<groupNodes.size();j++){
						SfcOperationBO sob = new SfcOperationBO();
						sob.setSite(sfcRouterBo.getSite());
						sob.setSfcRouter(sfcRouterBo);
						sob.setOperation(operationService.findByPk(allNodes.get(i).getOperationId()));
						sob.setStepId(groupNodes.get(j).getNodeId());
						sob.setSfcQty(0);
						sob.setThroughNum(0);
						sob.setActiveNum(0);
						sob.setQueueNum(0);
						sob.setLoopNum(0);
						sob.setActiveDate(curDate);
						sob.setTriggerUser(userBo);
						sob.setStepGroup(allNodes.get(i).getNodeId());
						if(allNodes.get(i).getNodeId().equals(firstNode.getNodeId())){
							sob.setSfcQty(sfcInfoBo.getQty());							
							sob.setPreviousOperation(sfcInfoBo.getSfcOperation());
							if(firstOperation != null && 
									StringUtils.isNotEmpty(firstOperation.getId())&& 
									firstOperation.getId() != null &&
									StringUtils.equals(firstOperation.getId(), allNodes.get(i).getOperationId())){								
								//不是排队状态
								if(!StringUtils.equals(operationStepQueueStatus.getId(), operationStatusBO.getId())){								
									sob.setStatus(operationStatusBO);	
									sob.setActiveNum(1);
								}else{
									sob.setStatus(operationStepQueueStatus);
									sob.setQueueNum(1);
								}		
							}else{
								sob.setStatus(operationStepQueueStatus);
								sob.setQueueNum(1);
							}				
						}	
						try {						
							sob.setId(this.sfcOperationService.save(sob));							
						} catch (Exception ex) {
							throw new ServiceException("4003","生成SFC["+sfcInfoBo.getSfcNo()+"]的工序步骤信息(sfcOperationBO)["+sob.getId()+"]信息失败!",ex);
						}
					}
					//如果步骤组是首工序,则设置SfcRouter的步骤组
					if(allNodes.get(i).getNodeId().equals(firstNode.getNodeId())){
						sfcRouterBo.setNodeGroup(allNodes.get(i).getNodeId());
						sfcInfoBo.setStepGroup(allNodes.get(i).getNodeId());
					}
				}				
			}
			//更新SfcRouter信息
			try {
				this.sfcRouterService.update(sfcRouterBo);
			} catch (Exception ex) {
				throw new ServiceException("4004","更新SFC["+sfcInfoBo.getSfcNo()+"]的SFC工艺路线(SfcRouterBO)["+sfcRouterBo.getId()+"]中的当前工序步骤失败!",ex);
			}
			//更新SfcInfo 信息
			sfcInfoBo.setOriginalStatus(sfcInfoBo.getStatus());
			sfcInfoBo.setStatus(statusBO);
			sfcInfoBo.setOperationStepStatus(operationStatusBO);
			sfcInfoBo.setRouter(routerBo);
			sfcInfoBo.setOperation(firstOperation);	
			sfcInfoBo.setSfcRouter(sfcRouterBo);
			sfcInfoBo.setSfcOperation(sfcRouterBo.getLastSfcOperationStep());
			sfcInfoBo.setLastHandleTime(curDate);
			sfcInfoBo.setLastHandleUser(userBo);
			sfcInfoBo.setCurrentResource(resource);
			sfcInfoBo.setStepId(firstNode.getNodeId());
			try {
				this.sfcInfoService.update(sfcInfoBo);
			} catch (Exception ex) {
				throw new ServiceException("4005","更新SfcInfo基本信息失败!",ex);
			}
	}
	@Override
	public boolean isFirstOperation(OperationBO operation, RouterBO routerBo) {
		//校验OperationBO是否为空
	    if(operation == null){
	    	throw new ServiceException("2034","调用MES工作流isFirstOperation时,传入的OperationBO为空!");
	    }
	    if(StringUtils.isEmpty(operation.getId())){
	    	throw new ServiceException("2035","调用MES工作流isFirstOperation时,传入的OperationBO对象ID为空!");
	    }
	    
	    //校验RouterBO是否为空
	    if(routerBo == null){
	    	throw new ServiceException("2036","调用MES工作流isFirstOperation时,传入的RouterBO为空!");
	    }
	    if(StringUtils.isEmpty(routerBo.getId())){
	    	throw new ServiceException("2037","调用MES工作流isFirstOperation时,传入的RouterBO ID为空!");
	    }
		
		NodeVo firstNode=null;
		firstNode=this.getFirstNode(routerBo);
		boolean flag=false;
		if(firstNode!=null){
			flag= this.isNodeOperation(operation, firstNode);
		}
		return flag;
	}
	
	public boolean isNodeOperation(OperationBO operation,NodeVo nodeVo){
		//校验OperationBO是否为空
	    if(operation == null){
	    	throw new ServiceException("2038","调用MES工作流isNodeOperation时,传入的OperationBO为空!");
	    }
	    if(StringUtils.isEmpty(operation.getId())){
	    	throw new ServiceException("2039","调用MES工作流isNodeOperation时,传入的OperationBO对象ID为空!");
	    }
	    
	    //校验NodeVo是否为空
	    if(nodeVo == null){
	    	throw new ServiceException("2040","调用MES工作流isNodeOperation时,传入的步骤ID为空!");
	    }
	    if(StringUtils.isEmpty(nodeVo.getNodeId())){
	    	throw new ServiceException("2041","调用MES工作流isNodeOperation时,传入的步骤ID为空!");
	    }
		
		if(StringUtils.equals("NODEGROUP", nodeVo.getExNodeType())){
			for(NodeVo nv:nodeVo.getGroupList()){
				if(StringUtils.equals(operation.getId(),nv.getOperationId())){
					return true;
				}				
			}
		}
		if(StringUtils.equals("OPERATION", nodeVo.getExNodeType())){
			if(StringUtils.equals(operation.getId(),nodeVo.getOperationId())){
				return true;
			}
		}
		return false;
	}
	
	public boolean isCurOperation(SfcInfoBO sfcInfoBo,OperationBO operationBo){
		//校验OperationBO是否为空
	    if(operationBo == null){
	    	throw new ServiceException("2042","调用MES工作流isCurOperation时,传入的OperationBO为空!");
	    }
	    if(StringUtils.isEmpty(operationBo.getId())){
	    	throw new ServiceException("2043","调用MES工作流isCurOperation时,传入的OperationBO对象ID为空!");
	    }
	    
	    //校验SfcInfo是否为空
	    if(sfcInfoBo == null){
	    	throw new ServiceException("2044","调用MES工作流isCurOperation时,传入的SfcInfoBO为空!");
	    }
	    if(StringUtils.isEmpty(sfcInfoBo.getId())){
	    	throw new ServiceException("2045","调用MES工作流isCurOperation时,传入的SfcInfoBO对象ID为空!");
	    }
	    
	    //查询Sfc基本信息
		try{
			sfcInfoBo = sfcInfoService.findByPk(sfcInfoBo.getId());	
		}catch(Exception ex){
			throw new ServiceException("2100","根据SFC ID["+sfcInfoBo.getId()+"]查询SFC 基本信息失败!",ex);
		}		
		if(sfcInfoBo == null){
			throw new ServiceException("2101","SFC无效!");
		}
		
		if(sfcInfoBo.getOperation() != null && StringUtils.isNotEmpty(sfcInfoBo.getOperation().getId())){
			if(StringUtils.equals(sfcInfoBo.getOperation().getId(), operationBo.getId())){
				return true;
			}else{
				return false;
			}
		}
		
		if(sfcInfoBo.getStepGroup() != null && StringUtils.isNotEmpty(sfcInfoBo.getStepGroup())){
			NodeVo nv = this.getNodeById(sfcInfoBo.getRouter(), sfcInfoBo.getStepGroup());
			return this.isNodeOperation(operationBo, nv);
		}		
		return false;
	}
	
	/**
	 * 监听事件执行方法
	 * @param event
	 * @param sfc
	 * @param routerBo
	 * @param operationBo
	 * @param resourceBo
	 * @param toNodeId
	 * @param userBo
	 */
	private void executeEvent(String event,SfcInfoBO sfcInfoBo,RouterBO routerBo,OperationBO operationBo,ResourceBO resourceBo,NodeVo nodeVo,UserBO userBo){
		String[] clazzes =  getListener().get(event);
		if(clazzes == null || clazzes.length == 0) return;
		for(String clazz : clazzes){
			try{
				Event e = (Event) BeanFactory.getClazzIns(clazz, BeanFactory.INSTANCE_SINGLETON);
				e.execute(sfcInfoBo,routerBo,operationBo,resourceBo,nodeVo,userBo,new WFContext(this));
			}catch(Exception ex){
				throw new ServiceException("2109","SFC["+sfcInfoBo.getSfcNo()+"]"+event+"执行MES业务功能代码["+clazz+"]异常!",ex);
			}
		}
	}
		
	public void setSfcInfoService(SfcInfoService sfcInfoService){
		this.sfcInfoService = sfcInfoService;
	}

	public void setStatusService(StatusService statusService) {
		this.statusService = statusService;
	}

	public void setSfcOperationService(SfcOperationService sfcOperationService) {
		this.sfcOperationService = sfcOperationService;
	}

	public void setSfcRouterService(SfcRouterService sfcRouterService) {
		this.sfcRouterService = sfcRouterService;
	}

	public void setRouterService(RouterService routerService) {
		this.routerService = routerService;
	}

	public void setOperationService(OperationService operationService) {
		this.operationService = operationService;
	}

	public void setSqlMapClient(SqlMapClient sqlMapClient) {
		this.sqlMapClient = sqlMapClient;
	}

	public void setResourceService(ResourceService resourceService) {
		this.resourceService = resourceService;
	}

	public void setExecuteActivityService(
			ExecuteActivityService executeActivityService) {
		this.executeActivityService = executeActivityService;
	}

	public void setActivityInfoService(ActivityInfoService activityInfoService) {
		this.activityInfoService = activityInfoService;
	}

	public void setListener(Map<String,String[]> listener) {
		this.listener = listener;
	}
	public Map<String,String[]> getListener() {
		return listener;
	}	
}

package com.byd.mes.plugins.workFlow;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
 

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import com.byd.mes.plugins.workFlow.impl.BydWorkFlowServiceImpl;


public class Test { 
 public static void main(String[] args) {   
  File file = new File("d:/js.txt");
  try {
   String str = IOUtils.toString(new FileReader(file));
   
   System.out.println(str);
   BydWorkFlowServiceImpl bw = new BydWorkFlowServiceImpl();
   
   Map mp = new HashMap();
   mp.put("NcCode1", "2");
   mp.put("LoopCount2",3);   
   String rl = bw.excuteJS(str, "getNextNode", mp).toString();
   System.out.println(rl);
  } catch (FileNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }
}

 

 

posted @ 2011-08-06 08:39  上善¤若水  阅读(406)  评论(0编辑  收藏  举报