package com.ruoyi.system.core.deviceEntity;

import com.ruoyi.system.core.ClientExecute;
import com.ruoyi.system.core.annotate.DeviceEntity;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

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

@Component
public class ProductEntityFactory {
    public Map<String, ProductEntity> map = new HashMap<>();

    public ProductEntityFactory(ApplicationContext applicationContext) {
        Map<String, ProductEntity> beans = applicationContext.getBeansOfType(ProductEntity.class);
        for (String key : beans.keySet()) {
            ProductEntity execute = beans.get(key);
            if (!execute.getClass().isAnnotationPresent(DeviceEntity.class)) {
                continue;
            } else {
                map.put(execute.getClass().getAnnotation(DeviceEntity.class).product(), execute);
            }
        }
    }

    public ProductEntity getProductEntity(String type) {
        return map.get(type);
    }
}
