package com.iailab.module.model.mdk.factory; import com.iailab.module.model.mcs.pre.entity.MmItemTypeEntity; import com.iailab.module.model.mcs.pre.service.MmItemTypeService; import com.iailab.module.model.mdk.predict.PredictItemHandler; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; /** * 创建预测项对象的工厂 */ @Slf4j @Component public class PredictItemFactory { @Autowired private ApplicationContext applicationContext; @Autowired private MmItemTypeService mmItemTypeService; /** * 根据预测项实体创建对应的预测项对象 * * @param itemId * @return */ public PredictItemHandler create(String itemId) { MmItemTypeEntity itemTypeEntity = mmItemTypeService.getItemTypeByItemId(itemId); //获取预测项的预测程序的类 Object itemObject = null; try { Class clazz = Class.forName(itemTypeEntity.getItemclasstype()); itemObject = applicationContext.getBean(clazz); } catch (Exception e) { log.error("exception message : {}", e.getMessage()); } return (PredictItemHandler) itemObject; } }