package com.zm.order.tool.server.handler;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import com.google.common.collect.Maps;

/**
 * @Author chang.n
 * @ClassName PerformanceHandle
 * @Date 2020/4/16 9:47 AM
 */
@Component
public class PerformanceHandle implements InitializingBean {

    @Autowired
    private List<RetailPerformanceHandler> handleList;

    private Map<String,RetailPerformanceHandler> handleMap = Maps.newHashMap();

    @Override
    public void afterPropertiesSet() {
        if (!CollectionUtils.isEmpty(handleList)) {
            handleList.forEach(handle -> {
                handleMap.put(handle.performanceType(), handle);
            });
        }
    }
    
    public RetailPerformanceHandler getPerformanceHandle(Integer performanceType) {
        if (!StringUtils.isEmpty(performanceType)) {
            return handleMap.get(performanceType.toString());
        }
        return null;
    }
}
