本文共 1929 字,大约阅读时间需要 6 分钟。
先判断村儿,再判断渠道,再判断用户类型,然后得到配置。
我按照这个思路画流程图,成功给自己画出了个闭环…其实还有一种思路,很简单:将所有配置读取到内存中,然后filter按条件筛选,最终选出来符合条件的配置。
/** * * @param channel 用户渠道 * @param village 村 * @param isPay 11 付费 21 未付费 */ public StrategyConfig getConfig(String channel, String village, Integer isPay){ Listlist = strategyDao.selectAll(); if (CollectionUtils.isEmpty(list)){ return new StrategyConfig(); } List filterList = list.stream().filter(StrategyConfig -> ((StringUtils.isEmpty(StrategyConfig.getIncludeVillage()) && StringUtils.isEmpty(StrategyConfig.getExcludeVillage())) || (StringUtils.isNotEmpty(StrategyConfig.getIncludeVillage)) && StrategyConfig.getIncludeVillage().toUpperCase().contains(village)) || (StringUtils.isNotEmpty(StrategyConfig.getExcludeVillage()) && !StrategyConfig.getExcludeVillage().toUpperCase().contains(village))) && ((StringUtils.isEmpty(StrategyConfig.getIncludeChannel()) && StringUtils.isEmpty(StrategyConfig.getExcludeChannel())) || (StringUtils.isNotEmpty(StrategyConfig.getIncludeChannel()) && StrategyConfig.getIncludeChannel().toUpperCase().contains(channel)) || (StringUtils.isNotEmpty(StrategyConfig.getExcludeChannel()) && !StrategyConfig.getExcludeChannel().toUpperCase().contains(channel))) && (StrategyConfig.getMalePayType()!=null && (StrategyConfig.getMalePayType().equals(isPay) || StrategyConfig.getMalePayType().equals(ALL))) ).collect(Collectors.toList()); if (CollectionUtils.isEmpty(filterList)){ return new StrategyConfig(); } if (filterList.size() == 1){ return filterList.get(0); } }
转载地址:http://zvgjx.baihongyu.com/