@Service
public class TradeFactory {
@Resource
private Map<String, AbstractTradeHandler> tradeMap;
/**
* 获取交易服务
* @param beanName
* @return
*/
public AbstractTradeHandler getTradeService(String beanName){
if (StringUtils.isEmpty(beanName)){
return null;
}
return tradeMap.get(beanName);
}
}
@Service
public class BizHandlerService {
@Resource
private TradeFactory tradeFactory;
/**
* 交易处理
* @param enums
* @param str
* @return
* @throws Exception
*/
public String tradeHandler(TradeInfoEnums enums, String str) throws Exception {
AbstractTradeHandler service = tradeFactory.getTradeService(enums.getBeanName());
return service.tradeHandler(enums, str);
}
}
public abstract class AbstractTradeHandler {
/**
* 交易接口
* @param enums
* @param str
* @return
*/
public abstract String tradeHandler(TradeInfoEnums enums, String str);
}