简单的策略模式
定义策略通用类
public interface ChannelStrategy { List<ClientDto> test(OpenClient openClient); }
@Slf4j @Component(ChennelConstant.JD) public class TFenXiaoChannelStrategy implements ChannelStrategy {
@Override
List<ClientDto> test(OpenClient openClient){
}
}
注入策略
@Service @Slf4j public class ChannelStrategy { @Autowired private final Map<String, ChannelStrategy> strategys = new ConcurrentHashMap<>(6); public ChannelStrategy getStrategy(String channel){ ChannelStrategy strategy = strategys.get(channel); if (strategy == null) { log.warn("not find strategy defined"); return null; } return strategy; } }
根据渠道获取策略
ChannelStrategy strategy = middleChannelStrategy.getStrategy(openClientShop.getChannel());
strategy.test();