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

import com.google.common.collect.Maps;
import com.zm.order.tool.server.handler.BusinessHandler;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

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

/**
 * @Description 索引订单生成器
 * @Author: ph
 * @Date: 2019/12/9 19:38
 */
@Component
public class BusinessHandlerHolder implements InitializingBean {

    @Autowired
    private List<BusinessHandler> orderGeneratorList;

    private Map<Integer, BusinessHandler> indexOrderGeneratorMap = Maps.newHashMap();

    @Override
    public void afterPropertiesSet() throws Exception {
        orderGeneratorList.forEach(businessHandler -> {
            indexOrderGeneratorMap.put(businessHandler.bizType(), businessHandler);
        });
    }

    public BusinessHandler orderGenerator(Integer bizType) {
        return indexOrderGeneratorMap.get(bizType);
    }
}
