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

import com.google.common.collect.Maps;
import com.zm.order.tool.server.handler.refund.RefundDocHandler;
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 zhuxiaofeng
 * @ClassName RefundDocHandleHolder
 * @date 2022-11-10 15:39:26
 */
@Component
public class RefundDocHandleHolder implements InitializingBean {

    @Autowired
    private List<RefundDocHandler> handlerList;

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

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

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