package com.vci.server.bof.server.transfer; import org.apache.commons.lang3.StringUtils; import com.vci.corba.common.data.VCIInvocationInfo; import com.vci.corba.omd.data.BusinessObject; import com.vci.corba.omd.lcm.LifeCycle; import com.vci.corba.omd.lcm.TransitionVO; import com.vci.server.base.persistence.dao.HibernateSessionFactory; import com.vci.server.base.utility.LogRecordUtil; import com.vci.server.base.utility.ServerServiceProvider; import com.vci.server.bof.server.ServiceFacadeExecuteHelper; import com.vci.server.bof.service.BOFactoryServices; import com.vci.server.cache.OMCacheProvider; import com.vci.corba.common.VCIError; public class TransferBO extends ServiceFacadeExecuteHelper{ private static ServiceFacadeExecuteHelper instance = null; public static ServiceFacadeExecuteHelper getInstance() { if(instance == null) { instance = new TransferBO(); } return instance; } @Override protected Object doAction() throws Throwable { boolean rs = false; BusinessObject bo = params.getBo(); TransitionVO vo = params.getVo(); TransitionVO vo2 = null; String boLcStatus = bo.lcStatus; if(boLcStatus == null || boLcStatus.trim()==""){ throw getLocalString("", new VCIError("P0010SOF-00023",new String[]{bo.name})); } boLcStatus = boLcStatus.trim(); LifeCycle curLC = null; try { curLC = OMCacheProvider.getLifeCycle(bo.lctId); if(curLC == null){ //TODO:提示出来 throw getLocalString("", new VCIError("P0010SOF-00024",new String[]{bo.name})); } if (vo.destination!=null && !vo.destination.trim().equals("") && vo.connect != null && !vo.connect.trim().equals("")) { for (int l = 0; l < curLC.routes.length; ++l) { TransitionVO route = curLC.routes[l]; if (route.source.trim().equals(boLcStatus)) { if (vo.connect.trim().equals(route.connect.trim()) && vo.destination.trim().equals(route.destination.trim())) { vo2 = route; break; } } } if (vo2 == null) { throw getLocalString("", new VCIError("P0010SOF-00027", new String[] { vo.destination })); } } else if (vo.destination!= null && !vo.destination.trim().equals("")) { for (int l = 0; l < curLC.routes.length; ++l) { TransitionVO route = curLC.routes[l]; if (route.source.equals(boLcStatus)) { if (vo.destination.equals(route.destination)) { vo2 = route; break; } } } if (vo2 == null) { throw getLocalString("", new VCIError("P0010SOF-00027", new String[] { vo.destination })); } } else if (vo.connect !=null && !vo.connect.trim().equals("")) { for (int l = 0; l < curLC.routes.length; ++l) { TransitionVO route = curLC.routes[l]; if (route.source.equals(boLcStatus)) { if (vo.connect.equals(route.connect)) { vo2 = route; break; } } } if (vo2 == null) { throw getLocalString("", new VCIError("P0010SOF-00025", new String[] { vo.connect })); } } else { throw getLocalString("", new VCIError("P0010SOF-00026", new String[] {})); } BOFactoryServices services = BOFactoryServices.getInstance(); rs = services.transferBusinessObject(bo, vo2.destination, params.getReleaseStatus()); if (!rs) { return rs; } //执行跃迁事件 TransitionEventsExcuter excuter = new TransitionEventsExcuter(); excuter.excute(vo2, bo); //日志记录 VCIInvocationInfo info = HibernateSessionFactory.getVciSessionInfo(); String ip = "127.0.0.1"; if(info!=null){ ip = info.clientIPInfo == null||"".equals(info.clientIPInfo) ?"127.0.0.1":info.clientIPInfo; } String logInfo = StringUtils.isNotBlank(bo.name)?bo.name:(StringUtils.isNotBlank(bo.id)?bo.id:bo.oid); //recordLog(bo.modifier, bo.btName,ip, "跃迁", bo.btName,logInfo + "的状态改变,从【" + vo.source + "】到【" + vo.destination +"】", bo.oid); LogRecordUtil.writeGeneralSuccessLog(bo, "跃迁"); } catch (Exception e) { e.printStackTrace(); throw this.getLocalString("P0010SOF-00008", e); } catch (Throwable t) { t.printStackTrace(); throw this.getLocalString("P0010SOF-00008", t); } return rs; } }