package com.cyksj.service.order.post;

import com.cyksj.common.util.SpringCtxUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author chan
 * @className PostDataFactory
 * @description 数据回传工厂类
 * @date 2020/11/23 3:46 下午
 */
public class PostDataFactory {

    private static Map<String, AbstractPostDataService> strategyBean = new ConcurrentHashMap<>();

    // 初始化
    public static AbstractPostDataService getPostStrategy(String key) {
        try {
            if (StringUtils.isEmpty(key)) {
                return null;
            }else {
                key += "PostDataService";
            }
            AbstractPostDataService mapInPayNotify = strategyBean.get(key);
            if (mapInPayNotify != null) {
                return mapInPayNotify;
            }
            AbstractPostDataService newInPayNotify = SpringCtxUtils.getBean(key);
            strategyBean.put(key, newInPayNotify);
            return newInPayNotify;
        } catch (Exception e) {
            return null;
        }
    }

    public static void add(AbstractPostDataService postDataService, String key) {
        strategyBean.put(key,postDataService);
    }

}
