package org.activiti.engine.impl.listener;

import org.activiti.engine.impl.event.SubProcessEndEvent;
import org.activiti.engine.impl.event.SubProcessMultiInstanceStartEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Service;

import com.artfess.bpm.api.cmd.ActionCmd;
import com.artfess.bpm.api.context.ContextThreadUtil;
import com.artfess.bpm.model.def.SubProcessStartOrEndEventModel;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

/**
 * 内嵌子流程结束时事件
 */
@Service
public class SubProcessEndEventListener implements ApplicationListener<SubProcessEndEvent>, Ordered{

	@Override
	public int getOrder()
	{
		return 1;
	}

	@Override
	@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT, classes = SubProcessEndEvent.class)
	public void onApplicationEvent(SubProcessEndEvent ev)
	{
		SubProcessStartOrEndEventModel eventModel = (SubProcessStartOrEndEventModel) ev.getSource();
		ActionCmd cmd = ContextThreadUtil.getActionCmd();
		cmd.addTransitVars("CurrentEventType", "SubProcessStartOrEndEvent");
		cmd.addTransitVars("SubProcessStartOrEndEventModel", eventModel);

	}
}
