package com.uas.platform.b2b.event;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.ApplicationEvent;


/**
 * 新增事件
 * 
 * @param <S>
 *            拆分后的关键词库
 * @param <T>
 *            原单据
 * 
 * @author yingp
 * 
 */
public abstract class SaveEvent<S, T> extends ApplicationEvent {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private List<T> savedList;

	public SaveEvent(List<T> savedList) {
		super(savedList);
		this.savedList = savedList;
	}

	/**
	 * @param userRepository
	 *            用户信息dao接口
	 * @return
	 */
	public final List<S> split() {
		try {
			pusher(savedList);
		} catch (Exception e) {

		}
		List<S> splitList = new ArrayList<S>();
		for (T saved : savedList) {
            splitList.addAll(split(saved));
        }
		return splitList;
	}

	/**
	 * 单条记录拆分多个关键字
	 * 
	 * @param saved
	 * @return
	 */
	public abstract List<S> split(T saved);

	/**
	 * 推送消息
	 * 
	 * @param savedList
	 * @param userRepository
	 *            用户信息dao接口
	 */
	public abstract void pusher(List<T> savedList);

}
