public static void main(String[] args) {//100万条数据List<CrmInvestSaleUserCount> waitAssignUserList = new ArrayList<>();for (int i = 0; i < 1000000; i++) {waitAssignUserList.add(new CrmInvestSaleUserCount().setSales_username("test" + i).setCount(BigDecimal.valueOf(RandomUtils.nextDouble(0.00, 9.99))).setWeight(BigDecimal.valueOf(RandomUtils.nextInt(1, 50))));}//第一种方式 count升序/weight降序long startTime = System.currentTimeMillis();CrmInvestSaleUserCount saleUserCount = Linq.of(waitAssignUserList).orderBy(CrmInvestSaleUserCount::getCount).thenByDescending(CrmInvestSaleUserCount::getWeight).first();log.debug("min1:{},花费时间:{}", saleUserCount, System.currentTimeMillis() - startTime);//第二种方式 先按count分组,取最小组,再在最小组中取weight最大的startTime = System.currentTimeMillis();CrmInvestSaleUserCount crmInvestSaleUserCount = Linq.of(waitAssignUserList).groupBy(CrmInvestSaleUserCount::getCount).minBy(IGrouping::getKey).maxBy(CrmInvestSaleUserCount::getWeight);log.debug("min2:{},花费时间:{}", crmInvestSaleUserCount, System.currentTimeMillis() - startTime);}
使用的基础类
public class CrmInvestSaleUserCount {@Schema(description = "招商人员手机号")private String sales_username;@Schema(description = "招商人员显示名称")private String sales_display_name;@Schema(description = "招商人员已分配数量")private BigDecimal count;@Schema(description = "招商人员权重")private BigDecimal weight;
}