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

import com.google.common.collect.Maps;
import com.zm.order.tool.server.handler.CommentDocHandler;
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;

/**
 * 评价处理器
 *
 * @author nianchang
 * @ClassName CommentHandleHolder
 * @date 2021/07/06 5:45 下午
 */
@Component
public class CommentDocHandleHolder implements InitializingBean {

    @Autowired
    private List<CommentDocHandler> handlerList;

    private Map<Integer, CommentDocHandler> handlerMap = Maps.newHashMap();

    @Override
    public void afterPropertiesSet() throws Exception {
        handlerList.forEach(handle -> handlerMap.put(handle.bizType(), handle));
    }

    public CommentDocHandler obtainHandler(Integer bizType) {
        return handlerMap.get(bizType);
    }
}
