package com.huazheng.project.greenplum.flatmap;

import java.io.Serializable;

import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.util.Collector;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

import com.huazheng.project.greenplum.service.impl.GPServiceImpl;

import cn.hutool.core.util.ReflectUtil;

@Service
public class GreenPlumFlatMapFunction<T, O> implements FlatMapFunction<T, O>, ApplicationContextAware, Serializable {

	private static final long serialVersionUID = 1L;

	private static GPServiceImpl gpserviceImpl;
	
	@Override
	public void flatMap(T value, Collector<O> out) throws Exception {
		String simpleName = value.getClass().getSimpleName();
		ReflectUtil.invoke(gpserviceImpl, "process" + simpleName, value, out);
	}
	
	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		gpserviceImpl = (GPServiceImpl) applicationContext.getBean("GPServiceImpl");
	}

}
