java将一个集合按某种自定义过滤器分组成多个集合

public void insertDataPre(List mbTranHists) {

        MoveDataToolsService dataToolsService = SpringApplicationContext.getBean("moveDataToolsService");

        long subTableSize= Long.parseLong(env.getProperty("db.subTableSize"));//获取子表数
        long modResult= Long.parseLong(env.getProperty("db.result"));//模运算结果

        Predicate filter = mbTranHist -> !mbTranHist.getClientType().equals("90");
        Predicate filter2 = mbTranHist -> Long.parseLong(mbTranHist.getRouterKey()) % subTableSize == modResult;

        List insetTranHistNew = mbTranHists.stream().filter(filter.or(filter2)).collect(Collectors.toList());

        mbTranHists.removeAll(insetTranHistNew);

        Map> listMap = mbTranHists.stream()
                                                  .collect(Collectors.groupingBy(mbTranHist -> String.valueOf(Long.parseLong(mbTranHist.getRouterKey()) % subTableSize)));
        //插入mb_tran_hist_new
        dataToolsService.inserMbTranHistNewBatch(insetTranHistNew);
        //插入其他各个子表
        listMap.forEach((groupKey,list)->{
           dataToolsService.inserMbTranHistBatch(list);
       });

    }

 

你可能感兴趣的:(java)