package com.sckw.slope.detection.consumer;

import com.alibaba.fastjson2.JSONObject;
import com.sckw.core.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author lfdc
 * @description
 * @date 2023-11-15 17:11:09
 */
@Slf4j
@Service
public class HandlerFactory {

    @Autowired
    private Map<String, AbstractHandler> handlerMap = new HashMap<>();

    public AbstractHandler getHandler(String type) {
        AbstractHandler receiptHandler = handlerMap.get(type);
        log.info("mqtt当前定义接收:{}", JSONObject.toJSONString(handlerMap));
        if (receiptHandler == null) {
            throw new BusinessException("mqtt单据类型错误，type=" + type);
        }
        return receiptHandler;
    }
}
