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);
}
使用的基础类文章来源:https://www.toymoban.com/news/detail-629776.html
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;
}
文章来源地址https://www.toymoban.com/news/detail-629776.html
到了这里,关于java linq多字段排序时间比较的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!