public static void main(String[] args) {
//100萬條數(shù)據(jù)
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);
}
????????使用的基礎類文章來源:http://www.zghlxwxcb.cn/news/detail-629776.html
public class CrmInvestSaleUserCount {
@Schema(description = "招商人員手機號")
private String sales_username;
@Schema(description = "招商人員顯示名稱")
private String sales_display_name;
@Schema(description = "招商人員已分配數(shù)量")
private BigDecimal count;
@Schema(description = "招商人員權重")
private BigDecimal weight;
}
文章來源地址http://www.zghlxwxcb.cn/news/detail-629776.html
到了這里,關于java linq多字段排序時間比較的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!